mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
basic shortcut menu support
This commit is contained in:
@@ -259,6 +259,12 @@
|
|||||||
"vcmi.settingsMainWindow.adventureTab.hover" : "Adventure Map",
|
"vcmi.settingsMainWindow.adventureTab.hover" : "Adventure Map",
|
||||||
"vcmi.settingsMainWindow.adventureTab.help" : "Switches to Adventure Map Options tab (adventure map is the section of the game where players can control the movements of their heroes).",
|
"vcmi.settingsMainWindow.adventureTab.help" : "Switches to Adventure Map Options tab (adventure map is the section of the game where players can control the movements of their heroes).",
|
||||||
|
|
||||||
|
"vcmi.shortcuts.button.hover" : "Shortcuts",
|
||||||
|
"vcmi.shortcuts.button.help" : "{Shortcuts}\n\nShow menu for viewing and adjusting shortcuts and keybindings",
|
||||||
|
"vcmi.shortcuts.editButton.help" : "Edit key binding",
|
||||||
|
"vcmi.shortcuts.editButton.popup" : "You want to change keybinding for {%s}?\n\nSadly setting the key binding here is not supported yet. Bindings has to configured over {shortcutsConfig.json} in config folder.",
|
||||||
|
"vcmi.shortcuts.group.keyboard" : "Keyboard",
|
||||||
|
|
||||||
"vcmi.systemOptions.videoGroup" : "Video Settings",
|
"vcmi.systemOptions.videoGroup" : "Video Settings",
|
||||||
"vcmi.systemOptions.audioGroup" : "Audio Settings",
|
"vcmi.systemOptions.audioGroup" : "Audio Settings",
|
||||||
"vcmi.systemOptions.otherGroup" : "Other Settings", // unused right now
|
"vcmi.systemOptions.otherGroup" : "Other Settings", // unused right now
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ set(vcmiclientcommon_SRCS
|
|||||||
windows/settings/SettingsMainWindow.cpp
|
windows/settings/SettingsMainWindow.cpp
|
||||||
windows/settings/BattleOptionsTab.cpp
|
windows/settings/BattleOptionsTab.cpp
|
||||||
windows/settings/AdventureOptionsTab.cpp
|
windows/settings/AdventureOptionsTab.cpp
|
||||||
|
windows/settings/ShortcutsWindow.cpp
|
||||||
|
|
||||||
xBRZ/xbrz.cpp
|
xBRZ/xbrz.cpp
|
||||||
|
|
||||||
@@ -403,6 +404,7 @@ set(vcmiclientcommon_HEADERS
|
|||||||
windows/settings/SettingsMainWindow.h
|
windows/settings/SettingsMainWindow.h
|
||||||
windows/settings/BattleOptionsTab.h
|
windows/settings/BattleOptionsTab.h
|
||||||
windows/settings/AdventureOptionsTab.h
|
windows/settings/AdventureOptionsTab.h
|
||||||
|
windows/settings/ShortcutsWindow.h
|
||||||
|
|
||||||
xBRZ/xbrz.h
|
xBRZ/xbrz.h
|
||||||
xBRZ/xbrz_tools.h
|
xBRZ/xbrz_tools.h
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
|
|
||||||
#include "AdventureOptionsTab.h"
|
#include "AdventureOptionsTab.h"
|
||||||
|
#include "ShortcutsWindow.h"
|
||||||
|
|
||||||
#include "../../GameEngine.h"
|
#include "../../GameEngine.h"
|
||||||
#include "../../GameInstance.h"
|
#include "../../GameInstance.h"
|
||||||
@@ -163,6 +164,10 @@ AdventureOptionsTab::AdventureOptionsTab()
|
|||||||
GAME->interface()->localState->erasePath(GAME->interface()->localState->getCurrentHero());
|
GAME->interface()->localState->erasePath(GAME->interface()->localState->getCurrentHero());
|
||||||
ENGINE->windows().totalRedraw();
|
ENGINE->windows().totalRedraw();
|
||||||
});
|
});
|
||||||
|
addCallback("openShortcutMenu", [this](int dummyValue)
|
||||||
|
{
|
||||||
|
ENGINE->windows().createAndPushWindow<ShortcutsWindow>();
|
||||||
|
});
|
||||||
build(config);
|
build(config);
|
||||||
|
|
||||||
std::shared_ptr<CToggleGroup> playerHeroSpeedToggle = widget<CToggleGroup>("heroMovementSpeedPicker");
|
std::shared_ptr<CToggleGroup> playerHeroSpeedToggle = widget<CToggleGroup>("heroMovementSpeedPicker");
|
||||||
|
|||||||
134
client/windows/settings/ShortcutsWindow.cpp
Normal file
134
client/windows/settings/ShortcutsWindow.cpp
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* ShortcutsWindow.cpp, part of VCMI engine
|
||||||
|
*
|
||||||
|
* Authors: listed in file AUTHORS in main folder
|
||||||
|
*
|
||||||
|
* License: GNU General Public License v2.0 or later
|
||||||
|
* Full text of license available in license.txt file, in main folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "StdInc.h"
|
||||||
|
#include "ShortcutsWindow.h"
|
||||||
|
|
||||||
|
#include "../../gui/Shortcut.h"
|
||||||
|
#include "../../gui/WindowHandler.h"
|
||||||
|
#include "../../widgets/Buttons.h"
|
||||||
|
#include "../../widgets/GraphicalPrimitiveCanvas.h"
|
||||||
|
#include "../../widgets/Images.h"
|
||||||
|
#include "../../widgets/TextControls.h"
|
||||||
|
#include "../../widgets/Slider.h"
|
||||||
|
#include "../../windows/InfoWindows.h"
|
||||||
|
|
||||||
|
#include "../../../lib/texts/MetaString.h"
|
||||||
|
#include "../../../lib/json/JsonNode.h"
|
||||||
|
#include "../../../lib/json/JsonUtils.h"
|
||||||
|
|
||||||
|
ShortcutsWindow::ShortcutsWindow()
|
||||||
|
: CWindowObject(BORDERED)
|
||||||
|
{
|
||||||
|
OBJECT_CONSTRUCTION;
|
||||||
|
pos.w = 500;
|
||||||
|
pos.h = 450;
|
||||||
|
|
||||||
|
updateShadow();
|
||||||
|
center();
|
||||||
|
|
||||||
|
backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
|
||||||
|
buttonOk = std::make_shared<CButton>(Point(218, 404), AnimationPath::builtin("IOKAY"), CButton::tooltip(), [this](){ close(); }, EShortcut::GLOBAL_ACCEPT);
|
||||||
|
labelTitle = std::make_shared<CLabel>(
|
||||||
|
pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, MetaString::createFromTextID("vcmi.shortcuts.button.hover").toString()
|
||||||
|
);
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
count += group.second.Struct().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
slider = std::make_shared<CSlider>(Point(backgroundRect->pos.x - pos.x + backgroundRect->pos.w - 18, backgroundRect->pos.y - pos.y + 1), backgroundRect->pos.h - 3, [this](int pos){ fillList(pos); redraw(); }, MAX_LINES, count, 0, Orientation::VERTICAL, CSlider::BROWN);
|
||||||
|
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));
|
||||||
|
|
||||||
|
fillList(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShortcutsWindow::fillList(int start)
|
||||||
|
{
|
||||||
|
OBJECT_CONSTRUCTION;
|
||||||
|
|
||||||
|
listElements.clear();
|
||||||
|
int i = 0;
|
||||||
|
[&]{
|
||||||
|
for(auto & group : shortcuts.Struct())
|
||||||
|
{
|
||||||
|
if(i >= start)
|
||||||
|
listElements.push_back(std::make_shared<ShortcutElement>(group.first, listElements.size()));
|
||||||
|
i++;
|
||||||
|
if(listElements.size() == MAX_LINES)
|
||||||
|
return;
|
||||||
|
for(auto & elem : group.second.Struct())
|
||||||
|
{
|
||||||
|
if(i >= start)
|
||||||
|
listElements.push_back(std::make_shared<ShortcutElement>(elem.first, elem.second, listElements.size()));
|
||||||
|
i++;
|
||||||
|
if(listElements.size() == MAX_LINES)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
|
||||||
|
ShortcutElement::ShortcutElement(std::string id, JsonNode keys, int elem)
|
||||||
|
{
|
||||||
|
OBJECT_CONSTRUCTION;
|
||||||
|
|
||||||
|
pos.x += 14;
|
||||||
|
pos.y += 56;
|
||||||
|
pos.y += elem * LINE_HEIGHT;
|
||||||
|
|
||||||
|
std::string keyBinding = "";
|
||||||
|
if(keys.isString())
|
||||||
|
keyBinding = keys.String();
|
||||||
|
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, " | ");
|
||||||
|
}
|
||||||
|
|
||||||
|
labelName = std::make_shared<CLabel>(
|
||||||
|
0, LINE_HEIGHT / 2, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::WHITE, MetaString::createFromTextID("vcmi.shortcuts.shortcut." + id).toString(), 295
|
||||||
|
);
|
||||||
|
labelKeys = std::make_shared<CLabel>(
|
||||||
|
300, LINE_HEIGHT / 2, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::WHITE, keyBinding, 120
|
||||||
|
);
|
||||||
|
buttonEdit = std::make_shared<CButton>(Point(422, 3), AnimationPath::builtin("settingsWindow/button32"), std::make_pair("", MetaString::createFromTextID("vcmi.shortcuts.editButton.help").toString()));
|
||||||
|
buttonEdit->setOverlay(std::make_shared<CPicture>(ImagePath::builtin("settingsWindow/gear")));
|
||||||
|
buttonEdit->addCallback([id](){
|
||||||
|
auto str = MetaString::createFromTextID("vcmi.shortcuts.editButton.popup");
|
||||||
|
str.replaceTextID("vcmi.shortcuts.shortcut." + id);
|
||||||
|
CInfoWindow::showInfoDialog(str.toString(), {});
|
||||||
|
});
|
||||||
|
if(elem < MAX_LINES - 1)
|
||||||
|
seperationLine = std::make_shared<TransparentFilledRectangle>(Rect(0, LINE_HEIGHT, 456, 1), ColorRGBA(0, 0, 0, 64), ColorRGBA(128, 100, 75), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShortcutElement::ShortcutElement(std::string group, int elem)
|
||||||
|
{
|
||||||
|
OBJECT_CONSTRUCTION;
|
||||||
|
|
||||||
|
pos.x += 14;
|
||||||
|
pos.y += 56;
|
||||||
|
pos.y += elem * LINE_HEIGHT;
|
||||||
|
|
||||||
|
labelName = std::make_shared<CLabel>(
|
||||||
|
0, LINE_HEIGHT / 2, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, MetaString::createFromTextID("vcmi.shortcuts.group." + group).toString(), 300
|
||||||
|
);
|
||||||
|
if(elem < MAX_LINES - 1)
|
||||||
|
seperationLine = std::make_shared<TransparentFilledRectangle>(Rect(0, LINE_HEIGHT, 456, 1), ColorRGBA(0, 0, 0, 64), ColorRGBA(128, 100, 75), 1);
|
||||||
|
}
|
||||||
55
client/windows/settings/ShortcutsWindow.h
Normal file
55
client/windows/settings/ShortcutsWindow.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* ShortcutsWindow.h, part of VCMI engine
|
||||||
|
*
|
||||||
|
* Authors: listed in file AUTHORS in main folder
|
||||||
|
*
|
||||||
|
* License: GNU General Public License v2.0 or later
|
||||||
|
* Full text of license available in license.txt file, in main folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../CWindowObject.h"
|
||||||
|
#include "../../../lib/json/JsonNode.h"
|
||||||
|
|
||||||
|
class CFilledTexture;
|
||||||
|
class CButton;
|
||||||
|
class CLabel;
|
||||||
|
class TransparentFilledRectangle;
|
||||||
|
class CSlider;
|
||||||
|
|
||||||
|
const int MAX_LINES = 11;
|
||||||
|
const int LINE_HEIGHT = 30;
|
||||||
|
|
||||||
|
class ShortcutElement : public CIntObject
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::shared_ptr<CButton> buttonEdit;
|
||||||
|
std::shared_ptr<CLabel> labelName;
|
||||||
|
std::shared_ptr<CLabel> labelKeys;
|
||||||
|
std::shared_ptr<TransparentFilledRectangle> seperationLine; // rectangle is cleaner than line...
|
||||||
|
|
||||||
|
public:
|
||||||
|
ShortcutElement(std::string id, JsonNode keys, int elem);
|
||||||
|
ShortcutElement(std::string group, int elem);
|
||||||
|
};
|
||||||
|
|
||||||
|
class ShortcutsWindow : public CWindowObject
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::shared_ptr<CFilledTexture> backgroundTexture;
|
||||||
|
std::shared_ptr<CButton> buttonOk;
|
||||||
|
std::shared_ptr<CLabel> labelTitle;
|
||||||
|
std::shared_ptr<TransparentFilledRectangle> backgroundRect;
|
||||||
|
std::shared_ptr<CSlider> slider;
|
||||||
|
std::vector<std::shared_ptr<ShortcutElement>> listElements;
|
||||||
|
|
||||||
|
JsonNode shortcuts;
|
||||||
|
|
||||||
|
void fillList(int start);
|
||||||
|
|
||||||
|
public:
|
||||||
|
ShortcutsWindow();
|
||||||
|
};
|
||||||
|
|
||||||
@@ -305,6 +305,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"text": "vcmi.adventureOptions.minimapShowHeroes.hover"
|
"text": "vcmi.adventureOptions.minimapShowHeroes.hover"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": "vcmi.shortcuts.button.hover"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -343,6 +346,12 @@
|
|||||||
"name": "minimapShowHeroesCheckbox",
|
"name": "minimapShowHeroesCheckbox",
|
||||||
"help": "vcmi.adventureOptions.minimapShowHeroes",
|
"help": "vcmi.adventureOptions.minimapShowHeroes",
|
||||||
"callback": "minimapShowHeroesChanged"
|
"callback": "minimapShowHeroesChanged"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "shortcutButton",
|
||||||
|
"type": "buttonGear",
|
||||||
|
"help": "vcmi.shortcuts.button",
|
||||||
|
"callback": "openShortcutMenu"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user