Skip to content

Commit cf22334

Browse files
committed
feat(menus): Configuration
1 parent e5ac58c commit cf22334

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

plugin_files/configs/core.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,19 @@
1313
"language": "en",
1414
"patches_to_perform": [],
1515
"CS2ServerGuidelines": "https://blog.counter-strike.net/index.php/server_guidelines/",
16-
"FollowCS2ServerGuidelines": true
16+
"FollowCS2ServerGuidelines": true,
17+
"menu": {
18+
"sound": {
19+
"name": "UI.ContractType",
20+
"volume": 0.75
21+
},
22+
"buttons": {
23+
"use": "e",
24+
"scroll": "shift",
25+
"exit": {
26+
"option": false,
27+
"button": "tab"
28+
}
29+
}
30+
}
1731
}

plugin_files/translations/translation.core.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
"ro": "Ieșire"
4343
},
4444
"menu.footer": {
45-
"en": "SHIFT - Cycle | E - Select | Page {PAGE}/{MAXPAGES}",
46-
"ro": "SHIFT - Schimbă | E - Selectează | Pagina {PAGE}/{MAXPAGES}"
45+
"en": "{CYCLE_BUTTON} - Cycle | {USE_BUTTON} - Select | Page {PAGE}/{MAXPAGES}",
46+
"ro": "{CYCLE_BUTTON} - Schimbă | {USE_BUTTON} - Selectează | Pagina {PAGE}/{MAXPAGES}"
47+
},
48+
"menu.footer.nooption": {
49+
"en": "{CYCLE_BUTTON} - Cycle | {USE_BUTTON} - Select | {EXIT_BUTTON} - Exit | Page {PAGE}/{MAXPAGES}",
50+
"ro": "{CYCLE_BUTTON} - Schimbă | {USE_BUTTON} - Selectează | {EXIT_BUTTON} - Ieșire | Pagina {PAGE}/{MAXPAGES}"
4751
}
4852
}

src/configuration/Configuration.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,14 @@ bool Configuration::LoadConfiguration()
454454

455455
RegisterConfiguration(wasEdited, coreConfigFile, "core", "core", "language", "en");
456456

