Allow to toggle between Profession and Squad view instead of wasting screen space with a new column

develop
Pierre-David Bélanger 2014-06-10 22:59:28 -04:00
parent e0808c8c96
commit a751df4219
1 changed files with 43 additions and 57 deletions

@ -254,8 +254,7 @@ struct UnitInfo
enum altsort_mode { enum altsort_mode {
ALTSORT_NAME, ALTSORT_NAME,
ALTSORT_PROFESSION, ALTSORT_PROFESSION_OR_SQUAD,
ALTSORT_SQUAD,
ALTSORT_HAPPINESS, ALTSORT_HAPPINESS,
ALTSORT_ARRIVAL, ALTSORT_ARRIVAL,
ALTSORT_MAX ALTSORT_MAX
@ -355,8 +354,7 @@ bool sortBySkill (const UnitInfo *d1, const UnitInfo *d2)
enum display_columns { enum display_columns {
DISP_COLUMN_HAPPINESS, DISP_COLUMN_HAPPINESS,
DISP_COLUMN_NAME, DISP_COLUMN_NAME,
DISP_COLUMN_PROFESSION, DISP_COLUMN_PROFESSION_OR_SQUAD,
DISP_COLUMN_SQUAD,
DISP_COLUMN_LABORS, DISP_COLUMN_LABORS,
DISP_COLUMN_MAX, DISP_COLUMN_MAX,
}; };
@ -386,6 +384,7 @@ public:
protected: protected:
vector<UnitInfo *> units; vector<UnitInfo *> units;
altsort_mode altsort; altsort_mode altsort;
bool show_squad;
bool do_refresh_names; bool do_refresh_names;
int first_row, sel_row, num_rows; int first_row, sel_row, num_rows;
@ -438,6 +437,7 @@ viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src, int cur
units.push_back(cur); units.push_back(cur);
} }
altsort = ALTSORT_NAME; altsort = ALTSORT_NAME;
show_squad = false;
first_column = sel_column = 0; first_column = sel_column = 0;
refreshNames(); refreshNames();
@ -496,13 +496,11 @@ void viewscreen_unitlaborsst::calcSize()
int col_maxwidth[DISP_COLUMN_MAX]; int col_maxwidth[DISP_COLUMN_MAX];
col_minwidth[DISP_COLUMN_HAPPINESS] = 4; col_minwidth[DISP_COLUMN_HAPPINESS] = 4;
col_maxwidth[DISP_COLUMN_HAPPINESS] = 4; col_maxwidth[DISP_COLUMN_HAPPINESS] = 4;
col_minwidth[DISP_COLUMN_NAME] = 12; col_minwidth[DISP_COLUMN_NAME] = 16;
col_maxwidth[DISP_COLUMN_NAME] = 12; // adjusted in the loop below col_maxwidth[DISP_COLUMN_NAME] = 16; // adjusted in the loop below
col_minwidth[DISP_COLUMN_PROFESSION] = 10; col_minwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10;
col_maxwidth[DISP_COLUMN_PROFESSION] = 10; // adjusted in the loop below col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = 10; // adjusted in the loop below
col_minwidth[DISP_COLUMN_SQUAD] = 10; col_minwidth[DISP_COLUMN_LABORS] = num_columns*3/5; // 60%
col_maxwidth[DISP_COLUMN_SQUAD] = 10; // adjusted in the loop below
col_minwidth[DISP_COLUMN_LABORS] = num_columns / 2; // 50%
col_maxwidth[DISP_COLUMN_LABORS] = NUM_COLUMNS; col_maxwidth[DISP_COLUMN_LABORS] = NUM_COLUMNS;
// get max_name/max_prof from strings length // get max_name/max_prof from strings length
@ -510,10 +508,13 @@ void viewscreen_unitlaborsst::calcSize()
{ {
if (col_maxwidth[DISP_COLUMN_NAME] < units[i]->name.size()) if (col_maxwidth[DISP_COLUMN_NAME] < units[i]->name.size())
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()) if (show_squad) {
col_maxwidth[DISP_COLUMN_PROFESSION] = units[i]->profession.size(); if (col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] < units[i]->squad_info.size())
if (col_maxwidth[DISP_COLUMN_SQUAD] < units[i]->squad_info.size()) col_maxwidth[DISP_COLUMN_PROFESSION_OR_SQUAD] = units[i]->squad_info.size();
col_maxwidth[DISP_COLUMN_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 // check how much room we have
@ -784,21 +785,10 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
} }
break; break;
case DISP_COLUMN_PROFESSION: case DISP_COLUMN_PROFESSION_OR_SQUAD:
if (enabler->mouse_lbut || enabler->mouse_rbut)
{
input_sort = ALTSORT_PROFESSION;
if (enabler->mouse_lbut)
events->insert(interface_key::SECONDSCROLL_PAGEDOWN);
if (enabler->mouse_rbut)
events->insert(interface_key::SECONDSCROLL_PAGEUP);
}
break;
case DISP_COLUMN_SQUAD:
if (enabler->mouse_lbut || enabler->mouse_rbut) if (enabler->mouse_lbut || enabler->mouse_rbut)
{ {
input_sort = ALTSORT_SQUAD; input_sort = ALTSORT_PROFESSION_OR_SQUAD;
if (enabler->mouse_lbut) if (enabler->mouse_lbut)
events->insert(interface_key::SECONDSCROLL_PAGEDOWN); events->insert(interface_key::SECONDSCROLL_PAGEDOWN);
if (enabler->mouse_rbut) if (enabler->mouse_rbut)
@ -825,8 +815,7 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
break; break;
case DISP_COLUMN_NAME: case DISP_COLUMN_NAME:
case DISP_COLUMN_PROFESSION: case DISP_COLUMN_PROFESSION_OR_SQUAD:
case DISP_COLUMN_SQUAD:
// left-click to view, right-click to zoom // left-click to view, right-click to zoom
if (enabler->mouse_lbut) if (enabler->mouse_lbut)
{ {
@ -922,11 +911,8 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
case ALTSORT_NAME: case ALTSORT_NAME:
std::sort(units.begin(), units.end(), sortByName); std::sort(units.begin(), units.end(), sortByName);
break; break;
case ALTSORT_PROFESSION: case ALTSORT_PROFESSION_OR_SQUAD:
std::sort(units.begin(), units.end(), sortByProfession); std::sort(units.begin(), units.end(), show_squad ? sortBySquad : sortByProfession);
break;
case ALTSORT_SQUAD:
std::sort(units.begin(), units.end(), sortBySquad);
break; break;
case ALTSORT_HAPPINESS: case ALTSORT_HAPPINESS:
std::sort(units.begin(), units.end(), sortByHappiness); std::sort(units.begin(), units.end(), sortByHappiness);
@ -941,12 +927,9 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
switch (altsort) switch (altsort)
{ {
case ALTSORT_NAME: case ALTSORT_NAME:
altsort = ALTSORT_PROFESSION; altsort = ALTSORT_PROFESSION_OR_SQUAD;
break; break;
case ALTSORT_PROFESSION: case ALTSORT_PROFESSION_OR_SQUAD:
altsort = ALTSORT_SQUAD;
break;
case ALTSORT_SQUAD:
altsort = ALTSORT_HAPPINESS; altsort = ALTSORT_HAPPINESS;
break; break;
case ALTSORT_HAPPINESS: case ALTSORT_HAPPINESS:
@ -957,6 +940,10 @@ void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
break; break;
} }
} }
if (events->count(interface_key::OPTION20))
{
show_squad = !show_squad;
}
if (VIRTUAL_CAST_VAR(unitlist, df::viewscreen_unitlistst, parent)) if (VIRTUAL_CAST_VAR(unitlist, df::viewscreen_unitlistst, parent))
{ {
@ -998,8 +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_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_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");
Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_SQUAD], 2, "Squad");
for (int col = 0; col < col_widths[DISP_COLUMN_LABORS]; col++) for (int col = 0; col < col_widths[DISP_COLUMN_LABORS]; col++)
{ {
@ -1069,17 +1055,17 @@ void viewscreen_unitlaborsst::render()
name.resize(col_widths[DISP_COLUMN_NAME]); name.resize(col_widths[DISP_COLUMN_NAME]);
Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_NAME], 4 + row, 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; bg = 0;
string profession_or_squad;
Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_PROFESSION], 4 + row, profession); if (show_squad) {
fg = 11;
fg = 15; profession_or_squad = cur->squad_info;
string squad = cur->squad_info; } else {
squad.resize(col_widths[DISP_COLUMN_SQUAD]); fg = cur->color;
Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_SQUAD], 4 + row, squad); 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 // Print unit's skills and labor assignments
for (int col = 0; col < col_widths[DISP_COLUMN_LABORS]; col++) for (int col = 0; col < col_widths[DISP_COLUMN_LABORS]; col++)
@ -1209,6 +1195,9 @@ void viewscreen_unitlaborsst::render()
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::LEAVESCREEN)); OutputString(10, x, y, Screen::getKeyDisplay(interface_key::LEAVESCREEN));
OutputString(15, x, y, ": Done, "); 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_DOWN));
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::SECONDSCROLL_UP)); OutputString(10, x, y, Screen::getKeyDisplay(interface_key::SECONDSCROLL_UP));
OutputString(15, x, y, ": Sort by Skill, "); OutputString(15, x, y, ": Sort by Skill, ");
@ -1223,11 +1212,8 @@ void viewscreen_unitlaborsst::render()
case ALTSORT_NAME: case ALTSORT_NAME:
OutputString(15, x, y, "Name"); OutputString(15, x, y, "Name");
break; break;
case ALTSORT_PROFESSION: case ALTSORT_PROFESSION_OR_SQUAD:
OutputString(15, x, y, "Profession"); OutputString(15, x, y, show_squad ? "Squad" : "Profession");
break;
case ALTSORT_SQUAD:
OutputString(15, x, y, "Squad");
break; break;
case ALTSORT_HAPPINESS: case ALTSORT_HAPPINESS:
OutputString(15, x, y, "Happiness"); OutputString(15, x, y, "Happiness");