Skip to content

Commit

Permalink
Merge branch 'manipulator_show_squad' from git://github.com/pierredav…
Browse files Browse the repository at this point in the history
…idbelanger/dfhack.git into develop
  • Loading branch information
angavrilov committed Jun 17, 2014
2 parents 32d8efa + 436754d commit 2db73a4
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 40 deletions.
20 changes: 11 additions & 9 deletions Readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.11: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" />
<title>DFHack Readme</title>
<style type="text/css">

Expand Down Expand Up @@ -3374,12 +3374,14 @@ <h2><a class="toc-backref" href="#id161">Dwarf Manipulator</a></h2>
<img alt="images/manipulator.png" src="images/manipulator.png" />
<p>This tool implements a Dwarf Therapist-like interface within the game UI. The
far left column displays the unit's Happiness (color-coded based on its
value), and the right half of the screen displays each dwarf's labor settings
and skill levels (0-9 for Dabbling thru Professional, A-E for Great thru Grand
Master, and U-Z for Legendary thru Legendary+5).</p>
value), Name, Profession/Squad, and the right half of the screen displays each
dwarf's labor settings and skill levels (0-9 for Dabbling thru Professional, A-E for
Great thru Grand Master, and U-Z for Legendary thru Legendary+5).</p>
<p>Cells with teal backgrounds denote skills not controlled by labors, e.g.
military and social skills.</p>
<img alt="images/manipulator2.png" src="images/manipulator2.png" />
<p>Press <tt class="docutils literal">t</tt> to toggle between Profession and Squad view.</p>
<img alt="images/manipulator3.png" src="images/manipulator3.png" />
<p>Use the arrow keys or number pad to move the cursor around, holding Shift to
move 10 tiles at a time.</p>
<p>Press the Z-Up (&lt;) and Z-Down (&gt;) keys to move quickly between labor/skill
Expand All @@ -3388,20 +3390,20 @@ <h2><a class="toc-backref" href="#id161">Dwarf Manipulator</a></h2>
<p>Press Enter to toggle the selected labor for the selected unit, or Shift+Enter
to toggle all labors within the selected category.</p>
<p>Press the <tt class="docutils literal">+-</tt> keys to sort the unit list according to the currently selected
skill/labor, and press the <tt class="docutils literal">*/</tt> keys to sort the unit list by Name, Profession,
skill/labor, and press the <tt class="docutils literal">*/</tt> keys to sort the unit list by Name, Profession/Squad,
Happiness, or Arrival order (using Tab to select which sort method to use here).</p>
<p>With a unit selected, you can press the &quot;v&quot; key to view its properties (and
possibly set a custom nickname or profession) or the &quot;c&quot; key to exit
Manipulator and zoom to its position within your fortress.</p>
<p>The following mouse shortcuts are also available:</p>
<ul class="simple">
<li>Click on a column header to sort the unit list. Left-click to sort it in one
direction (descending for happiness or labors/skills, ascending for name or
profession) and right-click to sort it in the opposite direction.</li>
direction (descending for happiness or labors/skills, ascending for name,
profession or squad) and right-click to sort it in the opposite direction.</li>
<li>Left-click on a labor cell to toggle that labor. Right-click to move the
cursor onto that cell instead of toggling it.</li>
<li>Left-click on a unit's name or profession to view its properties.</li>
<li>Right-click on a unit's name or profession to zoom to it.</li>
<li>Left-click on a unit's name, profession or squad to view its properties.</li>
<li>Right-click on a unit's name, profession or squad to zoom to it.</li>
</ul>
<p>Pressing ESC normally returns to the unit screen, but Shift-ESC would exit
directly to the main dwarf mode screen.</p>
Expand Down
20 changes: 12 additions & 8 deletions Readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2538,15 +2538,19 @@ To activate, open the unit screen and press 'l'.

This tool implements a Dwarf Therapist-like interface within the game UI. The
far left column displays the unit's Happiness (color-coded based on its
value), and the right half of the screen displays each dwarf's labor settings
and skill levels (0-9 for Dabbling thru Professional, A-E for Great thru Grand
Master, and U-Z for Legendary thru Legendary+5).
value), Name, Profession/Squad, and the right half of the screen displays each
dwarf's labor settings and skill levels (0-9 for Dabbling thru Professional, A-E for
Great thru Grand Master, and U-Z for Legendary thru Legendary+5).

Cells with teal backgrounds denote skills not controlled by labors, e.g.
military and social skills.

