@ -13,16 +13,18 @@ CLEAR_PEN = to_pen{tile=909, ch=32, fg=0, bg=0, write_to_lower=true}
TRANSPARENT_PEN = to_pen { tile = 0 , ch = 0 }
TRANSPARENT_PEN = to_pen { tile = 0 , ch = 0 }
KEEP_LOWER_PEN = to_pen { ch = 32 , fg = 0 , bg = 0 , keep_lower = true }
KEEP_LOWER_PEN = to_pen { ch = 32 , fg = 0 , bg = 0 , keep_lower = true }
local FAKE_INPUT _KEYS = {
local MOUSE _KEYS = {
_MOUSE_L = true ,
_MOUSE_L = true ,
_MOUSE_R = true ,
_MOUSE_R = true ,
_MOUSE_M = true ,
_MOUSE_M = true ,
_MOUSE_L_DOWN = true ,
_MOUSE_L_DOWN = true ,
_MOUSE_R_DOWN = true ,
_MOUSE_R_DOWN = true ,
_MOUSE_M_DOWN = true ,
_MOUSE_M_DOWN = true ,
_STRING = true ,
}
}
local FAKE_INPUT_KEYS = copyall ( MOUSE_KEYS )
FAKE_INPUT_KEYS._STRING = true
function simulateInput ( screen , ... )
function simulateInput ( screen , ... )
local keys = { }
local keys = { }
local function push_key ( arg )
local function push_key ( arg )
@ -692,8 +694,35 @@ end
-----------------------------
-----------------------------
ZScreen = defclass ( ZScreen , Screen )
ZScreen = defclass ( ZScreen , Screen )
ZScreen.ATTRS {
initial_pause = true ,
force_pause = false ,
pass_pause = true ,
pass_movement_keys = false ,
pass_mouse_clicks = true ,
}
function ZScreen : init ( )
self.saved_pause_state = df.global . pause_state
if self.initial_pause then
df.global . pause_state = true
end
self.defocused = false
end
function ZScreen : dismiss ( )
ZScreen.super . dismiss ( self )
if self.force_pause or self.initial_pause then
-- never go from unpaused to paused, just from paused to unpaused
df.global . pause_state = df.global . pause_state and self.saved_pause_state
end
end
-- this is necessary for middle-click map scrolling to function
function ZScreen : onIdle ( )
function ZScreen : onIdle ( )
if self.force_pause then
df.global . pause_state = true
end
if self._native and self._native . parent then
if self._native and self._native . parent then
self._native . parent : logic ( )
self._native . parent : logic ( )
end
end
@ -704,17 +733,15 @@ function ZScreen:render(dc)
ZScreen.super . render ( self , dc )
ZScreen.super . render ( self , dc )
end
end
function ZScreen : isOnTop ( )
function ZScreen : hasFocus ( )
return dfhack.gui . getCurViewscreen ( true ) == self._native
return not self.defocused
end
and dfhack.gui . getCurViewscreen ( true ) == self._native
function ZScreen : togglePinned ( )
self.pinned = not self.pinned
end
end
function ZScreen : onInput ( keys )
function ZScreen : onInput ( keys )
if not self : isOnTop ( ) then
local has_mouse = self : isMouseOver ( )
if keys._MOUSE_L_DOWN and self : isMouseOver ( ) then
if not self : hasFocus ( ) then
if ( keys._MOUSE_L_DOWN or keys._MOUSE_R_DOWN ) and has_mouse then
self : raise ( )
self : raise ( )
else
else
self : sendInputToParent ( keys )
self : sendInputToParent ( keys )
@ -734,30 +761,42 @@ function ZScreen:onInput(keys)
return
return
end
end
if keys.CUSTOM_ALT_L then
if self.pass_mouse_clicks and keys._MOUSE_L_DOWN and not has_mouse then
self : togglePinned ( )
self.defocused = true
self : sendInputToParent ( keys )
return
return
end
elseif keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
if ( self : isMouseOver ( ) or not self.pinned )
and ( keys.LEAVESCREEN or keys._MOUSE_R_DOWN ) then
self : dismiss ( )
self : dismiss ( )
-- ensure underlying DF screens don't also react to the click
-- ensure underlying DF screens don't also react to the rclick
df.global . enabler.mouse_rbut_down = 0
df.global . enabler.mouse_rbut_down = 0
df.global . enabler.mouse_rbut = 0
df.global . enabler.mouse_rbut = 0
return
return
end
else
local passit = self.pass_pause and keys.D_PAUSE
if not keys._MOUSE_L or not self : isMouseOver ( ) then
if not passit and self.pass_mouse_clicks then
self : sendInputToParent ( keys )
for key in pairs ( MOUSE_KEYS ) do
if keys [ key ] then
passit = true
break
end
end
end
if not passit and self.pass_movement_keys then
passit = require ( ' gui.dwarfmode ' ) . getMapKey ( keys )
end
if passit then
self : sendInputToParent ( keys )
end
return
end
end
end
end
function ZScreen : raise ( )
function ZScreen : raise ( )
if self : isDismissed ( ) or self : isOnTop ( ) then
if self : isDismissed ( ) or self : hasFocus ( ) then
return self
return self
end
end
dscreen.raise ( self )
dscreen.raise ( self )
self.defocused = false
return self
return self
end
end
@ -809,8 +848,7 @@ local BASE_FRAME = {
title_pen = to_pen { fg = COLOR_BLACK , bg = COLOR_GREY } ,
title_pen = to_pen { fg = COLOR_BLACK , bg = COLOR_GREY } ,
inactive_title_pen = to_pen { fg = COLOR_GREY , bg = COLOR_BLACK } ,
inactive_title_pen = to_pen { fg = COLOR_GREY , bg = COLOR_BLACK } ,
signature_pen = to_pen { fg = COLOR_GREY , bg = COLOR_BLACK } ,
signature_pen = to_pen { fg = COLOR_GREY , bg = COLOR_BLACK } ,
pinned_pen = to_pen { tile = 779 , ch = 216 , fg = COLOR_GREY , bg = COLOR_GREEN } ,
paused_pen = to_pen { tile = 782 , ch = 216 , fg = COLOR_GREY , bg = COLOR_BLACK } ,
unpinned_pen = to_pen { tile = 782 , ch = 216 , fg = COLOR_GREY , bg = COLOR_BLACK } ,
}
}
local function make_frame ( name , double_line )
local function make_frame ( name , double_line )
@ -839,10 +877,8 @@ THIN_FRAME = make_frame('Thin', false)
-- for compatibility with pre-steam code
-- for compatibility with pre-steam code
GREY_LINE_FRAME = WINDOW_FRAME
GREY_LINE_FRAME = WINDOW_FRAME
BOUNDARY_FRAME = PANEL_FRAME
GREY_FRAME = MEDIUM_FRAME
function paint_frame ( dc , rect , style , title , show_pin, pinned , inactive )
function paint_frame ( dc , rect , style , title , inactive , pause_forced )
local pen = style.frame_pen
local pen = style.frame_pen
local x1 , y1 , x2 , y2 = dc.x1 + rect.x1 , dc.y1 + rect.y1 , dc.x1 + rect.x2 , dc.y1 + rect.y2
local x1 , y1 , x2 , y2 = dc.x1 + rect.x1 , dc.y1 + rect.y1 , dc.x1 + rect.x2 , dc.y1 + rect.y2
dscreen.paintTile ( style.lt_frame_pen or pen , x1 , y1 )
dscreen.paintTile ( style.lt_frame_pen or pen , x1 , y1 )
@ -867,27 +903,19 @@ function paint_frame(dc,rect,style,title,show_pin,pinned,inactive)
x , y1 , tstr )
x , y1 , tstr )
end
end
if show_pin then
if pause_forced then
if pinned and style.pinned_pen then
-- get the tiles for the activated pause symbol
local pin_texpos = dfhack.textures . getGreenPinTexposStart ( )
local pause_texpos_ul = dfhack.screen . findGraphicsTile ( ' INTERFACE_BITS ' , 18 , 28 )
if pin_texpos == - 1 then
local pause_texpos_ur = dfhack.screen . findGraphicsTile ( ' INTERFACE_BITS ' , 19 , 28 )
dscreen.paintTile ( style.pinned_pen , x2 - 1 , y1 )
local pause_texpos_ll = dfhack.screen . findGraphicsTile ( ' INTERFACE_BITS ' , 18 , 29 )
else
local pause_texpos_lr = dfhack.screen . findGraphicsTile ( ' INTERFACE_BITS ' , 19 , 29 )
dscreen.paintTile ( style.pinned_pen , x2 - 2 , y1 - 1 , nil , pin_texpos + 0 )
if not pause_texpos_ul then
dscreen.paintTile ( style.pinned_pen , x2 - 1 , y1 - 1 , nil , pin_texpos + 1 )
dscreen.paintTile ( style.paused_pen , x2 - 1 , y1 )
dscreen.paintTile ( style.pinned_pen , x2 - 2 , y1 , nil , pin_texpos + 2 )
else
dscreen.paintTile ( style.pinned_pen , x2 - 1 , y1 , nil , pin_texpos + 3 )
dscreen.paintTile ( style.paused_pen , x2 - 2 , y1 - 1 , nil , pause_texpos_ul )
end
dscreen.paintTile ( style.paused_pen , x2 - 1 , y1 - 1 , nil , pause_texpos_ur )
elseif not pinned and style.unpinned_pen then
dscreen.paintTile ( style.paused_pen , x2 - 2 , y1 , nil , pause_texpos_ll )
local pin_texpos = dfhack.textures . getRedPinTexposStart ( )
dscreen.paintTile ( style.paused_pen , x2 - 1 , y1 , nil , pause_texpos_lr )
if pin_texpos == - 1 then
dscreen.paintTile ( style.unpinned_pen , x2 - 1 , y1 )
else
dscreen.paintTile ( style.unpinned_pen , x2 - 2 , y1 - 1 , nil , pin_texpos + 0 )
dscreen.paintTile ( style.unpinned_pen , x2 - 1 , y1 - 1 , nil , pin_texpos + 1 )
dscreen.paintTile ( style.unpinned_pen , x2 - 2 , y1 , nil , pin_texpos + 2 )
dscreen.paintTile ( style.unpinned_pen , x2 - 1 , y1 , nil , pin_texpos + 3 )
end
end
end
end
end
end
end