feat: IW3 menu dumping and loading (#909)

* feat: IW3 menu dumping

* fix: IW3 menu dumper preserve menu ownerdraw flag masks

* fix: IW3 menu dumper preserve numeric script arguments

Emit numeric tokens without quotes so the linker keeps colour arguments separate.

Before: `"0.1" "0.1" "0.12" "0.5"` becomes `"0.10.10.120.5"`
After: `0.1 0.1 0.12 0.5`

This fixes `mouseExit` colour commands failing to clear menu hover borders.

* fix: IW3 menu dumper preserve empty item text

Keep explicit empty text distinct from null text when dumping menu items.

This fixes CD-key values overflowing their input boxes.

* test: cover IW3 menu dumper material case

* test: cover IW3 menu list path precedence

* chore: clang format

* fix: reverse order of union to avoid edge case bug in zcg

* feat: IW3 menu loading

* fix: validate menu expression name table

* chore: explain numeric token quoting in comment

* refactor: simplify menu dump fallback path

* chore: add more dynamic window flags

* refactor: reuse IW3 menu window flag constants

* refactor: use explicit menu item feature lookup

* refactor: represent menu item text as optional

* refactor: clarify shared IW3 and IW4 menu constants

IW4 only extends the type enum so they can be shared

* refactor: clarify IW3 menu zone state naming

* fix: log IW3 menu conversion failures

* refactor: align IW3 menu list loader with IW4

* refactor: align IW3 menu dumpers with IW4

* refactor: align IW3 menu converter with IW4

* chore: use default enum numeration for operationEnum

* chore: small optimization on edit field capability initialization

* fix: iw3 menu optimizations for rect not considering relative position to parent

* chore: align iw3 menu converting closer to iw4

* chore: align iw3 menu dumping closer to iw4

* fix: not dumping menu flags properties correctly

* chore: adjust iw3 expression dumping to work similar to iw4

* chore: adjust iw3 expression converting to work similar to iw4

* chore: use unordered_map for MenuExpressionMatchers

---------

Co-authored-by: Jan Laupetin <[email protected]>
This commit is contained in:
mo
2026-08-31 00:04:01 +02:00
committed by GitHub
co-authored by Jan Laupetin
parent 4d4921e230
commit 51770e7ae5
42 changed files with 3218 additions and 60 deletions
@@ -1,5 +1,7 @@
#include "MenuExpressionMatchers.h"
#include "Game/IW3/IW3.h"
#include "Game/IW3/MenuConstantsIW3.h"
#include "Game/IW4/IW4.h"
#include "Game/IW4/MenuConstantsIW4.h"
#include "Game/IW5/IW5.h"
@@ -48,11 +50,29 @@ std::unique_ptr<SimpleExpressionMatchers::matcher_t> MenuExpressionMatchers::Par
});
}
const std::map<std::string, size_t>& MenuExpressionMatchers::GetBaseFunctionMapForFeatureLevel(const FeatureLevel featureLevel)
const std::unordered_map<std::string, size_t>& MenuExpressionMatchers::GetBaseFunctionMapForFeatureLevel(const FeatureLevel featureLevel)
{
if (featureLevel == FeatureLevel::IW3)
{
static std::unordered_map<std::string, size_t> iw3FunctionMap;
static bool iw3FunctionMapInitialized = false;
if (!iw3FunctionMapInitialized)
{
for (size_t i = IW3::OP_FIRSTFUNCTIONCALL; i < std::extent_v<decltype(IW3::g_expFunctionNames)>; i++)
{
std::string functionName(IW3::g_expFunctionNames[i]);
utils::MakeStringLowerCase(functionName);
iw3FunctionMap.emplace(std::make_pair(std::move(functionName), i));
}
}
return iw3FunctionMap;
}
if (featureLevel == FeatureLevel::IW4)
{
static std::map<std::string, size_t> iw4FunctionMap;
static std::unordered_map<std::string, size_t> iw4FunctionMap;
static bool iw4FunctionMapInitialized = false;
if (!iw4FunctionMapInitialized)
@@ -69,7 +89,7 @@ const std::map<std::string, size_t>& MenuExpressionMatchers::GetBaseFunctionMapF
}
if (featureLevel == FeatureLevel::IW5)
{
static std::map<std::string, size_t> iw5FunctionMap;
static std::unordered_map<std::string, size_t> iw5FunctionMap;
static bool iw5FunctionMapInitialized = false;
if (!iw5FunctionMapInitialized)
@@ -4,15 +4,12 @@
#include "Parsing/Simple/Expression/SimpleExpressionMatchers.h"
#include <memory>
#include <unordered_map>
namespace menu
{
class MenuExpressionMatchers final : public SimpleExpressionMatchers
{
const MenuFileParserState* m_state;
static const std::map<std::string, size_t>& GetBaseFunctionMapForFeatureLevel(FeatureLevel featureLevel);
public:
MenuExpressionMatchers();
explicit MenuExpressionMatchers(const MenuFileParserState* state);
@@ -20,5 +17,10 @@ namespace menu
protected:
std::unique_ptr<matcher_t> ParseOperandExtension(const supplier_t* labelSupplier) const override;
std::unique_ptr<ISimpleExpression> ProcessOperandExtension(SequenceResult<SimpleParserValue>& result) const override;
private:
const MenuFileParserState* m_state;
static const std::unordered_map<std::string, size_t>& GetBaseFunctionMapForFeatureLevel(FeatureLevel featureLevel);
};
} // namespace menu