.. image:: images/manipulator2.png

Press ``t`` to toggle between Profession and Squad view.

.. image:: images/manipulator3.png

Use the arrow keys or number pad to move the cursor around, holding Shift to
move 10 tiles at a time.

Expand All @@ -2558,7 +2562,7 @@ Press Enter to toggle the selected labor for the selected unit, or Shift+Enter
to toggle all labors within the selected category.

Press the ``+-`` keys to sort the unit list according to the currently selected
skill/labor, and press the ``*/`` keys to sort the unit list by Name, Profession,
skill/labor, and press the ``*/`` keys to sort the unit list by Name, Profession/Squad,
Happiness, or Arrival order (using Tab to select which sort method to use here).

With a unit selected, you can press the "v" key to view its properties (and
Expand All @@ -2568,12 +2572,12 @@ Manipulator and zoom to its position within your fortress.
The following mouse shortcuts are also available:

* Click on a column header to sort the unit list. Left-click to sort it in one
direction (descending for happiness or labors/skills, ascending for name or
profession) and right-click to sort it in the opposite direction.
direction (descending for happiness or labors/skills, ascending for name,
profession or squad) and right-click to sort it in the opposite direction.
* Left-click on a labor cell to toggle that labor. Right-click to move the
cursor onto that cell instead of toggling it.
* Left-click on a unit's name or profession to view its properties.
* Right-click on a unit's name or profession to zoom to it.
* Left-click on a unit's name, profession or squad to view its properties.
* Right-click on a unit's name, profession or squad to zoom to it.

Pressing ESC normally returns to the unit screen, but Shift-ESC would exit
directly to the main dwarf mode screen.
Expand Down
Binary file modified images/manipulator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/manipulator2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/manipulator3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions library/include/modules/Units.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ DFHACK_EXPORT std::string getCasteProfessionName(int race, int caste, df::profes

DFHACK_EXPORT int8_t getProfessionColor(df::unit *unit, bool ignore_noble = false);
DFHACK_EXPORT int8_t getCasteProfessionColor(int race, int caste, df::profession pid);

DFHACK_EXPORT std::string getSquadName(df::unit *unit);
}
}
#endif
13 changes: 13 additions & 0 deletions library/modules/Units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ using namespace std;
#include "df/unit_misc_trait.h"
#include "df/unit_skill.h"
#include "df/curse_attr_change.h"
#include "df/squad.h"

using namespace DFHack;
using namespace df::enums;
Expand Down Expand Up @@ -1552,3 +1553,15 @@ int8_t DFHack::Units::getCasteProfessionColor(int race, int casteid, df::profess
// default to dwarven peasant color
return 3;
}

std::string DFHack::Units::getSquadName(df::unit *unit)
{
if (unit->military.squad_id == -1)
return "";
df::squad *squad = df::squad::find(unit->military.squad_id);
if (!squad)
return "";
if (squad->alias.size() > 0)
return squad->alias;
return Translation::TranslateName(&squad->name, true);
}
108 changes: 85 additions & 23 deletions plugins/manipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,13 @@ struct UnitInfo
string profession;
int8_t color;
int active_index;
string squad_effective_name;
string squad_info;
};

enum altsort_mode {
ALTSORT_NAME,
ALTSORT_PROFESSION,
ALTSORT_PROFESSION_OR_SQUAD,
ALTSORT_HAPPINESS,
ALTSORT_ARRIVAL,
ALTSORT_MAX
Expand All @@ -278,6 +280,22 @@ bool sortByProfession (const UnitInfo *d1, const UnitInfo *d2)
return (d1->profession < d2->profession);
}

bool sortBySquad (const UnitInfo *d1, const UnitInfo *d2)
{
bool gt = false;
if (d1->unit->military.squad_id == -1 && d2->unit->military.squad_id == -1)
gt = d1->name > d2->name;
else if (d1->unit->military.squad_id == -1)
gt = true;
else if (d2->unit->military.squad_id == -1)
gt = false;
else if (d1->unit->military.squad_id != d2->unit->military.squad_id)
gt = d1->squad_effective_name > d2->squad_effective_name;
else
gt = d1->unit->military.squad_position > d2->unit->military.squad_position;
return descending ? gt : !gt;
}

