advfort: added site name display.

develop
Warmist 2013-03-03 17:33:07 +02:00
parent b0528d283b
commit 54046c74da
1 changed files with 54 additions and 19 deletions

@ -73,6 +73,31 @@ function showHelp()
Disclaimer(helptext)
dialog.showMessage("Help!?!",helptext)
end
--[[ Util functions ]]--
function advGlobalPos()
local map=df.global.world.map
local wd=df.global.world.world_data
local adv=df.global.world.units.active[0]
--wd.adv_region_x*16+wd.adv_emb_x,wd.adv_region_y*16+wd.adv_emb_y
--return wd.adv_region_x*16+wd.adv_emb_x,wd.adv_region_y*16+wd.adv_emb_y
--return wd.adv_region_x*16+wd.adv_emb_x+adv.pos.x/16,wd.adv_region_y*16+wd.adv_emb_y+adv.pos.y/16
--print(map.region_x,map.region_y,adv.pos.x,adv.pos.y)
--print(map.region_x+adv.pos.x/48, map.region_y+adv.pos.y/48,wd.adv_region_x*16+wd.adv_emb_x,wd.adv_region_y*16+wd.adv_emb_y)
return math.floor(map.region_x+adv.pos.x/48), math.floor(map.region_y+adv.pos.y/48)
end
function inSite()
local tx,ty=advGlobalPos()
--print(tx,ty)
for k,v in pairs(df.global.world.world_data.sites) do
local tp={v.pos.x,v.pos.y}
if tx>=tp[1]*16+v.rgn_min_x and tx<=tp[1]*16+v.rgn_max_x and
ty>=tp[2]*16+v.rgn_min_y and ty<=tp[2]*16+v.rgn_max_y then
--print(k)
return v
end
end
end
--[[ low level job management ]]--
function getLastJobLink()
local st=df.global.world.job_list
@ -827,8 +852,17 @@ function usetool:init(args)
visible=false,
text={
{id="text1",gap=1,key=keybinds.workshop.key,key_sep="()", text="Workshop menu",pen=dfhack.pen.parse{fg=COLOR_YELLOW,bg=0}}}
},
wid.Label{
view_id="siteLabel",
frame = {t=1,xalign=-1,yalign=0},
visible=false,
text={
{id="text1", text="Site:"},{id="site", text="name"}
}
}
}
end
function usetool:onIdle()
@ -948,7 +982,7 @@ function usetool:openPutWindow(building)
local adv=df.global.world.units.active[0]
local items=EnumItems{pos=adv.pos,unit=adv,
inv={[df.unit_inventory_item.T_mode.Hauled]=true,[df.unit_inventory_item.T_mode.Worn]=true,
inv={[df.unit_inventory_item.T_mode.Hauled]=true,--[df.unit_inventory_item.T_mode.Worn]=true,
[df.unit_inventory_item.T_mode.Weapon]=true,},deep=true}
local choices={}
for k,v in pairs(items) do
@ -1040,7 +1074,12 @@ function usetool:armCleanTrap(building)
LoadStoneTrap,
LoadWeaponTrap,
]]
if building.trap_type==df.trap_type.Lever then
--link
return
end
--building.trap_type==df.trap_type.PressurePlate then
--settings/link
local args={unit=adv,post_actions={AssignBuildingRef,AssignJobItems},pos=adv.pos,from_pos=adv.pos,job_type=df.job_type.CleanTrap}
if building.trap_type==df.trap_type.CageTrap then
args.job_type=df.job_type.LoadCageTrap
@ -1157,7 +1196,7 @@ MODES={
input=usetool.operatePump,
},
[df.building_type.Trap]={
name="Arm/Clean Trap",
name="Interact",
input=usetool.armCleanTrap,
},
[df.building_type.Hive]={
@ -1168,8 +1207,8 @@ MODES={
function usetool:shopMode(enable,mode,building)
self.subviews.shopLabel.visible=enable
if mode then
self.subviews.shopLabel:itemById("text1").text=mode.name
self.building=building
self.subviews.shopLabel:itemById("text1").text=mode.name
self.building=building
end
self.mode=mode
end
@ -1178,20 +1217,7 @@ function usetool:shopInput(keys)
self:openShopWindowButtoned(self.in_shop)
end
end
function advGlobalPos()
local wd=df.global.world.world_data
return wd.adv_region_x*16+wd.adv_emb_x,wd.adv_region_y*16+wd.adv_emb_y
end
function inSite()
local tx,ty=advGlobalPos()
for k,v in pairs(df.global.world.world_data.sites) do
local tp={v.pos.x,v.pos.y}
if tx>=tp[1]*16+v.rgn_min_x and tx<=tp[1]*16+v.rgn_max_x and
ty>=tp[2]*16+v.rgn_min_y and ty<=tp[2]*16+v.rgn_max_y then
return v
end
end
end
function usetool:setupFields()
local adv=df.global.world.units.active[0]
local civ_id=df.global.world.units.active[0].civ_id
@ -1271,6 +1297,7 @@ function usetool:fieldInput(keys)
end
function usetool:onInput(keys)
local adv=df.global.world.units.active[0]
if keys.LEAVESCREEN then
if df.global.cursor.x~=-30000 then
self:sendInputToParent("LEAVESCREEN")
@ -1298,6 +1325,14 @@ function usetool:onInput(keys)
self:fieldInput(keys)
end
end
local site=inSite()
if site then
self.subviews.siteLabel.visible=true
self.subviews.siteLabel:itemById("site").text=dfhack.TranslateName(site.name)
else
self.subviews.siteLabel.visible=false
end
end
function usetool:isOnBuilding()
local adv=df.global.world.units.active[0]