|
|
@ -4,22 +4,13 @@ local utils = require 'utils'
|
|
|
|
local gui = require 'gui'
|
|
|
|
local gui = require 'gui'
|
|
|
|
local guidm = require 'gui.dwarfmode'
|
|
|
|
local guidm = require 'gui.dwarfmode'
|
|
|
|
|
|
|
|
|
|
|
|
function getBuildingName(building)
|
|
|
|
|
|
|
|
return utils.call_with_string(building, 'getName')
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getBuildingCenter(building)
|
|
|
|
|
|
|
|
return xyz2pos(building.centerx, building.centery, building.z)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function listMechanismLinks(building)
|
|
|
|
function listMechanismLinks(building)
|
|
|
|
local lst = {}
|
|
|
|
local lst = {}
|
|
|
|
local function push(item, mode)
|
|
|
|
local function push(item, mode)
|
|
|
|
if item then
|
|
|
|
if item then
|
|
|
|
lst[#lst+1] = {
|
|
|
|
lst[#lst+1] = {
|
|
|
|
obj = item, mode = mode,
|
|
|
|
obj = item, mode = mode,
|
|
|
|
name = getBuildingName(item),
|
|
|
|
name = utils.getBuildingName(item)
|
|
|
|
center = getBuildingCenter(item)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -64,8 +55,9 @@ end
|
|
|
|
function MechanismList:fillList(building)
|
|
|
|
function MechanismList:fillList(building)
|
|
|
|
local links = listMechanismLinks(building)
|
|
|
|
local links = listMechanismLinks(building)
|
|
|
|
|
|
|
|
|
|
|
|
links[1].viewport = self:getViewport()
|
|
|
|
self.old_viewport = self:getViewport()
|
|
|
|
links[1].cursor = guidm.getCursorPos()
|
|
|
|
self.old_cursor = guidm.getCursorPos()
|
|
|
|
|
|
|
|
|
|
|
|
if #links <= 1 then
|
|
|
|
if #links <= 1 then
|
|
|
|
links[1].mode = 'none'
|
|
|
|
links[1].mode = 'none'
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -103,22 +95,10 @@ function MechanismList:onRenderBody(dc)
|
|
|
|
dc:string("Enter", COLOR_LIGHTGREEN):string(": Switch")
|
|
|
|
dc:string("Enter", COLOR_LIGHTGREEN):string(": Switch")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function MechanismList:zoomToLink(link,back)
|
|
|
|
|
|
|
|
df.global.world.selected_building = link.obj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if back then
|
|
|
|
|
|
|
|
guidm.setCursorPos(link.cursor)
|
|
|
|
|
|
|
|
self:getViewport(link.viewport):set()
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
guidm.setCursorPos(link.center)
|
|
|
|
|
|
|
|
self:getViewport():reveal(link.center, 5, 0, 10):set()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MechanismList:changeSelected(delta)
|
|
|
|
function MechanismList:changeSelected(delta)
|
|
|
|
if #self.links <= 1 then return end
|
|
|
|
if #self.links <= 1 then return end
|
|
|
|
self.selected = 1 + (self.selected + delta - 1) % #self.links
|
|
|
|
self.selected = 1 + (self.selected + delta - 1) % #self.links
|
|
|
|
self:zoomToLink(self.links[self.selected])
|
|
|
|
self:selectBuilding(self.links[self.selected].obj)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function MechanismList:onInput(keys)
|
|
|
|
function MechanismList:onInput(keys)
|
|
|
@ -129,7 +109,7 @@ function MechanismList:onInput(keys)
|
|
|
|
elseif keys.LEAVESCREEN then
|
|
|
|
elseif keys.LEAVESCREEN then
|
|
|
|
self:dismiss()
|
|
|
|
self:dismiss()
|
|
|
|
if self.selected ~= 1 then
|
|
|
|
if self.selected ~= 1 then
|
|
|
|
self:zoomToLink(self.links[1], true)
|
|
|
|
self:selectBuilding(self.links[1].obj, self.old_cursor, self.old_view)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif keys.SELECT_ALL then
|
|
|
|
elseif keys.SELECT_ALL then
|
|
|
|
if self.selected > 1 then
|
|
|
|
if self.selected > 1 then
|
|
|
|