local panel = "tracker" local goals = { 5, 10, 20 } local completed, choice, note, show_progress local function update() local goal = goals[choice] l2.ui.label(panel, "status", string.format("%d of %d completed", completed, goal)) if show_progress then l2.ui.progress(panel, "progress", completed, goal) else l2.ui.remove(panel, "progress") end end local function create() completed = l2.settings.get("completed", 0) choice = l2.settings.get("goal", 1) note = l2.settings.get("note", "") show_progress = l2.settings.get("show-progress", true) l2.ui.panel(panel, "Goal tracker", "") l2.ui.dropdown(panel, "goal", { "Goal: 5", "Goal: 10", "Goal: 20" }, choice) l2.ui.button(panel, "increment", "Complete one") l2.ui.checkbox(panel, "show-progress", "Show progress", show_progress) l2.ui.input(panel, "note", note, "Type a note and press Enter") update() end function main() if not l2.has("ui") or not l2.has("settings") then l2.ui.panel(panel, "Goal tracker", "Update the client to use this demo.") return end l2.on("world.ready", create) l2.on("ui.clicked", function(event) if event.panel == panel and event.widget == "increment" then completed = completed + 1 l2.settings.set("completed", completed) update() end end) l2.on("ui.changed", function(event) if event.panel ~= panel then return end if event.widget == "goal" then choice = event.value l2.settings.set("goal", choice) elseif event.widget == "show-progress" then show_progress = event.value l2.settings.set("show-progress", show_progress) end update() end) l2.on("ui.submitted", function(event) if event.panel == panel and event.widget == "note" then note = event.value l2.settings.set("note", note) end end) end