bool sortByHappiness (const UnitInfo *d1, const UnitInfo *d2)
{
if (descending)
Expand Down Expand Up @@ -336,7 +354,7 @@ bool sortBySkill (const UnitInfo *d1, const UnitInfo *d2)
enum display_columns {
DISP_COLUMN_HAPPINESS,
DISP_COLUMN_NAME,
DISP_COLUMN_PROFESSION,
DISP_COLUMN_PROFESSION_OR_SQUAD,
DISP_COLUMN_LABORS,
DISP_COLUMN_MAX,
};
Expand Down Expand Up @@ -366,6 +384,7 @@ class viewscreen_unitlaborsst : public dfhack_viewscreen {
protected:
vector<UnitInfo *> units;
altsort_mode altsort;
bool show_squad;

bool do_refresh_names;
int first_row, sel_row, num_rows;
Expand Down Expand Up @@ -418,6 +437,7 @@ viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src, int cur
units.push_back(cur);
}
altsort = ALTSORT_NAME;
show_squad = false;
first_column = sel_column = 0;

refreshNames();
Expand Down Expand Up @@ -450,6 +470,13 @@ void viewscreen_unitlaborsst::refreshNames()
cur->name = Translation::TranslateName(Units::getVisibleName(unit), false);
cur->transname = Translation::TranslateName(Units::getVisibleName(unit), true);
cur->profession = Units::getProfessionName(unit);
if (unit->military.squad_id > -1) {
cur->squad_effective_name = Units::getSquadName(unit);
cur->squad_info = stl_sprintf("%i", unit->military.squad_position + 1) + "." + cur->squad_effective_name;
} else {
cur->squad_effective_name = "";
cur->squad_info = "";
}
}
calcSize();
}
Expand All @@ -458,7 +485,7 @@ void viewscreen_unitlaborsst::calcSize()
{
auto dim = Screen::getWindowSize();

num_rows = dim.y - 10;
num_rows = dim.y - 11;
if (num_rows > units.size())
num_rows = units.size();

Expand All @@ -471,8 +498,8 @@ void viewscreen_unitlaborsst::calcSize()
col_maxwidth[DISP_COLUMN_HAPPINESS] = 4;
col_minwidth[DISP_COLUMN_NAME] = 16;
col_maxwidth[DISP_COLUMN_NAME] = 16; // adjusted in the loop below
col_minwidth[DISP_COLUMN_PROFESSION] = 10;
col_maxwidth[DISP_COLUMN_PROFESSION] = 10; // adjusted in the loop below
col_minwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10;
col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10; // adjusted in the loop below
col_minwidth[DISP_COLUMN_LABORS] = num_columns*3/5; // 60%
col_maxwidth[DISP_COLUMN_LABORS] = NUM_COLUMNS;

Expand All @@ -481,8 +508,13 @@ void viewscreen_unitlaborsst::calcSize()
{
if (col_maxwidth[DISP_COLUMN_NAME] < units[i]->name.size())
col_maxwidth[DISP_COLUMN_NAME] = units[i]->name.size();
if (col_maxwidth[DISP_COLUMN_PROFESSION] < units[i]->profession.size())
col_maxwidth[DISP_COLUMN_PROFESSION] = units[i]->profession.size();
if (show_squad) {
if (col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] < units[i]->squad_info.size())
col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = units[i]->squad_info.size();
} else {
if (col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] < units[i]->profession.size())
col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = units[i]->profession.size();
}
}

// check how much room we have
Expand Down Expand Up @@ -753,10 +785,10 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
}
break;

