Add a key handler to refresh the mechanism screen without exiting it.

develop
Alexander Gavrilov 2012-08-21 20:34:15 +04:00
parent 15235cc938
commit 44e3e318d0
1 changed files with 16 additions and 3 deletions

@ -45,17 +45,25 @@ MechanismList = defclass(MechanismList, guidm.MenuOverlay)
MechanismList.focus_path = 'mechanisms' MechanismList.focus_path = 'mechanisms'
function MechanismList.new(building) function MechanismList.new(building)
local links = listMechanismLinks(building)
local self = { local self = {
links = links, links = {},
selected = 1 selected = 1
} }
return mkinstance(MechanismList, self):init(building)
end
function MechanismList:init(building)
local links = listMechanismLinks(building)
links[1].viewport = guidm.getViewportPos() links[1].viewport = guidm.getViewportPos()
links[1].cursor = guidm.getCursorPos() links[1].cursor = guidm.getCursorPos()
if #links <= 1 then if #links <= 1 then
links[1].mode = 'none' links[1].mode = 'none'
end end
return mkinstance(MechanismList, self)
self.links = links
self.selected = 1
return self
end end
local colors = { local colors = {
@ -117,6 +125,11 @@ function MechanismList:onInput(keys)
if self.selected ~= 1 then if self.selected ~= 1 then
self:zoomToLink(self.links[1]) self:zoomToLink(self.links[1])
end end
elseif keys.SELECT_ALL then
if self.selected > 1 then
self:init(self.links[self.selected].obj)
self.invalidate()
end
elseif keys.SELECT then elseif keys.SELECT then
self:dismiss() self:dismiss()
end end