From 8395f3dc789faa9e495153a298164705b638cec7 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Tue, 26 May 2015 07:01:37 -0700 Subject: [PATCH] radio buttons! --- Lua/cheat menu.lua | 26 +++++++++++++++++--------- Lua/menu classes.lua | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/Lua/cheat menu.lua b/Lua/cheat menu.lua index 4dd237e..8e80d48 100755 --- a/Lua/cheat menu.lua +++ b/Lua/cheat menu.lua @@ -5,6 +5,8 @@ require "classes" require "menu classes" require "messages" +local dummy = Callbacks() + local passives = {} Passive = Class(Callbacks) @@ -49,13 +51,17 @@ function self_destruct:on() addrs.hearts(0) end -local playas_child = Callbacks() -function playas_child:run() - addrs.age_modifier_global(1) +local playas_child = Passive() +function playas_child:tick() + if self.state then + addrs.age_modifier_global(1) + end end -local playas_adult = Callbacks() -function playas_adult:run() - addrs.age_modifier_global(0) +local playas_adult = Passive() +function playas_adult:tick() + if self.state then + addrs.age_modifier_global(0) + end end local playas_human = Callbacks() @@ -84,12 +90,14 @@ function playas_fd:on() addrs.transformation(0) end +local playas_group = {} + local playas_menu = oot and Menu{ Screen{ Text("Play as..."), - --Radial("Default", playas_group), - Oneshot("Child Link", playas_child), - Oneshot("Adult Link", playas_adult), + Radio("Default", playas_group, dummy), + Radio("Child Link", playas_group, playas_child), + Radio("Adult Link", playas_group, playas_adult), Back(), }, } or Menu{ diff --git a/Lua/menu classes.lua b/Lua/menu classes.lua index b92f0a6..ad84a27 100644 --- a/Lua/menu classes.lua +++ b/Lua/menu classes.lua @@ -10,6 +10,7 @@ LinkTo = Class(Text) Active = Class(Text) Toggle = Class(Active) +Radio = Class(Active) Hold = Class(Active) Oneshot = Class(Active) Flags = Class(Active) @@ -104,6 +105,40 @@ function Toggle:draw(brush, y) brush(4, y, color, self.text) end +function Radio:init(text, group, callbacks) + Active.init(self, text, callbacks) + self.state = #group == 0 + table.insert(group, self) + self.group = group +end +function Radio:run() + if self.state then + -- we're already selected! + self.callbacks:hold() + return self + end + + for _, active in pairs(self.group) do + -- FIXME: shouldn't really be invading their namespace + if active ~= self then + active.state = false + active.callbacks:off(false) + end + end + + self.state = true + self.callbacks:on(true) + return self +end +function Radio:draw(brush, y) + local color = self.focused and 'yellow' or 'white' + brush(0, y, 'cyan', '( )') + if self.state then + brush(1, y, color, 'x') + end + brush(4, y, color, self.text) +end + function Oneshot:run() self.callbacks:on() return self