From 05926d9734925f88aba21db6f16eed4f20851b9c Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 26 Dec 2015 11:47:55 -0500 Subject: [PATCH] New tweak: title-start-rename Adds a safe rename option to the title screen "Start Playing" menu --- NEWS.rst | 5 +- docs/Plugins.rst | 1 + library/xml | 2 +- plugins/tweak/tweak.cpp | 7 ++ plugins/tweak/tweaks/title-start-rename.h | 112 ++++++++++++++++++++++ 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 plugins/tweak/tweaks/title-start-rename.h diff --git a/NEWS.rst b/NEWS.rst index 5d4ef51e3..4444ded39 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -9,7 +9,7 @@ Internals Lua - New [Internal Commands | Plugins | Scripts | Tweaks] + New [Internal Commands | Plugins | Scripts | Features] Fixes Misc Improvements Removed @@ -36,6 +36,9 @@ New Features ------------ - `confirm`: Added a confirmation for retiring locations - `search-plugin`: Support for the location occupation assignment menu +- `tweak`: + + - ``tweak title-start-rename``: Adds a safe rename option to the title screen "Start Playing" menu Fixes ----- diff --git a/docs/Plugins.rst b/docs/Plugins.rst index 677d75c82..952813180 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -315,6 +315,7 @@ Subcommands that persist until disabled or DF quits: :nestbox-color: Fixes the color of built nestboxes :shift-8-scroll: Gives Shift-8 (or :kbd:`*`) priority when scrolling menus, instead of scrolling the map :stable-cursor: Saves the exact cursor position between t/q/k/d/b/etc menus of fortress mode. +:title-start-rename: Adds a safe rename option to the title screen "Start Playing" menu :tradereq-pet-gender: Displays pet genders on the trade request screen .. _fix-armory: diff --git a/library/xml b/library/xml index 73a475830..11dfc8f83 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 73a4758307b01396ed28c8df011a6f95867450cf +Subproject commit 11dfc8f838617ee5d42524a838345491704d9dff diff --git a/plugins/tweak/tweak.cpp b/plugins/tweak/tweak.cpp index 98ec21eb3..6b7f11603 100644 --- a/plugins/tweak/tweak.cpp +++ b/plugins/tweak/tweak.cpp @@ -14,6 +14,7 @@ #include "modules/Materials.h" #include "modules/MapCache.h" #include "modules/Buildings.h" +#include "modules/Filesystem.h" #include "MiscUtils.h" @@ -96,6 +97,7 @@ #include "tweaks/nestbox-color.h" #include "tweaks/shift-8-scroll.h" #include "tweaks/stable-cursor.h" +#include "tweaks/title-start-rename.h" #include "tweaks/tradereq-pet-gender.h" using std::set; @@ -218,6 +220,8 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector save_dir).c_str(), full_save_dir(entry).c_str()) != 0) + return false; + save->save_dir = entry; + entry = ""; + return true; + } + + DEFINE_VMETHOD_INTERPOSE(void, render, ()) + { + INTERPOSE_NEXT(render)(); + if (sel_subpage == T_sel_subpage::StartSelectWorld || sel_subpage == T_sel_subpage::StartSelectMode) + { + auto save = get_cur_save(); + if (save) + { + int x = 1, y = 7; + OutputHotkeyString(x, y, + in_rename ? entry.c_str() : "Rename", + df::interface_key::CUSTOM_R, + false, 0, + rename_failed ? COLOR_LIGHTRED : COLOR_WHITE, + in_rename ? COLOR_RED : COLOR_LIGHTRED); + if (in_rename) + OutputString(COLOR_LIGHTGREEN, x, y, "_"); + } + } + } + + DEFINE_VMETHOD_INTERPOSE(void, feed, (std::set *input)) + { + using namespace df::enums::interface_key; + if (in_rename) + { + rename_failed = false; + auto string_key = get_string_key(input); + if (input->count(SELECT) && !entry.empty()) + { + if (do_rename()) + in_rename = false; + else + rename_failed = true; + } + else if (input->count(STRING_A000)) + { + if (!entry.empty()) + entry.erase(entry.size() - 1); + } + else if (string_key != NONE) + { + entry += Screen::keyToChar(string_key); + } + else if (input->count(LEAVESCREEN) || (input->count(SELECT) && entry.empty()) || + input->count(STANDARDSCROLL_UP) || input->count(STANDARDSCROLL_DOWN)) + { + entry = ""; + in_rename = false; + std::set tmp; + if (input->count(STANDARDSCROLL_UP)) + tmp.insert(STANDARDSCROLL_UP); + if (input->count(STANDARDSCROLL_DOWN)) + tmp.insert(STANDARDSCROLL_DOWN); + INTERPOSE_NEXT(feed)(&tmp); + } + } + else if (input->count(CUSTOM_R)) + { + in_rename = true; + } + else + { + INTERPOSE_NEXT(feed)(input); + } + } +}; + +IMPLEMENT_VMETHOD_INTERPOSE(title_start_rename_hook, render); +IMPLEMENT_VMETHOD_INTERPOSE(title_start_rename_hook, feed); + +df::viewscreen_titlest::T_sel_subpage title_start_rename_hook::last_subpage = + df::viewscreen_titlest::T_sel_subpage::None; +bool title_start_rename_hook::in_rename = false; +bool title_start_rename_hook::rename_failed = false; +std::string title_start_rename_hook::entry;