|
|
@ -11,6 +11,7 @@ local keybindings={
|
|
|
|
insert={key="CUSTOM_ALT_I",desc="Insert a new value to the vector"},
|
|
|
|
insert={key="CUSTOM_ALT_I",desc="Insert a new value to the vector"},
|
|
|
|
delete={key="CUSTOM_ALT_D",desc="Delete selected entry"},
|
|
|
|
delete={key="CUSTOM_ALT_D",desc="Delete selected entry"},
|
|
|
|
help={key="HELP",desc="Show this help"},
|
|
|
|
help={key="HELP",desc="Show this help"},
|
|
|
|
|
|
|
|
NOT_USED={key="SEC_SELECT",desc="Choose an enum value from a list"}, --not a binding...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function getTargetFromScreens()
|
|
|
|
function getTargetFromScreens()
|
|
|
|
local my_trg
|
|
|
|
local my_trg
|
|
|
@ -75,6 +76,7 @@ function GmEditorUi:init(args)
|
|
|
|
local helpPage=widgets.Panel{
|
|
|
|
local helpPage=widgets.Panel{
|
|
|
|
subviews={widgets.Label{text=helptext,frame = {l=1,t=1,yalign=0}}}}
|
|
|
|
subviews={widgets.Label{text=helptext,frame = {l=1,t=1,yalign=0}}}}
|
|
|
|
local mainList=widgets.List{view_id="list_main",choices={},frame = {l=1,t=3,yalign=0},on_submit=self:callback("editSelected"),
|
|
|
|
local mainList=widgets.List{view_id="list_main",choices={},frame = {l=1,t=3,yalign=0},on_submit=self:callback("editSelected"),
|
|
|
|
|
|
|
|
on_submit2=self:callback("editSelectedEnum"),
|
|
|
|
text_pen=dfhack.pen.parse{fg=COLOR_DARKGRAY,bg=0},cursor_pen=dfhack.pen.parse{fg=COLOR_YELLOW,bg=0}}
|
|
|
|
text_pen=dfhack.pen.parse{fg=COLOR_DARKGRAY,bg=0},cursor_pen=dfhack.pen.parse{fg=COLOR_YELLOW,bg=0}}
|
|
|
|
local mainPage=widgets.Panel{
|
|
|
|
local mainPage=widgets.Panel{
|
|
|
|
subviews={
|
|
|
|
subviews={
|
|
|
@ -155,6 +157,29 @@ end
|
|
|
|
function GmEditorUi:currentTarget()
|
|
|
|
function GmEditorUi:currentTarget()
|
|
|
|
return self.stack[#self.stack]
|
|
|
|
return self.stack[#self.stack]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GmEditorUi:editSelectedEnum(index,choice)
|
|
|
|
|
|
|
|
local trg=self:currentTarget()
|
|
|
|
|
|
|
|
local trg_key=trg.keys[index]
|
|
|
|
|
|
|
|
if trg.target._field==nil then qerror("not an enum") end
|
|
|
|
|
|
|
|
local enum=trg.target:_field(trg_key)._type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if enum._kind=="enum-type" then
|
|
|
|
|
|
|
|
local list={}
|
|
|
|
|
|
|
|
for i=enum._first_item, enum._last_item do
|
|
|
|
|
|
|
|
table.insert(list,{text=tostring(enum[i]),value=i})
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
guiScript.start(function()
|
|
|
|
|
|
|
|
local ret,idx,choice=guiScript.showListPrompt("Choose item:",nil,3,list)
|
|
|
|
|
|
|
|
if ret then
|
|
|
|
|
|
|
|
trg.target[trg_key]=choice.value
|
|
|
|
|
|
|
|
self:updateTarget(true)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
qerror("not an enum")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
function GmEditorUi:editSelected(index,choice)
|
|
|
|
function GmEditorUi:editSelected(index,choice)
|
|
|
|
local trg=self:currentTarget()
|
|
|
|
local trg=self:currentTarget()
|
|
|
|
local trg_key=trg.keys[index]
|
|
|
|
local trg_key=trg.keys[index]
|
|
|
@ -206,7 +231,6 @@ function GmEditorUi:set(key,input)
|
|
|
|
self:updateTarget(true)
|
|
|
|
self:updateTarget(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
function GmEditorUi:onInput(keys)
|
|
|
|
function GmEditorUi:onInput(keys)
|
|
|
|
|
|
|
|
|
|
|
|
if keys.LEAVESCREEN then
|
|
|
|
if keys.LEAVESCREEN then
|
|
|
|
if self.subviews.pages:getSelected()==2 then
|
|
|
|
if self.subviews.pages:getSelected()==2 then
|
|
|
|
self.subviews.pages:setSelected(1)
|
|
|
|
self.subviews.pages:setSelected(1)
|
|
|
@ -233,6 +257,27 @@ function GmEditorUi:onInput(keys)
|
|
|
|
|
|
|
|
|
|
|
|
self.super.onInput(self,keys)
|
|
|
|
self.super.onInput(self,keys)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function getStringValue(trg,field)
|
|
|
|
|
|
|
|
local obj=trg.target
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local text=tostring(obj[field])
|
|
|
|
|
|
|
|
pcall(function()
|
|
|
|
|
|
|
|
if obj._field ~= nil then
|
|
|
|
|
|
|
|
local enum=obj:_field(field)._type
|
|
|
|
|
|
|
|
if enum._kind=="enum-type" then
|
|
|
|
|
|
|
|
text=text.."("..tostring(enum[obj[field]])..")"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--[[local ok,ret=pcall(function() return trg.target[field]._enum end)
|
|
|
|
|
|
|
|
if ok then
|
|
|
|
|
|
|
|
print(trg.target[field]._kind,ok,ret)
|
|
|
|
|
|
|
|
text=text.."("..tostring(ret[field])..")"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return text]]
|
|
|
|
|
|
|
|
end
|
|
|
|
function GmEditorUi:updateTarget(preserve_pos,reindex)
|
|
|
|
function GmEditorUi:updateTarget(preserve_pos,reindex)
|
|
|
|
local trg=self:currentTarget()
|
|
|
|
local trg=self:currentTarget()
|
|
|
|
if reindex then
|
|
|
|
if reindex then
|
|
|
@ -244,7 +289,7 @@ function GmEditorUi:updateTarget(preserve_pos,reindex)
|
|
|
|
self.subviews.lbl_current_item:itemById('name').text=tostring(trg.target)
|
|
|
|
self.subviews.lbl_current_item:itemById('name').text=tostring(trg.target)
|
|
|
|
local t={}
|
|
|
|
local t={}
|
|
|
|
for k,v in pairs(trg.keys) do
|
|
|
|
for k,v in pairs(trg.keys) do
|
|
|
|
table.insert(t,{text={{text=string.format("%-25s",tostring(v))},{gap=1,text=tostring(trg.target[v]),}}})
|
|
|
|
table.insert(t,{text={{text=string.format("%-25s",tostring(v))},{gap=1,text=getStringValue(trg,v)}}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local last_pos
|
|
|
|
local last_pos
|
|
|
|
if preserve_pos then
|
|
|
|
if preserve_pos then
|
|
|
|