summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorjj2012-09-19 14:29:09 +0200
committerjj2012-09-19 15:05:42 +0200
commit27fd3f5fc7148981948925a20658db8b62c21761 (patch)
tree44946622f6013740606d3d92325e39ef73869096 /scripts
parent45c057b3d2e5809941fc618624b955ffa46b0b87 (diff)
parent65a382a2d7b4c910fe498112687c9c584d5408cb (diff)
downloaddfhack-27fd3f5fc7148981948925a20658db8b62c21761.tar.gz
dfhack-27fd3f5fc7148981948925a20658db8b62c21761.tar.bz2
dfhack-27fd3f5fc7148981948925a20658db8b62c21761.tar.xz
Merge branch 'master' of git://github.com/angavrilov/dfhack
Diffstat (limited to 'scripts')
-rw-r--r--scripts/gui/hello-world.lua20
-rw-r--r--scripts/gui/liquids.lua25
-rw-r--r--scripts/gui/mechanisms.lua10
-rw-r--r--scripts/gui/power-meter.lua8
-rw-r--r--scripts/gui/room-list.lua23
-rw-r--r--scripts/gui/siege-engine.lua40
6 files changed, 59 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 47043cbb..c98cb167 100644
--- a/scripts/gui/siege-engine.lua
+++ b/scripts/gui/siege-engine.lua
@@ -21,6 +21,7 @@ local item_choices = {
{ caption = 'trap components', item_type = df.item_type.TRAPCOMP },
{ caption = 'bins', item_type = df.item_type.BIN },
{ caption = 'barrels', item_type = df.item_type.BARREL },
+ { caption = 'cages', item_type = df.item_type.CAGE },
{ caption = 'anything', item_type = -1 },
}
@@ -33,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()
@@ -486,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()