|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
-- Interface powered item editor.
|
|
|
|
|
-- TODO use this: MechanismList = defclass(MechanismList, guidm.MenuOverlay)
|
|
|
|
|
local gui = require 'gui'
|
|
|
|
|
local dialog = require 'gui.dialogs'
|
|
|
|
|
|
|
|
|
@ -40,19 +39,24 @@ end
|
|
|
|
|
|
|
|
|
|
local MODE_BROWSE=0
|
|
|
|
|
local MODE_EDIT=1
|
|
|
|
|
local item_screen={
|
|
|
|
|
GmEditorUi = defclass(GmEditorUi, gui.FramedScreen)
|
|
|
|
|
GmEditorUi.ATTRS={
|
|
|
|
|
frame_style = gui.GREY_LINE_FRAME,
|
|
|
|
|
frame_title = "GameMaster's editor",
|
|
|
|
|
stack={},
|
|
|
|
|
item_count=0,
|
|
|
|
|
mode=MODE_BROWSE,
|
|
|
|
|
|
|
|
|
|
keys={},
|
|
|
|
|
}
|
|
|
|
|
function GmEditorUi:init(args)
|
|
|
|
|
self.stack={}
|
|
|
|
|
self.item_count=0
|
|
|
|
|
self.mode=MODE_BROWSE
|
|
|
|
|
self.keys={}
|
|
|
|
|
self:pushTarget(args.target)
|
|
|
|
|
|
|
|
|
|
insertNew=function(self,typename)
|
|
|
|
|
return self
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:insertNew(typename)
|
|
|
|
|
local tp=typename
|
|
|
|
|
if typename== nil then
|
|
|
|
|
dialog.showInputPrompt("Class type","Input class type\n:",COLOR_WHITE,"",dfhack.curry(self.insertNew,self))
|
|
|
|
|
dialog.showInputPrompt("Class type","Input class type:",COLOR_WHITE,"",dfhack.curry(self.insertNew,self))
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local ntype=df[tp]
|
|
|
|
@ -67,22 +71,22 @@ local item_screen={
|
|
|
|
|
dfhack.call_with_finalizer(1,false,df.delete,thing,trg.target.insert,trg.target,'#',thing)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
deleteSelected=function(self)
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:deleteSelected()
|
|
|
|
|
local trg=self:currentTarget()
|
|
|
|
|
if trg.target and trg.target._kind and trg.target._kind=="container" then
|
|
|
|
|
trg.target:erase(trg.keys[trg.selected])
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
currentTarget=function(self)
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:currentTarget()
|
|
|
|
|
return self.stack[#self.stack]
|
|
|
|
|
end,
|
|
|
|
|
changeSelected = function (self,delta)
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:changeSelected(delta)
|
|
|
|
|
local trg=self:currentTarget()
|
|
|
|
|
if trg.item_count <= 1 then return end
|
|
|
|
|
trg.selected = 1 + (trg.selected + delta - 1) % trg.item_count
|
|
|
|
|
end,
|
|
|
|
|
editSelected = function(self)
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:editSelected()
|
|
|
|
|
local trg=self:currentTarget()
|
|
|
|
|
if trg.target and trg.target._kind and trg.target._kind=="bitfield" then
|
|
|
|
|
trg.target[trg.keys[trg.selected]]= not trg.target[trg.keys[trg.selected]]
|
|
|
|
@ -96,19 +100,19 @@ local item_screen={
|
|
|
|
|
trg.target[trg.keys[trg.selected]]= not trg.target[trg.keys[trg.selected]]
|
|
|
|
|
elseif trg_type=='userdata' then
|
|
|
|
|
self:pushTarget(trg.target[trg.keys[trg.selected]])
|
|
|
|
|
--local screen = mkinstance(gui.FramedScreen,item_screen):init(trg.target[trg.keys[trg.selected]]) -- does not work
|
|
|
|
|
--local screen = mkinstance(gui.FramedScreen,GmEditorUi):init(trg.target[trg.keys[trg.selected]]) -- does not work
|
|
|
|
|
--screen:show()
|
|
|
|
|
else
|
|
|
|
|
print("Unknow type:"..trg_type)
|
|
|
|
|
print("Subtype:"..tostring(trg.target[trg.keys[trg.selected]]._kind))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
cancelEdit = function(self)
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:cancelEdit()
|
|
|
|
|
self.mode=MODE_BROWSE
|
|
|
|
|
self.input=""
|
|
|
|
|
end,
|
|
|
|
|
commitEdit = function(self)
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:commitEdit()
|
|
|
|
|
local trg=self:currentTarget()
|
|
|
|
|
self.mode=MODE_BROWSE
|
|
|
|
|
if type(trg.target[trg.keys[trg.selected]])=='number' then
|
|
|
|
@ -116,16 +120,19 @@ local item_screen={
|
|
|
|
|
elseif type(trg.target[trg.keys[trg.selected]])=='string' then
|
|
|
|
|
trg.target[trg.keys[trg.selected]]=self.input
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
onRenderBody = function(self, dc)
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:onRenderBody( dc)
|
|
|
|
|
local trg=self:currentTarget()
|
|
|
|
|
dc:seek(2,1):string(tostring(trg.target), COLOR_RED)
|
|
|
|
|
local offset=2
|
|
|
|
|
local page_offset=0
|
|
|
|
|
local current_item=1
|
|
|
|
|
local t_col
|
|
|
|
|
if math.floor(trg.selected / (self.frame_height-offset-2)) >0 then
|
|
|
|
|
page_offset=math.floor(trg.selected / (self.frame_height-offset-2))*(self.frame_height-offset-2)-1
|
|
|
|
|
local width,height=self:getWindowSize()
|
|
|
|
|
local window_height=height-offset-2
|
|
|
|
|
local cursor_window=math.floor(trg.selected / window_height)
|
|
|
|
|
if cursor_window>0 then
|
|
|
|
|
page_offset=cursor_window*window_height-1
|
|
|
|
|
end
|
|
|
|
|
for k,v in pairs(trg.target) do
|
|
|
|
|
|
|
|
|
@ -144,12 +151,15 @@ local item_screen={
|
|
|
|
|
else
|
|
|
|
|
dc:seek(20,y_pos):string(tostring(v),t_col)
|
|
|
|
|
end
|
|
|
|
|
if y_pos+3>height then
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
current_item=current_item+1
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
current_item=current_item+1
|
|
|
|
|
|
|
|
|
|
onInput = function(self,keys)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:onInput(keys)
|
|
|
|
|
if self.mode==MODE_BROWSE then
|
|
|
|
|
if keys.LEAVESCREEN then
|
|
|
|
|
self:popTarget()
|
|
|
|
@ -185,8 +195,8 @@ local item_screen={
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
pushTarget=function(self,target_to_push)
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:pushTarget(target_to_push)
|
|
|
|
|
local new_tbl={}
|
|
|
|
|
new_tbl.target=target_to_push
|
|
|
|
|
new_tbl.keys={}
|
|
|
|
@ -196,21 +206,14 @@ local item_screen={
|
|
|
|
|
end
|
|
|
|
|
new_tbl.item_count=#new_tbl.keys
|
|
|
|
|
table.insert(self.stack,new_tbl)
|
|
|
|
|
end,
|
|
|
|
|
popTarget=function(self)
|
|
|
|
|
end
|
|
|
|
|
function GmEditorUi:popTarget()
|
|
|
|
|
table.remove(self.stack) --removes last element
|
|
|
|
|
if #self.stack==0 then
|
|
|
|
|
self:dismiss()
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
init = function(self,item_to_edit)
|
|
|
|
|
self:pushTarget(item_to_edit)
|
|
|
|
|
self.frame_width,self.frame_height=dfhack.screen.getWindowSize()
|
|
|
|
|
return self
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local screen = GmEditorUi{target=my_trg}
|
|
|
|
|
|
|
|
|
|
local screen = mkinstance(gui.FramedScreen,item_screen):init(my_trg)
|
|
|
|
|
screen:show()
|