mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-11-20 19:58:39 +00:00
fix: Keep menus of IW4 menu lists loaded by an earlier list (#1064)
* fix: Keep menus of IW4 menu lists loaded by an earlier list * chore: add change to all menu loaders, not only IW4 --------- Co-authored-by: Jan Laupetin <[email protected]>
This commit is contained in:
1 parent
737cfecf6d
commit
28605c74ae
12 files changed
+490
-244
No files matched your search
@@ -60,6 +60,13 @@ namespace
|
||||
menus.emplace_back(menu->Asset());
|
||||
registration.AddDependency(menu);
|
||||
}
|
||||
|
||||
if (const auto menusToLoad = conversionState.m_menus_to_load_by_filename.find(assetName);
|
||||
menusToLoad != conversionState.m_menus_to_load_by_filename.end())
|
||||
{
|
||||
for (const auto& menuToLoad : menusToLoad->second)
|
||||
menuLoadQueue.emplace_back(menuToLoad);
|
||||
}
|
||||
}
|
||||
|
||||
while (!menuLoadQueue.empty())
|
||||
@@ -114,7 +121,10 @@ namespace
|
||||
if (!ProcessParsedResults(menuFilePath, context, *menuFileResult, zoneState, conversionState, menus, registration))
|
||||
return false;
|
||||
if (!menuFileResult->m_menus_to_load.empty())
|
||||
{
|
||||
con::warn("Menu file has menus to load even though it is not a menu list, ignoring: \"{}\"", menuFilePath);
|
||||
conversionState.m_menus_to_load_by_filename.emplace(menuFilePath, std::move(menuFileResult->m_menus_to_load));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,5 +15,6 @@ namespace IW3
|
||||
void AddLoadedFile(std::string loadedFileName, std::vector<XAssetInfo<menuDef_t>*> menusOfFile);
|
||||
|
||||
std::unordered_map<std::string, std::vector<XAssetInfo<menuDef_t>*>> m_menus_by_filename;
|
||||
std::unordered_map<std::string, std::vector<std::string>> m_menus_to_load_by_filename;
|
||||
};
|
||||
} // namespace IW3
|
||||
@@ -52,6 +52,21 @@ namespace
|
||||
else
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto* menu : alreadyLoadedMenuListFileMenus->second)
|
||||
{
|
||||
menus.emplace_back(menu->Asset());
|
||||
registration.AddDependency(menu);
|
||||
}
|
||||
|
||||
if (const auto menusToLoad = conversionState.m_menus_to_load_by_filename.find(assetName);
|
||||
menusToLoad != conversionState.m_menus_to_load_by_filename.end())
|
||||
{
|
||||
for (const auto& menuToLoad : menusToLoad->second)
|
||||
menuLoadQueue.emplace_back(menuToLoad);
|
||||
}
|
||||
}
|
||||
|
||||
while (!menuLoadQueue.empty())
|
||||
{
|
||||
@@ -110,7 +125,10 @@ namespace
|
||||
if (!ProcessParsedResults(menuFilePath, context, *menuFileResult, zoneState, conversionState, menus, registration))
|
||||
return false;
|
||||
if (!menuFileResult->m_menus_to_load.empty())
|
||||
{
|
||||
con::warn("Menu file has menus to load even though it is not a menu list, ignoring: \"{}\"", menuFilePath);
|
||||
conversionState.m_menus_to_load_by_filename.emplace(menuFilePath, std::move(menuFileResult->m_menus_to_load));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace IW4
|
||||
void FinalizeSupportingData() const;
|
||||
|
||||
std::unordered_map<std::string, std::vector<XAssetInfo<menuDef_t>*>> m_menus_by_filename;
|
||||
std::unordered_map<std::string, std::vector<std::string>> m_menus_to_load_by_filename;
|
||||
ExpressionSupportingData* m_supporting_data;
|
||||
|
||||
private:
|
||||
|
||||
@@ -52,6 +52,21 @@ namespace
|
||||
else
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto* menu : alreadyLoadedMenuListFileMenus->second)
|
||||
{
|
||||
menus.emplace_back(menu->Asset());
|
||||
registration.AddDependency(menu);
|
||||
}
|
||||
|
||||
if (const auto menusToLoad = conversionState.m_menus_to_load_by_filename.find(assetName);
|
||||
menusToLoad != conversionState.m_menus_to_load_by_filename.end())
|
||||
{
|
||||
for (const auto& menuToLoad : menusToLoad->second)
|
||||
menuLoadQueue.emplace_back(menuToLoad);
|
||||
}
|
||||
}
|
||||
|
||||
while (!menuLoadQueue.empty())
|
||||
{
|
||||
@@ -110,7 +125,10 @@ namespace
|
||||
if (!ProcessParsedResults(menuFilePath, context, *menuFileResult, zoneState, conversionState, menus, registration))
|
||||
return false;
|
||||
if (!menuFileResult->m_menus_to_load.empty())
|
||||
{
|
||||
con::warn("Menu file has menus to load even though it is not a menu list, ignoring: \"{}\"", menuFilePath);
|
||||
conversionState.m_menus_to_load_by_filename.emplace(menuFilePath, std::move(menuFileResult->m_menus_to_load));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace IW5
|
||||
void FinalizeSupportingData() const;
|
||||
|
||||
std::unordered_map<std::string, std::vector<XAssetInfo<menuDef_t>*>> m_menus_by_filename;
|
||||
std::unordered_map<std::string, std::vector<std::string>> m_menus_to_load_by_filename;
|
||||
ExpressionSupportingData* m_supporting_data;
|
||||
|
||||
private:
|
||||
|
||||
@@ -60,6 +60,13 @@ namespace
|
||||
menus.emplace_back(menu->Asset());
|
||||
registration.AddDependency(menu);
|
||||
}
|
||||
|
||||
if (const auto menusToLoad = conversionState.m_menus_to_load_by_filename.find(assetName);
|
||||
menusToLoad != conversionState.m_menus_to_load_by_filename.end())
|
||||
{
|
||||
for (const auto& menuToLoad : menusToLoad->second)
|
||||
menuLoadQueue.emplace_back(menuToLoad);
|
||||
}
|
||||
}
|
||||
|
||||
while (!menuLoadQueue.empty())
|
||||
@@ -114,7 +121,10 @@ namespace
|
||||
if (!ProcessParsedResults(menuFilePath, context, *menuFileResult, zoneState, conversionState, menus, registration))
|
||||
return false;
|
||||
if (!menuFileResult->m_menus_to_load.empty())
|
||||
{
|
||||
con::warn("Menu file has menus to load even though it is not a menu list, ignoring: \"{}\"", menuFilePath);
|
||||
conversionState.m_menus_to_load_by_filename.emplace(menuFilePath, std::move(menuFileResult->m_menus_to_load));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,5 +15,6 @@ namespace T4
|
||||
void AddLoadedFile(std::string loadedFileName, std::vector<XAssetInfo<menuDef_t>*> menusOfFile);
|
||||
|
||||
std::unordered_map<std::string, std::vector<XAssetInfo<menuDef_t>*>> m_menus_by_filename;
|
||||
std::unordered_map<std::string, std::vector<std::string>> m_menus_to_load_by_filename;
|
||||
};
|
||||
} // namespace T4
|
||||
@@ -45,7 +45,7 @@ namespace
|
||||
return m_loader->CreateAsset(name, m_context);
|
||||
}
|
||||
|
||||
menuDef_t* GetMenu(const std::string& name)
|
||||
[[nodiscard]] menuDef_t* GetMenu(const std::string& name) const
|
||||
{
|
||||
const auto* asset = m_zone.m_pools.GetAsset(ASSET_TYPE_MENU, name);
|
||||
REQUIRE(asset);
|
||||
@@ -60,19 +60,20 @@ namespace
|
||||
IgnoredAssetLookup m_ignored_asset_lookup;
|
||||
AssetCreationContext m_context;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("MenuListLoaderIW3: Loads dumped menus and preserves IW3 data", "[iw3][menu][assetloader]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
const auto* backgroundMaterial = helper.AddMaterial("background_material");
|
||||
const auto* selectMaterial = helper.AddMaterial("select_material");
|
||||
TEST_CASE("MenuListLoaderIW3: Loads dumped menus and preserves IW3 data", "[iw3][menu][assetloader]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
const auto* backgroundMaterial = helper.AddMaterial("background_material");
|
||||
const auto* selectMaterial = helper.AddMaterial("select_material");
|
||||
|
||||
helper.AddFile("ui_mp/menus.txt", R"MENU({
|
||||
helper.AddFile("ui_mp/menus.txt", R"MENU({
|
||||
loadMenu { "ui_mp/main.menu" }
|
||||
loadMenu { "ui_mp/popup.menu" }
|
||||
}
|
||||
)MENU");
|
||||
helper.AddFile("ui_mp/main.menu", R"MENU({
|
||||
helper.AddFile("ui_mp/main.menu", R"MENU({
|
||||
menuDef
|
||||
{
|
||||
name "main"
|
||||
@@ -143,7 +144,7 @@ namespace
|
||||
}
|
||||
}
|
||||
)MENU");
|
||||
helper.AddFile("ui_mp/popup.menu", R"MENU({
|
||||
helper.AddFile("ui_mp/popup.menu", R"MENU({
|
||||
menuDef
|
||||
{
|
||||
name "popup"
|
||||
@@ -157,78 +158,77 @@ namespace
|
||||
}
|
||||
)MENU");
|
||||
|
||||
const auto result = helper.LoadMenuList("ui_mp/menus.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
const auto result = helper.LoadMenuList("ui_mp/menus.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* mainMenu = helper.GetMenu("main");
|
||||
const auto* popupMenu = helper.GetMenu("popup");
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* mainMenu = helper.GetMenu("main");
|
||||
const auto* popupMenu = helper.GetMenu("popup");
|
||||
|
||||
REQUIRE(menuList->name == "ui_mp/menus.txt"s);
|
||||
REQUIRE(menuList->menuCount == 2);
|
||||
REQUIRE(menuList->menus[0] == mainMenu);
|
||||
REQUIRE(menuList->menus[1] == popupMenu);
|
||||
REQUIRE(menuList->name == "ui_mp/menus.txt"s);
|
||||
REQUIRE(menuList->menuCount == 2);
|
||||
REQUIRE(menuList->menus[0] == mainMenu);
|
||||
REQUIRE(menuList->menus[1] == popupMenu);
|
||||
|
||||
REQUIRE(mainMenu->window.background == backgroundMaterial);
|
||||
REQUIRE(mainMenu->window.dynamicFlags[0] & 0x10000);
|
||||
REQUIRE_THAT(mainMenu->disableColor[0], WithinRel(0.2f));
|
||||
REQUIRE_THAT(mainMenu->disableColor[3], WithinRel(0.5f));
|
||||
REQUIRE(mainMenu->visibleExp.numEntries == 3);
|
||||
REQUIRE(mainMenu->visibleExp.entries[0]->type == EET_OPERATOR);
|
||||
REQUIRE(mainMenu->visibleExp.entries[0]->data.op == OP_DVARBOOL);
|
||||
REQUIRE(mainMenu->visibleExp.entries[1]->data.operand.dataType == VAL_STRING);
|
||||
REQUIRE(mainMenu->visibleExp.entries[1]->data.operand.internals.stringVal == "ui_show_main"s);
|
||||
REQUIRE(mainMenu->visibleExp.entries[2]->data.op == OP_RIGHTPAREN);
|
||||
REQUIRE(mainMenu->onOpen == R"("play" "menu_open" ; "setLocalVarInt" "ui_highlight" "5" ; )"s);
|
||||
REQUIRE(mainMenu->window.background == backgroundMaterial);
|
||||
REQUIRE(mainMenu->window.dynamicFlags[0] & 0x10000);
|
||||
REQUIRE_THAT(mainMenu->disableColor[0], WithinRel(0.2f));
|
||||
REQUIRE_THAT(mainMenu->disableColor[3], WithinRel(0.5f));
|
||||
REQUIRE(mainMenu->visibleExp.numEntries == 3);
|
||||
REQUIRE(mainMenu->visibleExp.entries[0]->type == EET_OPERATOR);
|
||||
REQUIRE(mainMenu->visibleExp.entries[0]->data.op == OP_DVARBOOL);
|
||||
REQUIRE(mainMenu->visibleExp.entries[1]->data.operand.dataType == VAL_STRING);
|
||||
REQUIRE(mainMenu->visibleExp.entries[1]->data.operand.internals.stringVal == "ui_show_main"s);
|
||||
REQUIRE(mainMenu->visibleExp.entries[2]->data.op == OP_RIGHTPAREN);
|
||||
REQUIRE(mainMenu->onOpen == R"("play" "menu_open" ; "setLocalVarInt" "ui_highlight" "5" ; )"s);
|
||||
|
||||
REQUIRE(mainMenu->itemCount == 5);
|
||||
const auto* emptyTextItem = mainMenu->items[0];
|
||||
REQUIRE(emptyTextItem->parent == mainMenu);
|
||||
REQUIRE(emptyTextItem->text != nullptr);
|
||||
REQUIRE(emptyTextItem->text == ""s);
|
||||
REQUIRE(emptyTextItem->dvar == "ui_fallback_text"s);
|
||||
REQUIRE(emptyTextItem->window.dynamicFlags[0] & 0x4);
|
||||
REQUIRE(emptyTextItem->window.dynamicFlags[0] & 0x10000);
|
||||
REQUIRE(
|
||||
emptyTextItem->action
|
||||
REQUIRE(mainMenu->itemCount == 5);
|
||||
const auto* emptyTextItem = mainMenu->items[0];
|
||||
REQUIRE(emptyTextItem->parent == mainMenu);
|
||||
REQUIRE(emptyTextItem->text != nullptr);
|
||||
REQUIRE(emptyTextItem->text == ""s);
|
||||
REQUIRE(emptyTextItem->dvar == "ui_fallback_text"s);
|
||||
REQUIRE(emptyTextItem->window.dynamicFlags[0] & 0x4);
|
||||
REQUIRE(emptyTextItem->window.dynamicFlags[0] & 0x10000);
|
||||
REQUIRE(emptyTextItem->action
|
||||
== R"("setItemColor" "empty_text" "borderColor" "0.1" "0.1" "0.12" "0.5" ; "execondvarstringvalue" "ui_zfeather" "0" "set cg_laserLight 0" ; )"s);
|
||||
REQUIRE(emptyTextItem->materialExp.numEntries == 3);
|
||||
REQUIRE(emptyTextItem->materialExp.entries[0]->data.op == OP_LOCALVARSTRING);
|
||||
REQUIRE(emptyTextItem->materialExp.numEntries == 3);
|
||||
REQUIRE(emptyTextItem->materialExp.entries[0]->data.op == OP_LOCALVARSTRING);
|
||||
|
||||
const auto* saveGameInfoItem = mainMenu->items[1];
|
||||
REQUIRE(saveGameInfoItem->text == "savegameinfo"s);
|
||||
REQUIRE(saveGameInfoItem->itemFlags == ITEM_FLAG_SAVE_GAME_INFO);
|
||||
const auto* saveGameInfoItem = mainMenu->items[1];
|
||||
REQUIRE(saveGameInfoItem->text == "savegameinfo"s);
|
||||
REQUIRE(saveGameInfoItem->itemFlags == ITEM_FLAG_SAVE_GAME_INFO);
|
||||
|
||||
const auto* cinematicSubtitleItem = mainMenu->items[2];
|
||||
REQUIRE(cinematicSubtitleItem->text == "cinematicsubtitle"s);
|
||||
REQUIRE(cinematicSubtitleItem->itemFlags == ITEM_FLAG_CINEMATIC_SUBTITLE);
|
||||
const auto* cinematicSubtitleItem = mainMenu->items[2];
|
||||
REQUIRE(cinematicSubtitleItem->text == "cinematicsubtitle"s);
|
||||
REQUIRE(cinematicSubtitleItem->itemFlags == ITEM_FLAG_CINEMATIC_SUBTITLE);
|
||||
|
||||
const auto* listItem = mainMenu->items[3];
|
||||
REQUIRE(listItem->typeData.listBox);
|
||||
REQUIRE(listItem->typeData.listBox->numColumns == 2);
|
||||
REQUIRE(listItem->typeData.listBox->columnInfo[1].pos == 120);
|
||||
REQUIRE(listItem->typeData.listBox->columnInfo[1].width == 180);
|
||||
REQUIRE(listItem->typeData.listBox->notselectable == 1);
|
||||
REQUIRE(listItem->typeData.listBox->noScrollBars == 1);
|
||||
REQUIRE(listItem->typeData.listBox->usePaging == 1);
|
||||
REQUIRE_THAT(listItem->typeData.listBox->disableColor[0], WithinRel(0.6f));
|
||||
REQUIRE(listItem->typeData.listBox->selectIcon == selectMaterial);
|
||||
REQUIRE(listItem->typeData.listBox->onDoubleClick == R"("play" "mouse_click" ; )"s);
|
||||
const auto* listItem = mainMenu->items[3];
|
||||
REQUIRE(listItem->typeData.listBox);
|
||||
REQUIRE(listItem->typeData.listBox->numColumns == 2);
|
||||
REQUIRE(listItem->typeData.listBox->columnInfo[1].pos == 120);
|
||||
REQUIRE(listItem->typeData.listBox->columnInfo[1].width == 180);
|
||||
REQUIRE(listItem->typeData.listBox->notselectable == 1);
|
||||
REQUIRE(listItem->typeData.listBox->noScrollBars == 1);
|
||||
REQUIRE(listItem->typeData.listBox->usePaging == 1);
|
||||
REQUIRE_THAT(listItem->typeData.listBox->disableColor[0], WithinRel(0.6f));
|
||||
REQUIRE(listItem->typeData.listBox->selectIcon == selectMaterial);
|
||||
REQUIRE(listItem->typeData.listBox->onDoubleClick == R"("play" "mouse_click" ; )"s);
|
||||
|
||||
const auto* defaultTextItem = mainMenu->items[4];
|
||||
REQUIRE(defaultTextItem->type == 0);
|
||||
REQUIRE(defaultTextItem->typeData.editField);
|
||||
REQUIRE(defaultTextItem->typeData.editField->maxChars == 2);
|
||||
const auto* defaultTextItem = mainMenu->items[4];
|
||||
REQUIRE(defaultTextItem->type == 0);
|
||||
REQUIRE(defaultTextItem->typeData.editField);
|
||||
REQUIRE(defaultTextItem->typeData.editField->maxChars == 2);
|
||||
|
||||
REQUIRE(popupMenu->window.staticFlags & 0x01000000);
|
||||
REQUIRE(popupMenu->onESC == R"("close" "self" ; )"s);
|
||||
}
|
||||
REQUIRE(popupMenu->window.staticFlags & 0x01000000);
|
||||
REQUIRE(popupMenu->onESC == R"("close" "self" ; )"s);
|
||||
}
|
||||
|
||||
TEST_CASE("MenuListLoaderIW3: Ensure optimizing item rect considers relative positions", "[iw3][menu][assetloader]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
TEST_CASE("MenuListLoaderIW3: Ensure optimizing item rect considers relative positions", "[iw3][menu][assetloader]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile("ui_mp/test.menu", R"MENU({
|
||||
helper.AddFile("ui_mp/test.menu", R"MENU({
|
||||
menuDef
|
||||
{
|
||||
name "test"
|
||||
@@ -243,23 +243,62 @@ namespace
|
||||
}
|
||||
)MENU");
|
||||
|
||||
const auto result = helper.LoadMenuList("ui_mp/test.menu");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
const auto result = helper.LoadMenuList("ui_mp/test.menu");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* testMenu = helper.GetMenu("test");
|
||||
const auto* testMenu = helper.GetMenu("test");
|
||||
|
||||
REQUIRE(testMenu->window.rectClient.x == Approx(2));
|
||||
REQUIRE(testMenu->window.rectClient.y == Approx(4));
|
||||
REQUIRE(testMenu->window.rect.x == Approx(2));
|
||||
REQUIRE(testMenu->window.rect.y == Approx(4));
|
||||
REQUIRE(testMenu->window.rectClient.x == Approx(2));
|
||||
REQUIRE(testMenu->window.rectClient.y == Approx(4));
|
||||
REQUIRE(testMenu->window.rect.x == Approx(2));
|
||||
REQUIRE(testMenu->window.rect.y == Approx(4));
|
||||
|
||||
REQUIRE(testMenu->itemCount == 1);
|
||||
const auto* item = testMenu->items[0];
|
||||
REQUIRE(item->rectXExp.numEntries == 0);
|
||||
REQUIRE(item->rectYExp.numEntries == 0);
|
||||
REQUIRE(item->window.rectClient.x == Approx(5));
|
||||
REQUIRE(item->window.rectClient.y == Approx(7));
|
||||
REQUIRE(item->window.rect.x == Approx(7));
|
||||
REQUIRE(item->window.rect.y == Approx(11));
|
||||
REQUIRE(testMenu->itemCount == 1);
|
||||
const auto* item = testMenu->items[0];
|
||||
REQUIRE(item->rectXExp.numEntries == 0);
|
||||
REQUIRE(item->rectYExp.numEntries == 0);
|
||||
REQUIRE(item->window.rectClient.x == Approx(5));
|
||||
REQUIRE(item->window.rectClient.y == Approx(7));
|
||||
REQUIRE(item->window.rect.x == Approx(7));
|
||||
REQUIRE(item->window.rect.y == Approx(11));
|
||||
}
|
||||
|
||||
TEST_CASE("MenuParsingIW3IT: Keeps the menus of a menu list loaded by an earlier one", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile("ui_mp/ingame.txt", R"testmenu(
|
||||
{
|
||||
loadMenu { "ui_mp/scriptmenus/killstreak.menu" }
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
helper.AddFile("ui_mp/scriptmenus/killstreak.menu", R"testmenu(
|
||||
{
|
||||
loadMenu { "ui_mp/killstreak_hint.menu" }
|
||||
menuDef
|
||||
{
|
||||
name "killstreak"
|
||||
}
|
||||
} // namespace
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
helper.AddFile("ui_mp/killstreak_hint.menu", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
name "killstreak_hint"
|
||||
}
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
REQUIRE(helper.LoadMenuList("ui_mp/ingame.txt").HasBeenSuccessful());
|
||||
|
||||
const auto result = helper.LoadMenuList("ui_mp/scriptmenus/killstreak.menu");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<const MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
REQUIRE(menuList->menuCount == 2);
|
||||
REQUIRE(menuList->menus[0] == helper.GetMenu("killstreak"));
|
||||
REQUIRE(menuList->menus[1] == helper.GetMenu("killstreak_hint"));
|
||||
}
|
||||
@@ -30,25 +30,15 @@ namespace
|
||||
}
|
||||
};
|
||||
|
||||
class MenuParsingItHelper
|
||||
class MenuLoadingTestHelper
|
||||
{
|
||||
static constexpr const char* DEFAULT_ASSET_NAME = "test.txt";
|
||||
|
||||
Zone m_zone;
|
||||
MockSearchPath m_search_path;
|
||||
std::unique_ptr<IAssetCreator> m_asset_creator;
|
||||
AssetCreatorCollection m_creator_collection;
|
||||
IgnoredAssetLookup m_ignored_asset_lookup;
|
||||
AssetCreationContext m_context;
|
||||
|
||||
public:
|
||||
MenuParsingItHelper()
|
||||
MenuLoadingTestHelper()
|
||||
: m_zone("MockZone", 0, GameId::IW4, GamePlatform::PC),
|
||||
m_creator_collection(m_zone),
|
||||
m_ignored_asset_lookup(),
|
||||
m_context(m_zone, &m_creator_collection, &m_ignored_asset_lookup)
|
||||
{
|
||||
m_asset_creator = ::menu::CreateMenuListLoaderIW4(m_zone.Memory(), m_search_path);
|
||||
m_loader = menu::CreateMenuListLoaderIW4(m_zone.Memory(), m_search_path);
|
||||
}
|
||||
|
||||
void AddFile(std::string fileName, std::string data)
|
||||
@@ -56,11 +46,6 @@ namespace
|
||||
m_search_path.AddFileData(std::move(fileName), std::move(data));
|
||||
}
|
||||
|
||||
void AddFile(std::string data)
|
||||
{
|
||||
AddFile(DEFAULT_ASSET_NAME, std::move(data));
|
||||
}
|
||||
|
||||
Material* AddMaterial(const std::string& name)
|
||||
{
|
||||
auto* material = m_zone.Memory().Alloc<Material>();
|
||||
@@ -71,27 +56,33 @@ namespace
|
||||
return material;
|
||||
}
|
||||
|
||||
AssetCreationResult RunIntegrationTest()
|
||||
AssetCreationResult LoadMenuList(const std::string& name)
|
||||
{
|
||||
return m_asset_creator->CreateAsset(DEFAULT_ASSET_NAME, m_context);
|
||||
return m_loader->CreateAsset(name, m_context);
|
||||
}
|
||||
|
||||
menuDef_t* GetMenuAsset(const std::string& menuName) const
|
||||
[[nodiscard]] menuDef_t* GetMenu(const std::string& name) const
|
||||
{
|
||||
const auto addedAsset = m_zone.m_pools.GetAsset(ASSET_TYPE_MENU, menuName);
|
||||
REQUIRE(addedAsset);
|
||||
REQUIRE(addedAsset->m_type == ASSET_TYPE_MENU);
|
||||
|
||||
return static_cast<menuDef_t*>(addedAsset->m_ptr);
|
||||
const auto* asset = m_zone.m_pools.GetAsset(ASSET_TYPE_MENU, name);
|
||||
REQUIRE(asset);
|
||||
return static_cast<menuDef_t*>(asset->m_ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
Zone m_zone;
|
||||
MockSearchPath m_search_path;
|
||||
std::unique_ptr<IAssetCreator> m_loader;
|
||||
AssetCreatorCollection m_creator_collection;
|
||||
IgnoredAssetLookup m_ignored_asset_lookup;
|
||||
AssetCreationContext m_context;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Can convert simple menu without properties", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -100,11 +91,11 @@ TEST_CASE("MenuParsingIW4IT: Can convert simple menu without properties", "[pars
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = (MenuList*)result.GetAssetInfo()->m_ptr;
|
||||
const auto* menu = helper.GetMenuAsset("Hello");
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* menu = helper.GetMenu("Hello");
|
||||
|
||||
REQUIRE(menuList->menuCount == 1);
|
||||
REQUIRE(menuList->menus);
|
||||
@@ -118,9 +109,9 @@ TEST_CASE("MenuParsingIW4IT: Can convert simple menu without properties", "[pars
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Can convert simple menu", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
#define COOL_STYLE 5
|
||||
#define VISIBILITY_ENABLED 1
|
||||
#define HIDE_STUPID_ELEMENTS 0
|
||||
@@ -181,11 +172,11 @@ TEST_CASE("MenuParsingIW4IT: Can convert simple menu", "[parsing][converting][me
|
||||
|
||||
const auto* funnyDogMaterial = helper.AddMaterial("funny_dog.png");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = (MenuList*)result.GetAssetInfo()->m_ptr;
|
||||
const auto* menu = helper.GetMenuAsset("Bla");
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* menu = helper.GetMenu("Bla");
|
||||
|
||||
REQUIRE(menuList->menuCount == 1);
|
||||
REQUIRE(menuList->menus);
|
||||
@@ -315,9 +306,9 @@ TEST_CASE("MenuParsingIW4IT: Can convert simple menu", "[parsing][converting][me
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Can use numeric focus dvar values", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -330,10 +321,10 @@ TEST_CASE("MenuParsingIW4IT: Can use numeric focus dvar values", "[parsing][conv
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menu = helper.GetMenuAsset("NumericFocusDvar");
|
||||
const auto* menu = helper.GetMenu("NumericFocusDvar");
|
||||
REQUIRE(menu->itemCount == 1);
|
||||
REQUIRE(menu->items != nullptr);
|
||||
|
||||
@@ -345,9 +336,9 @@ TEST_CASE("MenuParsingIW4IT: Can use numeric focus dvar values", "[parsing][conv
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Can omit list box column alignment", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -368,10 +359,10 @@ TEST_CASE("MenuParsingIW4IT: Can omit list box column alignment", "[parsing][con
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menu = helper.GetMenuAsset("ListBoxColumns");
|
||||
const auto* menu = helper.GetMenu("ListBoxColumns");
|
||||
REQUIRE(menu->itemCount == 2);
|
||||
REQUIRE(menu->items != nullptr);
|
||||
|
||||
@@ -398,9 +389,9 @@ TEST_CASE("MenuParsingIW4IT: Can omit list box column alignment", "[parsing][con
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Can specify event handler multiple times", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -433,11 +424,11 @@ TEST_CASE("MenuParsingIW4IT: Can specify event handler multiple times", "[parsin
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = (MenuList*)result.GetAssetInfo()->m_ptr;
|
||||
const auto* menu = helper.GetMenuAsset("Blab");
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* menu = helper.GetMenu("Blab");
|
||||
|
||||
REQUIRE(menuList->menuCount == 1);
|
||||
REQUIRE(menuList->menus);
|
||||
@@ -476,9 +467,9 @@ TEST_CASE("MenuParsingIW4IT: Can specify event handler multiple times", "[parsin
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Optimized exp rect considers parent pos", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -501,11 +492,11 @@ TEST_CASE("MenuParsingIW4IT: Optimized exp rect considers parent pos", "[parsing
|
||||
}
|
||||
})testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* menu = helper.GetMenuAsset("Blab");
|
||||
const auto* menu = helper.GetMenu("Blab");
|
||||
|
||||
REQUIRE(menuList->menuCount == 1);
|
||||
REQUIRE(menuList->menus);
|
||||
@@ -544,9 +535,9 @@ TEST_CASE("MenuParsingIW4IT: Optimized exp rect considers parent pos", "[parsing
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Optimized exp rect considers parent optimized pos", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -568,11 +559,11 @@ TEST_CASE("MenuParsingIW4IT: Optimized exp rect considers parent optimized pos",
|
||||
}
|
||||
})testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* menu = helper.GetMenuAsset("Blab");
|
||||
const auto* menu = helper.GetMenu("Blab");
|
||||
|
||||
REQUIRE(menuList->menuCount == 1);
|
||||
REQUIRE(menuList->menus);
|
||||
@@ -606,14 +597,14 @@ TEST_CASE("MenuParsingIW4IT: Integer text expressions respect permissive mode",
|
||||
CAPTURE(permissive, optimization);
|
||||
ObjLoading::Configuration.MenuPermissiveParsing = permissive;
|
||||
ObjLoading::Configuration.MenuNoOptimization = !optimization;
|
||||
MenuParsingItHelper helper;
|
||||
helper.AddFile(R"MENU({ menuDef { name "test" itemDef { text "fallback" exp text (3); } } })MENU");
|
||||
MenuLoadingTestHelper helper;
|
||||
helper.AddFile("test.txt", R"MENU({ menuDef { name "test" itemDef { text "fallback" exp text (3); } } })MENU");
|
||||
|
||||
REQUIRE(helper.RunIntegrationTest().HasBeenSuccessful() == permissive);
|
||||
REQUIRE(helper.LoadMenuList("test.txt").HasBeenSuccessful() == permissive);
|
||||
if (!permissive)
|
||||
return;
|
||||
|
||||
const auto* menu = helper.GetMenuAsset("test");
|
||||
const auto* menu = helper.GetMenu("test");
|
||||
REQUIRE(menu->itemCount == 1);
|
||||
const auto* item = menu->items[0];
|
||||
REQUIRE(item->text);
|
||||
@@ -643,14 +634,14 @@ TEST_CASE("MenuParsingIW4IT: Double text expressions respect permissive mode", "
|
||||
CAPTURE(permissive, optimization);
|
||||
ObjLoading::Configuration.MenuPermissiveParsing = permissive;
|
||||
ObjLoading::Configuration.MenuNoOptimization = !optimization;
|
||||
MenuParsingItHelper helper;
|
||||
helper.AddFile(R"MENU({ menuDef { name "test" itemDef { text "fallback" exp text (3.5); } } })MENU");
|
||||
MenuLoadingTestHelper helper;
|
||||
helper.AddFile("test.txt", R"MENU({ menuDef { name "test" itemDef { text "fallback" exp text (3.5); } } })MENU");
|
||||
|
||||
REQUIRE(helper.RunIntegrationTest().HasBeenSuccessful() == permissive);
|
||||
REQUIRE(helper.LoadMenuList("test.txt").HasBeenSuccessful() == permissive);
|
||||
if (!permissive)
|
||||
return;
|
||||
|
||||
const auto* menu = helper.GetMenuAsset("test");
|
||||
const auto* menu = helper.GetMenu("test");
|
||||
REQUIRE(menu->itemCount == 1);
|
||||
const auto* item = menu->items[0];
|
||||
REQUIRE(item->text);
|
||||
@@ -671,3 +662,43 @@ TEST_CASE("MenuParsingIW4IT: Double text expressions respect permissive mode", "
|
||||
CHECK(expression->entries[0].data.operand.internals.floatVal == Approx(3.5));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Keeps the menus of a menu list loaded by an earlier one", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile("ui_mp/ingame.txt", R"testmenu(
|
||||
{
|
||||
loadMenu { "ui_mp/scriptmenus/killstreak.menu" }
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
helper.AddFile("ui_mp/scriptmenus/killstreak.menu", R"testmenu(
|
||||
{
|
||||
loadMenu { "ui_mp/killstreak_hint.menu" }
|
||||
menuDef
|
||||
{
|
||||
name "killstreak"
|
||||
}
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
helper.AddFile("ui_mp/killstreak_hint.menu", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
name "killstreak_hint"
|
||||
}
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
REQUIRE(helper.LoadMenuList("ui_mp/ingame.txt").HasBeenSuccessful());
|
||||
|
||||
const auto result = helper.LoadMenuList("ui_mp/scriptmenus/killstreak.menu");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<const MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
REQUIRE(menuList->menuCount == 2);
|
||||
REQUIRE(menuList->menus[0] == helper.GetMenu("killstreak"));
|
||||
REQUIRE(menuList->menus[1] == helper.GetMenu("killstreak_hint"));
|
||||
}
|
||||
@@ -22,6 +22,43 @@ namespace
|
||||
ObjLoading::Configuration = original;
|
||||
}
|
||||
};
|
||||
|
||||
class MenuLoadingTestHelper
|
||||
{
|
||||
public:
|
||||
MenuLoadingTestHelper()
|
||||
: m_zone("MockZone", 0, GameId::IW5, GamePlatform::PC),
|
||||
m_creator_collection(m_zone),
|
||||
m_context(m_zone, &m_creator_collection, &m_ignored_asset_lookup)
|
||||
{
|
||||
m_loader = menu::CreateMenuListLoaderIW5(m_zone.Memory(), m_search_path);
|
||||
}
|
||||
|
||||
void AddFile(std::string fileName, std::string data)
|
||||
{
|
||||
m_search_path.AddFileData(std::move(fileName), std::move(data));
|
||||
}
|
||||
|
||||
AssetCreationResult LoadMenuList(const std::string& name)
|
||||
{
|
||||
return m_loader->CreateAsset(name, m_context);
|
||||
}
|
||||
|
||||
[[nodiscard]] menuDef_t* GetMenu(const std::string& name) const
|
||||
{
|
||||
const auto* asset = m_zone.m_pools.GetAsset(ASSET_TYPE_MENU, name);
|
||||
REQUIRE(asset);
|
||||
return static_cast<menuDef_t*>(asset->m_ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
Zone m_zone;
|
||||
MockSearchPath m_search_path;
|
||||
std::unique_ptr<IAssetCreator> m_loader;
|
||||
AssetCreatorCollection m_creator_collection;
|
||||
IgnoredAssetLookup m_ignored_asset_lookup;
|
||||
AssetCreationContext m_context;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("MenuParsingIW5IT: Integer text expressions respect permissive mode", "[parsing][converting][menu][it]")
|
||||
@@ -113,3 +150,43 @@ TEST_CASE("MenuParsingIW5IT: Double text expressions respect permissive mode", "
|
||||
CHECK(expression->entries[0].data.operand.internals.floatVal == Approx(3.5));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("MenuParsingIW5IT: Keeps the menus of a menu list loaded by an earlier one", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile("ui_mp/ingame.txt", R"testmenu(
|
||||
{
|
||||
loadMenu { "ui_mp/scriptmenus/killstreak.menu" }
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
helper.AddFile("ui_mp/scriptmenus/killstreak.menu", R"testmenu(
|
||||
{
|
||||
loadMenu { "ui_mp/killstreak_hint.menu" }
|
||||
menuDef
|
||||
{
|
||||
name "killstreak"
|
||||
}
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
helper.AddFile("ui_mp/killstreak_hint.menu", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
name "killstreak_hint"
|
||||
}
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
REQUIRE(helper.LoadMenuList("ui_mp/ingame.txt").HasBeenSuccessful());
|
||||
|
||||
const auto result = helper.LoadMenuList("ui_mp/scriptmenus/killstreak.menu");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<const MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
REQUIRE(menuList->menuCount == 2);
|
||||
REQUIRE(menuList->menus[0] == helper.GetMenu("killstreak"));
|
||||
REQUIRE(menuList->menus[1] == helper.GetMenu("killstreak_hint"));
|
||||
}
|
||||
@@ -60,21 +60,22 @@ namespace
|
||||
IgnoredAssetLookup m_ignored_asset_lookup;
|
||||
AssetCreationContext m_context;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("MenuListLoaderT4: Loads dumped menus and preserves T4 data", "[t4][menu][assetloader]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
const auto* backgroundMaterial = helper.AddMaterial("background_material");
|
||||
const auto* selectMaterial = helper.AddMaterial("select_material");
|
||||
const auto* listboxBackgroundMaterial = helper.AddMaterial("listbox_background_material");
|
||||
const auto* highlightMaterial = helper.AddMaterial("highlight_material");
|
||||
TEST_CASE("MenuListLoaderT4: Loads dumped menus and preserves T4 data", "[t4][menu][assetloader]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
const auto* backgroundMaterial = helper.AddMaterial("background_material");
|
||||
const auto* selectMaterial = helper.AddMaterial("select_material");
|
||||
const auto* listboxBackgroundMaterial = helper.AddMaterial("listbox_background_material");
|
||||
const auto* highlightMaterial = helper.AddMaterial("highlight_material");
|
||||
|
||||
helper.AddFile("ui_mp/menus.txt", R"MENU({
|
||||
helper.AddFile("ui_mp/menus.txt", R"MENU({
|
||||
loadMenu { "ui_mp/main.menu" }
|
||||
loadMenu { "ui_mp/popup.menu" }
|
||||
}
|
||||
)MENU");
|
||||
helper.AddFile("ui_mp/main.menu", R"MENU({
|
||||
helper.AddFile("ui_mp/main.menu", R"MENU({
|
||||
menuDef
|
||||
{
|
||||
name "main"
|
||||
@@ -156,7 +157,7 @@ namespace
|
||||
}
|
||||
}
|
||||
)MENU");
|
||||
helper.AddFile("ui_mp/popup.menu", R"MENU({
|
||||
helper.AddFile("ui_mp/popup.menu", R"MENU({
|
||||
menuDef
|
||||
{
|
||||
name "popup"
|
||||
@@ -171,86 +172,85 @@ namespace
|
||||
}
|
||||
)MENU");
|
||||
|
||||
const auto result = helper.LoadMenuList("ui_mp/menus.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
const auto result = helper.LoadMenuList("ui_mp/menus.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* mainMenu = helper.GetMenu("main");
|
||||
const auto* popupMenu = helper.GetMenu("popup");
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* mainMenu = helper.GetMenu("main");
|
||||
const auto* popupMenu = helper.GetMenu("popup");
|
||||
|
||||
REQUIRE(menuList->name == "ui_mp/menus.txt"s);
|
||||
REQUIRE(menuList->menuCount == 2);
|
||||
REQUIRE(menuList->menus[0] == mainMenu);
|
||||
REQUIRE(menuList->menus[1] == popupMenu);
|
||||
REQUIRE(menuList->name == "ui_mp/menus.txt"s);
|
||||
REQUIRE(menuList->menuCount == 2);
|
||||
REQUIRE(menuList->menus[0] == mainMenu);
|
||||
REQUIRE(menuList->menus[1] == popupMenu);
|
||||
|
||||
REQUIRE(mainMenu->window.background == backgroundMaterial);
|
||||
REQUIRE(mainMenu->window.dynamicFlags[0] & WINDOW_FLAG_NON_DEFAULT_FORECOLOR);
|
||||
REQUIRE_THAT(mainMenu->disableColor[0], WithinRel(0.2f));
|
||||
REQUIRE_THAT(mainMenu->disableColor[3], WithinRel(0.5f));
|
||||
REQUIRE(mainMenu->visibleExp.numEntries == 3);
|
||||
REQUIRE(mainMenu->visibleExp.entries[0]->type == EET_OPERATOR);
|
||||
REQUIRE(mainMenu->visibleExp.entries[0]->data.op == OP_DVARBOOL);
|
||||
REQUIRE(mainMenu->visibleExp.entries[1]->data.operand.dataType == VAL_STRING);
|
||||
REQUIRE(mainMenu->visibleExp.entries[1]->data.operand.internals.stringVal == "ui_show_main"s);
|
||||
REQUIRE(mainMenu->visibleExp.entries[2]->data.op == OP_RIGHTPAREN);
|
||||
REQUIRE(mainMenu->onOpen == R"("play" "menu_open" ; "setLocalVarInt" "ui_highlight" "5" ; )"s);
|
||||
REQUIRE(mainMenu->onFocus == R"("setdvar" "ui_menu_focused" "1" ; )"s);
|
||||
REQUIRE(mainMenu->window.background == backgroundMaterial);
|
||||
REQUIRE(mainMenu->window.dynamicFlags[0] & WINDOW_FLAG_NON_DEFAULT_FORECOLOR);
|
||||
REQUIRE_THAT(mainMenu->disableColor[0], WithinRel(0.2f));
|
||||
REQUIRE_THAT(mainMenu->disableColor[3], WithinRel(0.5f));
|
||||
REQUIRE(mainMenu->visibleExp.numEntries == 3);
|
||||
REQUIRE(mainMenu->visibleExp.entries[0]->type == EET_OPERATOR);
|
||||
REQUIRE(mainMenu->visibleExp.entries[0]->data.op == OP_DVARBOOL);
|
||||
REQUIRE(mainMenu->visibleExp.entries[1]->data.operand.dataType == VAL_STRING);
|
||||
REQUIRE(mainMenu->visibleExp.entries[1]->data.operand.internals.stringVal == "ui_show_main"s);
|
||||
REQUIRE(mainMenu->visibleExp.entries[2]->data.op == OP_RIGHTPAREN);
|
||||
REQUIRE(mainMenu->onOpen == R"("play" "menu_open" ; "setLocalVarInt" "ui_highlight" "5" ; )"s);
|
||||
REQUIRE(mainMenu->onFocus == R"("setdvar" "ui_menu_focused" "1" ; )"s);
|
||||
|
||||
REQUIRE(mainMenu->itemCount == 5);
|
||||
const auto* emptyTextItem = mainMenu->items[0];
|
||||
REQUIRE(emptyTextItem->parent == mainMenu);
|
||||
REQUIRE(emptyTextItem->text != nullptr);
|
||||
REQUIRE(emptyTextItem->text == ""s);
|
||||
REQUIRE(emptyTextItem->dvar == "ui_fallback_text"s);
|
||||
REQUIRE(emptyTextItem->window.dynamicFlags[0] & WINDOW_FLAG_VISIBLE);
|
||||
REQUIRE(emptyTextItem->window.dynamicFlags[0] & WINDOW_FLAG_NON_DEFAULT_FORECOLOR);
|
||||
REQUIRE(
|
||||
emptyTextItem->action
|
||||
REQUIRE(mainMenu->itemCount == 5);
|
||||
const auto* emptyTextItem = mainMenu->items[0];
|
||||
REQUIRE(emptyTextItem->parent == mainMenu);
|
||||
REQUIRE(emptyTextItem->text != nullptr);
|
||||
REQUIRE(emptyTextItem->text == ""s);
|
||||
REQUIRE(emptyTextItem->dvar == "ui_fallback_text"s);
|
||||
REQUIRE(emptyTextItem->window.dynamicFlags[0] & WINDOW_FLAG_VISIBLE);
|
||||
REQUIRE(emptyTextItem->window.dynamicFlags[0] & WINDOW_FLAG_NON_DEFAULT_FORECOLOR);
|
||||
REQUIRE(emptyTextItem->action
|
||||
== R"("setItemColor" "empty_text" "borderColor" "0.1" "0.1" "0.12" "0.5" ; "execondvarstringvalue" "ui_zfeather" "0" "set cg_laserLight 0" ; )"s);
|
||||
REQUIRE(emptyTextItem->materialExp.numEntries == 3);
|
||||
REQUIRE(emptyTextItem->materialExp.entries[0]->data.op == OP_LOCALVARSTRING);
|
||||
REQUIRE(emptyTextItem->materialExp.numEntries == 3);
|
||||
REQUIRE(emptyTextItem->materialExp.entries[0]->data.op == OP_LOCALVARSTRING);
|
||||
|
||||
const auto* saveGameInfoItem = mainMenu->items[1];
|
||||
REQUIRE(saveGameInfoItem->text == "savegameinfo"s);
|
||||
REQUIRE(saveGameInfoItem->itemFlags == ITEM_FLAG_SAVE_GAME_INFO);
|
||||
const auto* saveGameInfoItem = mainMenu->items[1];
|
||||
REQUIRE(saveGameInfoItem->text == "savegameinfo"s);
|
||||
REQUIRE(saveGameInfoItem->itemFlags == ITEM_FLAG_SAVE_GAME_INFO);
|
||||
|
||||
const auto* cinematicSubtitleItem = mainMenu->items[2];
|
||||
REQUIRE(cinematicSubtitleItem->text == "cinematicsubtitle"s);
|
||||
REQUIRE(cinematicSubtitleItem->itemFlags == ITEM_FLAG_CINEMATIC_SUBTITLE);
|
||||
const auto* cinematicSubtitleItem = mainMenu->items[2];
|
||||
REQUIRE(cinematicSubtitleItem->text == "cinematicsubtitle"s);
|
||||
REQUIRE(cinematicSubtitleItem->itemFlags == ITEM_FLAG_CINEMATIC_SUBTITLE);
|
||||
|
||||
const auto* listItem = mainMenu->items[3];
|
||||
REQUIRE(listItem->typeData.listBox);
|
||||
REQUIRE(listItem->typeData.listBox->numColumns == 2);
|
||||
REQUIRE(listItem->typeData.listBox->columnInfo[1].pos == 120);
|
||||
REQUIRE(listItem->typeData.listBox->columnInfo[1].width == 180);
|
||||
REQUIRE(listItem->typeData.listBox->notselectable == 1);
|
||||
REQUIRE(listItem->typeData.listBox->noScrollBars == 1);
|
||||
REQUIRE(listItem->typeData.listBox->usePaging == 1);
|
||||
REQUIRE_THAT(listItem->typeData.listBox->disableColor[0], WithinRel(0.6f));
|
||||
REQUIRE_THAT(listItem->typeData.listBox->focusColor[2], WithinRel(0.3f));
|
||||
REQUIRE(listItem->typeData.listBox->selectIcon == selectMaterial);
|
||||
REQUIRE(listItem->typeData.listBox->backgroundItemListbox == listboxBackgroundMaterial);
|
||||
REQUIRE(listItem->typeData.listBox->highlightTexture == highlightMaterial);
|
||||
REQUIRE(listItem->typeData.listBox->onDoubleClick == R"("play" "mouse_click" ; )"s);
|
||||
REQUIRE(listItem->onListboxSelectionChange == R"("setdvar" "ui_server_selected" "1" ; )"s);
|
||||
const auto* listItem = mainMenu->items[3];
|
||||
REQUIRE(listItem->typeData.listBox);
|
||||
REQUIRE(listItem->typeData.listBox->numColumns == 2);
|
||||
REQUIRE(listItem->typeData.listBox->columnInfo[1].pos == 120);
|
||||
REQUIRE(listItem->typeData.listBox->columnInfo[1].width == 180);
|
||||
REQUIRE(listItem->typeData.listBox->notselectable == 1);
|
||||
REQUIRE(listItem->typeData.listBox->noScrollBars == 1);
|
||||
REQUIRE(listItem->typeData.listBox->usePaging == 1);
|
||||
REQUIRE_THAT(listItem->typeData.listBox->disableColor[0], WithinRel(0.6f));
|
||||
REQUIRE_THAT(listItem->typeData.listBox->focusColor[2], WithinRel(0.3f));
|
||||
REQUIRE(listItem->typeData.listBox->selectIcon == selectMaterial);
|
||||
REQUIRE(listItem->typeData.listBox->backgroundItemListbox == listboxBackgroundMaterial);
|
||||
REQUIRE(listItem->typeData.listBox->highlightTexture == highlightMaterial);
|
||||
REQUIRE(listItem->typeData.listBox->onDoubleClick == R"("play" "mouse_click" ; )"s);
|
||||
REQUIRE(listItem->onListboxSelectionChange == R"("setdvar" "ui_server_selected" "1" ; )"s);
|
||||
|
||||
const auto* defaultTextItem = mainMenu->items[4];
|
||||
REQUIRE(defaultTextItem->type == 0);
|
||||
REQUIRE(defaultTextItem->typeData.editField);
|
||||
REQUIRE(defaultTextItem->typeData.editField->maxChars == 2);
|
||||
const auto* defaultTextItem = mainMenu->items[4];
|
||||
REQUIRE(defaultTextItem->type == 0);
|
||||
REQUIRE(defaultTextItem->typeData.editField);
|
||||
REQUIRE(defaultTextItem->typeData.editField->maxChars == 2);
|
||||
|
||||
REQUIRE(popupMenu->window.staticFlags & WINDOW_FLAG_POPUP);
|
||||
REQUIRE(popupMenu->visibleExp.numEntries == 2);
|
||||
REQUIRE(popupMenu->visibleExp.entries[0]->data.op == OP_PARTYISMISSINGMAPPACK);
|
||||
REQUIRE(popupMenu->visibleExp.entries[1]->data.op == OP_RIGHTPAREN);
|
||||
REQUIRE(popupMenu->onESC == R"("close" "self" ; )"s);
|
||||
}
|
||||
REQUIRE(popupMenu->window.staticFlags & WINDOW_FLAG_POPUP);
|
||||
REQUIRE(popupMenu->visibleExp.numEntries == 2);
|
||||
REQUIRE(popupMenu->visibleExp.entries[0]->data.op == OP_PARTYISMISSINGMAPPACK);
|
||||
REQUIRE(popupMenu->visibleExp.entries[1]->data.op == OP_RIGHTPAREN);
|
||||
REQUIRE(popupMenu->onESC == R"("close" "self" ; )"s);
|
||||
}
|
||||
|
||||
TEST_CASE("MenuListLoaderT4: Ensure optimizing item rect considers relative positions", "[t4][menu][assetloader]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
TEST_CASE("MenuListLoaderT4: Ensure optimizing item rect considers relative positions", "[t4][menu][assetloader]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile("ui_mp/test.menu", R"MENU({
|
||||
helper.AddFile("ui_mp/test.menu", R"MENU({
|
||||
menuDef
|
||||
{
|
||||
name "test"
|
||||
@@ -265,23 +265,62 @@ namespace
|
||||
}
|
||||
)MENU");
|
||||
|
||||
const auto result = helper.LoadMenuList("ui_mp/test.menu");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
const auto result = helper.LoadMenuList("ui_mp/test.menu");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* testMenu = helper.GetMenu("test");
|
||||
const auto* testMenu = helper.GetMenu("test");
|
||||
|
||||
REQUIRE(testMenu->window.rectClient.x == Approx(2));
|
||||
REQUIRE(testMenu->window.rectClient.y == Approx(4));
|
||||
REQUIRE(testMenu->window.rect.x == Approx(2));
|
||||
REQUIRE(testMenu->window.rect.y == Approx(4));
|
||||
REQUIRE(testMenu->window.rectClient.x == Approx(2));
|
||||
REQUIRE(testMenu->window.rectClient.y == Approx(4));
|
||||
REQUIRE(testMenu->window.rect.x == Approx(2));
|
||||
REQUIRE(testMenu->window.rect.y == Approx(4));
|
||||
|
||||
REQUIRE(testMenu->itemCount == 1);
|
||||
const auto* item = testMenu->items[0];
|
||||
REQUIRE(item->rectXExp.numEntries == 0);
|
||||
REQUIRE(item->rectYExp.numEntries == 0);
|
||||
REQUIRE(item->window.rectClient.x == Approx(5));
|
||||
REQUIRE(item->window.rectClient.y == Approx(7));
|
||||
REQUIRE(item->window.rect.x == Approx(7));
|
||||
REQUIRE(item->window.rect.y == Approx(11));
|
||||
REQUIRE(testMenu->itemCount == 1);
|
||||
const auto* item = testMenu->items[0];
|
||||
REQUIRE(item->rectXExp.numEntries == 0);
|
||||
REQUIRE(item->rectYExp.numEntries == 0);
|
||||
REQUIRE(item->window.rectClient.x == Approx(5));
|
||||
REQUIRE(item->window.rectClient.y == Approx(7));
|
||||
REQUIRE(item->window.rect.x == Approx(7));
|
||||
REQUIRE(item->window.rect.y == Approx(11));
|
||||
}
|
||||
|
||||
TEST_CASE("MenuParsingT4IT: Keeps the menus of a menu list loaded by an earlier one", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile("ui_mp/ingame.txt", R"testmenu(
|
||||
{
|
||||
loadMenu { "ui_mp/scriptmenus/killstreak.menu" }
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
helper.AddFile("ui_mp/scriptmenus/killstreak.menu", R"testmenu(
|
||||
{
|
||||
loadMenu { "ui_mp/killstreak_hint.menu" }
|
||||
menuDef
|
||||
{
|
||||
name "killstreak"
|
||||
}
|
||||
} // namespace
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
helper.AddFile("ui_mp/killstreak_hint.menu", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
name "killstreak_hint"
|
||||
}
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
REQUIRE(helper.LoadMenuList("ui_mp/ingame.txt").HasBeenSuccessful());
|
||||
|
||||
const auto result = helper.LoadMenuList("ui_mp/scriptmenus/killstreak.menu");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<const MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
REQUIRE(menuList->menuCount == 2);
|
||||
REQUIRE(menuList->menus[0] == helper.GetMenu("killstreak"));
|
||||
REQUIRE(menuList->menus[1] == helper.GetMenu("killstreak_hint"));
|
||||
}
|
||||
Reference in new issue
Block a user