@@ -399,25 +399,33 @@ end
399
399
-- MassRemoveToolbarOverlay
400
400
--
401
401
402
- -- The overlay is positioned so that (by default) its button is placed next to
403
- -- the right-most button of the secondary toolbar displayed for the "erase" tool
402
+ -- The overlay is positioned (by default) so that, no matter what size interface
403
+ -- is being used, the overlay's button is placed one column to the right of the
404
+ -- right-most button of the secondary toolbar displayed for the "erase" tool
404
405
-- (used to remove designations).
405
406
406
407
-- This would be straightforward in a full_interface overlay (just set its
407
- -- l/r/t/b frame positioning fields). However, to preserve player-positioning,
408
- -- we take a more circuitous route.
409
-
410
- -- In a minimum-size interface area, the player is allowed to place the overlay
411
- -- (a combination of the button and the tooltip) anywhere inside the interface
412
- -- area. When the interface area is resized (usually through window resizes, but
413
- -- also through interface percentage changes), placement is maintained relative
414
- -- to the "ideal" position of the button (i.e. positions are relative to the
415
- -- "ideal" position). When repositioning the overlay in a larger-than-minimum
416
- -- interface area the overlays size is artificially inflated so that the overlay
417
- -- can not be positioned (with respect to the "ideal" button position) farther
418
- -- away than is possible in a minimum-size interface area. This limits the
419
- -- positioning, but keeps the (relative) position consistent across all possible
420
- -- resizes.
408
+ -- l/r/t/b frame positioning fields based on the "erase" toolbar's position).
409
+ -- However, to preserve player-positioning, we take a more circuitous route.
410
+
411
+ -- Usually, the player-configured positions are relative to the edges of the DF
412
+ -- interface area. But because the button of this overlay needs to "stick with"
413
+ -- the rest of the toolbar buttons, the player-configured positioning is
414
+ -- reinterpreted a bit.
415
+
416
+ -- The offset between the overlay's default position and its player-configured
417
+ -- position is used as the overlay's effective offset from its "ideal" position.
418
+ -- This "effective offset" is realized by updating the overlay's width, not its
419
+ -- position (which we leave in the hands of the overlay system, under player
420
+ -- control). When combined with the player-configured position, this results in
421
+ -- translating the overlay position to be relative to its "ideal" position so
422
+ -- that the overlay "moves with" the rest of the toolbar buttons, but still
423
+ -- allows for player customization.
424
+
425
+ -- Note: This "position reinterpretation" currently only works when the overlay
426
+ -- is anchored to the left and bottom edges of the interface area. If the
427
+ -- overlay is player-reconfigured to be anchored to the right or top edges, it
428
+ -- will result in normal edge-relative positioning.
421
429
422
430
local tb = reqscript (' internal/df-bottom-toolbars' )
423
431
@@ -438,12 +446,17 @@ local function mass_remove_button_offsets(interface_rect)
438
446
}
439
447
end
440
448
441
- local MR_MIN_OFFSETS = mass_remove_button_offsets (tb .MINIMUM_INTERFACE_RECT )
449
+ -- This value is compatible with the initial release of the overlay, but it not
450
+ -- the actual left-offset of this overlay; if bumping overlay version, this
451
+ -- could be changed to mass_remove_button_offsets(tb.MINIMUM_INTERFACE_RECT).l
452
+ -- Adopting the calculated value would let the overlay be moved all the way to
453
+ -- the left (in a minimum-size interface).
454
+ local MR_DEFAULT_OFFSET = 41
442
455
443
456
MassRemoveToolbarOverlay = defclass (MassRemoveToolbarOverlay , overlay .OverlayWidget )
444
457
MassRemoveToolbarOverlay .ATTRS {
445
458
desc = ' Adds a button to the erase toolbar to open the mass removal tool.' ,
446
- default_pos = {x = MR_MIN_OFFSETS . l + 1 , y =- (MR_MIN_OFFSETS . b + 1 )},
459
+ default_pos = {x = MR_DEFAULT_OFFSET + 1 , y =- (tb . TOOLBAR_HEIGHT + 1 )},
447
460
default_enabled = true ,
448
461
viewscreens = ' dwarfmode/Designate/ERASE' ,
449
462
frame = {w = MR_WIDTH , h = MR_HEIGHT },
@@ -458,57 +471,51 @@ function MassRemoveToolbarOverlay:init()
458
471
459
472
self :addviews {
460
473
widgets .Panel {
461
- view_id = ' tt_and_icon' ,
462
- frame = { r = 0 , t = 0 , w = MR_WIDTH , h = MR_HEIGHT },
463
- subviews = {
464
- widgets .Panel {
465
- frame = {t = 0 , l = 0 , w = MR_WIDTH , h = MR_TOOLTIP_HEIGHT },
466
- frame_style = gui .FRAME_PANEL ,
467
- frame_background = gui .CLEAR_PEN ,
468
- frame_inset = {l = 1 , r = 1 },
469
- visible = function () return self .subviews .icon :getMousePos () end ,
470
- subviews = {
471
- widgets .Label {
472
- text = {
473
- ' Open mass removal' , NEWLINE ,
474
- ' interface.' , NEWLINE ,
475
- NEWLINE ,
476
- {text = ' Hotkey: ' , pen = COLOR_GRAY }, {key = ' CUSTOM_M' },
477
- },
478
- },
474
+ frame = {t = 0 , r = 0 , w = MR_WIDTH , h = MR_TOOLTIP_HEIGHT },
475
+ frame_style = gui .FRAME_PANEL ,
476
+ frame_background = gui .CLEAR_PEN ,
477
+ frame_inset = {l = 1 , r = 1 },
478
+ visible = function () return self .subviews .icon :getMousePos () end ,
479
+ subviews = {
480
+ widgets .Label {
481
+ text = {
482
+ ' Open mass removal' , NEWLINE ,
483
+ ' interface.' , NEWLINE ,
484
+ NEWLINE ,
485
+ {text = ' Hotkey: ' , pen = COLOR_GRAY }, {key = ' CUSTOM_M' },
479
486
},
480
487
},
481
- widgets .Panel {
482
- view_id = ' icon' ,
483
- frame = {b = 0 , l = 0 , w = MR_BUTTON_WIDTH , h = tb .SECONDARY_TOOLBAR_HEIGHT },
484
- subviews = {
485
- widgets .Label {
486
- text = widgets .makeButtonLabelText {
487
- chars = button_chars ,
488
- pens = COLOR_GRAY ,
489
- tileset = toolbar_textures ,
490
- tileset_offset = 1 ,
491
- tileset_stride = 8 ,
492
- },
493
- on_click = launch_mass_remove ,
494
- visible = function () return not self .subviews .icon :getMousePos () end ,
495
- },
496
- widgets .Label {
497
- text = widgets .makeButtonLabelText {
498
- chars = button_chars ,
499
- pens = {
500
- {COLOR_WHITE , COLOR_WHITE , COLOR_WHITE , COLOR_WHITE },
501
- {COLOR_WHITE , COLOR_GRAY , COLOR_GRAY , COLOR_WHITE },
502
- {COLOR_WHITE , COLOR_WHITE , COLOR_WHITE , COLOR_WHITE },
503
- },
504
- tileset = toolbar_textures ,
505
- tileset_offset = 5 ,
506
- tileset_stride = 8 ,
507
- },
508
- on_click = launch_mass_remove ,
509
- visible = function () return self .subviews .icon :getMousePos () end ,
488
+ },
489
+ },
490
+ widgets .Panel {
491
+ view_id = ' icon' ,
492
+ frame = {b = 0 , r = 0 , w = MR_WIDTH , h = tb .SECONDARY_TOOLBAR_HEIGHT },
493
+ subviews = {
494
+ widgets .Label {
495
+ text = widgets .makeButtonLabelText {
496
+ chars = button_chars ,
497
+ pens = COLOR_GRAY ,
498
+ tileset = toolbar_textures ,
499
+ tileset_offset = 1 ,
500
+ tileset_stride = 8 ,
501
+ },
502
+ on_click = launch_mass_remove ,
503
+ visible = function () return not self .subviews .icon :getMousePos () end ,
504
+ },
505
+ widgets .Label {
506
+ text = widgets .makeButtonLabelText {
507
+ chars = button_chars ,
508
+ pens = {
509
+ {COLOR_WHITE , COLOR_WHITE , COLOR_WHITE , COLOR_WHITE },
510
+ {COLOR_WHITE , COLOR_GRAY , COLOR_GRAY , COLOR_WHITE },
511
+ {COLOR_WHITE , COLOR_WHITE , COLOR_WHITE , COLOR_WHITE },
510
512
},
513
+ tileset = toolbar_textures ,
514
+ tileset_offset = 5 ,
515
+ tileset_stride = 8 ,
511
516
},
517
+ on_click = launch_mass_remove ,
518
+ visible = function () return self .subviews .icon :getMousePos () end ,
512
519
},
513
520
},
514
521
},
517
524
518
525
function MassRemoveToolbarOverlay :preUpdateLayout (parent_rect )
519
526
local offsets = mass_remove_button_offsets (parent_rect )
520
- local r = offsets .r - MR_MIN_OFFSETS .r
521
- local l = offsets .l - MR_MIN_OFFSETS .l
522
- local t = offsets .t - MR_MIN_OFFSETS .t
523
- local b = offsets .b - MR_MIN_OFFSETS .b
524
- self .frame .w = MR_WIDTH + l + r
525
- self .frame .h = MR_HEIGHT + t + b
526
- self .subviews .tt_and_icon .frame .l = l
527
- self .subviews .tt_and_icon .frame .r = r
528
- self .subviews .tt_and_icon .frame .t = t
529
- self .subviews .tt_and_icon .frame .b = b
527
+ self .frame .w = MR_WIDTH + offsets .l - MR_DEFAULT_OFFSET
530
528
end
531
529
532
530
function MassRemoveToolbarOverlay :onInput (keys )
0 commit comments