case DISP_COLUMN_PROFESSION:
case DISP_COLUMN_PROFESSION_OR_SQUAD:
if (enabler->mouse_lbut || enabler->mouse_rbut)
{
input_sort = ALTSORT_PROFESSION;
input_sort = ALTSORT_PROFESSION_OR_SQUAD;
if (enabler->mouse_lbut)
events->insert(interface_key::SECONDSCROLL_PAGEDOWN);
if (enabler->mouse_rbut)
Expand All @@ -783,7 +815,7 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
break;

case DISP_COLUMN_NAME:
case DISP_COLUMN_PROFESSION:
case DISP_COLUMN_PROFESSION_OR_SQUAD:
// left-click to view, right-click to zoom
if (enabler->mouse_lbut)
{
Expand Down Expand Up @@ -879,8 +911,8 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
case ALTSORT_NAME:
std::sort(units.begin(), units.end(), sortByName);
break;
case ALTSORT_PROFESSION:
std::sort(units.begin(), units.end(), sortByProfession);
case ALTSORT_PROFESSION_OR_SQUAD:
std::sort(units.begin(), units.end(), show_squad ? sortBySquad : sortByProfession);
break;
case ALTSORT_HAPPINESS:
std::sort(units.begin(), units.end(), sortByHappiness);
Expand All @@ -895,9 +927,9 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
switch (altsort)
{
case ALTSORT_NAME:
altsort = ALTSORT_PROFESSION;
altsort = ALTSORT_PROFESSION_OR_SQUAD;
break;
case ALTSORT_PROFESSION:
case ALTSORT_PROFESSION_OR_SQUAD:
altsort = ALTSORT_HAPPINESS;
break;
case ALTSORT_HAPPINESS:
Expand All @@ -908,6 +940,10 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
break;
}
}
if (events->count(interface_key::OPTION20))
{
show_squad = !show_squad;
}

if (VIRTUAL_CAST_VAR(unitlist, df::viewscreen_unitlistst, parent))
{
Expand Down Expand Up @@ -949,7 +985,7 @@ void viewscreen_unitlaborsst::render()

Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_HAPPINESS], 2, "Hap.");
Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_NAME], 2, "Name");
Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_PROFESSION], 2, "Profession");
Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_PROFESSION_OR_SQUAD], 2, show_squad ? "Squad" : "Profession");

for (int col = 0; col < col_widths[DISP_COLUMN_LABORS]; col++)
{
Expand Down Expand Up @@ -1019,12 +1055,17 @@ void viewscreen_unitlaborsst::render()
name.resize(col_widths[DISP_COLUMN_NAME]);
Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_NAME], 4 + row, name);

string profession = cur->profession;
profession.resize(col_widths[DISP_COLUMN_PROFESSION]);
fg = cur->color;
bg = 0;

Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_PROFESSION], 4 + row, profession);
string profession_or_squad;
if (show_squad) {
fg = 11;
profession_or_squad = cur->squad_info;
} else {
fg = cur->color;
profession_or_squad = cur->profession;
}
profession_or_squad.resize(col_widths[DISP_COLUMN_PROFESSION_OR_SQUAD]);
Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_PROFESSION_OR_SQUAD], 4 + row, profession_or_squad);

// Print unit's skills and labor assignments
for (int col = 0; col < col_widths[DISP_COLUMN_LABORS]; col++)
Expand Down Expand Up @@ -1114,7 +1155,25 @@ void viewscreen_unitlaborsst::render()
else
str = stl_sprintf("Not %s (0/500)", ENUM_ATTR_STR(job_skill, caption_noun, columns[sel_column].skill));
}
Screen::paintString(Screen::Pen(' ', 9, 0), x, 3 + num_rows + 2, str);
Screen::paintString(Screen::Pen(' ', 9, 0), x, y, str);

if (cur->unit->military.squad_id > -1) {

x = 1;
y++;

string squadLabel = "Squad: ";
Screen::paintString(white_pen, x, y, squadLabel);
x += squadLabel.size();

string squad = cur->squad_effective_name;
Screen::paintString(Screen::Pen(' ', 11, 0), x, y, squad);
x += squad.size();

string pos = stl_sprintf(" Pos %i", cur->unit->military.squad_position + 1);
Screen::paintString(Screen::Pen(' ', 9, 0), x, y, pos);

}

canToggle = (cur->allowEdit) && (columns[sel_column].labor != unit_labor::NONE);
}
Expand All @@ -1136,6 +1195,9 @@ void viewscreen_unitlaborsst::render()
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::LEAVESCREEN));
OutputString(15, x, y, ": Done, ");

OutputString(10, x, y, Screen::getKeyDisplay(interface_key::OPTION20));
OutputString(15, x, y, ": Toggle View, ");

OutputString(10, x, y, Screen::getKeyDisplay(interface_key::SECONDSCROLL_DOWN));
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::SECONDSCROLL_UP));
OutputString(15, x, y, ": Sort by Skill, ");
Expand All @@ -1150,8 +1212,8 @@ void viewscreen_unitlaborsst::render()
case ALTSORT_NAME:
OutputString(15, x, y, "Name");
break;
case ALTSORT_PROFESSION:
OutputString(15, x, y, "Profession");
case ALTSORT_PROFESSION_OR_SQUAD:
OutputString(15, x, y, show_squad ? "Squad" : "Profession");
break;
case ALTSORT_HAPPINESS:
OutputString(15, x, y, "Happiness");
Expand Down

0 comments on commit 2db73a4

Please sign in to comment.