457+
RegisterConfiguration(wasEdited, coreConfigFile, "core", "core", "menu.sound.name", "UI.ContractType");
458+
RegisterConfiguration(wasEdited, coreConfigFile, "core", "core", "menu.sound.volume", 0.75);
459+
460+
RegisterConfiguration(wasEdited, coreConfigFile, "core", "core", "menu.buttons.use", "e");
461+
RegisterConfiguration(wasEdited, coreConfigFile, "core", "core", "menu.buttons.scroll", "shift");
462+
RegisterConfiguration(wasEdited, coreConfigFile, "core", "core", "menu.buttons.exit.option", false);
463+
RegisterConfiguration(wasEdited, coreConfigFile, "core", "core", "menu.buttons.exit.button", "tab");
464+
457465
if (wasEdited)
458466
{
459467
rapidjson::StringBuffer buffer;

src/menus/Menu.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Menu.h"
22

33
#include "../utils/utils.h"
4+
#include "../configuration/Configuration.h"
45

56
Menu::Menu(std::string id, std::string title, std::string color, std::vector<std::pair<std::string, std::string>> options, bool tmp)
67
{
@@ -43,27 +44,28 @@ size_t Menu::GetItemsOnPage(int page)
4344
return processedOptions[page - 1].size();
4445
}
4546

46-
// TODO: Translation for Next, Back, Exit (Maybe a file called Generic for generic translations?)
4747
void Menu::ProcessOptions()
4848
{
4949
int pages = 0;
5050
int processedItems = 0;
5151
int totalProcessedItems = 0;
5252
std::vector<std::pair<std::string, std::string>> tempmap;
5353

54+
int maxProcessedItems = (g_Config->FetchValue<bool>("core.menu.buttons.exit.option") ? (pages == 0 ? 4 : 3) : (pages == 0 ? 5 : 4));
5455
for (const std::pair<std::string, std::string> entry : this->options)
5556
{
5657
++processedItems;
5758
++totalProcessedItems;
5859
tempmap.push_back({entry.first, entry.second});
59-
if (processedItems == (pages == 0 ? 4 : 3))
60+
if (processedItems == maxProcessedItems)
6061
{
6162
if (options.size() - totalProcessedItems > 0)
6263
tempmap.push_back({g_translations->FetchTranslation("core.menu.next"), "menunext"});
6364
if (pages != 0)
6465
tempmap.push_back({g_translations->FetchTranslation("core.menu.back"), "menuback"});
6566

66-
tempmap.push_back({g_translations->FetchTranslation("core.menu.exit"), "menuexit"});
67+
if (g_Config->FetchValue<bool>("core.menu.buttons.exit.option"))
68+
tempmap.push_back({g_translations->FetchTranslation("core.menu.exit"), "menuexit"});
6769

6870
processedItems = 0;
6971
pages++;
@@ -77,7 +79,8 @@ void Menu::ProcessOptions()
7779
if (this->processedOptions.size() != 0)
7880
tempmap.push_back({g_translations->FetchTranslation("core.menu.back"), "menuback"});
7981

80-
tempmap.push_back({g_translations->FetchTranslation("core.menu.exit"), "menuexit"});
82+
if (g_Config->FetchValue<bool>("core.menu.buttons.exit.option"))
83+
tempmap.push_back({g_translations->FetchTranslation("core.menu.exit"), "menuexit"});
8184

8285
processedItems = 0;
8386
this->processedOptions.push_back(tempmap);
@@ -104,7 +107,13 @@ void Menu::RegeneratePage(int playerid, int page, int selected)
104107
for (int i = 0; i < processedOptions[page - 1].size(); i++)
105108
stringPage += string_format("<div><font color=\"#%s\">%s%s</font></div><br/>", (i == selected ? this->color.c_str() : "ffffff"), (i == selected ? "➤&nbsp;" : "&nbsp;&nbsp;&nbsp;&nbsp;"), processedOptions[page - 1][i].first.c_str());
106109

107-
stringPage += string_format("<font class='fontSize-s'>%s</font>", replace(replace(g_translations->FetchTranslation("core.menu.footer"), "{PAGE}", std::to_string(page)), "{MAXPAGES}", std::to_string(processedOptions.size())).c_str());
110+
std::string footer = replace(g_translations->FetchTranslation(g_Config->FetchValue<bool>("core.menu.buttons.exit.option") ? "core.menu.footer" : "core.menu.footer.nooption"), "{PAGE}", std::to_string(page));
111+
footer = replace(footer, "{MAXPAGES}", std::to_string(processedOptions.size()));
112+
footer = replace(footer, "{CYCLE_BUTTON}", str_toupper(g_Config->FetchValue<std::string>("core.menu.buttons.scroll")));
113+
footer = replace(footer, "{USE_BUTTON}", str_toupper(g_Config->FetchValue<std::string>("core.menu.buttons.use")));
114+
footer = replace(footer, "{EXIT_BUTTON}", str_toupper(g_Config->FetchValue<std::string>("core.menu.buttons.exit.button")));
115+
116+
stringPage += string_format("<font class='fontSize-s'>%s</font>", footer.c_str());
108117

109118
this->generatedPages[playerid][page - 1] = stringPage;
110119
}

src/player/Player.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "../utils/utils.h"
66
#include "../menus/MenuManager.h"
77
#include "../commands/CommandsManager.h"
8+
#include "../configuration/Configuration.h"
89

910
#include "networkbasetypes.pb.h"
1011
#include "../sdk/entity/CRecipientFilters.h"
@@ -471,15 +472,25 @@ void Player::PerformMenuAction(std::string button)
471472
if (!this->HasMenuShown())
472473
return;
473474

474-
if (button == "shift")
475+
if (button == g_Config->FetchValue<std::string>("core.menu.buttons.scroll"))
475476
{
476-
this->PerformCommand("play sounds/ui/csgo_ui_contract_type2.vsnd_c");
477+
CCSPlayerController *controller = this->GetPlayerController();
478+
if (controller)
479+
controller->EmitSound(g_Config->FetchValue<std::string>("core.menu.sound.name"), 100, g_Config->FetchValue<double>("core.menu.sound.volume"), 0);
480+
477481
this->MoveSelection();
478482
this->RenderMenu();
479483
}
480-
else if (button == "e")
484+
else if (!g_Config->FetchValue<bool>("core.menu.buttons.exit.option") && button == g_Config->FetchValue<std::string>("core.menu.buttons.exit.button"))
485+
{
486+
this->HideMenu();
487+
}
488+
else if (button == g_Config->FetchValue<std::string>("core.menu.buttons.use"))
481489
{
482-
this->PerformCommand("play sounds/ui/csgo_ui_contract_type2.vsnd_c");
490+
CCSPlayerController *controller = this->GetPlayerController();
491+
if (controller)
492+
controller->EmitSound(g_Config->FetchValue<std::string>("core.menu.sound.name"), 100, g_Config->FetchValue<double>("core.menu.sound.volume"), 0);
493+
483494
std::string cmd = this->GetMenu()->GetCommandFromOption(this->GetPage(), this->GetSelection());
484495
if (cmd == "menunext")
485496
{
@@ -491,7 +502,7 @@ void Player::PerformMenuAction(std::string button)
491502
this->SetPage(this->GetPage() - 1);
492503
this->RenderMenu();
493504
}
494-
else if (cmd == "menuexit")
505+
else if (g_Config->FetchValue<bool>("core.menu.buttons.exit.option") && cmd == "menuexit")
495506
{
496507
this->HideMenu();
497508
}

0 commit comments

Comments
 (0)