diff options
| author | Alexander Gavrilov | 2012-09-18 20:30:25 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-09-18 20:30:25 +0400 |
| commit | 57b72831ca700ab556566a85f2245e014ca96c30 (patch) | |
| tree | 50163cb2125460dc4207fda24666d1412c9c04dd /scripts | |
| parent | a7998f71a2ee95d2d21f34468761118fd6b8585f (diff) | |
| download | dfhack-57b72831ca700ab556566a85f2245e014ca96c30.tar.gz dfhack-57b72831ca700ab556566a85f2245e014ca96c30.tar.bz2 dfhack-57b72831ca700ab556566a85f2245e014ca96c30.tar.xz | |
Overhaul the concept of lua 'class' initialization yet again.
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/gui/hello-world.lua | 20 | ||||
| -rw-r--r-- | scripts/gui/liquids.lua | 25 | ||||
| -rw-r--r-- | scripts/gui/mechanisms.lua | 10 | ||||
| -rw-r--r-- | scripts/gui/power-meter.lua | 8 | ||||
| -rw-r--r-- | scripts/gui/room-list.lua | 23 | ||||
| -rw-r--r-- | scripts/gui/siege-engine.lua | 39 |
6 files changed, 58 insertions, 67 deletions
diff --git a/scripts/gui/hello-world.lua b/scripts/gui/hello-world.lua index 80986bbf..c8cd3bd0 100644 --- a/scripts/gui/hello-world.lua +++ b/scripts/gui/hello-world.lua @@ -4,19 +4,21 @@ local gui = require 'gui' local text = 'Woohoo, lua viewscreen :)' -local screen = mkinstance(gui.FramedScreen, { +local screen = gui.FramedScreen{ frame_style = gui.GREY_LINE_FRAME, frame_title = 'Hello World', frame_width = #text+6, frame_height = 3, - onRenderBody = function(self, dc) - dc:seek(3,1):string(text, COLOR_LIGHTGREEN) - end, - onInput = function(self,keys) - if keys.LEAVESCREEN or keys.SELECT then - self:dismiss() - end +} + +function screen:onRenderBody(dc) + dc:seek(3,1):string(text, COLOR_LIGHTGREEN) +end + +function screen:onInput(keys) + if keys.LEAVESCREEN or keys.SELECT then + self:dismiss() end -}):init() +end screen:show() diff --git a/scripts/gui/liquids.lua b/scripts/gui/liquids.lua index 89f08b7c..cddb9f01 100644 --- a/scripts/gui/liquids.lua +++ b/scripts/gui/liquids.lua @@ -53,13 +53,7 @@ local permaflows = { Toggle = defclass(Toggle) -function Toggle:init(items) - self:init_fields{ - items = items, - selected = 1 - } - return self -end +Toggle.ATTRS{ items = {}, selected = 1 } function Toggle:get() return self.items[self.selected] @@ -89,16 +83,14 @@ LiquidsUI = defclass(LiquidsUI, guidm.MenuOverlay) LiquidsUI.focus_path = 'liquids' function LiquidsUI:init() - self:init_fields{ - brush = mkinstance(Toggle):init(brushes), - paint = mkinstance(Toggle):init(paints), - flow = mkinstance(Toggle):init(flowbits), - set = mkinstance(Toggle):init(setmode), - permaflow = mkinstance(Toggle):init(permaflows), + self:assign{ + brush = Toggle{ items = brushes }, + paint = Toggle{ items = paints }, + flow = Toggle{ items = flowbits }, + set = Toggle{ items = setmode }, + permaflow = Toggle{ items = permaflows }, amount = 7, } - guidm.MenuOverlay.init(self) - return self end function LiquidsUI:onDestroy() @@ -201,6 +193,7 @@ function LiquidsUI:onRenderBody(dc) end function ensure_blocks(cursor, size, cb) + size = size or xyz2pos(1,1,1) local cx,cy,cz = pos2xyz(cursor) local all = true for x=1,size.x or 1,16 do @@ -298,5 +291,5 @@ if not string.match(dfhack.gui.getCurFocus(), '^dwarfmode/LookAround') then qerror("This script requires the main dwarfmode view in 'k' mode") end -local list = mkinstance(LiquidsUI):init() +local list = LiquidsUI() list:show() diff --git a/scripts/gui/mechanisms.lua b/scripts/gui/mechanisms.lua index c14bfcbe..d1e8ec80 100644 --- a/scripts/gui/mechanisms.lua +++ b/scripts/gui/mechanisms.lua @@ -43,13 +43,11 @@ MechanismList = defclass(MechanismList, guidm.MenuOverlay) MechanismList.focus_path = 'mechanisms' -function MechanismList:init(building) - self:init_fields{ +function MechanismList:init(info) + self:assign{ links = {}, selected = 1 } - guidm.MenuOverlay.init(self) - self:fillList(building) - return self + self:fillList(info.building) end function MechanismList:fillList(building) @@ -126,6 +124,6 @@ if not string.match(dfhack.gui.getCurFocus(), '^dwarfmode/QueryBuilding/Some') t qerror("This script requires the main dwarfmode view in 'q' mode") end -local list = mkinstance(MechanismList):init(df.global.world.selected_building) +local list = MechanismList{ building = df.global.world.selected_building } list:show() list:changeSelected(1) diff --git a/scripts/gui/power-meter.lua b/scripts/gui/power-meter.lua index 8baf43e7..6c2f699a 100644 --- a/scripts/gui/power-meter.lua +++ b/scripts/gui/power-meter.lua @@ -13,15 +13,13 @@ PowerMeter = defclass(PowerMeter, guidm.MenuOverlay) PowerMeter.focus_path = 'power-meter' function PowerMeter:init() - self:init_fields{ + self:assign{ min_power = 0, max_power = -1, invert = false, } - guidm.MenuOverlay.init(self) - return self end function PowerMeter:onShow() - guidm.MenuOverlay.onShow(self) + PowerMeter.super.onShow(self) -- Send an event to update the errors bselector.plate_info.flags.whole = 0 @@ -112,5 +110,5 @@ then qerror("This script requires the main dwarfmode view in build pressure plate mode") end -local list = mkinstance(PowerMeter):init() +local list = PowerMeter() list:show() diff --git a/scripts/gui/room-list.lua b/scripts/gui/room-list.lua index a4507466..0de82db5 100644 --- a/scripts/gui/room-list.lua +++ b/scripts/gui/room-list.lua @@ -78,15 +78,17 @@ RoomList = defclass(RoomList, guidm.MenuOverlay) RoomList.focus_path = 'room-list' -function RoomList:init(unit) +RoomList.ATTRS{ unit = DEFAULT_NIL } + +function RoomList:init(info) + local unit = info.unit local base_bld = df.global.world.selected_building - self:init_fields{ - unit = unit, base_building = base_bld, + self:assign{ + base_building = base_bld, items = {}, selected = 1, own_rooms = {}, spouse_rooms = {} } - guidm.MenuOverlay.init(self) self.old_viewport = self:getViewport() self.old_cursor = guidm.getCursorPos() @@ -115,8 +117,6 @@ function RoomList:init(unit) self.items = concat_lists({self.base_item}, self.items) ::found:: end - - return self end local sex_char = { [0] = 12, [1] = 11 } @@ -235,12 +235,13 @@ function RoomList:onInput(keys) end local focus = dfhack.gui.getCurFocus() -if focus == 'dwarfmode/QueryBuilding/Some' then - local base = df.global.world.selected_building - mkinstance(RoomList):init(base.owner):show() -elseif focus == 'dwarfmode/QueryBuilding/Some/Assign/Unit' then + +if focus == 'dwarfmode/QueryBuilding/Some/Assign/Unit' then local unit = df.global.ui_building_assign_units[df.global.ui_building_item_cursor] - mkinstance(RoomList):init(unit):show() + RoomList{ unit = unit }:show() +elseif string.match(dfhack.gui.getCurFocus(), '^dwarfmode/QueryBuilding/Some') then + local base = df.global.world.selected_building + RoomList{ unit = base.owner }:show() else qerror("This script requires the main dwarfmode view in 'q' mode") end diff --git a/scripts/gui/siege-engine.lua b/scripts/gui/siege-engine.lua index 7a76d767..c98cb167 100644 --- a/scripts/gui/siege-engine.lua +++ b/scripts/gui/siege-engine.lua @@ -34,30 +34,29 @@ SiegeEngine = defclass(SiegeEngine, guidm.MenuOverlay) SiegeEngine.focus_path = 'siege-engine' -function SiegeEngine:init(building) - self:init_fields{ - building = building, - center = utils.getBuildingCenter(building), +SiegeEngine.ATTRS{ building = DEFAULT_NIL } + +function SiegeEngine:init() + self:assign{ + center = utils.getBuildingCenter(self.building), selected_pile = 1, + mode_main = { + render = self:callback 'onRenderBody_main', + input = self:callback 'onInput_main', + }, + mode_aim = { + render = self:callback 'onRenderBody_aim', + input = self:callback 'onInput_aim', + }, + mode_pile = { + render = self:callback 'onRenderBody_pile', + input = self:callback 'onInput_pile', + } } - guidm.MenuOverlay.init(self) - self.mode_main = { - render = self:callback 'onRenderBody_main', - input = self:callback 'onInput_main', - } - self.mode_aim = { - render = self:callback 'onRenderBody_aim', - input = self:callback 'onInput_aim', - } - self.mode_pile = { - render = self:callback 'onRenderBody_pile', - input = self:callback 'onInput_pile', - } - return self end function SiegeEngine:onShow() - guidm.MenuOverlay.onShow(self) + SiegeEngine.super.onShow(self) self.old_cursor = guidm.getCursorPos() self.old_viewport = self:getViewport() @@ -487,5 +486,5 @@ if not df.building_siegeenginest:is_instance(building) then qerror("A siege engine must be selected") end -local list = mkinstance(SiegeEngine):init(df.global.world.selected_building) +local list = SiegeEngine{ building = building } list:show() |
