1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-11-04 20:09:03 -08:00

radio buttons!

This commit is contained in:
Connor Olding 2015-05-26 07:01:37 -07:00
parent b05b3621fb
commit 8395f3dc78
2 changed files with 52 additions and 9 deletions

View file

@ -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{

View file

@ -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