New tweak: title-start-rename

Adds a safe rename option to the title screen "Start Playing" menu
develop
lethosor 2015-12-26 11:47:55 -05:00
parent a9ad2f40f1
commit 05926d9734
5 changed files with 125 additions and 2 deletions

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

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

@ -1 +1 @@
Subproject commit 73a4758307b01396ed28c8df011a6f95867450cf
Subproject commit 11dfc8f838617ee5d42524a838345491704d9dff

@ -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 <Plugi
" tweak shift-8-scroll [disable]\n"
" Gives Shift+8 (or *) priority when scrolling menus, instead of \n"
" scrolling the map\n"
" tweak title-start-rename [disable]\n"
" Adds a safe rename option to the title screen \"Start Playing\" menu\n"
" tweak tradereq-pet-gender [disable]\n"
" Displays the gender of pets in the trade request list\n"
// " tweak military-training [disable]\n"
@ -277,6 +281,9 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
TWEAK_HOOK("stable-cursor", stable_cursor_hook, feed);
TWEAK_HOOK("title-start-rename", title_start_rename_hook, feed);
TWEAK_HOOK("title-start-rename", title_start_rename_hook, render);
TWEAK_HOOK("tradereq-pet-gender", pet_gender_hook, render);
return CR_OK;

@ -0,0 +1,112 @@
#include "df/viewscreen_titlest.h"
using namespace DFHack;
struct title_start_rename_hook : df::viewscreen_titlest {
typedef df::viewscreen_titlest interpose_base;
typedef interpose_base::T_sel_subpage T_sel_subpage;
static T_sel_subpage last_subpage;
static bool in_rename;
static bool rename_failed;
static std::string entry;
inline df::viewscreen_titlest::T_start_savegames *get_cur_save()
{
return vector_get(start_savegames, sel_submenu_line);
}
inline std::string full_save_dir(const std::string &region_name)
{
return std::string("data/save/") + region_name;
}
bool do_rename()
{
auto save = get_cur_save();
if (!save)
return false;
if (Filesystem::isdir(full_save_dir(entry)))
return false;
if (rename(full_save_dir(save->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<df::interface_key> *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<df::interface_key> 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;