Skip to content

Commit 7aacd39

Browse files
authored
Merge pull request #260 from getcetc/development
VS2026 compat; mod & script menu overhaul
2 parents 4ca315b + 86a160d commit 7aacd39

File tree

3 files changed

+223
-43
lines changed

3 files changed

+223
-43
lines changed

RTEA.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<CharacterSet>MultiByte</CharacterSet>
5151
<PlatformToolset Condition="'$(VisualStudioVersion)'=='16.0'">v142</PlatformToolset>
5252
<PlatformToolset Condition="'$(VisualStudioVersion)'=='17.0'">v143</PlatformToolset>
53+
<PlatformToolset Condition="'$(VisualStudioVersion)'=='18.0'">v145</PlatformToolset>
5354
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
5455
<IntDir>_Bin\$(Platform)\$(Configuration)\</IntDir>
5556
<OutDir>.\</OutDir>
@@ -236,6 +237,7 @@
236237
<IncludeInUnityFile>false</IncludeInUnityFile>
237238
<AddCodeAfterSourceInclude>#undef GetClassName</AddCodeAfterSourceInclude>
238239
<OmitFramePointers>false</OmitFramePointers>
240+
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
239241
</ClCompile>
240242
<Link>
241243
<AdditionalDependencies>winmm.lib;ws2_32.lib;dinput8.lib;ddraw.lib;dxguid.lib;dsound.lib;imm32.lib;setupapi.lib;version.lib;zlibstatic.lib;libminizip.lib;libpng16-static.lib;fmod_vc.lib;allegro-debug.lib;loadpng-debug.lib;liblz4_debug_static.lib;luajit-debug.lib;luabind-debug.lib;raknet-debug.lib;SDL3_image-static-debug.lib;SDL3-static-debug.lib;opengl32.lib;dbghelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -342,6 +344,7 @@
342344
<IncludeInUnityFile>false</IncludeInUnityFile>
343345
<AddCodeAfterSourceInclude>#undef GetClassName</AddCodeAfterSourceInclude>
344346
<OmitFramePointers>false</OmitFramePointers>
347+
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
345348
</ClCompile>
346349
<Link>
347350
<AdditionalDependencies>winmm.lib;ws2_32.lib;dinput8.lib;ddraw.lib;dxguid.lib;dsound.lib;imm32.lib;setupapi.lib;version.lib;zlibstatic.lib;libminizip.lib;libpng16-static.lib;fmod_vc.lib;allegro-debug.lib;loadpng-debug.lib;liblz4_debug_static.lib;luajit-debug-release.lib;luabind-debug.lib;raknet-debug.lib;SDL3-static-debug.lib;SDL3_image-static-debug.lib;opengl32.lib;dbghelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -525,6 +528,7 @@
525528
<ConformanceMode>true</ConformanceMode>
526529
<IncludeInUnityFile>false</IncludeInUnityFile>
527530
<AddCodeAfterSourceInclude>#undef GetClassName</AddCodeAfterSourceInclude>
531+
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
528532
</ClCompile>
529533
<Link>
530534
<AdditionalDependencies>winmm.lib;ws2_32.lib;dinput8.lib;ddraw.lib;dxguid.lib;dsound.lib;imm32.lib;setupapi.lib;version.lib;zlibstatic.lib;libminizip.lib;libpng16-static.lib;fmod_vc.lib;allegro-debug-release.lib;loadpng-debug-release.lib;liblz4_release_static.lib;luajit-debug-release.lib;luabind-debug-release.lib;raknet-release.lib;opengl32.lib;SDL3-static.lib;SDL3_image-static.lib;dbghelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -587,6 +591,7 @@
587591
<ConformanceMode>true</ConformanceMode>
588592
<IncludeInUnityFile>false</IncludeInUnityFile>
589593
<AddCodeAfterSourceInclude>#undef GetClassName</AddCodeAfterSourceInclude>
594+
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
590595
</ClCompile>
591596
<Link>
592597
<AdditionalDependencies>winmm.lib;ws2_32.lib;dinput8.lib;ddraw.lib;dxguid.lib;dsound.lib;imm32.lib;setupapi.lib;version.lib;zlibstatic.lib;libminizip.lib;libpng16-static.lib;fmod_vc.lib;allegro-debug-release.lib;loadpng-debug-release.lib;liblz4_release_static.lib;luajit-debug-release.lib;luabind-debug-release.lib;raknet-release.lib;opengl32.lib;SDL3-static.lib;SDL3_image-static.lib;dbghelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -707,6 +712,7 @@
707712
<ConformanceMode>true</ConformanceMode>
708713
<IncludeInUnityFile>false</IncludeInUnityFile>
709714
<AddCodeAfterSourceInclude>#undef GetClassName</AddCodeAfterSourceInclude>
715+
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
710716
</ClCompile>
711717
<Link>
712718
<AdditionalDependencies>winmm.lib;ws2_32.lib;dinput8.lib;ddraw.lib;dxguid.lib;dsound.lib;imm32.lib;setupapi.lib;version.lib;zlibstatic.lib;libminizip.lib;libpng16-static.lib;fmod_vc.lib;allegro-release.lib;loadpng-release.lib;liblz4_release_static.lib;luajit-release.lib;luabind-release.lib;raknet-release.lib;opengl32.lib;SDL3-static.lib;SDL3_image-static.lib;dbghelp.lib;%(AdditionalDependencies)</AdditionalDependencies>

