diff options
| author | Alexander Gavrilov | 2012-09-20 11:48:53 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-09-20 11:48:53 +0400 |
| commit | 1f7c10252e79415bf56c461cd2eb19a5018433fb (patch) | |
| tree | 7d13af061f9af21682682103af8660431e0139c7 | |
| parent | 462bedb75708043f3ef9520e8fb84640ebaec945 (diff) | |
| download | dfhack-1f7c10252e79415bf56c461cd2eb19a5018433fb.tar.gz dfhack-1f7c10252e79415bf56c461cd2eb19a5018433fb.tar.bz2 dfhack-1f7c10252e79415bf56c461cd2eb19a5018433fb.tar.xz | |
Support renaming activity zones.
This one required hooking the dwarfmode render method.
| -rw-r--r-- | README.rst | 8 | ||||
| -rw-r--r-- | Readme.html | 8 | ||||
| -rw-r--r-- | plugins/rename.cpp | 47 |
3 files changed, 52 insertions, 11 deletions
@@ -703,7 +703,8 @@ Options :rename unit-profession "custom profession": Change proffession name of the highlighted unit/creature. :rename building "name": Set a custom name for the selected building. - The building must be one of stockpile, workshop, furnace, trap or siege engine. + The building must be one of stockpile, workshop, furnace, trap, + siege engine or an activity zone. reveal ====== @@ -1549,7 +1550,8 @@ via a simple dialog in the game ui. * ``gui/rename [building]`` in 'q' mode changes the name of a building. - The selected building must be one of stockpile, workshop, furnace, trap or siege engine. + The selected building must be one of stockpile, workshop, furnace, trap, or siege engine. + It is also possible to rename zones from the 'i' menu. * ``gui/rename [unit]`` with a unit selected changes the nickname. @@ -1645,7 +1647,7 @@ is extracted from the workshop raws. machine connection cannot be modified. As a result, the workshop can only immediately connect to machine components built AFTER it. This also means that engines cannot be chained without intermediate -short axles that can be built later. +short axles that can be built later than both of the engines. Operation --------- diff --git a/Readme.html b/Readme.html index 4c005b6f..7b41dc74 100644 --- a/Readme.html +++ b/Readme.html @@ -1480,7 +1480,8 @@ highlighted unit/creature.</td> </tr> <tr class="field"><th class="field-name" colspan="2">rename building "name":</th></tr> <tr class="field"><td> </td><td class="field-body">Set a custom name for the selected building. -The building must be one of stockpile, workshop, furnace, trap or siege engine.</td> +The building must be one of stockpile, workshop, furnace, trap, +siege engine or an activity zone.</td> </tr> </tbody> </table> @@ -2423,7 +2424,8 @@ configuration page, but configures parameters relevant to the modded power meter via a simple dialog in the game ui.</p> <ul> <li><p class="first"><tt class="docutils literal">gui/rename [building]</tt> in 'q' mode changes the name of a building.</p> -<p>The selected building must be one of stockpile, workshop, furnace, trap or siege engine.</p> +<p>The selected building must be one of stockpile, workshop, furnace, trap, or siege engine. +It is also possible to rename zones from the 'i' menu.</p> </li> <li><p class="first"><tt class="docutils literal">gui/rename [unit]</tt> with a unit selected changes the nickname.</p> </li> @@ -2497,7 +2499,7 @@ is extracted from the workshop raws.</p> machine connection cannot be modified. As a result, the workshop can only immediately connect to machine components built AFTER it. This also means that engines cannot be chained without intermediate -short axles that can be built later.</p> +short axles that can be built later than both of the engines.</p> </div> <div class="section" id="operation"> <h3><a class="toc-backref" href="#id192">Operation</a></h3> diff --git a/plugins/rename.cpp b/plugins/rename.cpp index f9de83bd..059a4be6 100644 --- a/plugins/rename.cpp +++ b/plugins/rename.cpp @@ -10,9 +10,11 @@ #include "modules/Translation.h" #include "modules/Units.h" #include "modules/World.h" +#include "modules/Screen.h" #include <VTableInterpose.h> #include "df/ui.h" +#include "df/ui_sidebar_menus.h" #include "df/world.h" #include "df/squad.h" #include "df/unit.h" @@ -27,6 +29,8 @@ #include "df/building_furnacest.h" #include "df/building_trapst.h" #include "df/building_siegeenginest.h" +#include "df/building_civzonest.h" +#include "df/viewscreen_dwarfmodest.h" #include "RemoteServer.h" #include "rename.pb.h" @@ -43,6 +47,7 @@ using namespace df::enums; using namespace dfproto; using df::global::ui; +using df::global::ui_sidebar_menus; using df::global::world; DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event); @@ -66,8 +71,8 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi " (a building must be highlighted via 'q')\n" )); - if (Core::getInstance().isMapLoaded()) - plugin_onstatechange(out, SC_MAP_LOADED); + if (Core::getInstance().isWorldLoaded()) + plugin_onstatechange(out, SC_WORLD_LOADED); } return CR_OK; @@ -78,10 +83,10 @@ static void init_buildings(bool enable); DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) { switch (event) { - case SC_MAP_LOADED: + case SC_WORLD_LOADED: init_buildings(true); break; - case SC_MAP_UNLOADED: + case SC_WORLD_UNLOADED: init_buildings(false); break; default: @@ -105,7 +110,8 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out ) BUILDING('w', building_workshopst, NULL) \ BUILDING('e', building_furnacest, NULL) \ BUILDING('T', building_trapst, NULL) \ - BUILDING('i', building_siegeenginest, NULL) + BUILDING('i', building_siegeenginest, NULL) \ + BUILDING('Z', building_civzonest, "Zone") #define BUILDING(code, cname, tag) \ struct cname##_hook : df::cname { \ @@ -128,6 +134,32 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out ) KNOWN_BUILDINGS #undef BUILDING +struct dwarf_render_zone_hook : df::viewscreen_dwarfmodest { + typedef df::viewscreen_dwarfmodest interpose_base; + + DEFINE_VMETHOD_INTERPOSE(void, render, ()) + { + INTERPOSE_NEXT(render)(); + + if (ui->main.mode == ui_sidebar_mode::Zones && + ui_sidebar_menus && ui_sidebar_menus->zone.selected && + !ui_sidebar_menus->zone.selected->name.empty()) + { + auto dims = Gui::getDwarfmodeViewDims(); + int width = dims.menu_x2 - dims.menu_x1 - 1; + + Screen::Pen pen(' ',COLOR_WHITE); + Screen::fillRect(pen, dims.menu_x1, dims.y1+1, dims.menu_x2, dims.y1+1); + + std::string name; + ui_sidebar_menus->zone.selected->getName(&name); + Screen::paintString(pen, dims.menu_x1+1, dims.y1+1, name.substr(0, width)); + } + } +}; + +IMPLEMENT_VMETHOD_INTERPOSE(dwarf_render_zone_hook, render); + static char getBuildingCode(df::building *bld) { CHECK_NULL_POINTER(bld); @@ -142,6 +174,9 @@ KNOWN_BUILDINGS static bool enable_building_rename(char code, bool enable) { + if (code == 'Z') + INTERPOSE_HOOK(dwarf_render_zone_hook, render).apply(enable); + switch (code) { #define BUILDING(code, cname, tag) \ case code: return INTERPOSE_HOOK(cname##_hook, getName).apply(enable); @@ -154,6 +189,8 @@ KNOWN_BUILDINGS static void disable_building_rename() { + INTERPOSE_HOOK(dwarf_render_zone_hook, render).remove(); + #define BUILDING(code, cname, tag) \ INTERPOSE_HOOK(cname##_hook, getName).remove(); KNOWN_BUILDINGS |
