From 1f7c10252e79415bf56c461cd2eb19a5018433fb Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Thu, 20 Sep 2012 11:48:53 +0400
Subject: Support renaming activity zones.
This one required hooking the dwarfmode render method.
---
README.rst | 8 +++++---
Readme.html | 8 +++++---
plugins/rename.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 52 insertions(+), 11 deletions(-)
diff --git a/README.rst b/README.rst
index 589451a9..9e3d5d3f 100644
--- a/README.rst
+++ b/README.rst
@@ -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.
| 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.
@@ -2423,7 +2424,8 @@ configuration page, but configures parameters relevant to the modded power meter
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.
@@ -2497,7 +2499,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.
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
#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 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
--
cgit v1.2.1