Clean up gui/dfstatus.lua

develop
lethosor 2015-04-18 19:19:43 -04:00
parent e3b7d61bc1
commit 3eb814ce51
2 changed files with 59 additions and 68 deletions

@ -72,6 +72,7 @@ keybinding add Ctrl-Shift-Z@dwarfmode/Default "stocks show"
# open an overview window summarising some stocks (dfstatus) # open an overview window summarising some stocks (dfstatus)
keybinding add Ctrl-Shift-I@dwarfmode/Default "gui/dfstatus" keybinding add Ctrl-Shift-I@dwarfmode/Default "gui/dfstatus"
keybinding add Ctrl-Shift-I@dfhack/lua/dfstatus "gui/dfstatus"
# q->stockpile - copy & paste stockpiles # q->stockpile - copy & paste stockpiles
keybinding add Alt-P copystock keybinding add Alt-P copystock

@ -1,29 +1,19 @@
-- dfstatus 1.5 - a quick access status screen. -- dfstatus 1.5 - a quick access status screen.
-- written by enjia2000@gmail.com, fixed by Lethosor and PeridexisErrant -- originally written by enjia2000@gmail.com
local gui = require 'gui' local gui = require 'gui'
function draw() dfstatus = defclass(dfstatus, gui.FramedScreen)
screen2 = gui.FramedScreen{ dfstatus.ATTRS = {
frame_style = gui.GREY_LINE_FRAME, frame_style = gui.GREY_LINE_FRAME,
frame_title = 'dfstatus', frame_title = 'dfstatus',
frame_width = 16, frame_width = 16,
frame_height = 17, frame_height = 17,
frame_inset = 1, frame_inset = 1,
} focus_path = 'dfstatus',
end }
if (not shown) then
draw()
screen2:show()
shown = true
else
shown = nil
screen2:dismiss()
end
function screen2:onRenderBody(dc) function dfstatus:onRenderBody(dc)
local drink = 0 local drink = 0
local wood = 0 local wood = 0
--local meat = 0 --local meat = 0
@ -43,79 +33,79 @@ function screen2:onRenderBody(dc)
local tannedhides = 0 local tannedhides = 0
local cloth = 0 local cloth = 0
--print("------------------------------") for _, item in ipairs(df.global.world.items.all) do
for _,item in ipairs(df.global.world.items.all) do if not item.flags.rotten and not item.flags.dump and not item.flags.forbid then
if(not item.flags.rotten and not item.flags.dump and not item.flags.forbid) then if (item:getType() == df.item_type.WOOD) then wood = wood + item:getStackSize()
if(item:getType() ~= df.item_type.THREAD and item:getType() ~= df.item_type.REMAINS and item:getType() ~= df.item_type.ARMOR and item:getType() ~= df.item_type.SHOES and item:getType() ~= df.item_type.SHIELD and item:getType() ~= df.item_type.HELM and item:getType() ~= df.item_type.GOVES) then elseif (item:getType() == df.item_type.DRINK) then drink = drink + item:getStackSize()
--print(item:getType() .. ":" .. dfhack.items.getDescription(item,0)) elseif (item:getType() == df.item_type.SKIN_TANNED) then tannedhides = tannedhides + item:getStackSize()
end elseif (item:getType() == df.item_type.CLOTH) then cloth = cloth + item:getStackSize()
if(item:getType() == df.item_type.DRINK)then --elseif (item:getType() == df.item_type.MEAT) then meat = meat + item:getStackSize()
--print(item:getType() .. ":" .. dfhack.items.getDescription(item,0)) --elseif (item:getType() == df.item_type.FISH_RAW) then raw_fish = raw_fish + item:getStackSize()
end --elseif (item:getType() == df.item_type.PLANT) then plants = plants + item:getStackSize()
elseif (item:getType() == df.item_type.FOOD) then prepared_meals = prepared_meals + item:getStackSize()
if (item:getType() == df.item_type.WOOD) then wood = wood + item:getStackSize() elseif (item:getType() == df.item_type.BAR) then
elseif (item:getType() == df.item_type.DRINK) then drink = drink + item:getStackSize() for token in string.gmatch(dfhack.items.getDescription(item,0),"[^%s]+") do
elseif (item:getType() == df.item_type.SKIN_TANNED) then tannedhides = tannedhides + item:getStackSize() if (token == "silver") then silver = silver + item:getStackSize()
elseif (item:getType() == df.item_type.CLOTH) then cloth = cloth + item:getStackSize() elseif (token == "charcoal" or token == "coke") then fuel = fuel + item:getStackSize()
--elseif (item:getType() == df.item_type.MEAT) then meat = meat + item:getStackSize() elseif (token == "iron") then iron = iron + item:getStackSize()
--elseif (item:getType() == df.item_type.FISH_RAW) then raw_fish = raw_fish + item:getStackSize() elseif (token == "pig") then pigiron = pigiron + item:getStackSize()
--elseif (item:getType() == df.item_type.PLANT) then plants = plants + item:getStackSize() elseif (token == "copper") then copper = copper + item:getStackSize()
elseif (item:getType() == df.item_type.FOOD) then prepared_meals = prepared_meals + item:getStackSize() elseif (token == "gold") then gold = gold + item:getStackSize()
elseif (item:getType() == df.item_type.BAR) then elseif (token == "steel") then steel = steel + item:getStackSize()
for token in string.gmatch(dfhack.items.getDescription(item,0),"[^%s]+") do end
if (token == "silver") then silver = silver + item:getStackSize() break -- only need to look at the 1st token of each item.
elseif (token == "charcoal" or token == "coke") then fuel = fuel + item:getStackSize()
elseif (token == "iron") then iron = iron + item:getStackSize()
elseif (token == "pig") then pigiron = pigiron + item:getStackSize()
elseif (token == "copper") then copper = copper + item:getStackSize()
elseif (token == "gold") then gold = gold + item:getStackSize()
elseif (token == "steel") then steel = steel + item:getStackSize()
end end
break -- only need to look at the 1st token of each item.
end end
end end
end end
end dc:pen(COLOR_LIGHTGREEN)
--print("------------------------------") dc:string("Drinks: " .. drink)
dc:string("Drinks: ".. drink, COLOR_LIGHTGREEN)
dc:newline(0) dc:newline(0)
dc:string("Meals: ".. prepared_meals, COLOR_LIGHTGREEN) dc:string("Meals: " .. prepared_meals)
dc:newline(0) dc:newline(0)
dc:newline(0) dc:newline(0)
dc:string("Wood: ".. wood, COLOR_LIGHTGREEN) dc:string("Wood: " .. wood)
dc:newline(0) dc:newline(0)
dc:newline(0) dc:newline(0)
dc:string("Hides: ".. tannedhides, COLOR_LIGHTGREEN) dc:string("Hides: " .. tannedhides)
dc:newline(0) dc:newline(0)
dc:string("Cloth: ".. cloth, COLOR_LIGHTGREEN) dc:string("Cloth: " .. cloth)
dc:newline(0) dc:newline(0)
-- dc:string("Raw Fish: ".. raw_fish, COLOR_LIGHTGREEN) -- dc:string("Raw Fish: ".. raw_fish)
-- dc:newline(0) -- dc:newline(0)
-- dc:string("Plants: ".. plants, COLOR_LIGHTGREEN) -- dc:string("Plants: ".. plants)
-- dc:newline(0) -- dc:newline(0)
dc:newline(0) dc:newline(0)
dc:string("Bars:", COLOR_LIGHTGREEN) dc:string("Bars:")
dc:newline(1) dc:newline(1)
dc:string("Fuel: ".. fuel, COLOR_LIGHTGREEN) dc:string("Fuel: " .. fuel)
dc:newline(1) dc:newline(1)
dc:string("Pig Iron: ".. pigiron, COLOR_LIGHTGREEN) dc:string("Pig Iron: " .. pigiron)
dc:newline(1) dc:newline(1)
dc:string("Steel: ".. steel, COLOR_LIGHTGREEN) dc:string("Steel: " .. steel)
dc:newline(1) dc:newline(1)
dc:string("Iron: ".. iron, COLOR_LIGHTGREEN) dc:string("Iron: " .. iron)
dc:newline(1) dc:newline(1)
dc:newline(1) dc:newline(1)
dc:string("Copper: ".. copper, COLOR_LIGHTGREEN) dc:string("Copper: " .. copper)
dc:newline(1) dc:newline(1)
dc:string("Silver: ".. silver, COLOR_LIGHTGREEN) dc:string("Silver: " .. silver)
dc:newline(1) dc:newline(1)
dc:string("Gold: ".. gold, COLOR_LIGHTGREEN) dc:string("Gold: " .. gold)
end end
function screen2:onInput(keys) function dfstatus:onInput(keys)
if keys.LEAVESCREEN or keys.SELECT then if keys.LEAVESCREEN or keys.SELECT then
shown = nil
self:dismiss() self:dismiss()
scr = nil
end end
end end
if not scr then
scr = dfstatus()
scr:show()
else
scr:dismiss()
scr = nil
end