Source/Menus/ModManagerGUI.cpp

Lines changed: 172 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,81 @@ void ModManagerGUI::PopulateKnownModsList() {
8888
m_ModsListFetched = true;
8989
}
9090

91-
void ModManagerGUI::PopulateKnownScriptsList() {
92-
std::list<Entity*> globalScriptList;
93-
g_PresetMan.GetAllOfType(globalScriptList, "GlobalScript");
94-
95-
for (Entity* globalScriptListEntry: globalScriptList) {
96-
if (const GlobalScript* globalScript = dynamic_cast<GlobalScript*>(globalScriptListEntry)) {
97-
ScriptRecord scriptRecord = {globalScript->GetModuleAndPresetName(), globalScript->GetDescription(), g_SettingsMan.IsGlobalScriptEnabled(scriptRecord.PresetName)};
98-
m_KnownScripts.emplace_back(scriptRecord);
91+
//todo to fetch
92+
void ModManagerGUI::InitializeKnownScripts() {
93+
int totalModuleCount = g_PresetMan.GetTotalModuleCount();
94+
for (int currentModuleIndex = 0; currentModuleIndex < totalModuleCount; ++currentModuleIndex) {
95+
// todo: try GetFriendlyName()
96+
std::list<Entity*> globalScriptListForThisModule;
97+
g_PresetMan.GetAllOfType(globalScriptListForThisModule, "GlobalScript", currentModuleIndex);
98+
99+
if (globalScriptListForThisModule.empty()) {
100+
continue;
99101
}
100-
}
101-
std::sort(m_KnownScripts.begin(), m_KnownScripts.end());
102102

103-
for (int i = 0; i < m_KnownScripts.size(); i++) {
104-
m_ScriptsListBox->AddItem(m_KnownScripts.at(i).GetDisplayString(), std::string(), nullptr, nullptr, i);
103+
104+
std::vector<ScriptRecord>& currentModuleScripts =
105+
m_KnownScriptsPerModule.emplace_back(
106+
g_PresetMan.GetDataModule(currentModuleIndex)->GetFileName(),
107+
g_PresetMan.GetDataModule(currentModuleIndex)->GetFriendlyName()
108+
+ "\n" + g_PresetMan.GetDataModule(currentModuleIndex)->GetDescription()
109+
).Records;
110+
111+
for (Entity* globalScriptListEntry: globalScriptListForThisModule) {
112+
if (const GlobalScript* globalScript = dynamic_cast<GlobalScript*>(globalScriptListEntry)) {
113+
ScriptRecord scriptRecord =
114+
{globalScript->GetPresetName(),
115+
globalScript->GetModuleAndPresetName(),
116+
globalScript->GetDescription(),
117+
g_SettingsMan.IsGlobalScriptEnabled(globalScript->GetModuleAndPresetName())};
118+
currentModuleScripts.emplace_back(scriptRecord);
119+
}
120+
}
121+
std::sort(currentModuleScripts.begin(), currentModuleScripts.end());
105122
}
106123
m_ScriptsListBox->ScrollToTop();
107124
m_ScriptsListFetched = true;
108125
}
109126

127+
int ModManagerGUI::ScriptListEntryEncodeExtraIndex(const int moduleNumber, const int scriptNumber) {
128+
return scriptNumber == -1
129+
? (moduleNumber << 10) | EXTRA_INDEX_IS_A_MODULE_LABEL_MASK
130+
: (moduleNumber << 10) + scriptNumber;
131+
}
132+
133+
std::pair<int, int> ModManagerGUI::ScriptListEntryDecodeExtraIndex(const int extraIndex) {
134+
if (extraIndex & EXTRA_INDEX_IS_A_MODULE_LABEL_MASK) {
135+
return {(extraIndex ^ EXTRA_INDEX_IS_A_MODULE_LABEL_MASK) >> 10, -1};
136+
} else {
137+
return {extraIndex >> 10, extraIndex - ((extraIndex >> 10) << 10)};
138+
}
139+
}
140+
141+
void ModManagerGUI::PopulateKnownScriptsList(bool clearBeforehand = false) {
142+
if (clearBeforehand) {
143+
m_ScriptsListBox->ClearList();
144+
}
145+
146+
for (int moduleIt = 0; moduleIt < m_KnownScriptsPerModule.size(); ++moduleIt) {
147+
auto& scriptRecordsInAModule = m_KnownScriptsPerModule[moduleIt];
148+
149+
//display the module ".rte" thingy
150+
m_ScriptsListBox->AddItem(scriptRecordsInAModule.GetDisplayString(),
151+
std::string(), nullptr, nullptr, ScriptListEntryEncodeExtraIndex(moduleIt, -1));
152+
153+
if (scriptRecordsInAModule.Collapsed) {
154+
continue;
155+
}
156+
157+
// then per each .rte display the scripts under:
158+
for (int scriptIt = 0; scriptIt < scriptRecordsInAModule.Records.size(); ++scriptIt) {
159+
auto& scriptRecord = scriptRecordsInAModule.Records[scriptIt];
160+
m_ScriptsListBox->AddItem(scriptRecord.GetDisplayString(),
161+
std::string(), nullptr, nullptr, ScriptListEntryEncodeExtraIndex(moduleIt, scriptIt));
162+
}
163+
}
164+
}
165+
110166
void ModManagerGUI::ToggleMod() {
111167
int index = m_ModsListBox->GetSelectedIndex();
112168
if (index > -1) {
@@ -133,62 +189,142 @@ void ModManagerGUI::ToggleMod() {
133189
}
134190
}
135191

136-
void ModManagerGUI::ToggleScript() {
192+
ModManagerGUI::ScriptRecord* ModManagerGUI::ScriptListExtraIndexToScriptRecord(int extraIndex) {
193+
194+
auto [moduleInd, scriptInd] = ScriptListEntryDecodeExtraIndex(extraIndex);
195+
// if the list item is a module label header - return nullptr
196+
if (scriptInd == -1) {
197+
return nullptr;
198+
}
199+
// else - a script, decode where to access it from the item's extra value
200+
return &m_KnownScriptsPerModule.at(moduleInd).Records.at(scriptInd);
201+
}
202+
203+
void ModManagerGUI::ToggleInScriptList() {
137204
int index = m_ScriptsListBox->GetSelectedIndex();
138-
if (index > -1) {
205+
if (index <= -1) {
206+
return;
207+
}
208+
209+
GUIListPanel::Item* selectedItem = m_ScriptsListBox->GetSelected();
210+
int extraIndex = selectedItem->m_ExtraIndex;
211+
auto [moduleInd, scriptInd] = ScriptListEntryDecodeExtraIndex(extraIndex);
212+
//if the list item is a module label header then collapse/expand it
213+
if (scriptInd == -1) {
214+
m_KnownScriptsPerModule[moduleInd].Collapsed ^= 1; //toggle it
215+
PopulateKnownScriptsList(true);
216+
}
217+
// else - it's a script, toggle it:
218+
else {
139219
std::unordered_map<std::string, bool>& enabledScriptList = g_SettingsMan.GetEnabledGlobalScriptMap();
140-
GUIListPanel::Item* selectedItem = m_ScriptsListBox->GetSelected();
141-
ScriptRecord& scriptRecord = m_KnownScripts.at(selectedItem->m_ExtraIndex);
142220

143-
scriptRecord.Enabled = !scriptRecord.Enabled;
144-
if (scriptRecord.Enabled) {
221+
ScriptRecord* scriptRecord = ScriptListExtraIndexToScriptRecord(extraIndex);
222+
scriptRecord->Enabled = !scriptRecord->Enabled;
223+
if (scriptRecord->Enabled) {
145224
m_ToggleScriptButton->SetText("Disable Script");
146-
if (enabledScriptList.find(scriptRecord.PresetName) != enabledScriptList.end()) {
147-
enabledScriptList.at(scriptRecord.PresetName) = true;
225+
if (enabledScriptList.find(scriptRecord->ModuleAndPresetName) != enabledScriptList.end()) {
226+
enabledScriptList.at(scriptRecord->ModuleAndPresetName) = true;
148227
} else {
149-
enabledScriptList.try_emplace(scriptRecord.PresetName, true);
228+
enabledScriptList.try_emplace(scriptRecord->ModuleAndPresetName, true);
150229
}
151230
} else {
152231
m_ToggleScriptButton->SetText("Enable Script");
153-
enabledScriptList.at(scriptRecord.PresetName) = false;
232+
enabledScriptList.at(scriptRecord->ModuleAndPresetName) = false;
154233
}
155-
selectedItem->m_Name = scriptRecord.GetDisplayString();
156-
m_ScriptsListBox->SetSelectedIndex(index);
157-
m_ScriptsListBox->Invalidate();
158-
g_GUISound.ItemChangeSound()->Play();
234+
235+
selectedItem->m_Name = scriptRecord->GetDisplayString();
159236
}
237+
m_ScriptsListBox->SetSelectedIndex(index);
238+
m_ScriptsListBox->Invalidate();
239+
g_GUISound.ItemChangeSound()->Play();
240+
}
241+
242+
void ModManagerGUI::ResetSelectionsAndGoToTop() {
243+
m_ModsListBox->ScrollToTop();
244+
m_ScriptsListBox->ScrollToTop();
245+
246+
m_ModOrScriptDescriptionLabel->SetText(m_DisclaimerText);
160247
}
161248

162249
bool ModManagerGUI::HandleInputEvents() {
163250
if (!ListsFetched()) {
251+
m_DisclaimerText = m_ModOrScriptDescriptionLabel->GetText();
164252
PopulateKnownModsList();
253+
InitializeKnownScripts();
165254
PopulateKnownScriptsList();
255+
ResetSelectionsAndGoToTop();
166256
}
167257
m_GUIControlManager->Update();
168258

169259
GUIEvent guiEvent;
170260
while (m_GUIControlManager->GetEvent(&guiEvent)) {
261+
// buttons
171262
if (guiEvent.GetType() == GUIEvent::Command) {
172263
if (guiEvent.GetControl() == m_BackToMainButton) {
264+
ResetSelectionsAndGoToTop();
173265
return true;
174266
} else if (guiEvent.GetControl() == m_ToggleModButton) {
175267
ToggleMod();
176268
} else if (guiEvent.GetControl() == m_ToggleScriptButton) {
177-
ToggleScript();
269+
ToggleInScriptList();
178270
}
179-
} else if (guiEvent.GetType() == GUIEvent::Notification) {
271+
}
272+
273+
else if (guiEvent.GetType() == GUIEvent::Notification) {
274+
// button hover sound
180275
if (guiEvent.GetMsg() == GUIButton::Focused && dynamic_cast<GUIButton*>(guiEvent.GetControl())) {
181276
g_GUISound.SelectionChangeSound()->Play();
182277
}
183278

184-
if (guiEvent.GetControl() == m_ModsListBox && (guiEvent.GetMsg() == GUIListBox::Select && m_ModsListBox->GetSelectedIndex() > -1)) {
185-
const ModRecord& modRecord = m_KnownMods.at(m_ModsListBox->GetSelected()->m_ExtraIndex);
186-
m_ModOrScriptDescriptionLabel->SetText(modRecord.Description);
187-
m_ToggleModButton->SetText(modRecord.Disabled ? "Enable Mod" : "Disable Mod");
188-
} else if (guiEvent.GetControl() == m_ScriptsListBox && (guiEvent.GetMsg() == GUIListBox::Select && m_ScriptsListBox->GetSelectedIndex() > -1)) {
189-
const ScriptRecord& scriptRecord = m_KnownScripts.at(m_ScriptsListBox->GetSelected()->m_ExtraIndex);
190-
m_ModOrScriptDescriptionLabel->SetText(scriptRecord.Description);
191-
m_ToggleScriptButton->SetText(scriptRecord.Enabled ? "Disable Script" : "Enable Script");
279+
// list entries
280+
if (guiEvent.GetControl() == m_ModsListBox && m_ModsListBox->GetSelectedIndex() > -1) {
281+
switch (guiEvent.GetMsg()) {
282+
case GUIListBox::Select: {
283+
g_GUISound.SelectionChangeSound()->Play();
284+
const ModRecord& modRecord = m_KnownMods.at(m_ModsListBox->GetSelected()->m_ExtraIndex);
285+
m_ModOrScriptDescriptionLabel->SetText(modRecord.Description);
286+
m_ToggleModButton->SetText(modRecord.Disabled ? "Enable Mod" : "Disable Mod");
287+
break;
288+
}
289+
case GUIListBox::KeyDown:
290+
if (guiEvent.GetData() != 13) //enter key but doesnt work, todo
291+
break;
292+
case GUIListBox::DoubleClick:
293+
g_GUISound.SelectionChangeSound()->FadeOut(0);
294+
g_GUISound.ItemChangeSound()->Play();
295+
ToggleMod();
296+
break;
297+
}
298+
} else if (guiEvent.GetControl() == m_ScriptsListBox && m_ScriptsListBox->GetSelectedIndex() > -1) {
299+
switch (guiEvent.GetMsg()) {
300+
case GUIListBox::Select: {
301+
g_GUISound.SelectionChangeSound()->Play();
302+
int extraIndex = m_ScriptsListBox->GetSelected()->m_ExtraIndex;
303+
auto [moduleInd, scriptInd] = ScriptListEntryDecodeExtraIndex(extraIndex);
304+
// if we're on a script item
305+
if (scriptInd != -1) {
306+
const ScriptRecord* scriptRecord = ScriptListExtraIndexToScriptRecord(extraIndex);
307+
m_ModOrScriptDescriptionLabel->SetText(scriptRecord->Description.empty() ? "No description." : scriptRecord->Description);
308+
m_ToggleScriptButton->SetText(scriptRecord->Enabled ? "Disable Script" : "Enable Script");
309+
}
310+
// if we're on a module label
311+
else {
312+
ScriptRecordsInAModule* module =
313+
&m_KnownScriptsPerModule[moduleInd];
314+
m_ModOrScriptDescriptionLabel->SetText(module->Description);
315+
m_ToggleScriptButton->SetText(module->Collapsed ? "Expand Category" : "Collapse Category");
316+
}
317+
break;
318+
}
319+
case GUIListBox::KeyDown:
320+
if (guiEvent.GetData() != 13) //todo, check above
321+
break;
322+
case GUIListBox::DoubleClick:
323+
g_GUISound.SelectionChangeSound()->FadeOut(0);
324+
g_GUISound.ItemChangeSound()->Play();
325+
ToggleInScriptList();
326+
break;
327+
}
192328
}
193329
}
194330
}

0 commit comments

Comments
 (0)