From 6a57cc445068a696882f2abe50a94cc3a4e15da0 Mon Sep 17 00:00:00 2001 From: myk002 Date: Sun, 23 Oct 2022 16:52:32 -0700 Subject: [PATCH 1/4] fix render errors with automaterial box boundaries --- docs/changelog.txt | 1 + plugins/automaterial.cpp | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index af2e6b3fa..570d21685 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -38,6 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes - `gui/create-item`: prevent materials list filter from intercepting sublist hotkeys - `tiletypes`: no longer resets dig priority to the default when updating other properties of a tile +- `automaterial`: fix rendering errors with box boundary markers ## Misc Improvements - `blueprint`: new ``--smooth`` option for recording all smoothed floors and walls instead of just the ones that require smoothing for later carving diff --git a/plugins/automaterial.cpp b/plugins/automaterial.cpp index b1b83d09e..62a03aff0 100644 --- a/plugins/automaterial.cpp +++ b/plugins/automaterial.cpp @@ -14,6 +14,7 @@ // DF data structure definition headers #include "DataDefs.h" +#include "Debug.h" #include "MiscUtils.h" #include "TileTypes.h" #include "df/build_req_choice_genst.h" @@ -52,6 +53,10 @@ REQUIRE_GLOBAL(gps); REQUIRE_GLOBAL(ui); REQUIRE_GLOBAL(ui_build_selector); +namespace DFHack { + DBG_DECLARE(automaterial,log,DebugCategory::LINFO); +} + struct MaterialDescriptor { df::item_type item_type; @@ -719,7 +724,6 @@ struct jobutils_hook : public df::viewscreen_dwarfmodest if (box_select_mode == SELECT_FIRST || (!show_box_selection && box_select_mode == SELECT_SECOND)) { int32_t x, y, z; - if (!Gui::getCursorCoords(x, y, z)) return; @@ -732,12 +736,13 @@ struct jobutils_hook : public df::viewscreen_dwarfmodest if (!Gui::getCursorCoords(box_second.x, box_second.y, box_second.z)) return; - int32_t xD = (box_second.x > box_first.x) ? 1 : -1; - int32_t yD = (box_second.y > box_first.y) ? 1 : -1; - for (int32_t xB = box_first.x; (xD > 0) ? (xB <= box_second.x) : (xB >= box_second.x); xB += xD) - { - for (int32_t yB = box_first.y; (yD > 0) ? (yB <= box_second.y) : (yB >= box_second.y); yB += yD) - { + Gui::DwarfmodeDims dims = Gui::getDwarfmodeViewDims(); + int32_t startx = std::max((int32_t)vport.x, std::min(box_first.x, box_second.x)); + int32_t endx = std::min(vport.x + dims.map_x2 - dims.map_x1, std::max(box_first.x, box_second.x)); + int32_t starty = std::max((int32_t)vport.y, std::min(box_first.y, box_second.y)); + int32_t endy = std::min(vport.y + dims.map_y2 - dims.map_y1, std::max(box_first.y, box_second.y)); + for (int32_t yB = starty; yB <= endy; ++yB) { + for (int32_t xB = startx; xB <= endx; ++xB) { if (hollow_selection && !(xB == box_first.x || xB == box_second.x || yB == box_first.y || yB == box_second.y)) continue; @@ -963,6 +968,11 @@ struct jobutils_hook : public df::viewscreen_dwarfmodest void move_cursor(df::coord &pos) { + int32_t x, y, z; + Gui::getCursorCoords(x, y, z); + DEBUG(log).print("moving cursor from %d, %d, %d to %d, %d, %d\n", + x, y, z, pos.x, pos.y, pos.z); + Gui::setCursorCoords(pos.x, pos.y, pos.z); Gui::refreshSidebar(); } @@ -1269,9 +1279,13 @@ struct jobutils_hook : public df::viewscreen_dwarfmodest label << "Selection: " << dX << "x" << dY; OutputString(COLOR_WHITE, x, ++y, label.str(), true, left_margin); - int cx = box_first.x; - int cy = box_first.y; - OutputString(COLOR_BROWN, cx, cy, "X", false, 0, 0, true /* map */); + df::coord vport = Gui::getViewportPos(); + int cx = box_first.x - vport.x + 1; + int cy = box_first.y - vport.y + 1; + + Gui::DwarfmodeDims dims = Gui::getDwarfmodeViewDims(); + if (cx >= 1 && cx <= dims.map_x2 && cy >= 1 && cy <= dims.map_y2) + OutputString(COLOR_BROWN, cx, cy, "X", false, 0, 0, true /* map */); break; } From 01c46f7a7e76b44a81ab9aa415d6d1ad5e67c61a Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 24 Oct 2022 09:35:59 -0700 Subject: [PATCH 2/4] fix z-level jumps when clicking quickly this happens when TWBT is enabled and multilevel is > 0 getDepthAt() returns inconsistent values for the same position, leading to a mismatch when we "unshift" the coordinates to account for render depth --- docs/changelog.txt | 1 + plugins/mousequery.cpp | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index af2e6b3fa..8447ec1fa 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -37,6 +37,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes - `gui/create-item`: prevent materials list filter from intercepting sublist hotkeys +- `mousequery`: fix the cursor jumping up z levels sometimes when using TWBT - `tiletypes`: no longer resets dig priority to the default when updating other properties of a tile ## Misc Improvements diff --git a/plugins/mousequery.cpp b/plugins/mousequery.cpp index 6358262f4..4c88bd2ac 100644 --- a/plugins/mousequery.cpp +++ b/plugins/mousequery.cpp @@ -56,10 +56,12 @@ static uint32_t scroll_delay = 100; static bool awaiting_lbut_up, awaiting_rbut_up; static enum { None, Left, Right } drag_mode; -static df::coord get_mouse_pos(int32_t &mx, int32_t &my) +static df::coord get_mouse_pos(int32_t &mx, int32_t &my, int32_t &depth) { df::coord pos = Gui::getMousePos(); - pos.z -= Gui::getDepthAt(pos.x, pos.y); + + depth = Gui::getDepthAt(pos.x, pos.y); + pos.z -= depth; df::coord vpos = Gui::getViewportPos(); mx = pos.x - vpos.x + 1; @@ -291,10 +293,13 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest return false; } - bool handleLeft(df::coord &mpos, int32_t mx, int32_t my) + bool handleLeft(df::coord &mpos, int32_t mx, int32_t my, int32_t depth) { - if (!(Core::getInstance().getModstate() & DFH_MOD_SHIFT)) - mpos.z += Gui::getDepthAt(mx, my); + if (Core::getInstance().getModstate() & DFH_MOD_SHIFT) { + DEBUG(log).print("shift is down; not adjusting tile depth\n"); + } + else + mpos.z += depth; bool cursor_still_here = (last_clicked_x == mpos.x && last_clicked_y == mpos.y && last_clicked_z == mpos.z); last_clicked_x = mpos.x; @@ -444,8 +449,8 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest bool handleMouse(const set *input) { - int32_t mx, my; - auto mpos = get_mouse_pos(mx, my); + int32_t mx, my, depth; + auto mpos = get_mouse_pos(mx, my, depth); if (mpos.x == -30000) return false; @@ -458,7 +463,7 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest last_move_pos = mpos; } else - return handleLeft(mpos, mx, my); + return handleLeft(mpos, mx, my, depth); } else if (enabler->mouse_rbut) { @@ -531,7 +536,8 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest if (mpos.x == x && mpos.y == y && mpos.z == z) return; - DEBUG(log).print("moving cursor to %d, %d, %d\n", x, y, z); + DEBUG(log).print("moving cursor to %d, %d, %d\n", + mpos.x, mpos.y, mpos.z); Gui::setCursorCoords(mpos.x, mpos.y, mpos.z); Gui::refreshSidebar(); } @@ -568,8 +574,8 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest auto dims = Gui::getDwarfmodeViewDims(); - int32_t mx, my; - auto mpos = get_mouse_pos(mx, my); + int32_t mx, my, depth; + auto mpos = get_mouse_pos(mx, my, depth); bool mpos_valid = mpos.x != -30000 && mpos.y != -30000 && mpos.z != -30000; // Check if in lever binding mode @@ -582,7 +588,7 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest if (awaiting_lbut_up && !enabler->mouse_lbut_down) { awaiting_lbut_up = false; - handleLeft(mpos, mx, my); + handleLeft(mpos, mx, my, depth); } if (awaiting_rbut_up && !enabler->mouse_rbut_down) From 8b61a17009438c119008bcc848464461bf98d233 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 24 Oct 2022 12:46:31 -0700 Subject: [PATCH 3/4] prevent z-level from changing after box select if the player clicks the mouse too fast after finishing a selection --- docs/changelog.txt | 1 + plugins/automaterial.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index af2e6b3fa..79ba705b1 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -36,6 +36,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## New Plugins ## Fixes +- `automaterial`: fix the cursor jumping up a z level when clicking quickly after box select - `gui/create-item`: prevent materials list filter from intercepting sublist hotkeys - `tiletypes`: no longer resets dig priority to the default when updating other properties of a tile diff --git a/plugins/automaterial.cpp b/plugins/automaterial.cpp index b1b83d09e..a99d66cfc 100644 --- a/plugins/automaterial.cpp +++ b/plugins/automaterial.cpp @@ -94,7 +94,7 @@ static bool show_box_selection = true; static bool hollow_selection = false; static deque box_select_materials; -#define SELECTION_IGNORE_TICKS 10 +#define SELECTION_IGNORE_TICKS 1 static int ignore_selection = SELECTION_IGNORE_TICKS; static map last_used_material; From 7b2119c4d13fb99611b3490e5b72d2216a06f7d5 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 24 Oct 2022 17:03:28 -0700 Subject: [PATCH 4/4] remove debug statement that doesn't help --- plugins/mousequery.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/mousequery.cpp b/plugins/mousequery.cpp index 4c88bd2ac..124664fa2 100644 --- a/plugins/mousequery.cpp +++ b/plugins/mousequery.cpp @@ -295,10 +295,7 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest bool handleLeft(df::coord &mpos, int32_t mx, int32_t my, int32_t depth) { - if (Core::getInstance().getModstate() & DFH_MOD_SHIFT) { - DEBUG(log).print("shift is down; not adjusting tile depth\n"); - } - else + if (!(Core::getInstance().getModstate() & DFH_MOD_SHIFT)) mpos.z += depth; bool cursor_still_here = (last_clicked_x == mpos.x && last_clicked_y == mpos.y && last_clicked_z == mpos.z);