Merge branch 'manipulator_show_squad' from git://github.com/pierredavidbelanger/dfhack.git into develop

develop
Alexander Gavrilov 2014-06-17 10:39:26 +04:00
commit 2db73a407d
8 changed files with 123 additions and 40 deletions

@ -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">
@ -3374,12 +3374,14 @@ you must enable the plugins which provide them.</p>
<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
@ -3388,7 +3390,7 @@ in the list. Backspace seeks to the top left corner.</p>
<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
@ -3396,12 +3398,12 @@ 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>

@ -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.
@ -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
@ -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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

@ -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

@ -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;
@ -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);
}

@ -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
@ -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)
@ -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,
};
@ -366,6 +384,7 @@ public:
protected:
vector<UnitInfo *> units;
altsort_mode altsort;
bool show_squad;
bool do_refresh_names;
int first_row, sel_row, num_rows;
@ -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();
@ -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();
}
@ -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();
@ -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;
@ -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
@ -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)
@ -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)
{
@ -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);
@ -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:
@ -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))
{
@ -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++)
{
@ -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++)
@ -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);
}
@ -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, ");
@ -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");