Skip to content

Commit e08891e

Browse files
committed
link map and homeworld, colony when focus
1 parent f558b1c commit e08891e

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

core/widget.lua

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,33 @@ function widget.draw_list(dom, texts, font_id, sprites)
7979
end
8080

8181
function widget.draw(batch, list, focus)
82-
local focus_region_func
83-
local focus_region_object
82+
local delay
8483
for _, obj in ipairs(list) do
8584
local o, x, y = table.unpack(obj)
8685
if type(o) == "function" then
87-
if x.region ~= focus then
88-
o(x)
86+
if focus and focus[x.region] then
87+
local f = o
88+
local arg = x
89+
local last = delay
90+
if delay then
91+
delay = function()
92+
last()
93+
f(arg)
94+
end
95+
else
96+
delay = function()
97+
f(arg)
98+
end
99+
end
89100
else
90-
focus_region_func = o
91-
focus_region_object = x
101+
o(x)
92102
end
93103
else
94104
batch:add(o, x, y)
95105
end
96106
end
97-
if focus_region_func then
98-
focus_region_func(focus_region_object)
107+
if delay then
108+
delay()
99109
end
100110
end
101111

soluna

visual/desktop.lua

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local ui = require "core.rules".ui
1313
local version = require "gameplay.version"
1414
local table = table
1515
local math = math
16-
global ipairs, error, pairs, print, tostring
16+
global ipairs, error, pairs, print, tostring, setmetatable
1717

1818
local DRAWLIST = {}
1919
local TESTLIST = {}
@@ -428,6 +428,20 @@ function M.additional(list)
428428
ADDITIONAL_LIST = list
429429
end
430430

431+
local focus_map = {
432+
map = {
433+
map = true,
434+
homeworld = true,
435+
colony = true,
436+
}
437+
}
438+
439+
setmetatable(focus_map, { __index = function (o,k)
440+
local r = { [k] = true }
441+
o[k] = r
442+
return r
443+
end })
444+
431445
function M.draw(count)
432446
if CAMERA then open_camera() end
433447
-- todo : find a better place to check unfocus :
@@ -437,7 +451,8 @@ function M.draw(count)
437451
map_focus(focus_state.lost)
438452
end
439453
-- todo : support multiple hud layer
440-
widget.draw(BATCH, DRAWLIST.hud, mouse.focus_region())
454+
local r = mouse.focus_region()
455+
widget.draw(BATCH, DRAWLIST.hud, r and focus_map[r])
441456

442457
if CAMERA then close_camera() end
443458
if DESC then

0 commit comments

Comments
 (0)