make DFHack logo respond to clicks, not mouseover

develop
Myk Taylor 2023-09-14 01:31:19 -07:00
parent 017e280b18
commit b11a3ead1e
No known key found for this signature in database
3 changed files with 39 additions and 43 deletions

Before

Width:  |  Height:  |  Size: 997 B

After

Width:  |  Height:  |  Size: 997 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 997 B

@ -5,7 +5,8 @@ local helpdb = require('helpdb')
local overlay = require('plugins.overlay') local overlay = require('plugins.overlay')
local widgets = require('gui.widgets') local widgets = require('gui.widgets')
local textures = dfhack.textures.loadTileset('hack/data/art/dfhack.png', 8, 12) local logo_textures = dfhack.textures.loadTileset('hack/data/art/logo.png', 8, 12)
local logo_hovered_textures = dfhack.textures.loadTileset('hack/data/art/logo_hovered.png', 8, 12)
local function get_command(cmdline) local function get_command(cmdline)
local first_word = cmdline:trim():split(' +')[1] local first_word = cmdline:trim():split(' +')[1]
@ -28,7 +29,6 @@ HotspotMenuWidget = defclass(HotspotMenuWidget, overlay.OverlayWidget)
HotspotMenuWidget.ATTRS{ HotspotMenuWidget.ATTRS{
default_pos={x=5,y=1}, default_pos={x=5,y=1},
default_enabled=true, default_enabled=true,
hotspot=false,
version=2, version=2,
viewscreens={ viewscreens={
'adopt_region', 'adopt_region',
@ -48,54 +48,50 @@ HotspotMenuWidget.ATTRS{
'update_region', 'update_region',
'world' 'world'
}, },
overlay_onupdate_max_freq_seconds=0,
frame={w=4, h=3} frame={w=4, h=3}
} }
function HotspotMenuWidget:init() function HotspotMenuWidget:init()
self.mouseover = false local to_pen = dfhack.pen.parse
end local function tp(idx, ch)
return to_pen{
function HotspotMenuWidget:overlay_onupdate() tile=function() return dfhack.textures.getTexposByHandle(logo_textures[idx]) end,
local hasMouse = self:getMousePos() ch=ch,
if hasMouse and not self.mouseover then fg=COLOR_GREY,
self.mouseover = true }
return true end
local function tph(idx, ch)
return to_pen{
tile=function() return dfhack.textures.getTexposByHandle(logo_hovered_textures[idx]) end,
ch=ch,
fg=COLOR_WHITE,
}
end
local function get_tile_token(idx, ch)
return {
tile=tp(idx, ch),
htile=tph(idx, ch),
width=1,
}
end end
self.mouseover = hasMouse
end
function HotspotMenuWidget:overlay_trigger() self:addviews{
return MenuScreen{hotspot=self}:show() widgets.Label{
text={
get_tile_token(1, '!'), get_tile_token(2, 'D'), get_tile_token(3, 'F'), get_tile_token(4, '!'), NEWLINE,
get_tile_token(5, '!'), get_tile_token(6, 'H'), get_tile_token(7, 'a'), get_tile_token(8, '!'), NEWLINE,
get_tile_token(9, '!'), get_tile_token(10, 'c'), get_tile_token(11, 'k'), get_tile_token(12, '!'),
},
},
}
end end
local dscreen = dfhack.screen function HotspotMenuWidget:onInput(keys)
if HotspotMenuWidget.super.onInput(self, keys) then
function HotspotMenuWidget:onRenderBody(dc) return true
local x, y = dc.x, dc.y elseif keys._MOUSE_L_DOWN and self:getMousePos() then
local tp = function(offset) MenuScreen{hotspot=self}:show()
return dfhack.textures.getTexposByHandle(textures[offset]) return true
end
if tp(1) == nil then
dscreen.paintString(COLOR_WHITE, x, y + 0, '!DF!')
dscreen.paintString(COLOR_WHITE, x, y + 1, '!Ha!')
dscreen.paintString(COLOR_WHITE, x, y + 2, '!ck!')
else
dscreen.paintTile(COLOR_WHITE, x + 0, y + 0, '!', tp(1))
dscreen.paintTile(COLOR_WHITE, x + 1, y + 0, 'D', tp(2))
dscreen.paintTile(COLOR_WHITE, x + 2, y + 0, 'F', tp(3))
dscreen.paintTile(COLOR_WHITE, x + 3, y + 0, '!', tp(4))
dscreen.paintTile(COLOR_WHITE, x + 0, y + 1, '!', tp(5))
dscreen.paintTile(COLOR_WHITE, x + 1, y + 1, 'H', tp(6))
dscreen.paintTile(COLOR_WHITE, x + 2, y + 1, 'a', tp(7))
dscreen.paintTile(COLOR_WHITE, x + 3, y + 1, '!', tp(8))
dscreen.paintTile(COLOR_WHITE, x + 0, y + 2, '!', tp(9))
dscreen.paintTile(COLOR_WHITE, x + 1, y + 2, 'c', tp(10))
dscreen.paintTile(COLOR_WHITE, x + 2, y + 2, 'k', tp(11))
dscreen.paintTile(COLOR_WHITE, x + 3, y + 2, '!', tp(12))
end end
end end
@ -290,7 +286,7 @@ function Menu:onInput(keys)
df.global.enabler.mouse_lbut = 0 df.global.enabler.mouse_lbut = 0
return true return true
end end
if not self:getMouseFramePos() and not self.hotspot:getMousePos() then if not self:getMouseFramePos() then
self.parent_view:dismiss() self.parent_view:dismiss()
return true return true
end end