yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
command_manager.cc
Go to the documentation of this file.
1#include "command_manager.h"
2
3#include <fstream>
4
5#include "app/gui/input.h"
6#include "imgui/imgui.h"
7
8namespace yaze {
9namespace editor {
10
11
12// When the player presses Space, a popup will appear fixed to the bottom of the
13// ImGui window with a list of the available key commands which can be used.
15 if (ImGui::IsKeyPressed(ImGuiKey_Space)) {
16 ImGui::OpenPopup("WhichKey");
17 }
18
19 ImGui::SetNextWindowPos(ImVec2(0, ImGui::GetIO().DisplaySize.y - 100),
20 ImGuiCond_Always);
21 ImGui::SetNextWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x, 100),
22 ImGuiCond_Always);
23 if (ImGui::BeginPopup("WhichKey")) {
24 // ESC to close the popup
25 if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
26 ImGui::CloseCurrentPopup();
27 }
28
29 const ImVec4 colors[] = {
30 ImVec4(0.8f, 0.2f, 0.2f, 1.0f), // Soft Red
31 ImVec4(0.2f, 0.8f, 0.2f, 1.0f), // Soft Green
32 ImVec4(0.2f, 0.2f, 0.8f, 1.0f), // Soft Blue
33 ImVec4(0.8f, 0.8f, 0.2f, 1.0f), // Soft Yellow
34 ImVec4(0.8f, 0.2f, 0.8f, 1.0f), // Soft Magenta
35 ImVec4(0.2f, 0.8f, 0.8f, 1.0f) // Soft Cyan
36 };
37 const int numColors = sizeof(colors) / sizeof(colors[0]);
38 int colorIndex = 0;
39
40 if (ImGui::BeginTable("CommandsTable", commands_.size(),
41 ImGuiTableFlags_SizingStretchProp)) {
42 for (const auto &[shortcut, info] : commands_) {
43 ImGui::TableNextColumn();
44 ImGui::TextColored(colors[colorIndex], "%c: %s",
45 info.command_info.mnemonic,
46 info.command_info.name.c_str());
47 colorIndex = (colorIndex + 1) % numColors;
48 }
49 ImGui::EndTable();
50 }
51 ImGui::EndPopup();
52 }
53}
54
55void CommandManager::SaveKeybindings(const std::string &filepath) {
56 std::ofstream out(filepath);
57 if (out.is_open()) {
58 for (const auto &[shortcut, info] : commands_) {
59 out << shortcut << " " << info.command_info.mnemonic << " "
60 << info.command_info.name << " " << info.command_info.desc << "\n";
61 }
62 out.close();
63 }
64}
65
66void CommandManager::LoadKeybindings(const std::string &filepath) {
67 std::ifstream in(filepath);
68 if (in.is_open()) {
69 commands_.clear();
70 std::string shortcut, name, desc;
71 char mnemonic;
72 while (in >> shortcut >> mnemonic >> name >> desc) {
73 commands_[shortcut].command_info = {nullptr, mnemonic, name, desc};
74 }
75 in.close();
76 }
77}
78
79} // namespace editor
80} // namespace yaze
std::unordered_map< std::string, CommandInfoOrPrefix > commands_
void LoadKeybindings(const std::string &filepath)
void SaveKeybindings(const std::string &filepath)
Editors are the view controllers for the application.
Main namespace for the application.
Definition controller.cc:18