mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
writing shortcuts
This commit is contained in:
@@ -91,8 +91,6 @@ void QuickSpellPanel::create()
|
||||
{
|
||||
OBJECT_CONSTRUCTION;
|
||||
|
||||
const JsonNode config = JsonUtils::assembleFromFiles("config/shortcutsConfig");
|
||||
|
||||
labels.clear();
|
||||
buttons.clear();
|
||||
buttonsDisabled.clear();
|
||||
@@ -132,7 +130,7 @@ void QuickSpellPanel::create()
|
||||
buttonsDisabled.push_back(std::make_shared<TransparentFilledRectangle>(Rect(2, 7 + 50 * i, 48, 36), ColorRGBA(0, 0, 0, 172)));
|
||||
}
|
||||
if(ENGINE->input().getCurrentInputMode() == InputMode::KEYBOARD_AND_MOUSE)
|
||||
labels.push_back(std::make_shared<CLabel>(7, 10 + 50 * i, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, config["keyboard"]["battleSpellShortcut" + std::to_string(i)].String()));
|
||||
labels.push_back(std::make_shared<CLabel>(7, 10 + 50 * i, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, shortcutsConfig["keyboard"]["battleSpellShortcut" + std::to_string(i)].String()));
|
||||
|
||||
buttons.push_back(button);
|
||||
}
|
||||
|
||||
@@ -13,21 +13,20 @@
|
||||
#include "ShortcutHandler.h"
|
||||
#include "Shortcut.h"
|
||||
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
#include "../../lib/json/JsonUtils.h"
|
||||
|
||||
ShortcutHandler::ShortcutHandler()
|
||||
{
|
||||
const JsonNode config = JsonUtils::assembleFromFiles("config/shortcutsConfig");
|
||||
|
||||
mappedKeyboardShortcuts = loadShortcuts(config["keyboard"]);
|
||||
mappedJoystickShortcuts = loadShortcuts(config["joystickButtons"]);
|
||||
mappedJoystickAxes = loadShortcuts(config["joystickAxes"]);
|
||||
mappedKeyboardShortcuts = loadShortcuts(shortcutsConfig["keyboard"]);
|
||||
mappedJoystickShortcuts = loadShortcuts(shortcutsConfig["joystickButtons"]);
|
||||
mappedJoystickAxes = loadShortcuts(shortcutsConfig["joystickAxes"]);
|
||||
|
||||
#ifndef ENABLE_GOLDMASTER
|
||||
std::vector<EShortcut> assignedShortcuts;
|
||||
std::vector<EShortcut> missingShortcuts;
|
||||
|
||||
for (auto const & entry : config["keyboard"].Struct())
|
||||
for (auto const & entry : shortcutsConfig["keyboard"].Struct())
|
||||
{
|
||||
EShortcut shortcutID = findShortcut(entry.first);
|
||||
assert(!vstd::contains(assignedShortcuts, shortcutID));
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "../../widgets/Slider.h"
|
||||
#include "../../windows/InfoWindows.h"
|
||||
|
||||
#include "../../../lib/CConfigHandler.h"
|
||||
#include "../../../lib/texts/MetaString.h"
|
||||
#include "../../../lib/json/JsonNode.h"
|
||||
#include "../../../lib/json/JsonUtils.h"
|
||||
@@ -44,10 +45,8 @@ ShortcutsWindow::ShortcutsWindow()
|
||||
);
|
||||
backgroundRect = std::make_shared<TransparentFilledRectangle>(Rect(8, 48, pos.w - 16, 348), ColorRGBA(0, 0, 0, 64), ColorRGBA(128, 100, 75), 1);
|
||||
|
||||
shortcuts = JsonUtils::assembleFromFiles("config/shortcutsConfig");
|
||||
|
||||
int count = 0;
|
||||
for(auto & group : shortcuts.Struct())
|
||||
for(auto & group : shortcutsConfig.toJsonNode().Struct())
|
||||
{
|
||||
count++;
|
||||
count += group.second.Struct().size();
|
||||
@@ -75,7 +74,7 @@ void ShortcutsWindow::fillList(int start)
|
||||
listElements.clear();
|
||||
int i = 0;
|
||||
[&]{
|
||||
for(auto group = shortcuts.Struct().rbegin(); group != shortcuts.Struct().rend(); ++group)
|
||||
for(auto group = shortcutsConfig.toJsonNode().Struct().rbegin(); group != shortcutsConfig.toJsonNode().Struct().rend(); ++group)
|
||||
{
|
||||
if(i >= start)
|
||||
listElements.push_back(std::make_shared<ShortcutElement>(group->first, listElements.size()));
|
||||
@@ -85,15 +84,15 @@ void ShortcutsWindow::fillList(int start)
|
||||
for(auto & elem : group->second.Struct())
|
||||
{
|
||||
if(i >= start)
|
||||
listElements.push_back(std::make_shared<ShortcutElement>(elem.first, elem.second, listElements.size(), [this](const std::string & id, const std::string & keyName){
|
||||
listElements.push_back(std::make_shared<ShortcutElement>(elem.first, elem.second, listElements.size(), [this, group](const std::string & id, const std::string & keyName){
|
||||
auto str = MetaString::createFromTextID("vcmi.shortcuts.inputSet");
|
||||
str.replaceTextID("vcmi.shortcuts.shortcut." + id);
|
||||
str.replaceRawString(keyName);
|
||||
|
||||
GAME->interface()->showYesNoDialog(str.toString(), [this, id, keyName](){
|
||||
setKeyBinding(id, keyName, true);
|
||||
}, [this, id, keyName](){
|
||||
setKeyBinding(id, keyName, false);
|
||||
GAME->interface()->showYesNoDialog(str.toString(), [this, group, id, keyName](){
|
||||
setKeyBinding(id, group->first, keyName, true);
|
||||
}, [this, group, id, keyName](){
|
||||
setKeyBinding(id, group->first, keyName, false);
|
||||
});
|
||||
}));
|
||||
i++;
|
||||
@@ -104,17 +103,32 @@ void ShortcutsWindow::fillList(int start)
|
||||
}();
|
||||
}
|
||||
|
||||
void ShortcutsWindow::setKeyBinding(const std::string & id, const std::string & keyName, bool append)
|
||||
void ShortcutsWindow::setKeyBinding(const std::string & id, const std::string & group, const std::string & keyName, bool append)
|
||||
{
|
||||
// TODO
|
||||
std::cout << id << " " << keyName << " " << append << "\n";
|
||||
auto existing = shortcutsConfig[group][id];
|
||||
Settings existingWrite = shortcutsConfig.write[group][id];
|
||||
if((existing.isVector() || (existing.isString() && !existing.String().empty())) && append)
|
||||
{
|
||||
JsonVector tmp;
|
||||
if(existing.isVector())
|
||||
tmp = existing.Vector();
|
||||
if(existing.isString())
|
||||
tmp.push_back(existing);
|
||||
tmp.push_back(JsonNode(keyName));
|
||||
existingWrite->Vector() = tmp;
|
||||
}
|
||||
else
|
||||
existingWrite->String() = keyName;
|
||||
|
||||
fillList(slider->getValue());
|
||||
}
|
||||
|
||||
void ShortcutsWindow::resetKeyBinding()
|
||||
{
|
||||
// TODO
|
||||
// FIXME: Not working yet
|
||||
Settings write = shortcutsConfig.write;
|
||||
write->clear();
|
||||
write->Struct() = JsonUtils::assembleFromFiles("config/shortcutsConfig.json").Struct();
|
||||
|
||||
fillList(slider->getValue());
|
||||
}
|
||||
|
||||
@@ -49,10 +49,8 @@ private:
|
||||
std::vector<std::shared_ptr<ShortcutElement>> listElements;
|
||||
std::shared_ptr<CButton> buttonReset;
|
||||
|
||||
JsonNode shortcuts;
|
||||
|
||||
void fillList(int start);
|
||||
void setKeyBinding(const std::string & id, const std::string & keyName, bool append);
|
||||
void setKeyBinding(const std::string & id, const std::string & group, const std::string & keyName, bool append);
|
||||
void resetKeyBinding();
|
||||
|
||||
public:
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// This file defines all shortcuts used by VCMI
|
||||
// For modders: create file with same name (Content/config/shortcutsConfig.json) to modify this set in your mod
|
||||
// For players (Windows): create file Documents/My Games/vcmi/config/shortcutsConfig.json to modify this set
|
||||
// For players (Linux): create file ~/.config/vcmi/shortcutsConfig.json (or ~/.var/app/eu.vcmi.VCMI/config for Flatpak) to modify this set
|
||||
//
|
||||
// When creating your own config, you can remove all hotkeys that you have not changed and game will read them from this file
|
||||
// It is possible to add modifiers to keys: Ctrl, Shift, or Alt. For example, "Ctrl+Tab" hotkey will only activate if Ctrl is pressed
|
||||
{
|
||||
"keyboard" : {
|
||||
|
||||
@@ -37,6 +37,7 @@ ConfigEditorDialog::ConfigEditorDialog(QWidget *parent):
|
||||
"settings.json",
|
||||
"persistentStorage.json",
|
||||
"modSettings.json",
|
||||
"shortcutsConfig.json",
|
||||
};
|
||||
ui->comboBox->addItems(files);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
SettingsStorage settings;
|
||||
SettingsStorage persistentStorage;
|
||||
SettingsStorage shortcutsConfig;
|
||||
|
||||
template<typename Accessor>
|
||||
SettingsStorage::NodeAccessor<Accessor>::NodeAccessor(SettingsStorage & _parent, std::vector<std::string> _path):
|
||||
|
||||
@@ -122,5 +122,6 @@ public:
|
||||
|
||||
extern DLL_LINKAGE SettingsStorage settings;
|
||||
extern DLL_LINKAGE SettingsStorage persistentStorage;
|
||||
extern DLL_LINKAGE SettingsStorage shortcutsConfig;
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@@ -160,6 +160,7 @@ void GameLibrary::initializeFilesystem(bool extractArchives)
|
||||
loadFilesystem(extractArchives);
|
||||
settings.init("config/settings.json", "vcmi:settings");
|
||||
persistentStorage.init("config/persistentStorage.json", "");
|
||||
shortcutsConfig.init("config/shortcutsConfig.json", "");
|
||||
loadModFilesystem();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user