From 85fc3384dd82f959be5fa0a8bedca995f674c67e Mon Sep 17 00:00:00 2001 From: Warmist Date: Fri, 7 Sep 2012 17:25:39 +0300 Subject: [PATCH] Little cleanup and update to gm-editor --- .../luafiles/patterns/supplementary.xml | 7 --- .../luafiles/patterns/xml_angavrilov.lua | 55 ------------------- scripts/gui/gm-editor.lua | 24 ++++++-- 3 files changed, 19 insertions(+), 67 deletions(-) delete mode 100644 plugins/Dfusion/luafiles/patterns/supplementary.xml delete mode 100644 plugins/Dfusion/luafiles/patterns/xml_angavrilov.lua diff --git a/plugins/Dfusion/luafiles/patterns/supplementary.xml b/plugins/Dfusion/luafiles/patterns/supplementary.xml deleted file mode 100644 index e341a1368..000000000 --- a/plugins/Dfusion/luafiles/patterns/supplementary.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/patterns/xml_angavrilov.lua b/plugins/Dfusion/luafiles/patterns/xml_angavrilov.lua deleted file mode 100644 index dbd3ad692..000000000 --- a/plugins/Dfusion/luafiles/patterns/xml_angavrilov.lua +++ /dev/null @@ -1,55 +0,0 @@ - -function parseargs(s) - local arg = {} - string.gsub(s, "([%w%-]+)=([\"'])(.-)%2", function (w, _, a) - arg[w] = a - end) - return arg -end - -function collect(s) - local stack = {} - local top = {} - table.insert(stack, top) - local ni,c,label,xarg, empty - local i, j = 1, 1 - while true do - ni,j,c,label,xarg, empty = string.find(s, "<(%/?)([%w:%-]+)(.-)(%/?)>", i) - if not ni then break end - local text = string.sub(s, i, ni-1) - if not string.find(text, "^%s*$") then - table.insert(top, text) - end - if empty == "/" then -- empty element tag - table.insert(top, {label=label, xarg=parseargs(xarg), empty=1}) - elseif c == "" then -- start tag - top = {label=label, xarg=parseargs(xarg)} - table.insert(stack, top) -- new level - else -- end tag - local toclose = table.remove(stack) -- remove top - top = stack[#stack] - if #stack < 1 then - error("nothing to close with "..label) - end - if toclose.label ~= label then - error("trying to close "..toclose.label.." with "..label) - end - table.insert(top, toclose) - end - i = j+1 - end - local text = string.sub(s, i) - if not string.find(text, "^%s*$") then - table.insert(stack[#stack], text) - end - if #stack > 1 then - error("unclosed "..stack[#stack].label) - end - return stack[1] -end - -function parseXmlFile(path) - local f, e = io.open(path, "r") - local xml = f:read("*a") - return collect(xml) -end \ No newline at end of file diff --git a/scripts/gui/gm-editor.lua b/scripts/gui/gm-editor.lua index 34e744ee2..d95cb652b 100644 --- a/scripts/gui/gm-editor.lua +++ b/scripts/gui/gm-editor.lua @@ -1,6 +1,7 @@ -- Interface powered item editor. -- TODO use this: MechanismList = defclass(MechanismList, guidm.MenuOverlay) local gui = require 'gui' +local dialog = require 'gui.dialogs' local my_trg if dfhack.gui.getCurFocus() == 'item' then @@ -47,12 +48,25 @@ local item_screen={ mode=MODE_BROWSE, keys={}, - insertNew=function(self) - --[=[local trg=self:currentTarget() -- not sure if possible... + + insertNew=function(self,typename) + local tp=typename + if typename== nil then + dialog.showInputPrompt("Class type","Input class type\n:",COLOR_WHITE,"",dfhack.curry(self.insertNew,self)) + return + end + local ntype=df[tp] + if ntype== nil then + dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_RED) + return + end + + local trg=self:currentTarget() if trg.target and trg.target._kind and trg.target._kind=="container" then - local thing=df.new('general_ref_contained_itemst') - trg.target:insert('#',trg.keys[trg.selected]) - end]=] + local thing=ntype:new() + dfhack.call_with_finalizer(1,false,df.delete,thing,trg.target.insert,trg.target,'#',thing) + + end end, deleteSelected=function(self) local trg=self:currentTarget()