Merge pull request #2542 from myk002/myk_dwarfmode_dims

clear out obsolete area map and menu logic from the Gui module
develop
Myk 2023-01-02 20:42:30 -08:00 committed by GitHub
commit 35ce361b09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 103 deletions

@ -46,6 +46,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- added DFHack architecture diagrams to the dev intro - added DFHack architecture diagrams to the dev intro
## API ## API
- ``Gui::getDwarfmodeDims``: now only returns map viewport dimensions; menu dimensions are obsolete
## Lua ## Lua
- ``gui.View``: ``visible`` and ``active`` can now be functions that return a boolean - ``gui.View``: ``visible`` and ``active`` can now be functions that return a boolean

@ -1011,7 +1011,7 @@ Fortress mode
* ``dfhack.gui.getDwarfmodeViewDims()`` * ``dfhack.gui.getDwarfmodeViewDims()``
Returns dimensions of the main fortress mode screen. See ``getPanelLayout()`` Returns dimensions of the displayed map viewport. See ``getPanelLayout()``
in the ``gui.dwarfmode`` module for a more Lua-friendly version. in the ``gui.dwarfmode`` module for a more Lua-friendly version.
* ``dfhack.gui.resetDwarfmodeView([pause])`` * ``dfhack.gui.resetDwarfmodeView([pause])``

@ -1436,17 +1436,8 @@ static int gui_getDwarfmodeViewDims(lua_State *state)
lua_newtable(state); lua_newtable(state);
Lua::TableInsert(state, "map_x1", dims.map_x1); Lua::TableInsert(state, "map_x1", dims.map_x1);
Lua::TableInsert(state, "map_x2", dims.map_x2); Lua::TableInsert(state, "map_x2", dims.map_x2);
Lua::TableInsert(state, "menu_x1", dims.menu_x1);
Lua::TableInsert(state, "menu_x2", dims.menu_x2);
Lua::TableInsert(state, "area_x1", dims.area_x1);
Lua::TableInsert(state, "area_x2", dims.area_x2);
Lua::TableInsert(state, "y1", dims.y1);
Lua::TableInsert(state, "y2", dims.y2);
Lua::TableInsert(state, "map_y1", dims.map_y1); Lua::TableInsert(state, "map_y1", dims.map_y1);
Lua::TableInsert(state, "map_y2", dims.map_y2); Lua::TableInsert(state, "map_y2", dims.map_y2);
Lua::TableInsert(state, "menu_on", dims.menu_on);
Lua::TableInsert(state, "area_on", dims.area_on);
Lua::TableInsert(state, "menu_forced", dims.menu_forced);
return 1; return 1;
} }

