From 09129ddec06dac85e919a515f1b0fef55fa9e458 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 28 Sep 2023 13:56:11 -0700 Subject: [PATCH 1/6] brighten ascii logo on hover as was originally intended. why is fg "de-bolded" by pens? --- docs/changelog.txt | 1 + plugins/lua/hotkeys.lua | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index aec12a96f..1859a7f79 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -60,6 +60,7 @@ Template for new versions: ## Misc Improvements - `dig`: `digtype` command now has options to choose between designating only visible tiles or hidden tiles, as well as "auto" dig mode. Z-level options adjusted to allow choosing z-levels above, below, or the same as the cursor. +- `hotkeys`: make the DFHack logo brighten on hover in ascii mode to indicate that it is clickable ## Documentation diff --git a/plugins/lua/hotkeys.lua b/plugins/lua/hotkeys.lua index 80f8816e8..71fda3d86 100644 --- a/plugins/lua/hotkeys.lua +++ b/plugins/lua/hotkeys.lua @@ -65,6 +65,7 @@ function HotspotMenuWidget:init() tile=function() return dfhack.textures.getTexposByHandle(logo_hovered_textures[idx]) end, ch=ch, fg=COLOR_WHITE, + bold=true, } end local function get_tile_token(idx, ch) From bff1b5e7b09cf77cb51a4bb2ef8e0596aaf6a9d2 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 28 Sep 2023 14:41:30 -0700 Subject: [PATCH 2/6] make the ascii DFHack logo easier to read --- docs/changelog.txt | 1 + plugins/lua/hotkeys.lua | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 1859a7f79..0c6b35fab 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -61,6 +61,7 @@ Template for new versions: ## Misc Improvements - `dig`: `digtype` command now has options to choose between designating only visible tiles or hidden tiles, as well as "auto" dig mode. Z-level options adjusted to allow choosing z-levels above, below, or the same as the cursor. - `hotkeys`: make the DFHack logo brighten on hover in ascii mode to indicate that it is clickable +- `hotkeys`: use vertical bars instead of "!" symbols for the DFHack logo to make it easier to read ## Documentation diff --git a/plugins/lua/hotkeys.lua b/plugins/lua/hotkeys.lua index 71fda3d86..6335de5e5 100644 --- a/plugins/lua/hotkeys.lua +++ b/plugins/lua/hotkeys.lua @@ -79,9 +79,9 @@ function HotspotMenuWidget:init() self:addviews{ widgets.Label{ text={ - get_tile_token(1, '!'), get_tile_token(2, 'D'), get_tile_token(3, 'F'), get_tile_token(4, '!'), NEWLINE, - get_tile_token(5, '!'), get_tile_token(6, 'H'), get_tile_token(7, 'a'), get_tile_token(8, '!'), NEWLINE, - get_tile_token(9, '!'), get_tile_token(10, 'c'), get_tile_token(11, 'k'), get_tile_token(12, '!'), + get_tile_token(1, 179), get_tile_token(2, 'D'), get_tile_token(3, 'F'), get_tile_token(4, 179), NEWLINE, + get_tile_token(5, 179), get_tile_token(6, 'H'), get_tile_token(7, 'a'), get_tile_token(8, 179), NEWLINE, + get_tile_token(9, 179), get_tile_token(10, 'c'), get_tile_token(11, 'k'), get_tile_token(12, 179), }, on_click=function() dfhack.run_command('hotkeys') end, }, From 13f83d2f95104bb03f8c8a4eb09b29e393506797 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 28 Sep 2023 16:35:29 -0700 Subject: [PATCH 3/6] protect against bad values in TranslateName --- docs/changelog.txt | 1 + library/modules/Translation.cpp | 49 +++++++++++++++++++++++++++------ plugins/autoslab.cpp | 20 +------------- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 1859a7f79..c9e24e70f 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -60,6 +60,7 @@ Template for new versions: ## Misc Improvements - `dig`: `digtype` command now has options to choose between designating only visible tiles or hidden tiles, as well as "auto" dig mode. Z-level options adjusted to allow choosing z-levels above, below, or the same as the cursor. +- ``dfhack.TranslateName``: protect against bad language indices added by mods - `hotkeys`: make the DFHack logo brighten on hover in ascii mode to indicate that it is clickable ## Documentation diff --git a/library/modules/Translation.cpp b/library/modules/Translation.cpp index 282039c02..af06eeb49 100644 --- a/library/modules/Translation.cpp +++ b/library/modules/Translation.cpp @@ -131,6 +131,37 @@ void Translation::setNickname(df::language_name *name, std::string nick) } } +static string translate_word(const df::language_name * name, size_t word_idx) { + CHECK_NULL_POINTER(name); + + auto translation = vector_get(world->raws.language.translations, name->language); + if (!translation) + return ""; + + auto word = vector_get(translation->words, word_idx); + if (!word) + return ""; + + return *word; +} + +static string translate_english_word(const df::language_name * name, size_t part_idx) { + CHECK_NULL_POINTER(name); + + if (part_idx >= 7) + return ""; + + auto words = vector_get(world->raws.language.words, name->words[part_idx]); + if (!words) + return ""; + + df::part_of_speech part = name->parts_of_speech[part_idx]; + if (part < df::part_of_speech::Noun || part > df::part_of_speech::VerbGerund) + return ""; + + return words->forms[part]; +} + string Translation::TranslateName(const df::language_name * name, bool inEnglish, bool onlyLastPart) { CHECK_NULL_POINTER(name); @@ -166,20 +197,20 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish { word.clear(); if (name->words[0] >= 0) - word.append(*world->raws.language.translations[name->language]->words[name->words[0]]); + word.append(translate_word(name, name->words[0])); if (name->words[1] >= 0) - word.append(*world->raws.language.translations[name->language]->words[name->words[1]]); + word.append(translate_word(name, name->words[1])); addNameWord(out, word); } word.clear(); for (int i = 2; i <= 5; i++) if (name->words[i] >= 0) - word.append(*world->raws.language.translations[name->language]->words[name->words[i]]); + word.append(translate_word(name, name->words[i])); addNameWord(out, word); if (name->words[6] >= 0) { word.clear(); - word.append(*world->raws.language.translations[name->language]->words[name->words[6]]); + word.append(translate_word(name, name->words[6])); addNameWord(out, word); } } @@ -189,9 +220,9 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish { word.clear(); if (name->words[0] >= 0) - word.append(world->raws.language.words[name->words[0]]->forms[name->parts_of_speech[0]]); + word.append(translate_english_word(name, 0)); if (name->words[1] >= 0) - word.append(world->raws.language.words[name->words[1]]->forms[name->parts_of_speech[1]]); + word.append(translate_english_word(name, 1)); addNameWord(out, word); } if (name->words[2] >= 0 || name->words[3] >= 0 || name->words[4] >= 0 || name->words[5] >= 0) @@ -201,10 +232,10 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish else out.append("The"); } - for (int i = 2; i <= 5; i++) + for (size_t i = 2; i <= 5; i++) { if (name->words[i] >= 0) - addNameWord(out, world->raws.language.words[name->words[i]]->forms[name->parts_of_speech[i]]); + addNameWord(out, translate_english_word(name, i)); } if (name->words[6] >= 0) { @@ -213,7 +244,7 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish else out.append("Of"); - addNameWord(out, world->raws.language.words[name->words[6]]->forms[name->parts_of_speech[6]]); + addNameWord(out, translate_english_word(name, 6)); } } diff --git a/plugins/autoslab.cpp b/plugins/autoslab.cpp index e78314bfd..32382a217 100644 --- a/plugins/autoslab.cpp +++ b/plugins/autoslab.cpp @@ -151,24 +151,6 @@ DFhackCExport command_result plugin_onupdate(color_ostream &out) return CR_OK; } -// Name functions taken from manipulator.cpp -static std::string get_first_name(df::unit *unit) -{ - return Translation::capitalize(unit->name.first_name); -} - -static std::string get_last_name(df::unit *unit) -{ - df::language_name name = unit->name; - std::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); -} - // Queue up a single order to engrave the slab for the given unit static void createSlabJob(df::unit *unit) { @@ -212,7 +194,7 @@ static void checkslabs(color_ostream &out) ) { createSlabJob(ghost); - auto fullName = get_first_name(ghost) + " " + get_last_name(ghost); + auto fullName = Translation::capitalize(Translation::TranslateName(&ghost->name, false), true); out.print("Added slab order for ghost %s\n", fullName.c_str()); } } From af65f185a1be7cf992fc17fe5d8d58dd9fa77855 Mon Sep 17 00:00:00 2001 From: Myk Date: Thu, 28 Sep 2023 17:43:06 -0700 Subject: [PATCH 4/6] Remove unneeded capitalize --- plugins/autoslab.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/autoslab.cpp b/plugins/autoslab.cpp index 32382a217..82333c822 100644 --- a/plugins/autoslab.cpp +++ b/plugins/autoslab.cpp @@ -194,7 +194,7 @@ static void checkslabs(color_ostream &out) ) { createSlabJob(ghost); - auto fullName = Translation::capitalize(Translation::TranslateName(&ghost->name, false), true); + auto fullName = Translation::TranslateName(&ghost->name, false); out.print("Added slab order for ghost %s\n", fullName.c_str()); } } From e1bf8c47fa2ec7bb30e6b07c4ac056b7e83aa098 Mon Sep 17 00:00:00 2001 From: Myk Date: Thu, 28 Sep 2023 20:12:40 -0700 Subject: [PATCH 5/6] Update docs/changelog.txt Co-authored-by: Alan --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index c9e24e70f..d6377e1ec 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -60,7 +60,7 @@ Template for new versions: ## Misc Improvements - `dig`: `digtype` command now has options to choose between designating only visible tiles or hidden tiles, as well as "auto" dig mode. Z-level options adjusted to allow choosing z-levels above, below, or the same as the cursor. -- ``dfhack.TranslateName``: protect against bad language indices added by mods +- ``dfhack.TranslateName()``: fixed crash on certain invalid names, which affected `warn-starving` - `hotkeys`: make the DFHack logo brighten on hover in ascii mode to indicate that it is clickable ## Documentation From 965c453b9b7c701b7fef5338bf53693210c09d11 Mon Sep 17 00:00:00 2001 From: Myk Date: Thu, 28 Sep 2023 20:13:55 -0700 Subject: [PATCH 6/6] Update changelog.txt --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index d6377e1ec..7f1944d08 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -57,10 +57,10 @@ Template for new versions: ## Fixes - `autolabor`: now unconditionally re-enables vanilla work details when the fort or the plugin is unloaded +- ``dfhack.TranslateName()``: fixed crash on certain invalid names, which affected `warn-starving` ## Misc Improvements - `dig`: `digtype` command now has options to choose between designating only visible tiles or hidden tiles, as well as "auto" dig mode. Z-level options adjusted to allow choosing z-levels above, below, or the same as the cursor. -- ``dfhack.TranslateName()``: fixed crash on certain invalid names, which affected `warn-starving` - `hotkeys`: make the DFHack logo brighten on hover in ascii mode to indicate that it is clickable ## Documentation