1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

fix reset

This commit is contained in:
Laserlicht
2025-07-19 15:45:34 +02:00
parent 72e60c6600
commit fe8a0ce301
4 changed files with 34 additions and 10 deletions

View File

@@ -264,6 +264,7 @@
"vcmi.shortcuts.editButton.help" : "Edit key binding",
"vcmi.shortcuts.input" : "Change key binding for {%s}.\n\nPlease enter a key or key kombination.",
"vcmi.shortcuts.inputSet" : "Key binding for {%s} will be changed to {%s}.\n\nAppend to existing bindings? Otherwise it will be replaced.",
"vcmi.shortcuts.popup" : "For %s the following keys are configured:\n\n",
"vcmi.shortcuts.reset" : "Reset",
"vcmi.shortcuts.reset.help" : "{Reset}\n\nResets key bindings to default",
"vcmi.shortcuts.resetConfirm" : "Do you want to reset all key bindings to default?",

View File

@@ -264,6 +264,7 @@
"vcmi.shortcuts.editButton.help" : "Tastenbelegung bearbeiten",
"vcmi.shortcuts.input" : "Tastenbelegung für {%s} ändern.\n\nBitte eine Taste oder Tastenkombination eingeben.",
"vcmi.shortcuts.inputSet" : "Tastenbelegung für {%s} wird zu {%s}. geändert\n\nZu den existierenten hinzufügen? Ansonsten wird ersetzt.",
"vcmi.shortcuts.popup" : "Für %s sind die folgenden Tastenbelegung konfiguriert:\n\n",
"vcmi.shortcuts.reset" : "Zurücks.",
"vcmi.shortcuts.reset.help" : "{Zurücksetzen}\n\nSetzt Tastenbelegungen auf Standardeinstellungen zurück",
"vcmi.shortcuts.resetConfirm" : "Alle Tastenkürzel auf Standardeinstellungen zurücksetzen?",

View File

@@ -56,7 +56,7 @@ ShortcutsWindow::ShortcutsWindow()
slider->setPanningStep(LINE_HEIGHT);
slider->setScrollBounds(Rect(-backgroundRect->pos.w + slider->pos.w, 0, slider->pos.x - pos.x + slider->pos.w, slider->pos.h));
buttonReset = std::make_shared<CButton>(Point(411, 403), AnimationPath::builtin("settingsWindow/button80"), std::make_pair("", MetaString::createFromTextID("vcmi.shortcuts.reset").toString()));
buttonReset = std::make_shared<CButton>(Point(411, 403), AnimationPath::builtin("settingsWindow/button80"), std::make_pair("", MetaString::createFromTextID("vcmi.shortcuts.reset.help").toString()));
buttonReset->setOverlay(std::make_shared<CLabel>(0, 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, MetaString::createFromTextID("vcmi.shortcuts.reset").toString()));
buttonReset->addCallback([this](){
GAME->interface()->showYesNoDialog(MetaString::createFromTextID("vcmi.shortcuts.resetConfirm").toString(), [this](){
@@ -114,7 +114,8 @@ void ShortcutsWindow::setKeyBinding(const std::string & id, const std::string &
tmp = existing.Vector();
if(existing.isString())
tmp.push_back(existing);
tmp.push_back(JsonNode(keyName));
if(!vstd::contains(tmp, JsonNode(keyName)))
tmp.push_back(JsonNode(keyName));
existingWrite->Vector() = tmp;
}
else
@@ -125,16 +126,21 @@ void ShortcutsWindow::setKeyBinding(const std::string & id, const std::string &
void ShortcutsWindow::resetKeyBinding()
{
// FIXME: Not working yet
Settings write = shortcutsConfig.write;
write->clear();
write->Struct() = JsonUtils::assembleFromFiles("config/shortcutsConfig.json").Struct();
{
Settings write = shortcutsConfig.write;
write->clear();
}
{
Settings write = shortcutsConfig.write;
write->Struct() = JsonUtils::assembleFromFiles("config/shortcutsConfig.json").Struct();
}
fillList(slider->getValue());
}
ShortcutElement::ShortcutElement(std::string id, JsonNode keys, int elem, std::function<void(const std::string & id, const std::string & keyName)> func)
: func(func)
: CIntObject(SHOW_POPUP)
, func(func)
{
OBJECT_CONSTRUCTION;
@@ -142,14 +148,21 @@ ShortcutElement::ShortcutElement(std::string id, JsonNode keys, int elem, std::f
pos.y += 56;
pos.y += elem * LINE_HEIGHT;
popupText = MetaString::createFromTextID("vcmi.shortcuts.popup");
popupText.replaceTextID("vcmi.shortcuts.shortcut." + id);
std::string keyBinding = "";
if(keys.isString())
{
keyBinding = keys.String();
popupText.appendRawString(keyBinding);
}
else if(keys.isVector())
{
std::vector<std::string> strings;
std::transform(keys.Vector().begin(), keys.Vector().end(), std::back_inserter(strings), [](const auto& k) { return k.String(); });
keyBinding = boost::join(strings, " {gray||} ");
keyBinding = boost::join(strings, " | ");
popupText.appendRawString(boost::join(strings, "\n"));
}
labelName = std::make_shared<CLabel>(
@@ -186,6 +199,11 @@ ShortcutElement::ShortcutElement(std::string group, int elem)
seperationLine = std::make_shared<TransparentFilledRectangle>(Rect(0, LINE_HEIGHT, 456, 1), ColorRGBA(0, 0, 0, 64), ColorRGBA(128, 100, 75), 1);
}
void ShortcutElement::showPopupWindow(const Point & cursorPosition)
{
CRClickPopup::createAndPush(popupText.toString());
}
ShortcutsEditWindow::ShortcutsEditWindow(const std::string & id, std::function<void(const std::string & id, const std::string & keyName)> func)
: CWindowObject(BORDERED)
, id(id)
@@ -207,7 +225,7 @@ ShortcutsEditWindow::ShortcutsEditWindow(const std::string & id, std::function<v
addUsedEvents(KEY_NAME);
}
void ShortcutsEditWindow::keyPressed(const std::string & keyName)
void ShortcutsEditWindow::keyReleased(const std::string & keyName)
{
if(boost::algorithm::ends_with(keyName, "Ctrl") || boost::algorithm::ends_with(keyName, "Shift") || boost::algorithm::ends_with(keyName, "Alt")) // skip if only control key pressed
return;

View File

@@ -12,6 +12,7 @@
#include "../CWindowObject.h"
#include "../../../lib/json/JsonNode.h"
#include "../../../lib/texts/MetaString.h"
class CFilledTexture;
class CButton;
@@ -31,8 +32,11 @@ private:
std::shared_ptr<CLabel> labelKeys;
std::shared_ptr<TransparentFilledRectangle> seperationLine; // rectangle is cleaner than line...
MetaString popupText;
std::function<void(const std::string & id, const std::string & keyName)> func;
void showPopupWindow(const Point & cursorPosition) override;
public:
ShortcutElement(std::string id, JsonNode keys, int elem, std::function<void(const std::string & id, const std::string & keyName)> func);
ShortcutElement(std::string group, int elem);
@@ -66,7 +70,7 @@ private:
std::string id;
std::function<void(const std::string & id, const std::string & keyName)> func;
void keyPressed(const std::string & keyName) override;
void keyReleased(const std::string & keyName) override;
public:
ShortcutsEditWindow(const std::string & id, std::function<void(const std::string & id, const std::string & keyName)> func);
};