2012-08-22 19:52:19 -06:00
|
|
|
// Dwarf Manipulator - a Therapist-style labor editor
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
#include "Core.h"
|
|
|
|
#include <Console.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <PluginManager.h>
|
|
|
|
#include <MiscUtils.h>
|
|
|
|
#include <modules/Screen.h>
|
|
|
|
#include <modules/Translation.h>
|
2012-08-22 10:15:05 -06:00
|
|
|
#include <modules/Units.h>
|
2015-01-08 18:55:37 -07:00
|
|
|
#include <modules/Filesystem.h>
|
2015-02-17 15:17:26 -07:00
|
|
|
#include <modules/Job.h>
|
2012-08-21 14:43:32 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <set>
|
2012-08-25 09:57:50 -06:00
|
|
|
#include <algorithm>
|
2015-03-24 10:25:50 -06:00
|
|
|
#include <tuple>
|
2012-08-21 14:43:32 -06:00
|
|
|
|
|
|
|
#include <VTableInterpose.h>
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/graphic.h"
|
|
|
|
#include "df/enabler.h"
|
|
|
|
#include "df/viewscreen_unitlistst.h"
|
|
|
|
#include "df/interface_key.h"
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/unit_soul.h"
|
|
|
|
#include "df/unit_skill.h"
|
2012-08-30 08:46:09 -06:00
|
|
|
#include "df/creature_graphics_role.h"
|
2012-08-21 15:41:20 -06:00
|
|
|
#include "df/creature_raw.h"
|
|
|
|
#include "df/caste_raw.h"
|
2014-06-24 07:36:36 -06:00
|
|
|
#include "df/historical_entity.h"
|
|
|
|
#include "df/entity_raw.h"
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2015-01-08 21:19:06 -07:00
|
|
|
#include "uicommon.h"
|
2015-07-28 19:48:00 -06:00
|
|
|
#include "listcolumn.h"
|
2015-01-08 21:19:06 -07:00
|
|
|
|
2015-01-09 13:05:49 -07:00
|
|
|
using std::stringstream;
|
2012-08-21 14:43:32 -06:00
|
|
|
using std::set;
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
2014-12-06 16:47:35 -07:00
|
|
|
DFHACK_PLUGIN("manipulator");
|
|
|
|
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
|
|
|
|
REQUIRE_GLOBAL(world);
|
|
|
|
REQUIRE_GLOBAL(ui);
|
|
|
|
REQUIRE_GLOBAL(gps);
|
|
|
|
REQUIRE_GLOBAL(enabler);
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2015-01-08 18:55:37 -07:00
|
|
|
#define CONFIG_PATH "manipulator"
|
|
|
|
|
2012-08-22 19:52:19 -06:00
|
|
|
struct SkillLevel
|
2012-08-21 15:41:20 -06:00
|
|
|
{
|
2012-08-25 09:57:50 -06:00
|
|
|
const char *name;
|
|
|
|
int points;
|
|
|
|
char abbrev;
|
2012-08-22 19:52:19 -06:00
|
|
|
};
|
2012-08-21 15:41:20 -06:00
|
|
|
|
2012-08-25 09:57:50 -06:00
|
|
|
#define NUM_SKILL_LEVELS (sizeof(skill_levels) / sizeof(SkillLevel))
|
2012-08-21 15:41:20 -06:00
|
|
|
|
|
|
|
// The various skill rankings. Zero skill is hardcoded to "Not" and '-'.
|
|
|
|
const SkillLevel skill_levels[] = {
|
2012-08-25 09:57:50 -06:00
|
|
|
{"Dabbling", 500, '0'},
|
|
|
|
{"Novice", 600, '1'},
|
|
|
|
{"Adequate", 700, '2'},
|
|
|
|
{"Competent", 800, '3'},
|
|
|
|
{"Skilled", 900, '4'},
|
|
|
|
{"Proficient", 1000, '5'},
|
|
|
|
{"Talented", 1100, '6'},
|
|
|
|
{"Adept", 1200, '7'},
|
|
|
|
{"Expert", 1300, '8'},
|
|
|
|
{"Professional",1400, '9'},
|
|
|
|
{"Accomplished",1500, 'A'},
|
|
|
|
{"Great", 1600, 'B'},
|
|
|
|
{"Master", 1700, 'C'},
|
|
|
|
{"High Master", 1800, 'D'},
|
|
|
|
{"Grand Master",1900, 'E'},
|
|
|
|
{"Legendary", 2000, 'U'},
|
|
|
|
{"Legendary+1", 2100, 'V'},
|
|
|
|
{"Legendary+2", 2200, 'W'},
|
|
|
|
{"Legendary+3", 2300, 'X'},
|
|
|
|
{"Legendary+4", 2400, 'Y'},
|
|
|
|
{"Legendary+5", 0, 'Z'}
|
2012-08-21 15:41:20 -06:00
|
|
|
};
|
|
|
|
|
2012-08-22 19:52:19 -06:00
|
|
|
struct SkillColumn
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
2012-08-30 08:46:09 -06:00
|
|
|
int group; // for navigation and mass toggling
|
|
|
|
int8_t color; // for column headers
|
|
|
|
df::profession profession; // to display graphical tiles
|
|
|
|
df::unit_labor labor; // toggled when pressing Enter
|
|
|
|
df::job_skill skill; // displayed rating
|
|
|
|
char label[3]; // column header
|
2012-08-21 14:43:32 -06:00
|
|
|
bool special; // specified labor is mutually exclusive with all other special labors
|
2014-06-24 07:36:36 -06:00
|
|
|
bool isValidLabor (df::historical_entity *entity = NULL) const
|
|
|
|
{
|
|
|
|
if (labor == unit_labor::NONE)
|
|
|
|
return false;
|
|
|
|
if (entity && entity->entity_raw && !entity->entity_raw->jobs.permitted_labor[labor])
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-22 19:52:19 -06:00
|
|
|
};
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-08-25 09:57:50 -06:00
|
|
|
#define NUM_COLUMNS (sizeof(columns) / sizeof(SkillColumn))
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-08-30 08:46:09 -06:00
|
|
|
// All of the skill/labor columns we want to display.
|
2012-08-21 15:41:20 -06:00
|
|
|
const SkillColumn columns[] = {
|
2012-08-21 14:43:32 -06:00
|
|
|
// Mining
|
2015-03-25 13:04:52 -06:00
|
|
|
{0, 7, profession::MINER, unit_labor::MINE, job_skill::MINING, "Mi", true},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Woodworking
|
2015-03-25 13:04:52 -06:00
|
|
|
{1, 14, profession::CARPENTER, unit_labor::CARPENTER, job_skill::CARPENTRY, "Ca"},
|
|
|
|
{1, 14, profession::BOWYER, unit_labor::BOWYER, job_skill::BOWYER, "Bw"},
|
|
|
|
{1, 14, profession::WOODCUTTER, unit_labor::CUTWOOD, job_skill::WOODCUTTING, "WC", true},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Stoneworking
|
2015-03-25 13:04:52 -06:00
|
|
|
{2, 15, profession::MASON, unit_labor::MASON, job_skill::MASONRY, "Ma"},
|
|
|
|
{2, 15, profession::ENGRAVER, unit_labor::DETAIL, job_skill::DETAILSTONE, "En"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Hunting/Related
|
2015-03-25 13:04:52 -06:00
|
|
|
{3, 2, profession::ANIMAL_TRAINER, unit_labor::ANIMALTRAIN, job_skill::ANIMALTRAIN, "Tn"},
|
|
|
|
{3, 2, profession::ANIMAL_CARETAKER, unit_labor::ANIMALCARE, job_skill::ANIMALCARE, "Ca"},
|
|
|
|
{3, 2, profession::HUNTER, unit_labor::HUNT, job_skill::SNEAK, "Hu", true},
|
|
|
|
{3, 2, profession::TRAPPER, unit_labor::TRAPPER, job_skill::TRAPPING, "Tr"},
|
|
|
|
{3, 2, profession::ANIMAL_DISSECTOR, unit_labor::DISSECT_VERMIN, job_skill::DISSECT_VERMIN, "Di"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Healthcare
|
2015-03-25 13:04:52 -06:00
|
|
|
{4, 5, profession::DIAGNOSER, unit_labor::DIAGNOSE, job_skill::DIAGNOSE, "Di"},
|
|
|
|
{4, 5, profession::SURGEON, unit_labor::SURGERY, job_skill::SURGERY, "Su"},
|
|
|
|
{4, 5, profession::BONE_SETTER, unit_labor::BONE_SETTING, job_skill::SET_BONE, "Bo"},
|
|
|
|
{4, 5, profession::SUTURER, unit_labor::SUTURING, job_skill::SUTURE, "St"},
|
|
|
|
{4, 5, profession::DOCTOR, unit_labor::DRESSING_WOUNDS, job_skill::DRESS_WOUNDS, "Dr"},
|
|
|
|
{4, 5, profession::NONE, unit_labor::FEED_WATER_CIVILIANS, job_skill::NONE, "Fd"},
|
|
|
|
{4, 5, profession::NONE, unit_labor::RECOVER_WOUNDED, job_skill::NONE, "Re"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Farming/Related
|
2015-03-25 13:04:52 -06:00
|
|
|
{5, 6, profession::BUTCHER, unit_labor::BUTCHER, job_skill::BUTCHER, "Bu"},
|
|
|
|
{5, 6, profession::TANNER, unit_labor::TANNER, job_skill::TANNER, "Ta"},
|
|
|
|
{5, 6, profession::PLANTER, unit_labor::PLANT, job_skill::PLANT, "Gr"},
|
|
|
|
{5, 6, profession::DYER, unit_labor::DYER, job_skill::DYER, "Dy"},
|
|
|
|
{5, 6, profession::SOAP_MAKER, unit_labor::SOAP_MAKER, job_skill::SOAP_MAKING, "So"},
|
|
|
|
{5, 6, profession::WOOD_BURNER, unit_labor::BURN_WOOD, job_skill::WOOD_BURNING, "WB"},
|
|
|
|
{5, 6, profession::POTASH_MAKER, unit_labor::POTASH_MAKING, job_skill::POTASH_MAKING, "Po"},
|
|
|
|
{5, 6, profession::LYE_MAKER, unit_labor::LYE_MAKING, job_skill::LYE_MAKING, "Ly"},
|
|
|
|
{5, 6, profession::MILLER, unit_labor::MILLER, job_skill::MILLING, "Ml"},
|
|
|
|
{5, 6, profession::BREWER, unit_labor::BREWER, job_skill::BREWING, "Br"},
|
|
|
|
{5, 6, profession::HERBALIST, unit_labor::HERBALIST, job_skill::HERBALISM, "He"},
|
|
|
|
{5, 6, profession::THRESHER, unit_labor::PROCESS_PLANT, job_skill::PROCESSPLANTS, "Th"},
|
|
|
|
{5, 6, profession::CHEESE_MAKER, unit_labor::MAKE_CHEESE, job_skill::CHEESEMAKING, "Ch"},
|
|
|
|
{5, 6, profession::MILKER, unit_labor::MILK, job_skill::MILK, "Mk"},
|
|
|
|
{5, 6, profession::SHEARER, unit_labor::SHEARER, job_skill::SHEARING, "Sh"},
|
|
|
|
{5, 6, profession::SPINNER, unit_labor::SPINNER, job_skill::SPINNING, "Sp"},
|
|
|
|
{5, 6, profession::COOK, unit_labor::COOK, job_skill::COOK, "Co"},
|
|
|
|
{5, 6, profession::PRESSER, unit_labor::PRESSING, job_skill::PRESSING, "Pr"},
|
|
|
|
{5, 6, profession::BEEKEEPER, unit_labor::BEEKEEPING, job_skill::BEEKEEPING, "Be"},
|
|
|
|
{5, 6, profession::GELDER, unit_labor::GELD, job_skill::GELD, "Ge"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Fishing/Related
|
2015-03-25 13:04:52 -06:00
|
|
|
{6, 1, profession::FISHERMAN, unit_labor::FISH, job_skill::FISH, "Fi"},
|
|
|
|
{6, 1, profession::FISH_CLEANER, unit_labor::CLEAN_FISH, job_skill::PROCESSFISH, "Cl"},
|
|
|
|
{6, 1, profession::FISH_DISSECTOR, unit_labor::DISSECT_FISH, job_skill::DISSECT_FISH, "Di"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Metalsmithing
|
2015-03-25 13:04:52 -06:00
|
|
|
{7, 8, profession::FURNACE_OPERATOR, unit_labor::SMELT, job_skill::SMELT, "Fu"},
|
|
|
|
{7, 8, profession::WEAPONSMITH, unit_labor::FORGE_WEAPON, job_skill::FORGE_WEAPON, "We"},
|
|
|
|
{7, 8, profession::ARMORER, unit_labor::FORGE_ARMOR, job_skill::FORGE_ARMOR, "Ar"},
|
|
|
|
{7, 8, profession::BLACKSMITH, unit_labor::FORGE_FURNITURE, job_skill::FORGE_FURNITURE, "Bl"},
|
|
|
|
{7, 8, profession::METALCRAFTER, unit_labor::METAL_CRAFT, job_skill::METALCRAFT, "Cr"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Jewelry
|
2015-03-25 13:04:52 -06:00
|
|
|
{8, 10, profession::GEM_CUTTER, unit_labor::CUT_GEM, job_skill::CUTGEM, "Cu"},
|
|
|
|
{8, 10, profession::GEM_SETTER, unit_labor::ENCRUST_GEM, job_skill::ENCRUSTGEM, "Se"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Crafts
|
2015-03-25 13:04:52 -06:00
|
|
|
{9, 9, profession::LEATHERWORKER, unit_labor::LEATHER, job_skill::LEATHERWORK, "Le"},
|
|
|
|
{9, 9, profession::WOODCRAFTER, unit_labor::WOOD_CRAFT, job_skill::WOODCRAFT, "Wo"},
|
|
|
|
{9, 9, profession::STONECRAFTER, unit_labor::STONE_CRAFT, job_skill::STONECRAFT, "St"},
|
|
|
|
{9, 9, profession::BONE_CARVER, unit_labor::BONE_CARVE, job_skill::BONECARVE, "Bo"},
|
|
|
|
{9, 9, profession::GLASSMAKER, unit_labor::GLASSMAKER, job_skill::GLASSMAKER, "Gl"},
|
|
|
|
{9, 9, profession::WEAVER, unit_labor::WEAVER, job_skill::WEAVING, "We"},
|
|
|
|
{9, 9, profession::CLOTHIER, unit_labor::CLOTHESMAKER, job_skill::CLOTHESMAKING, "Cl"},
|
|
|
|
{9, 9, profession::STRAND_EXTRACTOR, unit_labor::EXTRACT_STRAND, job_skill::EXTRACT_STRAND, "Ad"},
|
|
|
|
{9, 9, profession::POTTER, unit_labor::POTTERY, job_skill::POTTERY, "Po"},
|
|
|
|
{9, 9, profession::GLAZER, unit_labor::GLAZING, job_skill::GLAZING, "Gl"},
|
|
|
|
{9, 9, profession::WAX_WORKER, unit_labor::WAX_WORKING, job_skill::WAX_WORKING, "Wx"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Engineering
|
2015-03-25 13:04:52 -06:00
|
|
|
{10, 12, profession::SIEGE_ENGINEER, unit_labor::SIEGECRAFT, job_skill::SIEGECRAFT, "En"},
|
|
|
|
{10, 12, profession::SIEGE_OPERATOR, unit_labor::SIEGEOPERATE, job_skill::SIEGEOPERATE, "Op"},
|
|
|
|
{10, 12, profession::MECHANIC, unit_labor::MECHANIC, job_skill::MECHANICS, "Me"},
|
|
|
|
{10, 12, profession::PUMP_OPERATOR, unit_labor::OPERATE_PUMP, job_skill::OPERATE_PUMP, "Pu"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Hauling
|
2015-03-25 13:04:52 -06:00
|
|
|
{11, 3, profession::NONE, unit_labor::HAUL_STONE, job_skill::NONE, "St"},
|
|
|
|
{11, 3, profession::NONE, unit_labor::HAUL_WOOD, job_skill::NONE, "Wo"},
|
|
|
|
{11, 3, profession::NONE, unit_labor::HAUL_ITEM, job_skill::NONE, "It"},
|
|
|
|
{11, 3, profession::NONE, unit_labor::HAUL_BODY, job_skill::NONE, "Bu"},
|
|
|
|
{11, 3, profession::NONE, unit_labor::HAUL_FOOD, job_skill::NONE, "Fo"},
|
|
|
|
{11, 3, profession::NONE, unit_labor::HAUL_REFUSE, job_skill::NONE, "Re"},
|
|
|
|
{11, 3, profession::NONE, unit_labor::HAUL_FURNITURE, job_skill::NONE, "Fu"},
|
|
|
|
{11, 3, profession::NONE, unit_labor::HAUL_ANIMALS, job_skill::NONE, "An"},
|
|
|
|
{11, 3, profession::NONE, unit_labor::HANDLE_VEHICLES, job_skill::NONE, "Ve"},
|
|
|
|
{11, 3, profession::NONE, unit_labor::HAUL_TRADE, job_skill::NONE, "Tr"},
|
|
|
|
{11, 3, profession::NONE, unit_labor::HAUL_WATER, job_skill::NONE, "Wa"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Other Jobs
|
2015-03-25 13:04:52 -06:00
|
|
|
{12, 4, profession::ARCHITECT, unit_labor::ARCHITECT, job_skill::DESIGNBUILDING, "Ar"},
|
|
|
|
{12, 4, profession::ALCHEMIST, unit_labor::ALCHEMIST, job_skill::ALCHEMY, "Al"},
|
|
|
|
{12, 4, profession::NONE, unit_labor::CLEAN, job_skill::NONE, "Cl"},
|
|
|
|
{12, 4, profession::NONE, unit_labor::PULL_LEVER, job_skill::NONE, "Lv"},
|
|
|
|
{12, 4, profession::NONE, unit_labor::BUILD_ROAD, job_skill::NONE, "Ro"},
|
|
|
|
{12, 4, profession::NONE, unit_labor::BUILD_CONSTRUCTION, job_skill::NONE, "Co"},
|
|
|
|
{12, 4, profession::NONE, unit_labor::REMOVE_CONSTRUCTION, job_skill::NONE, "CR"},
|
2012-08-30 08:46:09 -06:00
|
|
|
// Military - Weapons
|
|
|
|
{13, 7, profession::WRESTLER, unit_labor::NONE, job_skill::WRESTLING, "Wr"},
|
|
|
|
{13, 7, profession::AXEMAN, unit_labor::NONE, job_skill::AXE, "Ax"},
|
|
|
|
{13, 7, profession::SWORDSMAN, unit_labor::NONE, job_skill::SWORD, "Sw"},
|
|
|
|
{13, 7, profession::MACEMAN, unit_labor::NONE, job_skill::MACE, "Mc"},
|
|
|
|
{13, 7, profession::HAMMERMAN, unit_labor::NONE, job_skill::HAMMER, "Ha"},
|
|
|
|
{13, 7, profession::SPEARMAN, unit_labor::NONE, job_skill::SPEAR, "Sp"},
|
|
|
|
{13, 7, profession::CROSSBOWMAN, unit_labor::NONE, job_skill::CROSSBOW, "Cb"},
|
|
|
|
{13, 7, profession::THIEF, unit_labor::NONE, job_skill::DAGGER, "Kn"},
|
|
|
|
{13, 7, profession::BOWMAN, unit_labor::NONE, job_skill::BOW, "Bo"},
|
|
|
|
{13, 7, profession::BLOWGUNMAN, unit_labor::NONE, job_skill::BLOWGUN, "Bl"},
|
|
|
|
{13, 7, profession::PIKEMAN, unit_labor::NONE, job_skill::PIKE, "Pk"},
|
|
|
|
{13, 7, profession::LASHER, unit_labor::NONE, job_skill::WHIP, "La"},
|
|
|
|
// Military - Other Combat
|
|
|
|
{14, 15, profession::NONE, unit_labor::NONE, job_skill::BITE, "Bi"},
|
|
|
|
{14, 15, profession::NONE, unit_labor::NONE, job_skill::GRASP_STRIKE, "St"},
|
|
|
|
{14, 15, profession::NONE, unit_labor::NONE, job_skill::STANCE_STRIKE, "Ki"},
|
|
|
|
{14, 15, profession::NONE, unit_labor::NONE, job_skill::MISC_WEAPON, "Mi"},
|
|
|
|
{14, 15, profession::NONE, unit_labor::NONE, job_skill::MELEE_COMBAT, "Fg"},
|
|
|
|
{14, 15, profession::NONE, unit_labor::NONE, job_skill::RANGED_COMBAT, "Ac"},
|
|
|
|
{14, 15, profession::NONE, unit_labor::NONE, job_skill::ARMOR, "Ar"},
|
|
|
|
{14, 15, profession::NONE, unit_labor::NONE, job_skill::SHIELD, "Sh"},
|
|
|
|
{14, 15, profession::NONE, unit_labor::NONE, job_skill::DODGING, "Do"},
|
|
|
|
// Military - Misc
|
|
|
|
{15, 8, profession::NONE, unit_labor::NONE, job_skill::LEADERSHIP, "Ld"},
|
|
|
|
{15, 8, profession::NONE, unit_labor::NONE, job_skill::TEACHING, "Te"},
|
|
|
|
{15, 8, profession::NONE, unit_labor::NONE, job_skill::KNOWLEDGE_ACQUISITION, "St"},
|
|
|
|
{15, 8, profession::NONE, unit_labor::NONE, job_skill::DISCIPLINE, "Di"},
|
|
|
|
{15, 8, profession::NONE, unit_labor::NONE, job_skill::CONCENTRATION, "Co"},
|
|
|
|
{15, 8, profession::NONE, unit_labor::NONE, job_skill::SITUATIONAL_AWARENESS, "Ob"},
|
|
|
|
{15, 8, profession::NONE, unit_labor::NONE, job_skill::COORDINATION, "Cr"},
|
|
|
|
{15, 8, profession::NONE, unit_labor::NONE, job_skill::BALANCE, "Ba"},
|
2014-07-21 12:18:29 -06:00
|
|
|
{15, 8, profession::NONE, unit_labor::NONE, job_skill::CLIMBING, "Cl"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Social
|
2012-08-30 08:46:09 -06:00
|
|
|
{16, 3, profession::NONE, unit_labor::NONE, job_skill::PERSUASION, "Pe"},
|
|
|
|
{16, 3, profession::NONE, unit_labor::NONE, job_skill::NEGOTIATION, "Ne"},
|
|
|
|
{16, 3, profession::NONE, unit_labor::NONE, job_skill::JUDGING_INTENT, "Ju"},
|
|
|
|
{16, 3, profession::NONE, unit_labor::NONE, job_skill::LYING, "Li"},
|
|
|
|
{16, 3, profession::NONE, unit_labor::NONE, job_skill::INTIMIDATION, "In"},
|
|
|
|
{16, 3, profession::NONE, unit_labor::NONE, job_skill::CONVERSATION, "Cn"},
|
|
|
|
{16, 3, profession::NONE, unit_labor::NONE, job_skill::COMEDY, "Cm"},
|
|
|
|
{16, 3, profession::NONE, unit_labor::NONE, job_skill::FLATTERY, "Fl"},
|
|
|
|
{16, 3, profession::NONE, unit_labor::NONE, job_skill::CONSOLE, "Cs"},
|
|
|
|
{16, 3, profession::NONE, unit_labor::NONE, job_skill::PACIFY, "Pc"},
|
2012-08-28 14:52:26 -06:00
|
|
|
// Noble
|
2012-08-30 08:46:09 -06:00
|
|
|
{17, 5, profession::TRADER, unit_labor::NONE, job_skill::APPRAISAL, "Ap"},
|
|
|
|
{17, 5, profession::ADMINISTRATOR, unit_labor::NONE, job_skill::ORGANIZATION, "Or"},
|
|
|
|
{17, 5, profession::CLERK, unit_labor::NONE, job_skill::RECORD_KEEPING, "RK"},
|
2012-08-21 14:43:32 -06:00
|
|
|
// Miscellaneous
|
2012-08-30 08:46:09 -06:00
|
|
|
{18, 3, profession::NONE, unit_labor::NONE, job_skill::THROW, "Th"},
|
|
|
|
{18, 3, profession::NONE, unit_labor::NONE, job_skill::CRUTCH_WALK, "CW"},
|
|
|
|
{18, 3, profession::NONE, unit_labor::NONE, job_skill::SWIMMING, "Sw"},
|
|
|
|
{18, 3, profession::NONE, unit_labor::NONE, job_skill::KNAPPING, "Kn"},
|
|
|
|
|
|
|
|
{19, 6, profession::NONE, unit_labor::NONE, job_skill::WRITING, "Wr"},
|
|
|
|
{19, 6, profession::NONE, unit_labor::NONE, job_skill::PROSE, "Pr"},
|
|
|
|
{19, 6, profession::NONE, unit_labor::NONE, job_skill::POETRY, "Po"},
|
|
|
|
{19, 6, profession::NONE, unit_labor::NONE, job_skill::READING, "Rd"},
|
|
|
|
{19, 6, profession::NONE, unit_labor::NONE, job_skill::SPEAKING, "Sp"},
|
|
|
|
|
|
|
|
{20, 5, profession::NONE, unit_labor::NONE, job_skill::MILITARY_TACTICS, "MT"},
|
|
|
|
{20, 5, profession::NONE, unit_labor::NONE, job_skill::TRACKING, "Tr"},
|
|
|
|
{20, 5, profession::NONE, unit_labor::NONE, job_skill::MAGIC_NATURE, "Dr"},
|
2012-08-21 14:43:32 -06:00
|
|
|
};
|
|
|
|
|
2012-08-22 19:52:19 -06:00
|
|
|
struct UnitInfo
|
|
|
|
{
|
|
|
|
df::unit *unit;
|
|
|
|
bool allowEdit;
|
|
|
|
string name;
|
|
|
|
string transname;
|
|
|
|
string profession;
|
|
|
|
int8_t color;
|
2012-09-23 06:41:14 -06:00
|
|
|
int active_index;
|
2014-06-09 19:58:16 -06:00
|
|
|
string squad_effective_name;
|
|
|
|
string squad_info;
|
2015-02-17 15:17:26 -07:00
|
|
|
string job_info;
|
2015-01-08 18:55:37 -07:00
|
|
|
bool selected;
|
2015-01-09 15:15:14 -07:00
|
|
|
struct {
|
|
|
|
// Used for custom professions, 1-indexed
|
|
|
|
int list_id; // Position in list
|
|
|
|
int list_id_group; // Position in list by group (e.g. craftsdwarf)
|
|
|
|
int list_id_prof; // Position in list by profession (e.g. woodcrafter)
|
|
|
|
void init() {
|
|
|
|
list_id = 0;
|
|
|
|
list_id_group = 0;
|
|
|
|
list_id_prof = 0;
|
|
|
|
}
|
|
|
|
} ids;
|
2012-08-22 19:52:19 -06:00
|
|
|
};
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2015-02-17 15:17:26 -07:00
|
|
|
enum detail_cols {
|
|
|
|
DETAIL_MODE_PROFESSION,
|
|
|
|
DETAIL_MODE_SQUAD,
|
|
|
|
DETAIL_MODE_JOB
|
|
|
|
};
|
2012-08-25 09:57:50 -06:00
|
|
|
enum altsort_mode {
|
|
|
|
ALTSORT_NAME,
|
2015-01-08 18:55:37 -07:00
|
|
|
ALTSORT_SELECTED,
|
2015-02-17 15:17:26 -07:00
|
|
|
ALTSORT_DETAIL,
|
2014-10-31 12:33:35 -06:00
|
|
|
ALTSORT_STRESS,
|
2012-09-23 06:41:14 -06:00
|
|
|
ALTSORT_ARRIVAL,
|
2012-08-25 09:57:50 -06:00
|
|
|
ALTSORT_MAX
|
|
|
|
};
|
|
|
|
|
2015-01-09 13:05:49 -07:00
|
|
|
string itos (int n)
|
|
|
|
{
|
|
|
|
stringstream ss;
|
|
|
|
ss << n;
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2012-08-25 09:57:50 -06:00
|
|
|
bool descending;
|
|
|
|
df::job_skill sort_skill;
|
|
|
|
df::unit_labor sort_labor;
|
|
|
|
|
|
|
|
bool sortByName (const UnitInfo *d1, const UnitInfo *d2)
|
|
|
|
{
|
|
|
|
if (descending)
|
|
|
|
return (d1->name > d2->name);
|
|
|
|
else
|
|
|
|
return (d1->name < d2->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sortByProfession (const UnitInfo *d1, const UnitInfo *d2)
|
|
|
|
{
|
|
|
|
if (descending)
|
|
|
|
return (d1->profession > d2->profession);
|
|
|
|
else
|
|
|
|
return (d1->profession < d2->profession);
|
|
|
|
}
|
|
|
|
|
2014-06-09 19:58:16 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-02-17 15:17:26 -07:00
|
|
|
bool sortByJob (const UnitInfo *d1, const UnitInfo *d2)
|
|
|
|
{
|
|
|
|
bool gt = false;
|
|
|
|
|
|
|
|
if (d1->job_info == "Idle")
|
|
|
|
gt = false;
|
|
|
|
else if (d2->job_info == "Idle")
|
|
|
|
gt = true;
|
|
|
|
else
|
|
|
|
gt = (d1->job_info > d2->job_info);
|
|
|
|
|
|
|
|
return descending ? gt : !gt;
|
|
|
|
}
|
|
|
|
|
2014-10-31 12:33:35 -06:00
|
|
|
bool sortByStress (const UnitInfo *d1, const UnitInfo *d2)
|
2012-09-13 14:42:51 -06:00
|
|
|
{
|
2014-10-31 12:33:35 -06:00
|
|
|
if (!d1->unit->status.current_soul)
|
|
|
|
return !descending;
|
|
|
|
if (!d2->unit->status.current_soul)
|
|
|
|
return descending;
|
|
|
|
|
2012-09-13 14:42:51 -06:00
|
|
|
if (descending)
|
2014-10-31 12:33:35 -06:00
|
|
|
return (d1->unit->status.current_soul->personality.stress_level > d2->unit->status.current_soul->personality.stress_level);
|
2012-09-13 14:42:51 -06:00
|
|
|
else
|
2014-10-31 12:33:35 -06:00
|
|
|
return (d1->unit->status.current_soul->personality.stress_level < d2->unit->status.current_soul->personality.stress_level);
|
2012-09-13 14:42:51 -06:00
|
|
|
}
|
|
|
|
|
2012-09-23 06:41:14 -06:00
|
|
|
bool sortByArrival (const UnitInfo *d1, const UnitInfo *d2)
|
|
|
|
{
|
|
|
|
if (descending)
|
|
|
|
return (d1->active_index > d2->active_index);
|
|
|
|
else
|
|
|
|
return (d1->active_index < d2->active_index);
|
|
|
|
}
|
|
|
|
|
2012-08-25 09:57:50 -06:00
|
|
|
bool sortBySkill (const UnitInfo *d1, const UnitInfo *d2)
|
|
|
|
{
|
|
|
|
if (sort_skill != job_skill::NONE)
|
|
|
|
{
|
2012-11-02 15:28:48 -06:00
|
|
|
if (!d1->unit->status.current_soul)
|
|
|
|
return !descending;
|
|
|
|
if (!d2->unit->status.current_soul)
|
|
|
|
return descending;
|
2012-10-26 10:29:21 -06:00
|
|
|
df::unit_skill *s1 = binsearch_in_vector<df::unit_skill,df::job_skill>(d1->unit->status.current_soul->skills, &df::unit_skill::id, sort_skill);
|
|
|
|
df::unit_skill *s2 = binsearch_in_vector<df::unit_skill,df::job_skill>(d2->unit->status.current_soul->skills, &df::unit_skill::id, sort_skill);
|
2012-08-25 09:57:50 -06:00
|
|
|
int l1 = s1 ? s1->rating : 0;
|
|
|
|
int l2 = s2 ? s2->rating : 0;
|
|
|
|
int e1 = s1 ? s1->experience : 0;
|
|
|
|
int e2 = s2 ? s2->experience : 0;
|
|
|
|
if (descending)
|
|
|
|
{
|
|
|
|
if (l1 != l2)
|
|
|
|
return l1 > l2;
|
|
|
|
if (e1 != e2)
|
|
|
|
return e1 > e2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (l1 != l2)
|
|
|
|
return l1 < l2;
|
|
|
|
if (e1 != e2)
|
|
|
|
return e1 < e2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sort_labor != unit_labor::NONE)
|
|
|
|
{
|
|
|
|
if (descending)
|
|
|
|
return d1->unit->status.labors[sort_labor] > d2->unit->status.labors[sort_labor];
|
|
|
|
else
|
|
|
|
return d1->unit->status.labors[sort_labor] < d2->unit->status.labors[sort_labor];
|
|
|
|
}
|
2014-10-21 22:49:50 -06:00
|
|
|
return false;
|
2012-08-25 09:57:50 -06:00
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2015-01-08 18:55:37 -07:00
|
|
|
bool sortBySelected (const UnitInfo *d1, const UnitInfo *d2)
|
|
|
|
{
|
|
|
|
return descending ? (d1->selected > d2->selected) : (d1->selected < d2->selected);
|
|
|
|
}
|
|
|
|
|
2015-01-09 11:24:03 -07:00
|
|
|
template<typename T>
|
|
|
|
class StringFormatter {
|
|
|
|
public:
|
2015-01-09 13:05:49 -07:00
|
|
|
typedef string(*T_callback)(T);
|
|
|
|
typedef std::tuple<string, string, T_callback> T_opt;
|
2015-01-09 11:24:03 -07:00
|
|
|
typedef vector<T_opt> T_optlist;
|
2015-01-09 15:15:14 -07:00
|
|
|
static bool compare_opts(const string &first, const string &second)
|
2015-01-09 13:05:49 -07:00
|
|
|
{
|
2015-01-09 15:15:14 -07:00
|
|
|
return first.size() > second.size();
|
2015-01-09 13:05:49 -07:00
|
|
|
}
|
2015-01-09 11:24:03 -07:00
|
|
|
StringFormatter() {}
|
|
|
|
void add_option(string spec, string help, string (*callback)(T))
|
|
|
|
{
|
2015-01-09 13:05:49 -07:00
|
|
|
opt_list.push_back(std::make_tuple(spec, help, callback));
|
|
|
|
}
|
|
|
|
T_optlist *get_options() { return &opt_list; }
|
|
|
|
void clear_options()
|
|
|
|
{
|
|
|
|
opt_list.clear();
|
|
|
|
}
|
|
|
|
string grab_opt (string s, size_t start)
|
|
|
|
{
|
2015-01-09 15:15:14 -07:00
|
|
|
vector<string> candidates;
|
2015-01-09 13:05:49 -07:00
|
|
|
for (auto it = opt_list.begin(); it != opt_list.end(); ++it)
|
|
|
|
{
|
|
|
|
string opt = std::get<0>(*it);
|
2015-01-09 15:15:14 -07:00
|
|
|
string slice = s.substr(start, opt.size());
|
|
|
|
if (slice == opt)
|
|
|
|
candidates.push_back(slice);
|
2015-01-09 13:05:49 -07:00
|
|
|
}
|
2015-01-09 15:15:14 -07:00
|
|
|
if (!candidates.size())
|
|
|
|
return "";
|
2015-01-09 18:02:44 -07:00
|
|
|
// Select the longest candidate
|
2015-01-09 15:15:14 -07:00
|
|
|
std::sort(candidates.begin(), candidates.end(), StringFormatter<T>::compare_opts);
|
|
|
|
return candidates[0];
|
2015-01-09 13:05:49 -07:00
|
|
|
}
|
|
|
|
T_callback get_callback (string s)
|
|
|
|
{
|
|
|
|
for (auto it = opt_list.begin(); it != opt_list.end(); ++it)
|
|
|
|
{
|
|
|
|
if (std::get<0>(*it) == s)
|
|
|
|
return std::get<2>(*it);
|
|
|
|
}
|
|
|
|
return NULL;
|
2015-01-09 11:24:03 -07:00
|
|
|
}
|
|
|
|
string format (T obj, string fmt)
|
|
|
|
{
|
2015-01-09 13:05:49 -07:00
|
|
|
string dest = "";
|
|
|
|
bool in_opt = false;
|
|
|
|
size_t i = 0;
|
|
|
|
while (i < fmt.size())
|
|
|
|
{
|
|
|
|
if (in_opt)
|
|
|
|
{
|
|
|
|
if (fmt[i] == '%')
|
|
|
|
{
|
|
|
|
// escape: %% -> %
|
|
|
|
in_opt = false;
|
|
|
|
dest.push_back('%');
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string opt = grab_opt(fmt, i);
|
|
|
|
if (opt.size())
|
|
|
|
{
|
|
|
|
T_callback func = get_callback(opt);
|
|
|
|
if (func != NULL)
|
|
|
|
dest += func(obj);
|
|
|
|
i += opt.size();
|
2015-01-09 18:02:44 -07:00
|
|
|
in_opt = false;
|
|
|
|
if (i < fmt.size() && fmt[i] == '$')
|
2015-01-09 15:15:14 -07:00
|
|
|
// Allow $ to terminate format options
|
|
|
|
i++;
|
2015-01-09 13:05:49 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Unrecognized format option; replace with original text
|
|
|
|
dest.push_back('%');
|
|
|
|
in_opt = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fmt[i] == '%')
|
|
|
|
in_opt = true;
|
|
|
|
else
|
|
|
|
dest.push_back(fmt[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dest;
|
2015-01-09 11:24:03 -07:00
|
|
|
}
|
|
|
|
protected:
|
2015-01-09 13:05:49 -07:00
|
|
|
T_optlist opt_list;
|
2015-01-09 11:24:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace unit_ops {
|
2015-01-09 13:05:49 -07:00
|
|
|
string get_real_name(UnitInfo *u)
|
|
|
|
{ return Translation::TranslateName(&u->unit->name, false); }
|
|
|
|
string get_nickname(UnitInfo *u)
|
|
|
|
{ return Translation::TranslateName(Units::getVisibleName(u->unit), false); }
|
|
|
|
string get_real_name_eng(UnitInfo *u)
|
|
|
|
{ return Translation::TranslateName(&u->unit->name, true); }
|
|
|
|
string get_nickname_eng(UnitInfo *u)
|
|
|
|
{ return Translation::TranslateName(Units::getVisibleName(u->unit), true); }
|
2015-01-09 18:28:05 -07:00
|
|
|
string get_first_nickname(UnitInfo *u)
|
|
|
|
{
|
|
|
|
return Translation::capitalize(u->unit->name.nickname.size() ?
|
|
|
|
u->unit->name.nickname : u->unit->name.first_name);
|
|
|
|
}
|
|
|
|
string get_first_name(UnitInfo *u)
|
|
|
|
{ return Translation::capitalize(u->unit->name.first_name); }
|
|
|
|
string get_last_name(UnitInfo *u)
|
|
|
|
{
|
|
|
|
df::language_name name = u->unit->name;
|
|
|
|
string ret = "";
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
if (name.words[i] >= 0)
|
|
|
|
ret += *world->raws.language.translations[name.language]->words[name.words[i]];
|
|
|
|
}
|
|
|
|
return Translation::capitalize(ret);
|
|
|
|
}
|
|
|
|
string get_last_name_eng(UnitInfo *u)
|
|
|
|
{
|
|
|
|
df::language_name name = u->unit->name;
|
|
|
|
string ret = "";
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
if (name.words[i] >= 0)
|
|
|
|
ret += world->raws.language.words[name.words[i]]->forms[name.parts_of_speech[i].value];
|
|
|
|
}
|
|
|
|
return Translation::capitalize(ret);
|
|
|
|
}
|
2015-01-09 13:05:49 -07:00
|
|
|
string get_profname(UnitInfo *u)
|
|
|
|
{ return Units::getProfessionName(u->unit); }
|
|
|
|
string get_real_profname(UnitInfo *u)
|
|
|
|
{
|
|
|
|
string tmp = u->unit->custom_profession;
|
|
|
|
u->unit->custom_profession = "";
|
|
|
|
string ret = get_profname(u);
|
|
|
|
u->unit->custom_profession = tmp;
|
|
|
|
return ret;
|
|
|
|
}
|
2015-01-09 18:28:05 -07:00
|
|
|
string get_base_profname(UnitInfo *u)
|
|
|
|
{
|
|
|
|
return ENUM_ATTR_STR(profession, caption, u->unit->profession);
|
|
|
|
}
|
|
|
|
string get_short_profname(UnitInfo *u)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_COLUMNS; i++)
|
|
|
|
{
|
|
|
|
if (columns[i].profession == u->unit->profession)
|
|
|
|
return string(columns[i].label);
|
|
|
|
}
|
|
|
|
return "??";
|
|
|
|
}
|
2015-01-09 15:15:14 -07:00
|
|
|
#define id_getter(id) \
|
|
|
|
string get_##id(UnitInfo *u) \
|
|
|
|
{ return itos(u->ids.id); }
|
|
|
|
id_getter(list_id);
|
|
|
|
id_getter(list_id_prof);
|
|
|
|
id_getter(list_id_group);
|
|
|
|
#undef id_getter
|
|
|
|
string get_unit_id(UnitInfo *u)
|
|
|
|
{ return itos(u->unit->id); }
|
2015-01-09 18:28:05 -07:00
|
|
|
string get_age(UnitInfo *u)
|
|
|
|
{ return itos((int)Units::getAge(u->unit)); }
|
2015-01-09 13:05:49 -07:00
|
|
|
void set_nickname(UnitInfo *u, std::string nick)
|
|
|
|
{
|
|
|
|
Units::setNickname(u->unit, nick);
|
|
|
|
u->name = get_nickname(u);
|
|
|
|
u->transname = get_nickname_eng(u);
|
|
|
|
}
|
|
|
|
void set_profname(UnitInfo *u, std::string prof)
|
|
|
|
{
|
|
|
|
u->unit->custom_profession = prof;
|
|
|
|
u->profession = get_profname(u);
|
|
|
|
}
|
2015-01-09 11:24:03 -07:00
|
|
|
}
|
|
|
|
|
2015-02-23 14:52:18 -07:00
|
|
|
struct ProfessionTemplate
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
bool mask;
|
|
|
|
std::vector<df::unit_labor> labors;
|
|
|
|
|
|
|
|
bool load(string directory, string file)
|
|
|
|
{
|
|
|
|
cerr << "Attempt to load " << file << endl;
|
|
|
|
std::ifstream infile(directory + "/" + file);
|
|
|
|
if (infile.bad()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string line;
|
|
|
|
name = file; // If no name is given we default to the filename
|
|
|
|
mask = false;
|
|
|
|
while (std::getline(infile, line)) {
|
|
|
|
if (strcmp(line.substr(0,5).c_str(),"NAME ")==0)
|
|
|
|
{
|
|
|
|
auto nextInd = line.find(' ');
|
|
|
|
name = line.substr(nextInd + 1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (line.compare("MASK")==0)
|
|
|
|
{
|
|
|
|
mask = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-03-19 01:30:03 -06:00
|
|
|
for (int i = 0; i < NUM_COLUMNS; i++)
|
|
|
|
{
|
2015-03-25 13:04:52 -06:00
|
|
|
if (line.compare(ENUM_KEY_STR(unit_labor, columns[i].labor)) == 0)
|
2015-03-19 01:30:03 -06:00
|
|
|
{
|
|
|
|
labors.push_back(columns[i].labor);
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 14:52:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool save(string directory)
|
|
|
|
{
|
|
|
|
std::ofstream outfile(directory + "/" + name);
|
|
|
|
if (outfile.bad())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
outfile << "NAME " << name << std::endl;
|
|
|
|
if (mask)
|
|
|
|
outfile << "MASK" << std::endl;
|
|
|
|
|
2015-03-19 01:30:03 -06:00
|
|
|
for (int i = 0; i < NUM_COLUMNS; i++)
|
|
|
|
{
|
|
|
|
if (hasLabor(columns[i].labor))
|
|
|
|
{
|
2015-03-25 13:04:52 -06:00
|
|
|
outfile << ENUM_KEY_STR(unit_labor, columns[i].labor) << std::endl;
|
2015-03-19 01:30:03 -06:00
|
|
|
}
|
|
|
|
}
|
2015-02-23 14:52:18 -07:00
|
|
|
|
|
|
|
outfile.flush();
|
|
|
|
outfile.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(UnitInfo* u)
|
|
|
|
{
|
|
|
|
if (!mask && name.size() > 0)
|
|
|
|
unit_ops::set_profname(u, name);
|
|
|
|
|
2015-03-19 01:30:03 -06:00
|
|
|
for (int i = 0; i < NUM_COLUMNS; i++)
|
2015-02-23 14:52:18 -07:00
|
|
|
{
|
2015-03-19 01:30:03 -06:00
|
|
|
df::unit_labor labor = columns[i].labor;
|
|
|
|
bool status = hasLabor(labor);
|
|
|
|
|
|
|
|
if (!mask || status) {
|
|
|
|
u->unit->status.labors[labor] = status;
|
2015-02-23 14:52:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-19 01:30:03 -06:00
|
|
|
void fromUnit(UnitInfo* u)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_COLUMNS; i++)
|
|
|
|
{
|
|
|
|
if (u->unit->status.labors[columns[i].labor])
|
|
|
|
labors.push_back(columns[i].labor);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-02-23 14:52:18 -07:00
|
|
|
bool hasLabor (df::unit_labor labor)
|
|
|
|
{
|
|
|
|
return std::find(labors.begin(), labors.end(), labor) != labors.end();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static std::string professions_folder = Filesystem::getcwd() + "/professions";
|
|
|
|
class ProfessionTemplateManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<ProfessionTemplate> templates;
|
|
|
|
|
|
|
|
void reload() {
|
|
|
|
unload();
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
void unload() {
|
|
|
|
templates.clear();
|
|
|
|
}
|
|
|
|
void load()
|
|
|
|
{
|
|
|
|
vector <string> files;
|
|
|
|
|
|
|
|
cerr << "Attempting to load professions: " << professions_folder.c_str() << endl;
|
2015-03-05 14:57:58 -07:00
|
|
|
if (!Filesystem::isdir(professions_folder) && !Filesystem::mkdir(professions_folder))
|
|
|
|
{
|
|
|
|
cerr << professions_folder << ": Does not exist and cannot be created" << endl;
|
|
|
|
return;
|
|
|
|
}
|
2015-02-23 14:52:18 -07:00
|
|
|
Filesystem::listdir(professions_folder, files);
|
|
|
|
for(size_t i = 0; i < files.size(); i++)
|
|
|
|
{
|
|
|
|
if (files[i].compare(".") == 0 || files[i].compare("..") == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ProfessionTemplate t;
|
|
|
|
if (t.load(professions_folder, files[i]))
|
|
|
|
{
|
|
|
|
templates.push_back(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void save_from_unit(UnitInfo *unit)
|
|
|
|
{
|
|
|
|
ProfessionTemplate t = {
|
|
|
|
unit_ops::get_profname(unit)
|
|
|
|
};
|
|
|
|
|
2015-03-19 01:30:03 -06:00
|
|
|
t.fromUnit(unit);
|
2015-02-23 14:52:18 -07:00
|
|
|
t.save(professions_folder);
|
|
|
|
reload();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static ProfessionTemplateManager manager;
|
|
|
|
|
2015-01-08 21:19:06 -07:00
|
|
|
class viewscreen_unitbatchopst : public dfhack_viewscreen {
|
|
|
|
public:
|
|
|
|
enum page { MENU, NICKNAME, PROFNAME };
|
2015-01-09 18:28:05 -07:00
|
|
|
viewscreen_unitbatchopst(vector<UnitInfo*> &base_units,
|
|
|
|
bool filter_selected = true,
|
|
|
|
bool *dirty_flag = NULL
|
|
|
|
)
|
|
|
|
:cur_page(MENU), entry(""), selection_empty(false), dirty(dirty_flag)
|
2015-01-08 21:19:06 -07:00
|
|
|
{
|
|
|
|
menu_options.multiselect = false;
|
|
|
|
menu_options.auto_select = true;
|
|
|
|
menu_options.allow_search = false;
|
|
|
|
menu_options.left_margin = 2;
|
|
|
|
menu_options.bottom_margin = 2;
|
|
|
|
menu_options.clear();
|
|
|
|
menu_options.add("Change nickname", page::NICKNAME);
|
|
|
|
menu_options.add("Change profession name", page::PROFNAME);
|
|
|
|
menu_options.filterDisplay();
|
2015-01-09 11:24:03 -07:00
|
|
|
formatter.add_option("n", "Displayed name (or nickname)", unit_ops::get_nickname);
|
|
|
|
formatter.add_option("N", "Real name", unit_ops::get_real_name);
|
2015-01-09 13:05:49 -07:00
|
|
|
formatter.add_option("en", "Displayed name (or nickname), in English", unit_ops::get_nickname_eng);
|
|
|
|
formatter.add_option("eN", "Real name, in English", unit_ops::get_real_name_eng);
|
2015-01-09 18:28:05 -07:00
|
|
|
formatter.add_option("fn", "Displayed first name (or nickname)", unit_ops::get_first_nickname);
|
|
|
|
formatter.add_option("fN", "Real first name", unit_ops::get_first_name);
|
|
|
|
formatter.add_option("ln", "Last name", unit_ops::get_last_name);
|
|
|
|
formatter.add_option("eln", "Last name, in English", unit_ops::get_last_name_eng);
|
2015-01-09 13:05:49 -07:00
|
|
|
formatter.add_option("p", "Displayed profession", unit_ops::get_profname);
|
2015-01-09 18:28:05 -07:00
|
|
|
formatter.add_option("P", "Real profession (non-customized)", unit_ops::get_real_profname);
|
|
|
|
formatter.add_option("bp", "Base profession (excluding nobles & other positions)", unit_ops::get_base_profname);
|
|
|
|
formatter.add_option("sp", "Short (base) profession name (from manipulator headers)", unit_ops::get_short_profname);
|
|
|
|
formatter.add_option("a", "Age (in years)", unit_ops::get_age);
|
2015-01-09 15:15:14 -07:00
|
|
|
formatter.add_option("i", "Position in list", unit_ops::get_list_id);
|
|
|
|
formatter.add_option("pi", "Position in list, among dwarves with same profession", unit_ops::get_list_id_prof);
|
|
|
|
formatter.add_option("gi", "Position in list, among dwarves in same profession group", unit_ops::get_list_id_group);
|
|
|
|
formatter.add_option("ri", "Raw unit ID", unit_ops::get_unit_id);
|
2015-01-09 13:05:49 -07:00
|
|
|
selection_empty = true;
|
2015-01-09 15:15:14 -07:00
|
|
|
for (auto it = base_units.begin(); it != base_units.end(); ++it)
|
2015-01-09 13:05:49 -07:00
|
|
|
{
|
2015-01-09 15:15:14 -07:00
|
|
|
UnitInfo* uinfo = *it;
|
|
|
|
if (uinfo->selected || !filter_selected)
|
|
|
|
{
|
2015-01-09 13:05:49 -07:00
|
|
|
selection_empty = false;
|
2015-01-09 15:15:14 -07:00
|
|
|
units.push_back(uinfo);
|
|
|
|
}
|
2015-01-09 13:05:49 -07:00
|
|
|
}
|
2015-01-08 21:19:06 -07:00
|
|
|
}
|
2015-01-09 11:24:03 -07:00
|
|
|
std::string getFocusString() { return "unitlabors/batch"; }
|
2015-01-08 21:19:06 -07:00
|
|
|
void select_page (page p)
|
|
|
|
{
|
|
|
|
if (p == NICKNAME || p == PROFNAME)
|
|
|
|
entry = "";
|
|
|
|
cur_page = p;
|
|
|
|
}
|
2015-01-09 13:05:49 -07:00
|
|
|
void apply(void (*func)(UnitInfo*, string), string arg, StringFormatter<UnitInfo*> *arg_formatter)
|
2015-01-09 11:24:03 -07:00
|
|
|
{
|
2015-01-09 18:28:05 -07:00
|
|
|
if (dirty)
|
|
|
|
*dirty = true;
|
2015-01-09 15:15:14 -07:00
|
|
|
for (auto it = units.begin(); it != units.end(); ++it)
|
2015-01-09 11:24:03 -07:00
|
|
|
{
|
2015-01-09 13:05:49 -07:00
|
|
|
UnitInfo* u = (*it);
|
2015-01-09 15:15:14 -07:00
|
|
|
if (!u || !u->unit || !u->allowEdit) continue;
|
2015-01-09 11:24:03 -07:00
|
|
|
string cur_arg = arg_formatter->format(u, arg);
|
|
|
|
func(u, cur_arg);
|
|
|
|
}
|
|
|
|
}
|
2015-01-08 21:19:06 -07:00
|
|
|
void feed(set<df::interface_key> *events)
|
|
|
|
{
|
|
|
|
if (cur_page == MENU)
|
|
|
|
{
|
|
|
|
if (events->count(interface_key::LEAVESCREEN))
|
2015-01-09 11:24:03 -07:00
|
|
|
{
|
2015-01-08 21:19:06 -07:00
|
|
|
Screen::dismiss(this);
|
|
|
|
return;
|
2015-01-09 11:24:03 -07:00
|
|
|
}
|
2015-01-09 13:05:49 -07:00
|
|
|
if (selection_empty)
|
|
|
|
return;
|
2015-01-09 11:24:03 -07:00
|
|
|
if (menu_options.feed(events))
|
|
|
|
{
|
|
|
|
// Allow left mouse button to trigger menu options
|
|
|
|
if (menu_options.feed_mouse_set_highlight)
|
|
|
|
events->insert(interface_key::SELECT);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (events->count(interface_key::SELECT))
|
|
|
|
select_page(menu_options.getFirstSelectedElem());
|
2015-01-08 21:19:06 -07:00
|
|
|
}
|
|
|
|
else if (cur_page == NICKNAME || cur_page == PROFNAME)
|
|
|
|
{
|
|
|
|
if (events->count(interface_key::LEAVESCREEN))
|
|
|
|
select_page(MENU);
|
2015-01-09 11:24:03 -07:00
|
|
|
else if (events->count(interface_key::SELECT))
|
|
|
|
{
|
|
|
|
apply((cur_page == NICKNAME) ? unit_ops::set_nickname : unit_ops::set_profname, entry, &formatter);
|
|
|
|
select_page(MENU);
|
|
|
|
}
|
2015-01-08 21:19:06 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (auto it = events->begin(); it != events->end(); ++it)
|
|
|
|
{
|
|
|
|
int ch = Screen::keyToChar(*it);
|
|
|
|
if (ch == 0 && entry.size())
|
|
|
|
entry.resize(entry.size() - 1);
|
|
|
|
else if (ch > 0)
|
|
|
|
entry.push_back(char(ch));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void render()
|
|
|
|
{
|
|
|
|
dfhack_viewscreen::render();
|
|
|
|
Screen::clear();
|
2015-01-09 13:05:49 -07:00
|
|
|
int x = 2, y = 2;
|
2015-01-08 21:19:06 -07:00
|
|
|
if (cur_page == MENU)
|
|
|
|
{
|
|
|
|
Screen::drawBorder(" Dwarf Manipulator - Batch Operations ");
|
2015-01-09 13:05:49 -07:00
|
|
|
if (selection_empty)
|
|
|
|
{
|
|
|
|
OutputString(COLOR_LIGHTRED, x, y, "No dwarves selected!");
|
|
|
|
return;
|
|
|
|
}
|
2015-01-08 21:19:06 -07:00
|
|
|
menu_options.display(true);
|
|
|
|
}
|
2015-01-09 15:15:14 -07:00
|
|
|
OutputString(COLOR_LIGHTGREEN, x, y, itos(units.size()));
|
|
|
|
OutputString(COLOR_GREY, x, y, string(" ") + (units.size() > 1 ? "dwarves" : "dwarf") + " selected: ");
|
|
|
|
int max_x = gps->dimx - 2;
|
|
|
|
size_t i = 0;
|
|
|
|
for ( ; i < units.size(); i++)
|
|
|
|
{
|
|
|
|
string name = unit_ops::get_nickname(units[i]);
|
|
|
|
if (name.size() + x + 12 >= max_x) // 12 = "and xxx more"
|
|
|
|
break;
|
|
|
|
OutputString(COLOR_WHITE, x, y, name + ", ");
|
|
|
|
}
|
|
|
|
if (i == units.size())
|
|
|
|
{
|
|
|
|
x -= 2;
|
|
|
|
OutputString(COLOR_WHITE, x, y, " ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OutputString(COLOR_GREY, x, y, "and " + itos(units.size() - i) + " more");
|
|
|
|
}
|
|
|
|
x = 2; y += 2;
|
|
|
|
if (cur_page == NICKNAME || cur_page == PROFNAME)
|
2015-01-08 21:19:06 -07:00
|
|
|
{
|
|
|
|
std::string name_type = (cur_page == page::NICKNAME) ? "Nickname" : "Profession name";
|
|
|
|
OutputString(COLOR_GREY, x, y, "Custom " + name_type + ":");
|
2015-01-09 15:15:14 -07:00
|
|
|
x = 2; y += 1;
|
2015-01-08 21:19:06 -07:00
|
|
|
OutputString(COLOR_WHITE, x, y, entry);
|
|
|
|
OutputString(COLOR_LIGHTGREEN, x, y, "_");
|
2015-01-09 13:05:49 -07:00
|
|
|
x = 2; y += 2;
|
|
|
|
OutputString(COLOR_DARKGREY, x, y, "(Leave blank to use original name)");
|
|
|
|
x = 2; y += 2;
|
|
|
|
OutputString(COLOR_WHITE, x, y, "Format options:");
|
|
|
|
StringFormatter<UnitInfo*>::T_optlist *format_options = formatter.get_options();
|
2015-01-09 11:24:03 -07:00
|
|
|
for (auto it = format_options->begin(); it != format_options->end(); ++it)
|
|
|
|
{
|
2015-01-09 13:05:49 -07:00
|
|
|
x = 2; y++;
|
2015-01-09 11:24:03 -07:00
|
|
|
auto opt = *it;
|
|
|
|
OutputString(COLOR_LIGHTCYAN, x, y, "%" + string(std::get<0>(opt)));
|
|
|
|
OutputString(COLOR_WHITE, x, y, ": " + string(std::get<1>(opt)));
|
|
|
|
}
|
2015-01-08 21:19:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
ListColumn<page> menu_options;
|
|
|
|
page cur_page;
|
2015-01-09 11:24:03 -07:00
|
|
|
string entry;
|
2015-01-09 15:15:14 -07:00
|
|
|
vector<UnitInfo*> units;
|
2015-01-09 13:05:49 -07:00
|
|
|
StringFormatter<UnitInfo*> formatter;
|
|
|
|
bool selection_empty;
|
2015-01-09 18:28:05 -07:00
|
|
|
bool *dirty;
|
2015-01-08 21:19:06 -07:00
|
|
|
private:
|
|
|
|
void resize(int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
dfhack_viewscreen::resize(x, y);
|
|
|
|
menu_options.resize();
|
|
|
|
}
|
|
|
|
};
|
2015-02-23 14:52:18 -07:00
|
|
|
class viewscreen_unitprofessionset : public dfhack_viewscreen {
|
|
|
|
public:
|
|
|
|
viewscreen_unitprofessionset(vector<UnitInfo*> &base_units,
|
|
|
|
bool filter_selected = true
|
|
|
|
)
|
|
|
|
{
|
|
|
|
menu_options.multiselect = false;
|
|
|
|
menu_options.auto_select = true;
|
|
|
|
menu_options.allow_search = false;
|
|
|
|
menu_options.left_margin = 2;
|
|
|
|
menu_options.bottom_margin = 2;
|
|
|
|
menu_options.clear();
|
|
|
|
|
|
|
|
manager.reload();
|
|
|
|
for (size_t i = 0; i < manager.templates.size(); i++) {
|
|
|
|
std::string name = manager.templates[i].name;
|
|
|
|
if (manager.templates[i].mask)
|
|
|
|
name += " (mask)";
|
|
|
|
ListEntry<size_t> elem(name, i+1);
|
|
|
|
menu_options.add(elem);
|
|
|
|
}
|
|
|
|
menu_options.filterDisplay();
|
|
|
|
|
|
|
|
selection_empty = true;
|
|
|
|
for (auto it = base_units.begin(); it != base_units.end(); ++it)
|
|
|
|
{
|
|
|
|
UnitInfo* uinfo = *it;
|
|
|
|
if (uinfo->selected || !filter_selected)
|
|
|
|
{
|
|
|
|
selection_empty = false;
|
|
|
|
units.push_back(uinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::string getFocusString() { return "unitlabors/profession"; }
|
|
|
|
void feed(set<df::interface_key> *events)
|
|
|
|
{
|
|
|
|
if (events->count(interface_key::LEAVESCREEN))
|
|
|
|
{
|
|
|
|
Screen::dismiss(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (menu_options.feed(events))
|
|
|
|
{
|
|
|
|
// Allow left mouse button to trigger menu options
|
|
|
|
if (menu_options.feed_mouse_set_highlight)
|
|
|
|
events->insert(interface_key::SELECT);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (events->count(interface_key::SELECT))
|
|
|
|
{
|
|
|
|
select_profession(menu_options.getFirstSelectedElem());
|
|
|
|
Screen::dismiss(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void select_profession(size_t selected)
|
|
|
|
{
|
2015-07-31 14:46:00 -06:00
|
|
|
if (selected >= manager.templates.size())
|
|
|
|
return;
|
2015-02-23 14:52:18 -07:00
|
|
|
ProfessionTemplate prof = manager.templates[selected - 1];
|
|
|
|
|
|
|
|
for (auto it = units.begin(); it != units.end(); ++it)
|
|
|
|
{
|
|
|
|
UnitInfo* u = (*it);
|
|
|
|
if (!u || !u->unit || !u->allowEdit) continue;
|
|
|
|
prof.apply(u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void render()
|
|
|
|
{
|
|
|
|
dfhack_viewscreen::render();
|
|
|
|
Screen::clear();
|
|
|
|
int x = 2, y = 2;
|
|
|
|
Screen::drawBorder(" Dwarf Manipulator - Custom Profession ");
|
2015-07-31 14:46:00 -06:00
|
|
|
if (!manager.templates.size())
|
|
|
|
{
|
|
|
|
OutputString(COLOR_LIGHTRED, x, y, "No saved professions");
|
|
|
|
return;
|
|
|
|
}
|
2015-02-23 14:52:18 -07:00
|
|
|
if (selection_empty)
|
|
|
|
{
|
|
|
|
OutputString(COLOR_LIGHTRED, x, y, "No dwarves selected!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
menu_options.display(true);
|
|
|
|
OutputString(COLOR_LIGHTGREEN, x, y, itos(units.size()));
|
|
|
|
OutputString(COLOR_GREY, x, y, string(" ") + (units.size() > 1 ? "dwarves" : "dwarf") + " selected: ");
|
|
|
|
int max_x = gps->dimx - 2;
|
|
|
|
size_t i = 0;
|
|
|
|
for ( ; i < units.size(); i++)
|
|
|
|
{
|
|
|
|
string name = unit_ops::get_nickname(units[i]);
|
|
|
|
if (name.size() + x + 12 >= max_x) // 12 = "and xxx more"
|
|
|
|
break;
|
|
|
|
OutputString(COLOR_WHITE, x, y, name + ", ");
|
|
|
|
}
|
|
|
|
if (i == units.size())
|
|
|
|
{
|
|
|
|
x -= 2;
|
|
|
|
OutputString(COLOR_WHITE, x, y, " ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OutputString(COLOR_GREY, x, y, "and " + itos(units.size() - i) + " more");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
bool selection_empty;
|
|
|
|
ListColumn<size_t> menu_options;
|
|
|
|
vector<UnitInfo*> units;
|
|
|
|
private:
|
|
|
|
void resize(int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
dfhack_viewscreen::resize(x, y);
|
|
|
|
menu_options.resize();
|
|
|
|
}
|
|
|
|
};
|
2015-01-08 21:19:06 -07:00
|
|
|
|
2012-09-13 14:42:51 -06:00
|
|
|
enum display_columns {
|
2014-10-31 12:33:35 -06:00
|
|
|
DISP_COLUMN_STRESS,
|
2015-01-08 18:55:37 -07:00
|
|
|
DISP_COLUMN_SELECTED,
|
2012-09-13 14:42:51 -06:00
|
|
|
DISP_COLUMN_NAME,
|
2015-02-17 15:17:26 -07:00
|
|
|
DISP_COLUMN_DETAIL,
|
2012-09-13 14:42:51 -06:00
|
|
|
DISP_COLUMN_LABORS,
|
|
|
|
DISP_COLUMN_MAX,
|
|
|
|
};
|
|
|
|
|
2012-08-22 02:23:56 -06:00
|
|
|
class viewscreen_unitlaborsst : public dfhack_viewscreen {
|
2012-08-21 14:43:32 -06:00
|
|
|
public:
|
|
|
|
void feed(set<df::interface_key> *events);
|
2012-08-22 08:18:19 -06:00
|
|
|
|
2012-09-20 02:27:03 -06:00
|
|
|
void logic() {
|
|
|
|
dfhack_viewscreen::logic();
|
|
|
|
if (do_refresh_names)
|
|
|
|
refreshNames();
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
void render();
|
|
|
|
void resize(int w, int h) { calcSize(); }
|
|
|
|
|
|
|
|
void help() { }
|
2012-08-22 02:23:56 -06:00
|
|
|
|
|
|
|
std::string getFocusString() { return "unitlabors"; }
|
|
|
|
|
2012-09-20 01:11:20 -06:00
|
|
|
df::unit *getSelectedUnit();
|
|
|
|
|
2012-09-19 09:20:18 -06:00
|
|
|
viewscreen_unitlaborsst(vector<df::unit*> &src, int cursor_pos);
|
2012-08-21 14:43:32 -06:00
|
|
|
~viewscreen_unitlaborsst() { };
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 19:52:19 -06:00
|
|
|
vector<UnitInfo *> units;
|
2012-08-25 09:57:50 -06:00
|
|
|
altsort_mode altsort;
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-09-20 02:27:03 -06:00
|
|
|
bool do_refresh_names;
|
2015-02-17 15:17:26 -07:00
|
|
|
int detail_mode;
|
2012-09-13 14:42:51 -06:00
|
|
|
int first_row, sel_row, num_rows;
|
2012-08-21 14:43:32 -06:00
|
|
|
int first_column, sel_column;
|
2015-01-08 18:55:37 -07:00
|
|
|
int last_selection;
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-09-13 14:42:51 -06:00
|
|
|
int col_widths[DISP_COLUMN_MAX];
|
|
|
|
int col_offsets[DISP_COLUMN_MAX];
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-09-20 02:27:03 -06:00
|
|
|
void refreshNames();
|
2015-01-09 15:15:14 -07:00
|
|
|
void calcIDs();
|
2012-08-21 14:43:32 -06:00
|
|
|
void calcSize ();
|
|
|
|
};
|
|
|
|
|
2012-09-19 09:20:18 -06:00
|
|
|
viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src, int cursor_pos)
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
2012-09-23 06:41:14 -06:00
|
|
|
std::map<df::unit*,int> active_idx;
|
|
|
|
auto &active = world->units.active;
|
|
|
|
for (size_t i = 0; i < active.size(); i++)
|
|
|
|
active_idx[active[i]] = i;
|
|
|
|
|
2012-08-25 09:57:50 -06:00
|
|
|
for (size_t i = 0; i < src.size(); i++)
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
2012-08-25 09:57:50 -06:00
|
|
|
df::unit *unit = src[i];
|
2012-09-28 17:38:32 -06:00
|
|
|
if (!unit)
|
2012-09-29 03:01:11 -06:00
|
|
|
{
|
|
|
|
if (cursor_pos > i)
|
|
|
|
cursor_pos--;
|
2012-09-28 17:38:32 -06:00
|
|
|
continue;
|
2012-09-29 03:01:11 -06:00
|
|
|
}
|
2012-09-28 17:38:32 -06:00
|
|
|
|
|
|
|
UnitInfo *cur = new UnitInfo;
|
|
|
|
|
2015-01-09 15:15:14 -07:00
|
|
|
cur->ids.init();
|
2012-08-22 19:52:19 -06:00
|
|
|
cur->unit = unit;
|
|
|
|
cur->allowEdit = true;
|
2015-01-08 18:55:37 -07:00
|
|
|
cur->selected = false;
|
2012-09-23 06:41:14 -06:00
|
|
|
cur->active_index = active_idx[unit];
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2015-01-28 14:26:17 -07:00
|
|
|
if (!Units::isOwnRace(unit))
|
2012-08-22 19:52:19 -06:00
|
|
|
cur->allowEdit = false;
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2015-01-28 14:26:17 -07:00
|
|
|
if (!Units::isOwnCiv(unit))
|
2012-08-22 19:52:19 -06:00
|
|
|
cur->allowEdit = false;
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-08-22 19:52:19 -06:00
|
|
|
if (unit->flags1.bits.dead)
|
|
|
|
cur->allowEdit = false;
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-08-22 19:52:19 -06:00
|
|
|
if (!ENUM_ATTR(profession, can_assign_labor, unit->profession))
|
|
|
|
cur->allowEdit = false;
|
|
|
|
|
|
|
|
cur->color = Units::getProfessionColor(unit);
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
units.push_back(cur);
|
|
|
|
}
|
2012-08-25 09:57:50 -06:00
|
|
|
altsort = ALTSORT_NAME;
|
2015-02-17 15:17:26 -07:00
|
|
|
detail_mode = DETAIL_MODE_PROFESSION;
|
2012-08-25 09:57:50 -06:00
|
|
|
first_column = sel_column = 0;
|
2012-09-19 09:20:18 -06:00
|
|
|
|
2012-09-20 02:27:03 -06:00
|
|
|
refreshNames();
|
2015-01-09 15:15:14 -07:00
|
|
|
calcIDs();
|
2012-09-20 02:27:03 -06:00
|
|
|
|
2012-09-19 09:20:18 -06:00
|
|
|
first_row = 0;
|
|
|
|
sel_row = cursor_pos;
|
2012-08-25 09:57:50 -06:00
|
|
|
calcSize();
|
2012-09-19 09:20:18 -06:00
|
|
|
|
|
|
|
// recalculate first_row to roughly match the original layout
|
|
|
|
first_row = 0;
|
|
|
|
while (first_row < sel_row - num_rows + 1)
|
|
|
|
first_row += num_rows + 2;
|
|
|
|
// make sure the selection stays visible
|
|
|
|
if (first_row > sel_row)
|
|
|
|
first_row = sel_row - num_rows + 1;
|
|
|
|
// don't scroll beyond the end
|
|
|
|
if (first_row > units.size() - num_rows)
|
|
|
|
first_row = units.size() - num_rows;
|
2015-01-08 18:55:37 -07:00
|
|
|
|
|
|
|
last_selection = -1;
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
|
2015-01-09 15:15:14 -07:00
|
|
|
void viewscreen_unitlaborsst::calcIDs()
|
|
|
|
{
|
|
|
|
static int list_prof_ids[NUM_COLUMNS];
|
|
|
|
static int list_group_ids[NUM_COLUMNS];
|
2015-01-09 18:28:05 -07:00
|
|
|
static map<df::profession, int> group_map;
|
|
|
|
static bool initialized = false;
|
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
initialized = true;
|
|
|
|
for (int i = 0; i < NUM_COLUMNS; i++)
|
|
|
|
group_map.insert(std::pair<df::profession, int>(columns[i].profession, columns[i].group));
|
|
|
|
}
|
2015-01-09 15:15:14 -07:00
|
|
|
memset(list_prof_ids, 0, sizeof(list_prof_ids));
|
|
|
|
memset(list_group_ids, 0, sizeof(list_group_ids));
|
|
|
|
for (size_t i = 0; i < units.size(); i++)
|
|
|
|
{
|
|
|
|
UnitInfo *cur = units[i];
|
|
|
|
cur->ids.list_id = (int)i + 1;
|
|
|
|
cur->ids.list_id_prof = ++list_prof_ids[cur->unit->profession];
|
2015-01-09 18:28:05 -07:00
|
|
|
cur->ids.list_id_group = 0;
|
|
|
|
auto it = group_map.find(cur->unit->profession);
|
|
|
|
if (it != group_map.end())
|
|
|
|
cur->ids.list_id_group = ++list_group_ids[it->second];
|
2015-01-09 15:15:14 -07:00
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
|
2012-09-20 02:27:03 -06:00
|
|
|
void viewscreen_unitlaborsst::refreshNames()
|
|
|
|
{
|
|
|
|
do_refresh_names = false;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < units.size(); i++)
|
|
|
|
{
|
|
|
|
UnitInfo *cur = units[i];
|
|
|
|
df::unit *unit = cur->unit;
|
|
|
|
|
2012-10-07 16:35:41 -06:00
|
|
|
cur->name = Translation::TranslateName(Units::getVisibleName(unit), false);
|
|
|
|
cur->transname = Translation::TranslateName(Units::getVisibleName(unit), true);
|
2012-09-20 02:27:03 -06:00
|
|
|
cur->profession = Units::getProfessionName(unit);
|
2015-02-17 15:17:26 -07:00
|
|
|
|
|
|
|
if (unit->job.current_job == NULL) {
|
|
|
|
cur->job_info = "Idle";
|
|
|
|
} else {
|
|
|
|
cur->job_info = DFHack::Job::getName(unit->job.current_job);
|
|
|
|
}
|
2014-06-09 19:58:16 -06:00
|
|
|
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 = "";
|
|
|
|
}
|
2012-09-20 02:27:03 -06:00
|
|
|
}
|
2012-09-28 05:52:54 -06:00
|
|
|
calcSize();
|
2012-09-20 02:27:03 -06:00
|
|
|
}
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
void viewscreen_unitlaborsst::calcSize()
|
|
|
|
{
|
2012-11-23 18:18:56 -07:00
|
|
|
auto dim = Screen::getWindowSize();
|
|
|
|
|
2014-06-09 19:58:16 -06:00
|
|
|
num_rows = dim.y - 11;
|
2012-09-13 14:42:51 -06:00
|
|
|
if (num_rows > units.size())
|
|
|
|
num_rows = units.size();
|
|
|
|
|
2012-11-23 18:18:56 -07:00
|
|
|
int num_columns = dim.x - DISP_COLUMN_MAX - 1;
|
2012-09-28 05:52:54 -06:00
|
|
|
|
|
|
|
// min/max width of columns
|
|
|
|
int col_minwidth[DISP_COLUMN_MAX];
|
|
|
|
int col_maxwidth[DISP_COLUMN_MAX];
|
2014-10-31 12:33:35 -06:00
|
|
|
col_minwidth[DISP_COLUMN_STRESS] = 6;
|
|
|
|
col_maxwidth[DISP_COLUMN_STRESS] = 6;
|
2015-01-08 18:55:37 -07:00
|
|
|
col_minwidth[DISP_COLUMN_SELECTED] = 1;
|
|
|
|
col_maxwidth[DISP_COLUMN_SELECTED] = 1;
|
2014-06-10 20:59:28 -06:00
|
|
|
col_minwidth[DISP_COLUMN_NAME] = 16;
|
|
|
|
col_maxwidth[DISP_COLUMN_NAME] = 16; // adjusted in the loop below
|
2015-02-17 15:17:26 -07:00
|
|
|
col_minwidth[DISP_COLUMN_DETAIL] = 10;
|
|
|
|
col_maxwidth[DISP_COLUMN_DETAIL] = 10; // adjusted in the loop below
|
2014-11-01 10:24:05 -06:00
|
|
|
col_minwidth[DISP_COLUMN_LABORS] = 1;
|
2012-09-28 05:52:54 -06:00
|
|
|
col_maxwidth[DISP_COLUMN_LABORS] = NUM_COLUMNS;
|
|
|
|
|
|
|
|
// get max_name/max_prof from strings length
|
|
|
|
for (size_t i = 0; i < units.size(); i++)
|
|
|
|
{
|
|
|
|
if (col_maxwidth[DISP_COLUMN_NAME] < units[i]->name.size())
|
|
|
|
col_maxwidth[DISP_COLUMN_NAME] = units[i]->name.size();
|
2015-02-17 15:17:26 -07:00
|
|
|
|
|
|
|
size_t detail_cmp;
|
|
|
|
if (detail_mode == DETAIL_MODE_SQUAD) {
|
|
|
|
detail_cmp = units[i]->squad_info.size();
|
|
|
|
} else if (detail_mode == DETAIL_MODE_JOB) {
|
|
|
|
detail_cmp = units[i]->job_info.size();
|
2014-06-10 20:59:28 -06:00
|
|
|
} else {
|
2015-02-17 15:17:26 -07:00
|
|
|
detail_cmp = units[i]->profession.size();
|
2014-06-10 20:59:28 -06:00
|
|
|
}
|
2015-02-17 15:17:26 -07:00
|
|
|
if (col_maxwidth[DISP_COLUMN_DETAIL] < detail_cmp)
|
|
|
|
col_maxwidth[DISP_COLUMN_DETAIL] = detail_cmp;
|
2012-09-28 05:52:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// check how much room we have
|
|
|
|
int width_min = 0, width_max = 0;
|
2012-09-13 14:42:51 -06:00
|
|
|
for (int i = 0; i < DISP_COLUMN_MAX; i++)
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
2012-09-28 05:52:54 -06:00
|
|
|
width_min += col_minwidth[i];
|
|
|
|
width_max += col_maxwidth[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width_max <= num_columns)
|
|
|
|
{
|
|
|
|
// lots of space, distribute leftover (except last column)
|
|
|
|
int col_margin = (num_columns - width_max) / (DISP_COLUMN_MAX-1);
|
|
|
|
int col_margin_r = (num_columns - width_max) % (DISP_COLUMN_MAX-1);
|
|
|
|
for (int i = DISP_COLUMN_MAX-1; i>=0; i--)
|
2012-09-13 14:42:51 -06:00
|
|
|
{
|
2012-09-28 05:52:54 -06:00
|
|
|
col_widths[i] = col_maxwidth[i];
|
|
|
|
|
|
|
|
if (i < DISP_COLUMN_MAX-1)
|
|
|
|
{
|
|
|
|
col_widths[i] += col_margin;
|
|
|
|
|
|
|
|
if (col_margin_r)
|
|
|
|
{
|
|
|
|
col_margin_r--;
|
|
|
|
col_widths[i]++;
|
|
|
|
}
|
|
|
|
}
|
2012-09-13 14:42:51 -06:00
|
|
|
}
|
2012-09-28 05:52:54 -06:00
|
|
|
}
|
|
|
|
else if (width_min <= num_columns)
|
|
|
|
{
|
|
|
|
// constrained, give between min and max to every column
|
|
|
|
int space = num_columns - width_min;
|
|
|
|
// max size columns not yet seen may consume
|
|
|
|
int next_consume_max = width_max - width_min;
|
|
|
|
|
|
|
|
for (int i = 0; i < DISP_COLUMN_MAX; i++)
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
2012-09-28 05:52:54 -06:00
|
|
|
// divide evenly remaining space
|
|
|
|
int col_margin = space / (DISP_COLUMN_MAX-i);
|
|
|
|
|
|
|
|
// take more if the columns after us cannot
|
|
|
|
next_consume_max -= (col_maxwidth[i]-col_minwidth[i]);
|
|
|
|
if (col_margin < space-next_consume_max)
|
|
|
|
col_margin = space - next_consume_max;
|
|
|
|
|
|
|
|
// no more than maxwidth
|
|
|
|
if (col_margin > col_maxwidth[i] - col_minwidth[i])
|
|
|
|
col_margin = col_maxwidth[i] - col_minwidth[i];
|
|
|
|
|
|
|
|
col_widths[i] = col_minwidth[i] + col_margin;
|
|
|
|
|
|
|
|
space -= col_margin;
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
}
|
2012-09-28 05:52:54 -06:00
|
|
|
else
|
2012-09-13 14:42:51 -06:00
|
|
|
{
|
2012-09-28 05:52:54 -06:00
|
|
|
// should not happen, min screen is 80x25
|
|
|
|
int space = num_columns;
|
|
|
|
for (int i = 0; i < DISP_COLUMN_MAX; i++)
|
|
|
|
{
|
|
|
|
col_widths[i] = space / (DISP_COLUMN_MAX-i);
|
|
|
|
space -= col_widths[i];
|
|
|
|
}
|
2012-09-13 14:42:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < DISP_COLUMN_MAX; i++)
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
2012-09-13 14:42:51 -06:00
|
|
|
if (i == 0)
|
|
|
|
col_offsets[i] = 1;
|
2012-08-21 14:43:32 -06:00
|
|
|
else
|
2012-09-13 14:42:51 -06:00
|
|
|
col_offsets[i] = col_offsets[i - 1] + col_widths[i - 1] + 1;
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:54:34 -06:00
|
|
|
// don't adjust scroll position immediately after the window opened
|
|
|
|
if (units.size() == 0)
|
|
|
|
return;
|
|
|
|
|
2012-08-22 09:43:26 -06:00
|
|
|
// if the window grows vertically, scroll upward to eliminate blank rows from the bottom
|
2012-09-13 14:42:51 -06:00
|
|
|
if (first_row > units.size() - num_rows)
|
|
|
|
first_row = units.size() - num_rows;
|
2012-08-22 09:43:26 -06:00
|
|
|
|
|
|
|
// if it shrinks vertically, scroll downward to keep the cursor visible
|
2012-09-13 14:42:51 -06:00
|
|
|
if (first_row < sel_row - num_rows + 1)
|
|
|
|
first_row = sel_row - num_rows + 1;
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-08-22 09:43:26 -06:00
|
|
|
// if the window grows horizontally, scroll to the left to eliminate blank columns from the right
|
2012-09-13 14:42:51 -06:00
|
|
|
if (first_column > NUM_COLUMNS - col_widths[DISP_COLUMN_LABORS])
|
|
|
|
first_column = NUM_COLUMNS - col_widths[DISP_COLUMN_LABORS];
|
2012-08-22 09:43:26 -06:00
|
|
|
|
|
|
|
// if it shrinks horizontally, scroll to the right to keep the cursor visible
|
2012-09-13 14:42:51 -06:00
|
|
|
if (first_column < sel_column - col_widths[DISP_COLUMN_LABORS] + 1)
|
|
|
|
first_column = sel_column - col_widths[DISP_COLUMN_LABORS] + 1;
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void viewscreen_unitlaborsst::feed(set<df::interface_key> *events)
|
|
|
|
{
|
2015-01-14 13:06:59 -07:00
|
|
|
int8_t modstate = Core::getInstance().getModstate();
|
2012-09-20 02:27:03 -06:00
|
|
|
bool leave_all = events->count(interface_key::LEAVESCREEN_ALL);
|
|
|
|
if (leave_all || events->count(interface_key::LEAVESCREEN))
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
|
|
|
events->clear();
|
|
|
|
Screen::dismiss(this);
|
2012-09-20 02:27:03 -06:00
|
|
|
if (leave_all)
|
|
|
|
{
|
|
|
|
events->insert(interface_key::LEAVESCREEN);
|
|
|
|
parent->feed(events);
|
2012-09-28 03:32:41 -06:00
|
|
|
events->clear();
|
2012-09-20 02:27:03 -06:00
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!units.size())
|
|
|
|
return;
|
|
|
|
|
2012-09-20 02:27:03 -06:00
|
|
|
if (do_refresh_names)
|
|
|
|
refreshNames();
|
|
|
|
|
2012-09-28 02:44:35 -06:00
|
|
|
int old_sel_row = sel_row;
|
|
|
|
|
2012-08-22 09:43:26 -06:00
|
|
|
if (events->count(interface_key::CURSOR_UP) || events->count(interface_key::CURSOR_UPLEFT) || events->count(interface_key::CURSOR_UPRIGHT))
|
2012-08-21 14:43:32 -06:00
|
|
|
sel_row--;
|
2012-08-22 09:43:26 -06:00
|
|
|
if (events->count(interface_key::CURSOR_UP_FAST) || events->count(interface_key::CURSOR_UPLEFT_FAST) || events->count(interface_key::CURSOR_UPRIGHT_FAST))
|
|
|
|
sel_row -= 10;
|
|
|
|
if (events->count(interface_key::CURSOR_DOWN) || events->count(interface_key::CURSOR_DOWNLEFT) || events->count(interface_key::CURSOR_DOWNRIGHT))
|
2012-08-21 14:43:32 -06:00
|
|
|
sel_row++;
|
2012-08-22 09:43:26 -06:00
|
|
|
if (events->count(interface_key::CURSOR_DOWN_FAST) || events->count(interface_key::CURSOR_DOWNLEFT_FAST) || events->count(interface_key::CURSOR_DOWNRIGHT_FAST))
|
|
|
|
sel_row += 10;
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-09-23 06:41:14 -06:00
|
|
|
if ((sel_row > 0) && events->count(interface_key::CURSOR_UP_Z_AUX))
|
|
|
|
{
|
|
|
|
sel_row = 0;
|
|
|
|
}
|
|
|
|
if ((sel_row < units.size()-1) && events->count(interface_key::CURSOR_DOWN_Z_AUX))
|
|
|
|
{
|
|
|
|
sel_row = units.size()-1;
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
if (sel_row < 0)
|
2012-09-28 02:44:35 -06:00
|
|
|
{
|
|
|
|
if (old_sel_row == 0 && events->count(interface_key::CURSOR_UP))
|
|
|
|
sel_row = units.size() - 1;
|
|
|
|
else
|
|
|
|
sel_row = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
if (sel_row > units.size() - 1)
|
2012-09-28 02:44:35 -06:00
|
|
|
{
|
|
|
|
if (old_sel_row == units.size()-1 && events->count(interface_key::CURSOR_DOWN))
|
|
|
|
sel_row = 0;
|
|
|
|
else
|
|
|
|
sel_row = units.size() - 1;
|
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-09-29 03:01:11 -06:00
|
|
|
if (events->count(interface_key::STRING_A000))
|
|
|
|
sel_row = 0;
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
if (sel_row < first_row)
|
|
|
|
first_row = sel_row;
|
2012-09-13 14:42:51 -06:00
|
|
|
if (first_row < sel_row - num_rows + 1)
|
|
|
|
first_row = sel_row - num_rows + 1;
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-08-22 09:43:26 -06:00
|
|
|
if (events->count(interface_key::CURSOR_LEFT) || events->count(interface_key::CURSOR_UPLEFT) || events->count(interface_key::CURSOR_DOWNLEFT))
|
2012-08-21 14:43:32 -06:00
|
|
|
sel_column--;
|
2012-08-22 09:43:26 -06:00
|
|
|
if (events->count(interface_key::CURSOR_LEFT_FAST) || events->count(interface_key::CURSOR_UPLEFT_FAST) || events->count(interface_key::CURSOR_DOWNLEFT_FAST))
|
|
|
|
sel_column -= 10;
|
|
|
|
if (events->count(interface_key::CURSOR_RIGHT) || events->count(interface_key::CURSOR_UPRIGHT) || events->count(interface_key::CURSOR_DOWNRIGHT))
|
2012-08-21 14:43:32 -06:00
|
|
|
sel_column++;
|
2012-08-22 09:43:26 -06:00
|
|
|
if (events->count(interface_key::CURSOR_RIGHT_FAST) || events->count(interface_key::CURSOR_UPRIGHT_FAST) || events->count(interface_key::CURSOR_DOWNRIGHT_FAST))
|
|
|
|
sel_column += 10;
|
|
|
|
|
|
|
|
if ((sel_column != 0) && events->count(interface_key::CURSOR_UP_Z))
|
|
|
|
{
|
|
|
|
// go to beginning of current column group; if already at the beginning, go to the beginning of the previous one
|
|
|
|
sel_column--;
|
2012-08-30 08:46:09 -06:00
|
|
|
int cur = columns[sel_column].group;
|
|
|
|
while ((sel_column > 0) && columns[sel_column - 1].group == cur)
|
2012-08-22 09:43:26 -06:00
|
|
|
sel_column--;
|
|
|
|
}
|
|
|
|
if ((sel_column != NUM_COLUMNS - 1) && events->count(interface_key::CURSOR_DOWN_Z))
|
|
|
|
{
|
2012-09-28 10:55:13 -06:00
|
|
|
// go to beginning of next group
|
2012-08-30 08:46:09 -06:00
|
|
|
int cur = columns[sel_column].group;
|
2012-09-28 10:55:13 -06:00
|
|
|
int next = sel_column+1;
|
|
|
|
while ((next < NUM_COLUMNS) && (columns[next].group == cur))
|
|
|
|
next++;
|
|
|
|
if ((next < NUM_COLUMNS) && (columns[next].group != cur))
|
|
|
|
sel_column = next;
|
2012-08-22 09:43:26 -06:00
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-09-29 03:01:11 -06:00
|
|
|
if (events->count(interface_key::STRING_A000))
|
|
|
|
sel_column = 0;
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
if (sel_column < 0)
|
|
|
|
sel_column = 0;
|
|
|
|
if (sel_column > NUM_COLUMNS - 1)
|
|
|
|
sel_column = NUM_COLUMNS - 1;
|
|
|
|
|
2012-09-28 10:58:58 -06:00
|
|
|
if (events->count(interface_key::CURSOR_DOWN_Z) || events->count(interface_key::CURSOR_UP_Z))
|
|
|
|
{
|
|
|
|
// when moving by group, ensure the whole group is shown onscreen
|
|
|
|
int endgroup_column = sel_column;
|
|
|
|
while ((endgroup_column < NUM_COLUMNS-1) && columns[endgroup_column+1].group == columns[sel_column].group)
|
|
|
|
endgroup_column++;
|
|
|
|
|
|
|
|
if (first_column < endgroup_column - col_widths[DISP_COLUMN_LABORS] + 1)
|
|
|
|
first_column = endgroup_column - col_widths[DISP_COLUMN_LABORS] + 1;
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
if (sel_column < first_column)
|
|
|
|
first_column = sel_column;
|
2012-09-13 14:42:51 -06:00
|
|
|
if (first_column < sel_column - col_widths[DISP_COLUMN_LABORS] + 1)
|
|
|
|
first_column = sel_column - col_widths[DISP_COLUMN_LABORS] + 1;
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-09-19 09:20:18 -06:00
|
|
|
int input_row = sel_row;
|
|
|
|
int input_column = sel_column;
|
|
|
|
int input_sort = altsort;
|
|
|
|
|
|
|
|
// Translate mouse input to appropriate keyboard input
|
2012-09-18 12:57:06 -06:00
|
|
|
if (enabler->tracking_on && gps->mouse_x != -1 && gps->mouse_y != -1)
|
|
|
|
{
|
|
|
|
int click_header = DISP_COLUMN_MAX; // group ID of the column header clicked
|
|
|
|
int click_body = DISP_COLUMN_MAX; // group ID of the column body clicked
|
|
|
|
|
|
|
|
int click_unit = -1; // Index into units[] (-1 if out of range)
|
|
|
|
int click_labor = -1; // Index into columns[] (-1 if out of range)
|
|
|
|
|
|
|
|
for (int i = 0; i < DISP_COLUMN_MAX; i++)
|
|
|
|
{
|
|
|
|
if ((gps->mouse_x >= col_offsets[i]) &&
|
|
|
|
(gps->mouse_x < col_offsets[i] + col_widths[i]))
|
|
|
|
{
|
|
|
|
if ((gps->mouse_y >= 1) && (gps->mouse_y <= 2))
|
|
|
|
click_header = i;
|
2014-08-05 19:28:09 -06:00
|
|
|
if ((gps->mouse_y >= 4) && (gps->mouse_y < 4 + num_rows))
|
2012-09-18 12:57:06 -06:00
|
|
|
click_body = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((gps->mouse_x >= col_offsets[DISP_COLUMN_LABORS]) &&
|
|
|
|
(gps->mouse_x < col_offsets[DISP_COLUMN_LABORS] + col_widths[DISP_COLUMN_LABORS]))
|
|
|
|
click_labor = gps->mouse_x - col_offsets[DISP_COLUMN_LABORS] + first_column;
|
2014-08-05 18:59:53 -06:00
|
|
|
if ((gps->mouse_y >= 4) && (gps->mouse_y < 4 + num_rows))
|
2012-09-18 12:57:06 -06:00
|
|
|
click_unit = gps->mouse_y - 4 + first_row;
|
|
|
|
|
|
|
|
switch (click_header)
|
|
|
|
{
|
2014-10-31 12:33:35 -06:00
|
|
|
case DISP_COLUMN_STRESS:
|
2012-09-18 12:57:06 -06:00
|
|
|
if (enabler->mouse_lbut || enabler->mouse_rbut)
|
|
|
|
{
|
2014-10-31 12:33:35 -06:00
|
|
|
input_sort = ALTSORT_STRESS;
|
2012-09-19 09:20:18 -06:00
|
|
|
if (enabler->mouse_lbut)
|
|
|
|
events->insert(interface_key::SECONDSCROLL_PAGEUP);
|
|
|
|
if (enabler->mouse_rbut)
|
|
|
|
events->insert(interface_key::SECONDSCROLL_PAGEDOWN);
|
2012-09-18 12:57:06 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-01-08 18:55:37 -07:00
|
|
|
case DISP_COLUMN_SELECTED:
|
|
|
|
if (enabler->mouse_lbut || enabler->mouse_rbut)
|
|
|
|
{
|
|
|
|
input_sort = ALTSORT_SELECTED;
|
|
|
|
if (enabler->mouse_lbut)
|
|
|
|
events->insert(interface_key::SECONDSCROLL_PAGEUP);
|
|
|
|
if (enabler->mouse_rbut)
|
|
|
|
events->insert(interface_key::SECONDSCROLL_PAGEDOWN);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-09-18 12:57:06 -06:00
|
|
|
case DISP_COLUMN_NAME:
|
|
|
|
if (enabler->mouse_lbut || enabler->mouse_rbut)
|
|
|
|
{
|
2012-09-19 09:20:18 -06:00
|
|
|
input_sort = ALTSORT_NAME;
|
|
|
|
if (enabler->mouse_lbut)
|
|
|
|
events->insert(interface_key::SECONDSCROLL_PAGEDOWN);
|
|
|
|
if (enabler->mouse_rbut)
|
|
|
|
events->insert(interface_key::SECONDSCROLL_PAGEUP);
|
2012-09-18 12:57:06 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-02-17 15:17:26 -07:00
|
|
|
case DISP_COLUMN_DETAIL:
|
2014-06-09 19:58:16 -06:00
|
|
|
if (enabler->mouse_lbut || enabler->mouse_rbut)
|
|
|
|
{
|
2015-02-17 15:17:26 -07:00
|
|
|
input_sort = ALTSORT_DETAIL;
|
2014-06-09 19:58:16 -06:00
|
|
|
if (enabler->mouse_lbut)
|
|
|
|
events->insert(interface_key::SECONDSCROLL_PAGEDOWN);
|
|
|
|
if (enabler->mouse_rbut)
|
|
|
|
events->insert(interface_key::SECONDSCROLL_PAGEUP);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-09-18 12:57:06 -06:00
|
|
|
case DISP_COLUMN_LABORS:
|
|
|
|
if (enabler->mouse_lbut || enabler->mouse_rbut)
|
|
|
|
{
|
2012-09-19 09:20:18 -06:00
|
|
|
input_column = click_labor;
|
|
|
|
if (enabler->mouse_lbut)
|
|
|
|
events->insert(interface_key::SECONDSCROLL_UP);
|
|
|
|
if (enabler->mouse_rbut)
|
|
|
|
events->insert(interface_key::SECONDSCROLL_DOWN);
|
2012-09-18 12:57:06 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (click_body)
|
|
|
|
{
|
2014-10-31 12:33:35 -06:00
|
|
|
case DISP_COLUMN_STRESS:
|
2012-09-18 12:57:06 -06:00
|
|
|
// do nothing
|
|
|
|
break;
|
|
|
|
|
2015-01-08 18:55:37 -07:00
|
|
|
case DISP_COLUMN_SELECTED:
|
2015-01-14 13:06:59 -07:00
|
|
|
// left-click to select, right-click or shift-click to extend selection
|
2015-01-18 11:03:42 -07:00
|
|
|
if (enabler->mouse_rbut || (enabler->mouse_lbut && (modstate & DFH_MOD_SHIFT)))
|
2015-01-08 18:55:37 -07:00
|
|
|
{
|
|
|
|
input_row = click_unit;
|
2015-01-14 13:06:59 -07:00
|
|
|
events->insert(interface_key::CUSTOM_SHIFT_X);
|
2015-01-08 18:55:37 -07:00
|
|
|
}
|
2015-01-14 13:06:59 -07:00
|
|
|
else if (enabler->mouse_lbut)
|
2015-01-08 18:55:37 -07:00
|
|
|
{
|
|
|
|
input_row = click_unit;
|
2015-01-14 13:06:59 -07:00
|
|
|
events->insert(interface_key::CUSTOM_X);
|
2015-01-08 18:55:37 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-09-18 12:57:06 -06:00
|
|
|
case DISP_COLUMN_NAME:
|
2015-02-17 15:17:26 -07:00
|
|
|
case DISP_COLUMN_DETAIL:
|
2012-09-18 12:57:06 -06:00
|
|
|
// left-click to view, right-click to zoom
|
|
|
|
if (enabler->mouse_lbut)
|
|
|
|
{
|
2012-09-19 09:20:18 -06:00
|
|
|
input_row = click_unit;
|
2012-09-18 12:57:06 -06:00
|
|
|
events->insert(interface_key::UNITJOB_VIEW);
|
|
|
|
}
|
|
|
|
if (enabler->mouse_rbut)
|
|
|
|
{
|
2012-09-19 09:20:18 -06:00
|
|
|
input_row = click_unit;
|
2012-09-18 12:57:06 -06:00
|
|
|
events->insert(interface_key::UNITJOB_ZOOM_CRE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DISP_COLUMN_LABORS:
|
|
|
|
// left-click to toggle, right-click to just highlight
|
|
|
|
if (enabler->mouse_lbut || enabler->mouse_rbut)
|
|
|
|
{
|
|
|
|
if (enabler->mouse_lbut)
|
2012-09-19 09:20:18 -06:00
|
|
|
{
|
|
|
|
input_row = click_unit;
|
|
|
|
input_column = click_labor;
|
2012-09-18 12:57:06 -06:00
|
|
|
events->insert(interface_key::SELECT);
|
2012-09-19 09:20:18 -06:00
|
|
|
}
|
|
|
|
if (enabler->mouse_rbut)
|
|
|
|
{
|
|
|
|
sel_row = click_unit;
|
|
|
|
sel_column = click_labor;
|
|
|
|
}
|
2012-09-18 12:57:06 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
enabler->mouse_lbut = enabler->mouse_rbut = 0;
|
|
|
|
}
|
|
|
|
|
2012-09-19 09:20:18 -06:00
|
|
|
UnitInfo *cur = units[input_row];
|
2014-06-24 07:36:36 -06:00
|
|
|
if (events->count(interface_key::SELECT) && (cur->allowEdit) && columns[input_column].isValidLabor(ui->main.fortress_entity))
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
2012-08-22 19:52:19 -06:00
|
|
|
df::unit *unit = cur->unit;
|
2012-09-19 09:20:18 -06:00
|
|
|
const SkillColumn &col = columns[input_column];
|
2012-08-30 09:03:12 -06:00
|
|
|
bool newstatus = !unit->status.labors[col.labor];
|
2012-08-21 14:43:32 -06:00
|
|
|
if (col.special)
|
|
|
|
{
|
2012-08-30 09:03:12 -06:00
|
|
|
if (newstatus)
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_COLUMNS; i++)
|
|
|
|
{
|
|
|
|
if ((columns[i].labor != unit_labor::NONE) && columns[i].special)
|
2012-08-22 19:52:19 -06:00
|
|
|
unit->status.labors[columns[i].labor] = false;
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-22 19:52:19 -06:00
|
|
|
unit->military.pickup_flags.bits.update = true;
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
2012-08-30 09:03:12 -06:00
|
|
|
unit->status.labors[col.labor] = newstatus;
|
|
|
|
}
|
2014-06-24 07:36:36 -06:00
|
|
|
if (events->count(interface_key::SELECT_ALL) && (cur->allowEdit) && columns[input_column].isValidLabor(ui->main.fortress_entity))
|
2012-08-30 09:03:12 -06:00
|
|
|
{
|
|
|
|
df::unit *unit = cur->unit;
|
2012-09-19 09:20:18 -06:00
|
|
|
const SkillColumn &col = columns[input_column];
|
2014-06-24 07:36:36 -06:00
|
|
|
bool newstatus = !unit->status.labors[col.labor];
|
2012-08-30 09:03:12 -06:00
|
|
|
for (int i = 0; i < NUM_COLUMNS; i++)
|
|
|
|
{
|
|
|
|
if (columns[i].group != col.group)
|
|
|
|
continue;
|
2014-06-24 07:36:36 -06:00
|
|
|
if (!columns[i].isValidLabor(ui->main.fortress_entity))
|
|
|
|
continue;
|
2012-08-30 09:03:12 -06:00
|
|
|
if (columns[i].special)
|
|
|
|
{
|
|
|
|
if (newstatus)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < NUM_COLUMNS; j++)
|
|
|
|
{
|
|
|
|
if ((columns[j].labor != unit_labor::NONE) && columns[j].special)
|
|
|
|
unit->status.labors[columns[j].labor] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unit->military.pickup_flags.bits.update = true;
|
|
|
|
}
|
|
|
|
unit->status.labors[columns[i].labor] = newstatus;
|
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
|
2012-08-25 09:57:50 -06:00
|
|
|
if (events->count(interface_key::SECONDSCROLL_UP) || events->count(interface_key::SECONDSCROLL_DOWN))
|
|
|
|
{
|
|
|
|
descending = events->count(interface_key::SECONDSCROLL_UP);
|
2012-09-19 09:20:18 -06:00
|
|
|
sort_skill = columns[input_column].skill;
|
|
|
|
sort_labor = columns[input_column].labor;
|
2014-10-21 22:43:56 -06:00
|
|
|
std::stable_sort(units.begin(), units.end(), sortBySkill);
|
2015-01-09 18:28:05 -07:00
|
|
|
calcIDs();
|
2012-08-25 09:57:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (events->count(interface_key::SECONDSCROLL_PAGEUP) || events->count(interface_key::SECONDSCROLL_PAGEDOWN))
|
|
|
|
{
|
|
|
|
descending = events->count(interface_key::SECONDSCROLL_PAGEUP);
|
2012-09-19 09:20:18 -06:00
|
|
|
switch (input_sort)
|
2012-08-25 09:57:50 -06:00
|
|
|
{
|
|
|
|
case ALTSORT_NAME:
|
2014-10-21 22:43:56 -06:00
|
|
|
std::stable_sort(units.begin(), units.end(), sortByName);
|
2012-08-25 09:57:50 -06:00
|
|
|
break;
|
2015-01-08 18:55:37 -07:00
|
|
|
case ALTSORT_SELECTED:
|
|
|
|
std::stable_sort(units.begin(), units.end(), sortBySelected);
|
|
|
|
break;
|
2015-02-17 15:17:26 -07:00
|
|
|
case ALTSORT_DETAIL:
|
|
|
|
if (detail_mode == DETAIL_MODE_SQUAD) {
|
|
|
|
std::stable_sort(units.begin(), units.end(), sortBySquad);
|
|
|
|
} else if (detail_mode == DETAIL_MODE_JOB) {
|
|
|
|
std::stable_sort(units.begin(), units.end(), sortByJob);
|
|
|
|
} else {
|
|
|
|
std::stable_sort(units.begin(), units.end(), sortByProfession);
|
|
|
|
}
|
2014-06-09 19:58:16 -06:00
|
|
|
break;
|
2014-10-31 12:33:35 -06:00
|
|
|
case ALTSORT_STRESS:
|
2014-11-02 02:05:51 -07:00
|
|
|
std::stable_sort(units.begin(), units.end(), sortByStress);
|
2012-09-13 14:42:51 -06:00
|
|
|
break;
|
2012-09-23 06:41:14 -06:00
|
|
|
case ALTSORT_ARRIVAL:
|
2014-10-21 22:43:56 -06:00
|
|
|
std::stable_sort(units.begin(), units.end(), sortByArrival);
|
2012-09-23 06:41:14 -06:00
|
|
|
break;
|
2012-08-25 09:57:50 -06:00
|
|
|
}
|
2015-01-09 18:28:05 -07:00
|
|
|
calcIDs();
|
2012-08-25 09:57:50 -06:00
|
|
|
}
|
|
|
|
if (events->count(interface_key::CHANGETAB))
|
|
|
|
{
|
|
|
|
switch (altsort)
|
|
|
|
{
|
|
|
|
case ALTSORT_NAME:
|
2015-01-08 18:55:37 -07:00
|
|
|
altsort = ALTSORT_SELECTED;
|
|
|
|
break;
|
|
|
|
case ALTSORT_SELECTED:
|
2015-02-17 15:17:26 -07:00
|
|
|
altsort = ALTSORT_DETAIL;
|
2014-06-09 19:58:16 -06:00
|
|
|
break;
|
2015-02-17 15:17:26 -07:00
|
|
|
case ALTSORT_DETAIL:
|
2014-10-31 12:33:35 -06:00
|
|
|
altsort = ALTSORT_STRESS;
|
2012-09-13 14:42:51 -06:00
|
|
|
break;
|
2014-10-31 12:33:35 -06:00
|
|
|
case ALTSORT_STRESS:
|
2012-09-23 06:41:14 -06:00
|
|
|
altsort = ALTSORT_ARRIVAL;
|
|
|
|
break;
|
|
|
|
case ALTSORT_ARRIVAL:
|
2012-08-25 09:57:50 -06:00
|
|
|
altsort = ALTSORT_NAME;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-10 20:59:28 -06:00
|
|
|
if (events->count(interface_key::OPTION20))
|
|
|
|
{
|
2015-02-17 15:17:26 -07:00
|
|
|
if (detail_mode == DETAIL_MODE_SQUAD) {
|
|
|
|
detail_mode = DETAIL_MODE_JOB;
|
|
|
|
} else if (detail_mode == DETAIL_MODE_JOB) {
|
|
|
|
detail_mode = DETAIL_MODE_PROFESSION;
|
|
|
|
} else {
|
|
|
|
detail_mode = DETAIL_MODE_SQUAD;
|
|
|
|
}
|
2014-06-10 20:59:28 -06:00
|
|
|
}
|
2012-08-26 12:58:37 -06:00
|
|
|
|
2015-01-08 18:55:37 -07:00
|
|
|
if (events->count(interface_key::CUSTOM_SHIFT_X))
|
|
|
|
{
|
|
|
|
if (last_selection == -1 || last_selection == input_row)
|
|
|
|
events->insert(interface_key::CUSTOM_X);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = std::min(input_row, last_selection);
|
|
|
|
i <= std::max(input_row, last_selection);
|
|
|
|
i++)
|
|
|
|
{
|
|
|
|
if (i == last_selection) continue;
|
2015-01-09 13:05:49 -07:00
|
|
|
if (!units[i]->allowEdit) continue;
|
2015-01-08 18:55:37 -07:00
|
|
|
units[i]->selected = units[last_selection]->selected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 13:05:49 -07:00
|
|
|
if (events->count(interface_key::CUSTOM_X) && cur->allowEdit)
|
2015-01-08 18:55:37 -07:00
|
|
|
{
|
|
|
|
cur->selected = !cur->selected;
|
|
|
|
last_selection = input_row;
|
|
|
|
}
|
|
|
|
|
2015-01-08 21:19:06 -07:00
|
|
|
if (events->count(interface_key::CUSTOM_A) || events->count(interface_key::CUSTOM_SHIFT_A))
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < units.size(); i++)
|
2015-01-09 13:05:49 -07:00
|
|
|
if (units[i]->allowEdit)
|
|
|
|
units[i]->selected = (bool)events->count(interface_key::CUSTOM_A);
|
2015-01-08 21:19:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (events->count(interface_key::CUSTOM_B))
|
|
|
|
{
|
2015-01-09 18:28:05 -07:00
|
|
|
Screen::show(new viewscreen_unitbatchopst(units, true, &do_refresh_names));
|
2015-01-09 15:15:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (events->count(interface_key::CUSTOM_E))
|
|
|
|
{
|
|
|
|
vector<UnitInfo*> tmp;
|
|
|
|
tmp.push_back(cur);
|
2015-01-09 18:28:05 -07:00
|
|
|
Screen::show(new viewscreen_unitbatchopst(tmp, false, &do_refresh_names));
|
2015-01-08 21:19:06 -07:00
|
|
|
}
|
|
|
|
|
2015-02-23 14:52:18 -07:00
|
|
|
if (events->count(interface_key::CUSTOM_P))
|
|
|
|
{
|
|
|
|
bool has_selected = false;
|
|
|
|
for (size_t i = 0; i < units.size(); i++)
|
|
|
|
if (units[i]->selected)
|
|
|
|
has_selected = true;
|
|
|
|
|
|
|
|
if (has_selected) {
|
|
|
|
Screen::show(new viewscreen_unitprofessionset(units, true));
|
|
|
|
} else {
|
|
|
|
vector<UnitInfo*> tmp;
|
|
|
|
tmp.push_back(cur);
|
|
|
|
Screen::show(new viewscreen_unitprofessionset(tmp, false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events->count(interface_key::CUSTOM_SHIFT_P))
|
|
|
|
{
|
|
|
|
manager.save_from_unit(cur);
|
|
|
|
}
|
|
|
|
|
2012-08-26 12:58:37 -06:00
|
|
|
if (VIRTUAL_CAST_VAR(unitlist, df::viewscreen_unitlistst, parent))
|
|
|
|
{
|
|
|
|
if (events->count(interface_key::UNITJOB_VIEW) || events->count(interface_key::UNITJOB_ZOOM_CRE))
|
|
|
|
{
|
|
|
|
for (int i = 0; i < unitlist->units[unitlist->page].size(); i++)
|
|
|
|
{
|
2012-09-19 09:20:18 -06:00
|
|
|
if (unitlist->units[unitlist->page][i] == units[input_row]->unit)
|
2012-08-26 12:58:37 -06:00
|
|
|
{
|
|
|
|
unitlist->cursor_pos[unitlist->page] = i;
|
|
|
|
unitlist->feed(events);
|
|
|
|
if (Screen::isDismissed(unitlist))
|
|
|
|
Screen::dismiss(this);
|
2012-09-20 02:27:03 -06:00
|
|
|
else
|
|
|
|
do_refresh_names = true;
|
2012-08-26 12:58:37 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void viewscreen_unitlaborsst::render()
|
|
|
|
{
|
|
|
|
if (Screen::isDismissed(this))
|
|
|
|
return;
|
|
|
|
|
2012-08-22 08:18:19 -06:00
|
|
|
dfhack_viewscreen::render();
|
|
|
|
|
2012-11-23 18:18:56 -07:00
|
|
|
auto dim = Screen::getWindowSize();
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
Screen::clear();
|
2012-09-13 07:27:28 -06:00
|
|
|
Screen::drawBorder(" Dwarf Manipulator - Manage Labors ");
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2014-10-31 12:33:35 -06:00
|
|
|
Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_STRESS], 2, "Stress");
|
2015-01-08 18:55:37 -07:00
|
|
|
Screen::paintTile(Screen::Pen('\373', 7, 0), col_offsets[DISP_COLUMN_SELECTED], 2);
|
2012-09-18 12:57:06 -06:00
|
|
|
Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_NAME], 2, "Name");
|
2015-02-17 15:17:26 -07:00
|
|
|
|
|
|
|
string detail_str;
|
|
|
|
if (detail_mode == DETAIL_MODE_SQUAD) {
|
|
|
|
detail_str = "Squad";
|
|
|
|
} else if (detail_mode == DETAIL_MODE_JOB) {
|
|
|
|
detail_str = "Job";
|
|
|
|
} else {
|
|
|
|
detail_str = "Profession";
|
|
|
|
}
|
|
|
|
Screen::paintString(Screen::Pen(' ', 7, 0), col_offsets[DISP_COLUMN_DETAIL], 2, detail_str);
|
2012-09-18 12:57:06 -06:00
|
|
|
|
2012-09-13 14:42:51 -06:00
|
|
|
for (int col = 0; col < col_widths[DISP_COLUMN_LABORS]; col++)
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
|
|
|
int col_offset = col + first_column;
|
2012-08-22 09:43:26 -06:00
|
|
|
if (col_offset >= NUM_COLUMNS)
|
|
|
|
break;
|
|
|
|
|
2012-08-30 08:46:09 -06:00
|
|
|
int8_t fg = columns[col_offset].color;
|
2012-08-22 15:54:34 -06:00
|
|
|
int8_t bg = 0;
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
if (col_offset == sel_column)
|
|
|
|
{
|
|
|
|
fg = 0;
|
|
|
|
bg = 7;
|
|
|
|
}
|
2012-08-25 09:57:50 -06:00
|
|
|
|
2012-09-13 14:42:51 -06:00
|
|
|
Screen::paintTile(Screen::Pen(columns[col_offset].label[0], fg, bg), col_offsets[DISP_COLUMN_LABORS] + col, 1);
|
|
|
|
Screen::paintTile(Screen::Pen(columns[col_offset].label[1], fg, bg), col_offsets[DISP_COLUMN_LABORS] + col, 2);
|
2012-08-30 08:46:09 -06:00
|
|
|
df::profession profession = columns[col_offset].profession;
|
2012-09-12 12:42:16 -06:00
|
|
|
if ((profession != profession::NONE) && (ui->race_id != -1))
|
2012-08-30 08:46:09 -06:00
|
|
|
{
|
|
|
|
auto graphics = world->raws.creatures.all[ui->race_id]->graphics;
|
|
|
|
Screen::paintTile(
|
|
|
|
Screen::Pen(' ', fg, 0,
|
|
|
|
graphics.profession_add_color[creature_graphics_role::DEFAULT][profession],
|
|
|
|
graphics.profession_texpos[creature_graphics_role::DEFAULT][profession]),
|
2012-09-13 14:42:51 -06:00
|
|
|
col_offsets[DISP_COLUMN_LABORS] + col, 3);
|
2012-08-30 08:46:09 -06:00
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
|
2012-09-13 14:42:51 -06:00
|
|
|
for (int row = 0; row < num_rows; row++)
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
|
|
|
int row_offset = row + first_row;
|
|
|
|
if (row_offset >= units.size())
|
|
|
|
break;
|
2012-08-25 09:57:50 -06:00
|
|
|
|
2012-08-22 19:52:19 -06:00
|
|
|
UnitInfo *cur = units[row_offset];
|
|
|
|
df::unit *unit = cur->unit;
|
2012-08-21 14:43:32 -06:00
|
|
|
int8_t fg = 15, bg = 0;
|
2012-09-13 14:42:51 -06:00
|
|
|
|
2014-10-31 12:33:35 -06:00
|
|
|
int stress_lvl = unit->status.current_soul ? unit->status.current_soul->personality.stress_level : 0;
|
|
|
|
// cap at 6 digits
|
|
|
|
if (stress_lvl < -99999) stress_lvl = -99999;
|
|
|
|
if (stress_lvl > 999999) stress_lvl = 999999;
|
|
|
|
string stress = stl_sprintf("%6i", stress_lvl);
|
|
|
|
if (stress_lvl >= 500000)
|
2012-09-13 14:42:51 -06:00
|
|
|
fg = 13; // 5:1
|
2014-10-31 12:33:35 -06:00
|
|
|
else if (stress_lvl >= 250000)
|
2012-09-13 14:42:51 -06:00
|
|
|
fg = 12; // 4:1
|
2014-10-31 12:33:35 -06:00
|
|
|
else if (stress_lvl >= 100000)
|
2012-09-13 14:42:51 -06:00
|
|
|
fg = 14; // 6:1
|
2014-10-31 12:33:35 -06:00
|
|
|
else if (stress_lvl >= 0)
|
2012-09-13 14:42:51 -06:00
|
|
|
fg = 2; // 2:0
|
2014-10-31 12:33:35 -06:00
|
|
|
else
|
2012-09-13 14:42:51 -06:00
|
|
|
fg = 10; // 2:1
|
2014-10-31 12:33:35 -06:00
|
|
|
Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_STRESS], 4 + row, stress);
|
2012-09-13 14:42:51 -06:00
|
|
|
|
2015-01-09 13:05:49 -07:00
|
|
|
Screen::paintTile(
|
|
|
|
(cur->selected) ? Screen::Pen('\373', COLOR_LIGHTGREEN, 0) :
|
|
|
|
((cur->allowEdit) ? Screen::Pen('-', COLOR_DARKGREY, 0) : Screen::Pen('-', COLOR_RED, 0)),
|
|
|
|
col_offsets[DISP_COLUMN_SELECTED], 4 + row);
|
2015-01-08 18:55:37 -07:00
|
|
|
|
2012-09-13 14:42:51 -06:00
|
|
|
fg = 15;
|
2012-08-21 14:43:32 -06:00
|
|
|
if (row_offset == sel_row)
|
|
|
|
{
|
|
|
|
fg = 0;
|
|
|
|
bg = 7;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:52:19 -06:00
|
|
|
string name = cur->name;
|
2012-09-13 14:42:51 -06:00
|
|
|
name.resize(col_widths[DISP_COLUMN_NAME]);
|
|
|
|
Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_NAME], 4 + row, name);
|
2012-08-21 14:43:32 -06:00
|
|
|
|
2012-08-21 15:41:20 -06:00
|
|
|
bg = 0;
|
2015-02-17 15:17:26 -07:00
|
|
|
if (detail_mode == DETAIL_MODE_SQUAD) {
|
2014-06-10 20:59:28 -06:00
|
|
|
fg = 11;
|
2015-02-17 15:17:26 -07:00
|
|
|
detail_str = cur->squad_info;
|
|
|
|
} else if (detail_mode == DETAIL_MODE_JOB) {
|
|
|
|
detail_str = cur->job_info;
|
|
|
|
if (detail_str == "Idle") {
|
|
|
|
fg = 14;
|
|
|
|
} else {
|
|
|
|
fg = 10;
|
|
|
|
}
|
2014-06-10 20:59:28 -06:00
|
|
|
} else {
|
|
|
|
fg = cur->color;
|
2015-02-17 15:17:26 -07:00
|
|
|
detail_str = cur->profession;
|
2014-06-10 20:59:28 -06:00
|
|
|
}
|
2015-02-17 15:17:26 -07:00
|
|
|
detail_str.resize(col_widths[DISP_COLUMN_DETAIL]);
|
|
|
|
Screen::paintString(Screen::Pen(' ', fg, bg), col_offsets[DISP_COLUMN_DETAIL], 4 + row, detail_str);
|
2012-08-21 14:43:32 -06:00
|
|
|
|
|
|
|
// Print unit's skills and labor assignments
|
2012-09-13 14:42:51 -06:00
|
|
|
for (int col = 0; col < col_widths[DISP_COLUMN_LABORS]; col++)
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
|
|
|
int col_offset = col + first_column;
|
|
|
|
fg = 15;
|
|
|
|
bg = 0;
|
2012-08-31 19:35:35 -06:00
|
|
|
uint8_t c = 0xFA;
|
2012-08-21 14:43:32 -06:00
|
|
|
if ((col_offset == sel_column) && (row_offset == sel_row))
|
|
|
|
fg = 9;
|
|
|
|
if (columns[col_offset].skill != job_skill::NONE)
|
|
|
|
{
|
2012-11-02 15:28:48 -06:00
|
|
|
df::unit_skill *skill = NULL;
|
|
|
|
if (unit->status.current_soul)
|
|
|
|
skill = binsearch_in_vector<df::unit_skill,df::job_skill>(unit->status.current_soul->skills, &df::unit_skill::id, columns[col_offset].skill);
|
2012-08-22 19:52:19 -06:00
|
|
|
if ((skill != NULL) && (skill->rating || skill->experience))
|
2012-08-21 14:43:32 -06:00
|
|
|
{
|
2012-08-21 15:41:20 -06:00
|
|
|
int level = skill->rating;
|
|
|
|
if (level > NUM_SKILL_LEVELS - 1)
|
|
|
|
level = NUM_SKILL_LEVELS - 1;
|
|
|
|
c = skill_levels[level].abbrev;
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
2012-08-27 08:04:32 -06:00
|
|
|
else
|
|
|
|
c = '-';
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
2012-08-27 08:04:32 -06:00
|
|
|
if (columns[col_offset].labor != unit_labor::NONE)
|
|
|
|
{
|
|
|
|
if (unit->status.labors[columns[col_offset].labor])
|
|
|
|
{
|
|
|
|
bg = 7;
|
|
|
|
if (columns[col_offset].skill == job_skill::NONE)
|
|
|
|
c = 0xF9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-11-24 09:37:22 -07:00
|
|
|
bg = 3;
|
2012-09-13 14:42:51 -06:00
|
|
|
Screen::paintTile(Screen::Pen(c, fg, bg), col_offsets[DISP_COLUMN_LABORS] + col, 4 + row);
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:52:19 -06:00
|
|
|
UnitInfo *cur = units[sel_row];
|
2012-08-30 09:03:12 -06:00
|
|
|
bool canToggle = false;
|
2012-08-22 19:52:19 -06:00
|
|
|
if (cur != NULL)
|
2012-08-21 15:41:20 -06:00
|
|
|
{
|
2012-08-22 19:52:19 -06:00
|
|
|
df::unit *unit = cur->unit;
|
2012-11-04 07:03:02 -07:00
|
|
|
int x = 1, y = 3 + num_rows + 2;
|
|
|
|
Screen::Pen white_pen(' ', 15, 0);
|
|
|
|
|
|
|
|
Screen::paintString(white_pen, x, y, (cur->unit && cur->unit->sex) ? "\x0b" : "\x0c");
|
|
|
|
x += 2;
|
|
|
|
Screen::paintString(white_pen, x, y, cur->transname);
|
2012-08-25 09:57:50 -06:00
|
|
|
x += cur->transname.length();
|
2012-08-21 15:41:20 -06:00
|
|
|
|
2012-08-25 09:57:50 -06:00
|
|
|
if (cur->transname.length())
|
|
|
|
{
|
2012-11-04 07:03:02 -07:00
|
|
|
Screen::paintString(white_pen, x, y, ", ");
|
2012-08-25 09:57:50 -06:00
|
|
|
x += 2;
|
|
|
|
}
|
2012-11-04 07:03:02 -07:00
|
|
|
Screen::paintString(white_pen, x, y, cur->profession);
|
2012-08-25 09:57:50 -06:00
|
|
|
x += cur->profession.length();
|
2012-11-04 07:03:02 -07:00
|
|
|
Screen::paintString(white_pen, x, y, ": ");
|
2012-08-25 09:57:50 -06:00
|
|
|
x += 2;
|
2012-08-21 15:41:20 -06:00
|
|
|
|
2012-08-25 09:57:50 -06:00
|
|
|
string str;
|
2012-08-21 15:41:20 -06:00
|
|
|
if (columns[sel_column].skill == job_skill::NONE)
|
|
|
|
{
|
|
|
|
str = ENUM_ATTR_STR(unit_labor, caption, columns[sel_column].labor);
|
|
|
|
if (unit->status.labors[columns[sel_column].labor])
|
|
|
|
str += " Enabled";
|
|
|
|
else
|
|
|
|
str += " Not Enabled";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-02 15:28:48 -06:00
|
|
|
df::unit_skill *skill = NULL;
|
|
|
|
if (unit->status.current_soul)
|
|
|
|
skill = binsearch_in_vector<df::unit_skill,df::job_skill>(unit->status.current_soul->skills, &df::unit_skill::id, columns[sel_column].skill);
|
2012-08-21 15:41:20 -06:00
|
|
|
if (skill)
|
|
|
|
{
|
|
|
|
int level = skill->rating;
|
|
|
|
if (level > NUM_SKILL_LEVELS - 1)
|
|
|
|
level = NUM_SKILL_LEVELS - 1;
|
2012-08-22 09:43:26 -06:00
|
|
|
str = stl_sprintf("%s %s", skill_levels[level].name, ENUM_ATTR_STR(job_skill, caption_noun, columns[sel_column].skill));
|
2012-08-21 15:41:20 -06:00
|
|
|
if (level != NUM_SKILL_LEVELS - 1)
|
2012-08-22 02:23:56 -06:00
|
|
|
str += stl_sprintf(" (%d/%d)", skill->experience, skill_levels[level].points);
|
2012-08-21 15:41:20 -06:00
|
|
|
}
|
|
|
|
else
|
2012-08-22 09:43:26 -06:00
|
|
|
str = stl_sprintf("Not %s (0/500)", ENUM_ATTR_STR(job_skill, caption_noun, columns[sel_column].skill));
|
2012-08-21 15:41:20 -06:00
|
|
|
}
|
2014-06-09 19:58:16 -06:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
2012-08-30 09:03:12 -06:00
|
|
|
|
2014-06-24 07:36:36 -06:00
|
|
|
canToggle = (cur->allowEdit) && columns[sel_column].isValidLabor(ui->main.fortress_entity);
|
2012-08-21 15:41:20 -06:00
|
|
|
}
|
|
|
|
|
2015-01-08 18:55:37 -07:00
|
|
|
int x = 2, y = dim.y - 4;
|
2012-11-23 18:23:06 -07:00
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::SELECT));
|
2012-11-23 18:18:56 -07:00
|
|
|
OutputString(canToggle ? 15 : 8, x, y, ": Toggle labor, ");
|
2012-08-30 09:03:12 -06:00
|
|
|
|
2012-11-23 18:23:06 -07:00
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::SELECT_ALL));
|
2012-11-23 18:18:56 -07:00
|
|
|
OutputString(canToggle ? 15 : 8, x, y, ": Toggle Group, ");
|
2012-08-26 12:58:37 -06:00
|
|
|
|
2012-11-23 18:18:56 -07:00
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::UNITJOB_VIEW));
|
|
|
|
OutputString(15, x, y, ": ViewCre, ");
|
2012-08-26 12:58:37 -06:00
|
|
|
|
2012-11-23 18:18:56 -07:00
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::UNITJOB_ZOOM_CRE));
|
|
|
|
OutputString(15, x, y, ": Zoom-Cre");
|
2012-08-25 09:57:50 -06:00
|
|
|
|
2015-01-08 18:55:37 -07:00
|
|
|
x = 2; y = dim.y - 3;
|
2012-11-23 18:18:56 -07:00
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::LEAVESCREEN));
|
|
|
|
OutputString(15, x, y, ": Done, ");
|
2012-08-30 09:03:12 -06:00
|
|
|
|
2014-06-10 20:59:28 -06:00
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::OPTION20));
|
|
|
|
OutputString(15, x, y, ": Toggle View, ");
|
2014-12-21 14:42:12 -07:00
|
|
|
|
2012-11-23 18:18:56 -07:00
|
|
|
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, ");
|
2012-08-25 09:57:50 -06:00
|
|
|
|
2012-11-23 18:18:56 -07:00
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::SECONDSCROLL_PAGEDOWN));
|
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::SECONDSCROLL_PAGEUP));
|
|
|
|
OutputString(15, x, y, ": Sort by (");
|
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::CHANGETAB));
|
|
|
|
OutputString(15, x, y, ") ");
|
2012-08-25 09:57:50 -06:00
|
|
|
switch (altsort)
|
|
|
|
{
|
|
|
|
case ALTSORT_NAME:
|
2012-11-23 18:18:56 -07:00
|
|
|
OutputString(15, x, y, "Name");
|
2012-08-25 09:57:50 -06:00
|
|
|
break;
|
2015-01-08 18:55:37 -07:00
|
|
|
case ALTSORT_SELECTED:
|
|
|
|
OutputString(15, x, y, "Selected");
|
|
|
|
break;
|
2015-02-17 15:17:26 -07:00
|
|
|
case ALTSORT_DETAIL:
|
|
|
|
if (detail_mode == DETAIL_MODE_SQUAD) {
|
|
|
|
OutputString(15, x, y, "Squad");
|
|
|
|
} else if (detail_mode == DETAIL_MODE_JOB) {
|
|
|
|
OutputString(15, x, y, "Job");
|
|
|
|
} else {
|
|
|
|
OutputString(15, x, y, "Profession");
|
|
|
|
}
|
2014-06-09 19:58:16 -06:00
|
|
|
break;
|
2014-10-31 12:33:35 -06:00
|
|
|
case ALTSORT_STRESS:
|
|
|
|
OutputString(15, x, y, "Stress Level");
|
2012-09-13 14:42:51 -06:00
|
|
|
break;
|
2012-09-23 06:41:14 -06:00
|
|
|
case ALTSORT_ARRIVAL:
|
2012-11-23 18:18:56 -07:00
|
|
|
OutputString(15, x, y, "Arrival");
|
2012-09-23 06:41:14 -06:00
|
|
|
break;
|
2012-08-25 09:57:50 -06:00
|
|
|
default:
|
2012-11-23 18:18:56 -07:00
|
|
|
OutputString(15, x, y, "Unknown");
|
2012-08-25 09:57:50 -06:00
|
|
|
break;
|
|
|
|
}
|
2015-01-08 18:55:37 -07:00
|
|
|
|
|
|
|
x = 2; y = dim.y - 2;
|
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::CUSTOM_X));
|
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::CUSTOM_SHIFT_X));
|
2015-01-08 21:19:06 -07:00
|
|
|
OutputString(15, x, y, ": Select ");
|
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::CUSTOM_A));
|
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::CUSTOM_SHIFT_A));
|
|
|
|
OutputString(15, x, y, ": all/none, ");
|
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::CUSTOM_B));
|
2015-01-09 15:15:14 -07:00
|
|
|
OutputString(15, x, y, ": Batch ");
|
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::CUSTOM_E));
|
|
|
|
OutputString(15, x, y, ": Edit ");
|
2015-02-23 14:52:18 -07:00
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::CUSTOM_P));
|
|
|
|
OutputString(15, x, y, ": Apply Profession ");
|
|
|
|
OutputString(10, x, y, Screen::getKeyDisplay(interface_key::CUSTOM_SHIFT_P));
|
2015-03-05 14:48:11 -07:00
|
|
|
OutputString(15, x, y, ": Save Prof. ");
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
|
2012-09-20 01:11:20 -06:00
|
|
|
df::unit *viewscreen_unitlaborsst::getSelectedUnit()
|
|
|
|
{
|
2012-09-20 02:27:03 -06:00
|
|
|
// This query might be from the rename plugin
|
|
|
|
do_refresh_names = true;
|
|
|
|
|
2012-09-20 01:11:20 -06:00
|
|
|
return units[sel_row]->unit;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:52:19 -06:00
|
|
|
struct unitlist_hook : df::viewscreen_unitlistst
|
|
|
|
{
|
2012-08-21 14:43:32 -06:00
|
|
|
typedef df::viewscreen_unitlistst interpose_base;
|
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, feed, (set<df::interface_key> *input))
|
|
|
|
{
|
|
|
|
if (input->count(interface_key::UNITVIEW_PRF_PROF))
|
|
|
|
{
|
2012-08-25 09:57:50 -06:00
|
|
|
if (units[page].size())
|
|
|
|
{
|
2012-09-19 09:20:18 -06:00
|
|
|
Screen::show(new viewscreen_unitlaborsst(units[page], cursor_pos[page]));
|
2012-08-25 09:57:50 -06:00
|
|
|
return;
|
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
}
|
|
|
|
INTERPOSE_NEXT(feed)(input);
|
|
|
|
}
|
2012-08-31 19:35:35 -06:00
|
|
|
|
|
|
|
DEFINE_VMETHOD_INTERPOSE(void, render, ())
|
|
|
|
{
|
|
|
|
INTERPOSE_NEXT(render)();
|
|
|
|
|
|
|
|
if (units[page].size())
|
|
|
|
{
|
2012-11-23 18:18:56 -07:00
|
|
|
auto dim = Screen::getWindowSize();
|
|
|
|
int x = 2, y = dim.y - 2;
|
|
|
|
OutputString(12, x, y, Screen::getKeyDisplay(interface_key::UNITVIEW_PRF_PROF));
|
|
|
|
OutputString(15, x, y, ": Manage labors (DFHack)");
|
2012-08-31 19:35:35 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(unitlist_hook, feed);
|
2012-08-31 19:35:35 -06:00
|
|
|
IMPLEMENT_VMETHOD_INTERPOSE(unitlist_hook, render);
|
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
DFhackCExport command_result plugin_enable(color_ostream &out, bool enable)
|
|
|
|
{
|
|
|
|
if (!gps)
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
|
|
|
if (enable != is_enabled)
|
|
|
|
{
|
|
|
|
if (!INTERPOSE_HOOK(unitlist_hook, feed).apply(enable) ||
|
|
|
|
!INTERPOSE_HOOK(unitlist_hook, render).apply(enable))
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
|
|
|
is_enabled = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:43:32 -06:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, vector <PluginCommand> &commands)
|
|
|
|
{
|
2015-01-08 18:55:37 -07:00
|
|
|
if (!Filesystem::isdir(CONFIG_PATH) && !Filesystem::mkdir(CONFIG_PATH))
|
|
|
|
{
|
|
|
|
out.printerr("manipulator: Could not create configuration folder: \"%s\"\n", CONFIG_PATH);
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-08-21 14:43:32 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
|
|
|
{
|
|
|
|
INTERPOSE_HOOK(unitlist_hook, feed).remove();
|
2012-08-31 19:35:35 -06:00
|
|
|
INTERPOSE_HOOK(unitlist_hook, render).remove();
|
2012-08-21 14:43:32 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|