@ -143,13 +143,10 @@ namespace DFHack
static const int MENU_WIDTH = 30; static const int MENU_WIDTH = 30;
struct DwarfmodeDims { struct DwarfmodeDims {
int map_x1, map_x2, menu_x1, menu_x2, area_x1, area_x2; int map_x1, map_x2;
int y1, y2;
int map_y1, map_y2; int map_y1, map_y2;
bool menu_on, area_on, menu_forced;
rect2d map() { return mkrect_xy(map_x1, map_y1, map_x2, map_y2); } rect2d map() { return mkrect_xy(map_x1, map_y1, map_x2, map_y2); }
rect2d menu() { return mkrect_xy(menu_x1, y1, menu_x2, y2); }
}; };
DFHACK_EXPORT DwarfmodeDims getDwarfmodeViewDims(); DFHACK_EXPORT DwarfmodeDims getDwarfmodeViewDims();
@ -198,18 +195,6 @@ namespace DFHack
/// get the size of the window buffer /// get the size of the window buffer
DFHACK_EXPORT bool getWindowSize(int32_t & width, int32_t & height); DFHACK_EXPORT bool getWindowSize(int32_t & width, int32_t & height);
/**
*Menu width:
*3:3 - menu and area map closed
*2:3 - menu open single width
*1:3 - menu open double width
*1:2 - menu and area map open
*2:2 - area map open
*/
DFHACK_EXPORT bool getMenuWidth(uint8_t & menu_width, uint8_t & area_map_width);
DFHACK_EXPORT bool setMenuWidth(const uint8_t menu_width, const uint8_t area_map_width);
namespace Hooks { namespace Hooks {
GUI_HOOK_DECLARE(depth_at, int, (int32_t x, int32_t y)); GUI_HOOK_DECLARE(depth_at, int, (int32_t x, int32_t y));
GUI_HOOK_DECLARE(dwarfmode_view_dims, DwarfmodeDims, ()); GUI_HOOK_DECLARE(dwarfmode_view_dims, DwarfmodeDims, ());

@ -71,30 +71,9 @@ end
function getPanelLayout() function getPanelLayout()
local dims = dfhack.gui.getDwarfmodeViewDims() local dims = dfhack.gui.getDwarfmodeViewDims()
local area_pos = df.global.ui_menu_width[1] return {
local menu_pos = df.global.ui_menu_width[0]
if dims.menu_forced then
menu_pos = area_pos - 1
end
local rv = {
menu_pos = menu_pos,
area_pos = area_pos,
map=gui.mkdims_xy(dims.map_x1, dims.map_y1, dims.map_x2, dims.map_y2), map=gui.mkdims_xy(dims.map_x1, dims.map_y1, dims.map_x2, dims.map_y2),
} }
if dims.menu_forced then
rv.menu_forced = true
end
if dims.menu_on then
rv.menu = gui.mkdims_xy(dims.menu_x1, dims.y1, dims.menu_x2, dims.y2)
end
if dims.area_on then
rv.area_map = gui.mkdims_xy(dims.area_x1, dims.y1, dims.area_x2, dims.y2)
end
return rv
end end
function getCursorPos() function getCursorPos()

@ -1919,47 +1919,14 @@ Gui::DwarfmodeDims getDwarfmodeViewDims_default()
{ {
Gui::DwarfmodeDims dims; Gui::DwarfmodeDims dims;
auto ws = Screen::getWindowSize(); bool use_graphics = Screen::inGraphicsMode();
dims.y1 = 1; auto dimx = use_graphics ? gps->main_viewport->dim_x : gps->dimx;
dims.y2 = ws.y-2; auto dimy = use_graphics ? gps->main_viewport->dim_y : gps->dimy;
dims.map_x1 = 1; dims.map_x1 = 0;
dims.map_x2 = ws.x-2; dims.map_x2 = dimx - 1;
dims.map_y1 = dims.y1; dims.map_y1 = 0;
dims.map_y2 = dims.y2; dims.map_y2 = dimy - 1;
dims.area_x1 = dims.area_x2 = dims.menu_x1 = dims.menu_x2 = -1;
dims.menu_forced = false;
int menu_pos = (ui_menu_width ? (*ui_menu_width)[0] : 2);
int area_pos = (ui_menu_width ? (*ui_menu_width)[1] : 3);
if (ui && ui->main.mode != ui_sidebar_mode::Default && ui->main.mode != ui_sidebar_mode::ArenaWeather && menu_pos >= area_pos)
{
dims.menu_forced = true;
menu_pos = area_pos-1;
}
dims.area_on = (area_pos < 3);
dims.menu_on = (menu_pos < area_pos);
if (dims.menu_on)
{
dims.menu_x2 = ws.x - 2;
dims.menu_x1 = dims.menu_x2 - Gui::MENU_WIDTH + 1;
if (menu_pos == 1)
dims.menu_x1 -= Gui::AREA_MAP_WIDTH + 1;
dims.map_x2 = dims.menu_x1 - 2;
}
if (dims.area_on)
{
dims.area_x2 = ws.x-2;
dims.area_x1 = dims.area_x2 - Gui::AREA_MAP_WIDTH + 1;
if (dims.menu_on)
dims.menu_x2 = dims.area_x1 - 2;
else
dims.map_x2 = dims.area_x1 - 2;
}
return dims; return dims;
} }
@ -2199,17 +2166,3 @@ bool Gui::getWindowSize (int32_t &width, int32_t &height)
return false; return false;
} }
} }
bool Gui::getMenuWidth(uint8_t &menu_width, uint8_t &area_map_width)
{
menu_width = (*ui_menu_width)[0];
area_map_width = (*ui_menu_width)[1];
return true;
}
bool Gui::setMenuWidth(const uint8_t menu_width, const uint8_t area_map_width)
{
(*ui_menu_width)[0] = menu_width;
(*ui_menu_width)[1] = area_map_width;
return true;
}