mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-09-08 15:07:06 +00:00
feat: add T4 menu dumping and loading (#986)
* feat: add T4 menu dumping * chore: align with latest changes * feat: add T4 menu loading Load T4 menulists and menu files through the shared menu parser. Preserve T4-specific menu and listbox fields and cover loading, dumping, linking, and round-trip behaviour. * chore: make flag fields unsigned * chore: rename `expOperationEnum` -> `operationEnum` * chore: use default enum numeration for T4 operationEnum * chore: remove unused members of operationEnum * chore: remove redundant op from operationEnum * refactor: align T4 expression operand names with IW3 * chore: small adjustment to iw3,t4 types --------- Co-authored-by: Jan Laupetin <[email protected]>
This commit is contained in:
@@ -0,0 +1,269 @@
|
||||
#include "Game/T4/Menu/LoaderMenuListT4.h"
|
||||
|
||||
#include "Game/T4/GameT4.h"
|
||||
#include "SearchPath/MockSearchPath.h"
|
||||
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using namespace T4;
|
||||
using namespace std::literals;
|
||||
using namespace Catch;
|
||||
using namespace Catch::Matchers;
|
||||
|
||||
namespace
|
||||
{
|
||||
class MenuLoadingTestHelper
|
||||
{
|
||||
public:
|
||||
MenuLoadingTestHelper()
|
||||
: m_zone("MockZone", 0, GameId::T4, GamePlatform::PC),
|
||||
m_creator_collection(m_zone),
|
||||
m_context(m_zone, &m_creator_collection, &m_ignored_asset_lookup)
|
||||
{
|
||||
m_loader = menu::CreateMenuListLoaderT4(m_zone.Memory(), m_search_path);
|
||||
}
|
||||
|
||||
void AddFile(std::string name, std::string contents)
|
||||
{
|
||||
m_search_path.AddFileData(std::move(name), std::move(contents));
|
||||
}
|
||||
|
||||
Material* AddMaterial(const std::string& name)
|
||||
{
|
||||
auto* material = m_zone.Memory().Alloc<Material>();
|
||||
material->info.name = m_zone.Memory().Dup(name.c_str());
|
||||
m_context.AddAsset<AssetMaterial>(name, material);
|
||||
return material;
|
||||
}
|
||||
|
||||
AssetCreationResult LoadMenuList(const std::string& name)
|
||||
{
|
||||
return m_loader->CreateAsset(name, m_context);
|
||||
}
|
||||
|
||||
menuDef_t* GetMenu(const std::string& name)
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
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({
|
||||
loadMenu { "ui_mp/main.menu" }
|
||||
loadMenu { "ui_mp/popup.menu" }
|
||||
}
|
||||
)MENU");
|
||||
helper.AddFile("ui_mp/main.menu", R"MENU({
|
||||
menuDef
|
||||
{
|
||||
name "main"
|
||||
fullscreen 1
|
||||
rect 0 0 640 480 0 0
|
||||
background "background_material"
|
||||
forecolor 0.8 0.7 0.6 0.5
|
||||
disablecolor 0.2 0.3 0.4 0.5
|
||||
visible when(dvarbool("ui_show_main"));
|
||||
onOpen
|
||||
{
|
||||
play menu_open;
|
||||
setLocalVarInt ui_highlight 5;
|
||||
}
|
||||
onFocus
|
||||
{
|
||||
setdvar ui_menu_focused 1;
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
name "empty_text"
|
||||
text ""
|
||||
rect 10 20 180 24 1 2
|
||||
type 1
|
||||
visible 1
|
||||
forecolor 0.9 0.9 1 0.07
|
||||
dvar "ui_fallback_text"
|
||||
action
|
||||
{
|
||||
setItemColor empty_text borderColor 0.1 0.1 0.12 0.5;
|
||||
execondvarstringvalue ui_zfeather 0 "set cg_laserLight 0";
|
||||
}
|
||||
exp material (localvarstring("ui_material"));
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
name "server_list"
|
||||
rect 20 60 300 200 0 0
|
||||
type 6
|
||||
columns 2 0 120 32 0 120 180 48 1
|
||||
elementwidth 300
|
||||
elementheight 20
|
||||
feeder 2
|
||||
elementtype 1
|
||||
notselectable
|
||||
noscrollbars
|
||||
usepaging
|
||||
disablecolor 0.6 0.5 0.4 0.3
|
||||
selectBorder 1 1 1 1
|
||||
focusColor 0.1 0.2 0.3 0.4
|
||||
selectIcon "select_material"
|
||||
backgroundItemListbox "listbox_background_material"
|
||||
highlightTexture "highlight_material"
|
||||
doubleclick
|
||||
{
|
||||
play mouse_click;
|
||||
}
|
||||
onListboxSelectionChange
|
||||
{
|
||||
setdvar ui_server_selected 1;
|
||||
}
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
name "default_text"
|
||||
text "-"
|
||||
maxChars 2
|
||||
}
|
||||
}
|
||||
}
|
||||
)MENU");
|
||||
helper.AddFile("ui_mp/popup.menu", R"MENU({
|
||||
menuDef
|
||||
{
|
||||
name "popup"
|
||||
rect 40 40 200 100 0 0
|
||||
popup
|
||||
visible when(partyismissingmappack());
|
||||
onESC
|
||||
{
|
||||
close self;
|
||||
}
|
||||
}
|
||||
}
|
||||
)MENU");
|
||||
|
||||
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");
|
||||
|
||||
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->itemCount == 3);
|
||||
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);
|
||||
|
||||
const auto* listItem = mainMenu->items[1];
|
||||
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[2];
|
||||
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);
|
||||
}
|
||||
|
||||
TEST_CASE("MenuListLoaderT4: Ensure optimizing item rect considers relative positions", "[t4][menu][assetloader]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile("ui_mp/test.menu", R"MENU({
|
||||
menuDef
|
||||
{
|
||||
name "test"
|
||||
rect 2 4 100 100
|
||||
itemDef
|
||||
{
|
||||
rect 1 2 20 20
|
||||
exp rect x (5)
|
||||
exp rect y (7)
|
||||
}
|
||||
}
|
||||
}
|
||||
)MENU");
|
||||
|
||||
const auto result = helper.LoadMenuList("ui_mp/test.menu");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
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->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));
|
||||
}
|
||||
} // namespace
|
||||
@@ -0,0 +1,616 @@
|
||||
#include "Game/T4/Menu/MenuDumperT4.h"
|
||||
|
||||
#include "Game/T4/Menu/MenuListDumperT4.h"
|
||||
#include "Parsing/Menu/MenuFileReader.h"
|
||||
#include "SearchPath/MockOutputPath.h"
|
||||
#include "SearchPath/MockSearchPath.h"
|
||||
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
using namespace T4;
|
||||
|
||||
namespace
|
||||
{
|
||||
expressionEntry Operator(const operationEnum operation)
|
||||
{
|
||||
expressionEntry entry{};
|
||||
entry.type = EET_OPERATOR;
|
||||
entry.data.op = operation;
|
||||
return entry;
|
||||
}
|
||||
|
||||
expressionEntry IntOperand(const int value)
|
||||
{
|
||||
expressionEntry entry{};
|
||||
entry.type = EET_OPERAND;
|
||||
entry.data.operand.dataType = VAL_INT;
|
||||
entry.data.operand.internals.intVal = value;
|
||||
return entry;
|
||||
}
|
||||
|
||||
expressionEntry StringOperand(const char* value)
|
||||
{
|
||||
expressionEntry entry{};
|
||||
entry.type = EET_OPERAND;
|
||||
entry.data.operand.dataType = VAL_STRING;
|
||||
entry.data.operand.internals.stringVal = value;
|
||||
return entry;
|
||||
}
|
||||
|
||||
template<std::size_t EntryCount> std::array<expressionEntry*, EntryCount> EntryPointers(std::array<expressionEntry, EntryCount>& entries)
|
||||
{
|
||||
std::array<expressionEntry*, EntryCount> result{};
|
||||
for (auto entryIndex = 0u; entryIndex < EntryCount; entryIndex++)
|
||||
result[entryIndex] = &entries[entryIndex];
|
||||
return result;
|
||||
}
|
||||
|
||||
TEST_CASE("MenuDumperT4: Can dump menu with expressions and scripts", "[t4][menu][assetdumper]")
|
||||
{
|
||||
constexpr auto UI_SHOW_FAVORITE_SERVERS = 0x00000004;
|
||||
constexpr auto UI_SHOW_NOT_FAVORITE_SERVERS = 0x00001000;
|
||||
|
||||
std::array menuVisibleValues{
|
||||
Operator(OP_DVARBOOL),
|
||||
StringOperand("ui_test"),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
};
|
||||
auto menuVisibleEntries = EntryPointers(menuVisibleValues);
|
||||
|
||||
std::array buttonVisibleValues{
|
||||
Operator(OP_LEFTPAREN),
|
||||
Operator(OP_LOCALVARINT),
|
||||
StringOperand("ui_highlight"),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
Operator(OP_EQUALS),
|
||||
IntOperand(5),
|
||||
Operator(OP_AND),
|
||||
Operator(OP_LOCALVARSTRING),
|
||||
StringOperand("ui_choicegroup"),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
Operator(OP_EQUALS),
|
||||
StringOperand("popmenu"),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
};
|
||||
auto buttonVisibleEntries = EntryPointers(buttonVisibleValues);
|
||||
|
||||
std::array materialExpressionValues{
|
||||
Operator(OP_LEFTPAREN),
|
||||
StringOperand("expression_material"),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
};
|
||||
auto materialExpressionEntries = EntryPointers(materialExpressionValues);
|
||||
|
||||
Material backgroundMaterial{};
|
||||
backgroundMaterial.info.name = "background_material";
|
||||
|
||||
ItemKeyHandler buttonKeyHandler{
|
||||
.key = 'a',
|
||||
.action = "open advanced;",
|
||||
.next = nullptr,
|
||||
};
|
||||
|
||||
itemDef_s button{};
|
||||
button.window.name = "button_test";
|
||||
button.window.group = "buttons";
|
||||
button.window.rectClient = {
|
||||
.x = 10.0f,
|
||||
.y = 20.0f,
|
||||
.w = 180.0f,
|
||||
.h = 24.0f,
|
||||
.horzAlign = 1,
|
||||
.vertAlign = 2,
|
||||
};
|
||||
button.window.style = 1;
|
||||
button.window.ownerDrawFlags = UI_SHOW_NOT_FAVORITE_SERVERS;
|
||||
button.window.backColor[0] = 0.1f;
|
||||
button.window.backColor[1] = 0.1f;
|
||||
button.window.backColor[2] = 0.1f;
|
||||
button.window.backColor[3] = 0.25f;
|
||||
button.window.foreColor[0] = 0.69f;
|
||||
button.window.foreColor[1] = 0.69f;
|
||||
button.window.foreColor[2] = 0.69f;
|
||||
button.window.foreColor[3] = 1.0f;
|
||||
button.window.background = &backgroundMaterial;
|
||||
button.type = ITEM_TYPE_BUTTON;
|
||||
button.text = "@MENU_TEST";
|
||||
button.textAlignMode = 10;
|
||||
button.textalignx = -6.0f;
|
||||
button.textscale = 0.4f;
|
||||
button.textStyle = 6;
|
||||
button.fontEnum = 1;
|
||||
button.onFocus = "play mouse_over; setlocalvarint ui_highlight 5;";
|
||||
button.leaveFocus = "setlocalvarint ui_highlight 0;";
|
||||
button.mouseExit = R"(setitemcolor button_test bordercolor "0.1" "0.1" "0.12" "0.5";)";
|
||||
button.action = "play mouse_click; open options;";
|
||||
button.onKey = &buttonKeyHandler;
|
||||
button.visibleExp = {.numEntries = static_cast<int>(buttonVisibleEntries.size()), .entries = buttonVisibleEntries.data()};
|
||||
button.materialExp = {.numEntries = static_cast<int>(materialExpressionEntries.size()), .entries = materialExpressionEntries.data()};
|
||||
|
||||
editFieldDef_s editField{};
|
||||
editField.minVal = -1.0f;
|
||||
editField.maxVal = -1.0f;
|
||||
editField.defVal = -1.0f;
|
||||
editField.maxChars = 16;
|
||||
editField.maxPaintChars = 16;
|
||||
|
||||
itemDef_s editItem{};
|
||||
editItem.window.name = "name_field";
|
||||
editItem.window.group = "fields";
|
||||
editItem.window.rectClient = {.x = 10.0f, .y = 56.0f, .w = 180.0f, .h = 24.0f, .horzAlign = 1, .vertAlign = 2};
|
||||
editItem.window.style = 1;
|
||||
editItem.window.border = 1;
|
||||
editItem.window.borderSize = 1.0f;
|
||||
editItem.window.dynamicFlags[0] = WINDOW_FLAG_VISIBLE;
|
||||
editItem.window.backColor[0] = 0.1f;
|
||||
editItem.window.backColor[1] = 0.1f;
|
||||
editItem.window.backColor[2] = 0.1f;
|
||||
editItem.window.backColor[3] = 0.25f;
|
||||
editItem.window.foreColor[0] = 1.0f;
|
||||
editItem.window.foreColor[1] = 1.0f;
|
||||
editItem.window.foreColor[2] = 1.0f;
|
||||
editItem.window.foreColor[3] = 1.0f;
|
||||
editItem.window.borderColor[0] = 0.5f;
|
||||
editItem.window.borderColor[1] = 0.5f;
|
||||
editItem.window.borderColor[2] = 0.5f;
|
||||
editItem.window.borderColor[3] = 1.0f;
|
||||
editItem.type = ITEM_TYPE_UPREDITFIELD;
|
||||
editItem.text = "";
|
||||
editItem.textAlignMode = 1;
|
||||
editItem.textalignx = -28.0f;
|
||||
editItem.textaligny = 14.0f;
|
||||
editItem.textscale = 0.3f;
|
||||
editItem.fontEnum = 1;
|
||||
editItem.onAccept = "setdvar ui_name player_name;";
|
||||
editItem.dvar = "player_name";
|
||||
editItem.typeData.editField = &editField;
|
||||
|
||||
itemDef_s* items[]{&button, &editItem};
|
||||
ItemKeyHandler menuKeyHandler{
|
||||
.key = 13,
|
||||
.action = "open key_help;",
|
||||
.next = nullptr,
|
||||
};
|
||||
|
||||
menuDef_t menu{};
|
||||
menu.window.name = "test_menu";
|
||||
menu.window.rect = {.x = 0.0f, .y = 0.0f, .w = 640.0f, .h = 480.0f, .horzAlign = 0, .vertAlign = 0};
|
||||
menu.window.style = 1;
|
||||
menu.window.ownerDrawFlags = UI_SHOW_FAVORITE_SERVERS;
|
||||
menu.window.border = 1;
|
||||
menu.window.borderSize = 2.0f;
|
||||
menu.window.backColor[0] = 0.1f;
|
||||
menu.window.backColor[1] = 0.2f;
|
||||
menu.window.backColor[2] = 0.3f;
|
||||
menu.window.backColor[3] = 0.75f;
|
||||
menu.window.foreColor[0] = 1.0f;
|
||||
menu.window.foreColor[1] = 1.0f;
|
||||
menu.window.foreColor[2] = 1.0f;
|
||||
menu.window.foreColor[3] = 1.0f;
|
||||
menu.fullScreen = 1;
|
||||
menu.fadeCycle = 16;
|
||||
menu.fadeClamp = 1.0f;
|
||||
menu.fadeAmount = 0.1f;
|
||||
menu.fadeInAmount = 0.2f;
|
||||
menu.blurRadius = 2.0f;
|
||||
menu.onOpen = "play mouse_open; setfocus button_test;";
|
||||
menu.onClose = "play mouse_close;";
|
||||
menu.onESC = "close self;";
|
||||
menu.onKey = &menuKeyHandler;
|
||||
menu.visibleExp = {.numEntries = static_cast<int>(menuVisibleEntries.size()), .entries = menuVisibleEntries.data()};
|
||||
menu.allowedBinding = "+activate";
|
||||
menu.soundName = "menu_music";
|
||||
menu.focusColor[0] = 1.0f;
|
||||
menu.focusColor[1] = 0.8f;
|
||||
menu.focusColor[2] = 0.2f;
|
||||
menu.focusColor[3] = 1.0f;
|
||||
menu.itemCount = static_cast<int>(std::size(items));
|
||||
menu.items = items;
|
||||
|
||||
Zone zone("MockZone", 0, GameId::T4, GamePlatform::PC);
|
||||
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<menuDef_t>>(ASSET_TYPE_MENU, menu.window.name, &menu));
|
||||
|
||||
MockSearchPath mockObjPath;
|
||||
MockOutputPath mockOutput;
|
||||
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
|
||||
|
||||
menu::MenuDumperT4 dumper;
|
||||
dumper.Dump(context);
|
||||
|
||||
const auto* file = mockOutput.GetMockedFile("ui_mp/test_menu.menu");
|
||||
REQUIRE(file);
|
||||
|
||||
const auto output = file->AsString();
|
||||
constexpr auto expectedOutput = R"({
|
||||
menuDef
|
||||
{
|
||||
name "test_menu"
|
||||
fullscreen 1
|
||||
rect 0 0 640 480 0 0
|
||||
style 1
|
||||
border 1
|
||||
borderSize 2
|
||||
backcolor 0.1 0.2 0.3 0.75
|
||||
focuscolor 1 0.8 0.2 1
|
||||
ownerdrawFlag 4
|
||||
soundLoop "menu_music"
|
||||
fadeClamp 1
|
||||
fadeCycle 16
|
||||
fadeAmount 0.1
|
||||
fadeInAmount 0.2
|
||||
blurWorld 2
|
||||
allowedBinding "+activate"
|
||||
visible when(dvarbool("ui_test"));
|
||||
onOpen
|
||||
{
|
||||
play mouse_open;
|
||||
setfocus button_test;
|
||||
}
|
||||
onClose
|
||||
{
|
||||
play mouse_close;
|
||||
}
|
||||
onESC
|
||||
{
|
||||
close self;
|
||||
}
|
||||
execKeyInt 13
|
||||
{
|
||||
open key_help;
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
name "button_test"
|
||||
text "@MENU_TEST"
|
||||
group "buttons"
|
||||
rect 10 20 180 24 1 2
|
||||
style 1
|
||||
type 1
|
||||
visible when(localvarint("ui_highlight") == 5 && localvarstring("ui_choicegroup") == "popmenu");
|
||||
ownerdrawFlag 4096
|
||||
textalign 10
|
||||
textalignx -6
|
||||
textscale 0.4
|
||||
textstyle 6
|
||||
textfont 1
|
||||
backcolor 0.1 0.1 0.1 0.25
|
||||
forecolor 0.69 0.69 0.69 1
|
||||
background "background_material"
|
||||
onFocus
|
||||
{
|
||||
play mouse_over;
|
||||
setlocalvarint ui_highlight 5;
|
||||
}
|
||||
leaveFocus
|
||||
{
|
||||
setlocalvarint ui_highlight 0;
|
||||
}
|
||||
mouseExit
|
||||
{
|
||||
setitemcolor button_test bordercolor 0.1 0.1 0.12 0.5;
|
||||
}
|
||||
action
|
||||
{
|
||||
play mouse_click;
|
||||
open options;
|
||||
}
|
||||
execKey "a"
|
||||
{
|
||||
open advanced;
|
||||
}
|
||||
exp material ("expression_material");
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
name "name_field"
|
||||
text ""
|
||||
group "fields"
|
||||
rect 10 56 180 24 1 2
|
||||
style 1
|
||||
type 18
|
||||
border 1
|
||||
borderSize 1
|
||||
visible 1
|
||||
textalign 1
|
||||
textalignx -28
|
||||
textaligny 14
|
||||
textscale 0.3
|
||||
textfont 1
|
||||
backcolor 0.1 0.1 0.1 0.25
|
||||
bordercolor 0.5 0.5 0.5 1
|
||||
accept
|
||||
{
|
||||
setdvar ui_name player_name;
|
||||
}
|
||||
dvar "player_name"
|
||||
maxChars 16
|
||||
maxPaintChars 16
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
REQUIRE(output == expectedOutput);
|
||||
|
||||
menu::MenuAssetZoneState zoneState;
|
||||
std::istringstream input(output);
|
||||
menu::MenuFileReader reader(input, "ui_mp/test_menu.menu", menu::FeatureLevel::IW4, mockObjPath);
|
||||
reader.IncludeZoneState(zoneState);
|
||||
|
||||
const auto parsed = reader.ReadMenuFile();
|
||||
REQUIRE(parsed);
|
||||
REQUIRE(parsed->m_menus.size() == 1);
|
||||
REQUIRE(parsed->m_menus[0]->m_name == "test_menu");
|
||||
REQUIRE(parsed->m_menus[0]->m_owner_draw_flags == UI_SHOW_FAVORITE_SERVERS);
|
||||
REQUIRE(parsed->m_menus[0]->m_items.size() == 2);
|
||||
REQUIRE(parsed->m_menus[0]->m_items[0]->m_name == "button_test");
|
||||
REQUIRE(parsed->m_menus[0]->m_items[0]->m_owner_draw_flags == UI_SHOW_NOT_FAVORITE_SERVERS);
|
||||
REQUIRE(parsed->m_menus[0]->m_items[1]->m_name == "name_field");
|
||||
REQUIRE(parsed->m_menus[0]->m_items[1]->m_dvar == "player_name");
|
||||
}
|
||||
|
||||
TEST_CASE("MenuDumperT4: Prefers parent menu list path over ui_mp fallback", "[t4][menu][assetdumper]")
|
||||
{
|
||||
menuDef_t menu{};
|
||||
menu.window.name = "test_menu";
|
||||
|
||||
menuDef_t* menus[]{&menu};
|
||||
|
||||
MenuList menuList{};
|
||||
menuList.name = "ui/menus.txt";
|
||||
menuList.menuCount = static_cast<int>(std::size(menus));
|
||||
menuList.menus = menus;
|
||||
|
||||
Zone zone("MockZone", 0, GameId::T4, GamePlatform::PC);
|
||||
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<menuDef_t>>(ASSET_TYPE_MENU, menu.window.name, &menu));
|
||||
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<MenuList>>(ASSET_TYPE_MENULIST, menuList.name, &menuList));
|
||||
|
||||
MockSearchPath mockObjPath;
|
||||
MockOutputPath mockOutput;
|
||||
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
|
||||
|
||||
menu::MenuListDumperT4 menuListDumper;
|
||||
menuListDumper.Dump(context);
|
||||
|
||||
menu::MenuDumperT4 menuDumper;
|
||||
menuDumper.Dump(context);
|
||||
|
||||
REQUIRE(mockOutput.GetMockedFile("ui/test_menu.menu"));
|
||||
REQUIRE_FALSE(mockOutput.GetMockedFile("ui_mp/test_menu.menu"));
|
||||
}
|
||||
|
||||
TEST_CASE("MenuDumperT4: Expressions are valid when dumped", "[t4][menu][assetdumper]")
|
||||
{
|
||||
std::array item0VisibleValues{
|
||||
Operator(OP_LEFTPAREN),
|
||||
Operator(OP_LOCALVARSTRING),
|
||||
StringOperand("ui_highlight"),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
};
|
||||
auto item0Entries = EntryPointers(item0VisibleValues);
|
||||
|
||||
itemDef_s item0{};
|
||||
item0.window.foreColor[0] = 1.0f;
|
||||
item0.window.foreColor[1] = 1.0f;
|
||||
item0.window.foreColor[2] = 1.0f;
|
||||
item0.window.foreColor[3] = 1.0f;
|
||||
item0.window.rectClient = {.x = 1, .y = 2, .w = 3, .h = 4, .horzAlign = 0, .vertAlign = 0};
|
||||
item0.textExp = {.numEntries = static_cast<int>(item0Entries.size()), .entries = item0Entries.data()};
|
||||
|
||||
std::array item1VisibleValues{
|
||||
Operator(OP_LEFTPAREN),
|
||||
IntOperand(2),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
};
|
||||
auto item1Entries = EntryPointers(item1VisibleValues);
|
||||
|
||||
itemDef_s item1{};
|
||||
item1.window.foreColor[0] = 1.0f;
|
||||
item1.window.foreColor[1] = 1.0f;
|
||||
item1.window.foreColor[2] = 1.0f;
|
||||
item1.window.foreColor[3] = 1.0f;
|
||||
item1.window.rectClient = {.x = 1, .y = 2, .w = 3, .h = 4, .horzAlign = 0, .vertAlign = 0};
|
||||
item1.textExp = {.numEntries = static_cast<int>(item1Entries.size()), .entries = item1Entries.data()};
|
||||
|
||||
std::array item2VisibleValues{
|
||||
Operator(OP_LEFTPAREN),
|
||||
IntOperand(3),
|
||||
Operator(OP_ADD),
|
||||
IntOperand(7),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
};
|
||||
auto item2Entries = EntryPointers(item2VisibleValues);
|
||||
|
||||
itemDef_s item2{};
|
||||
item2.window.foreColor[0] = 1.0f;
|
||||
item2.window.foreColor[1] = 1.0f;
|
||||
item2.window.foreColor[2] = 1.0f;
|
||||
item2.window.foreColor[3] = 1.0f;
|
||||
item2.window.rectClient = {.x = 1, .y = 2, .w = 3, .h = 4, .horzAlign = 0, .vertAlign = 0};
|
||||
item2.textExp = {.numEntries = static_cast<int>(item2Entries.size()), .entries = item2Entries.data()};
|
||||
|
||||
std::array item3VisibleValues{
|
||||
Operator(OP_LEFTPAREN),
|
||||
IntOperand(-3),
|
||||
Operator(OP_ADD),
|
||||
IntOperand(7),
|
||||
Operator(OP_MULTIPLY),
|
||||
Operator(OP_NOT),
|
||||
Operator(OP_SIN),
|
||||
Operator(OP_COS),
|
||||
IntOperand(7),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
};
|
||||
auto item3Entries = EntryPointers(item3VisibleValues);
|
||||
|
||||
itemDef_s item3{};
|
||||
item3.window.foreColor[0] = 1.0f;
|
||||
item3.window.foreColor[1] = 1.0f;
|
||||
item3.window.foreColor[2] = 1.0f;
|
||||
item3.window.foreColor[3] = 1.0f;
|
||||
item3.window.rectClient = {.x = 1, .y = 2, .w = 3, .h = 4, .horzAlign = 0, .vertAlign = 0};
|
||||
item3.textExp = {.numEntries = static_cast<int>(item3Entries.size()), .entries = item3Entries.data()};
|
||||
|
||||
itemDef_s* items[]{&item0, &item1, &item2, &item3};
|
||||
|
||||
menuDef_t menu{};
|
||||
menu.window.name = "test_menu";
|
||||
menu.window.foreColor[0] = 1.0f;
|
||||
menu.window.foreColor[1] = 1.0f;
|
||||
menu.window.foreColor[2] = 1.0f;
|
||||
menu.window.foreColor[3] = 1.0f;
|
||||
menu.window.rect = {.x = 1, .y = 2, .w = 3, .h = 4, .horzAlign = 0, .vertAlign = 0};
|
||||
menu.itemCount = static_cast<int>(std::size(items));
|
||||
menu.items = items;
|
||||
|
||||
Zone zone("MockZone", 0, GameId::T4, GamePlatform::PC);
|
||||
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<menuDef_t>>(ASSET_TYPE_MENU, menu.window.name, &menu));
|
||||
|
||||
MockSearchPath mockObjPath;
|
||||
MockOutputPath mockOutput;
|
||||
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
|
||||
|
||||
menu::MenuDumperT4 dumper;
|
||||
dumper.Dump(context);
|
||||
|
||||
const auto* file = mockOutput.GetMockedFile("ui_mp/test_menu.menu");
|
||||
REQUIRE(file);
|
||||
|
||||
const auto output = file->AsString();
|
||||
constexpr auto expectedOutput = R"({
|
||||
menuDef
|
||||
{
|
||||
name "test_menu"
|
||||
rect 1 2 3 4 0 0
|
||||
itemDef
|
||||
{
|
||||
rect 1 2 3 4 0 0
|
||||
exp text (localvarstring("ui_highlight"));
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
rect 1 2 3 4 0 0
|
||||
exp text (2);
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
rect 1 2 3 4 0 0
|
||||
exp text (3 + 7);
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
rect 1 2 3 4 0 0
|
||||
exp text (-3 + 7 * !sin(cos(7)));
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
REQUIRE(output == expectedOutput);
|
||||
}
|
||||
|
||||
TEST_CASE("MenuDumperT4: Can dump T4-specific menu properties", "[t4][menu][assetdumper]")
|
||||
{
|
||||
std::array visibleValues{
|
||||
Operator(OP_PARTYISMISSINGMAPPACK),
|
||||
Operator(OP_RIGHTPAREN),
|
||||
};
|
||||
auto visibleEntries = EntryPointers(visibleValues);
|
||||
|
||||
Material selectIcon{};
|
||||
selectIcon.info.name = "listbox_select_icon";
|
||||
|
||||
Material listboxBackground{};
|
||||
listboxBackground.info.name = "listbox_background";
|
||||
|
||||
Material highlightTexture{};
|
||||
highlightTexture.info.name = "listbox_highlight";
|
||||
|
||||
listBoxDef_s listBox{};
|
||||
listBox.onDoubleClick = "play mouse_click;";
|
||||
listBox.focusColor[0] = 1.0f;
|
||||
listBox.focusColor[1] = 0.8f;
|
||||
listBox.focusColor[2] = 0.2f;
|
||||
listBox.focusColor[3] = 1.0f;
|
||||
listBox.selectIcon = &selectIcon;
|
||||
listBox.backgroundItemListbox = &listboxBackground;
|
||||
listBox.highlightTexture = &highlightTexture;
|
||||
|
||||
itemDef_s serverList{};
|
||||
serverList.window.name = "server_list";
|
||||
serverList.window.rectClient = {.x = 20.0f, .y = 80.0f, .w = 400.0f, .h = 180.0f, .horzAlign = 1, .vertAlign = 2};
|
||||
serverList.window.foreColor[0] = 1.0f;
|
||||
serverList.window.foreColor[1] = 1.0f;
|
||||
serverList.window.foreColor[2] = 1.0f;
|
||||
serverList.window.foreColor[3] = 1.0f;
|
||||
serverList.type = ITEM_TYPE_LISTBOX;
|
||||
serverList.onListboxSelectionChange = "setdvar ui_server_selected 1;";
|
||||
serverList.typeData.listBox = &listBox;
|
||||
|
||||
itemDef_s* items[]{&serverList};
|
||||
|
||||
menuDef_t menu{};
|
||||
menu.window.name = "t4_menu";
|
||||
menu.window.rect = {.x = 0.0f, .y = 0.0f, .w = 640.0f, .h = 480.0f, .horzAlign = 0, .vertAlign = 0};
|
||||
menu.window.foreColor[0] = 1.0f;
|
||||
menu.window.foreColor[1] = 1.0f;
|
||||
menu.window.foreColor[2] = 1.0f;
|
||||
menu.window.foreColor[3] = 1.0f;
|
||||
menu.onFocus = "setdvar ui_hint t4_menu;";
|
||||
menu.visibleExp = {.numEntries = static_cast<int>(visibleEntries.size()), .entries = visibleEntries.data()};
|
||||
menu.itemCount = static_cast<int>(std::size(items));
|
||||
menu.items = items;
|
||||
|
||||
Zone zone("MockZone", 0, GameId::T4, GamePlatform::PC);
|
||||
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<menuDef_t>>(ASSET_TYPE_MENU, menu.window.name, &menu));
|
||||
|
||||
MockSearchPath mockObjPath;
|
||||
MockOutputPath mockOutput;
|
||||
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
|
||||
|
||||
menu::MenuDumperT4 dumper;
|
||||
dumper.Dump(context);
|
||||
|
||||
const auto* file = mockOutput.GetMockedFile("ui_mp/t4_menu.menu");
|
||||
REQUIRE(file);
|
||||
|
||||
constexpr auto expectedOutput = R"({
|
||||
menuDef
|
||||
{
|
||||
name "t4_menu"
|
||||
rect 0 0 640 480 0 0
|
||||
visible when(partyismissingmappack());
|
||||
onFocus
|
||||
{
|
||||
setdvar ui_hint t4_menu;
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
name "server_list"
|
||||
rect 20 80 400 180 1 2
|
||||
type 6
|
||||
doubleclick
|
||||
{
|
||||
play mouse_click;
|
||||
}
|
||||
onListboxSelectionChange
|
||||
{
|
||||
setdvar ui_server_selected 1;
|
||||
}
|
||||
focusColor 1 0.8 0.2 1
|
||||
selectIcon "listbox_select_icon"
|
||||
backgroundItemListbox "listbox_background"
|
||||
highlightTexture "listbox_highlight"
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
REQUIRE(file->AsString() == expectedOutput);
|
||||
}
|
||||
} // namespace
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "Game/T4/Menu/MenuListDumperT4.h"
|
||||
|
||||
#include "SearchPath/MockOutputPath.h"
|
||||
#include "SearchPath/MockSearchPath.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
|
||||
using namespace T4;
|
||||
|
||||
namespace
|
||||
{
|
||||
TEST_CASE("MenuListDumperT4: Can dump several menu entries", "[t4][menu][menulist][assetdumper]")
|
||||
{
|
||||
menuDef_t mainMenu{};
|
||||
mainMenu.window.name = "main";
|
||||
|
||||
menuDef_t optionsMenu{};
|
||||
optionsMenu.window.name = "options";
|
||||
|
||||
menuDef_t confirmationMenu{};
|
||||
confirmationMenu.window.name = ",confirmation";
|
||||
|
||||
menuDef_t* menus[]{&mainMenu, &optionsMenu, &confirmationMenu};
|
||||
|
||||
MenuList menuList{};
|
||||
menuList.name = "ui_mp/menus.txt";
|
||||
menuList.menuCount = static_cast<int>(std::size(menus));
|
||||
menuList.menus = menus;
|
||||
|
||||
Zone zone("MockZone", 0, GameId::T4, GamePlatform::PC);
|
||||
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<MenuList>>(ASSET_TYPE_MENULIST, menuList.name, &menuList));
|
||||
|
||||
MockSearchPath mockObjPath;
|
||||
MockOutputPath mockOutput;
|
||||
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
|
||||
|
||||
menu::MenuListDumperT4 dumper;
|
||||
dumper.Dump(context);
|
||||
|
||||
const auto* file = mockOutput.GetMockedFile("ui_mp/menus.txt");
|
||||
REQUIRE(file);
|
||||
|
||||
constexpr auto expectedOutput = R"({
|
||||
loadMenu { "ui_mp/main.menu" }
|
||||
loadMenu { "ui_mp/options.menu" }
|
||||
loadMenu { "ui_mp/confirmation.menu" }
|
||||
}
|
||||
)";
|
||||
REQUIRE(file->AsString() == expectedOutput);
|
||||
}
|
||||
} // namespace
|
||||
@@ -0,0 +1,3 @@
|
||||
>game,T4
|
||||
|
||||
menulist,ui_mp/menus.txt
|
||||
@@ -0,0 +1,46 @@
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
name "main"
|
||||
fullscreen 1
|
||||
rect 0 0 640 480 0 0
|
||||
disablecolor 0.2 0.3 0.4 0.5
|
||||
forecolor 0.8 0.7 0.6 0.5
|
||||
visible when(dvarbool("ui_show_main"));
|
||||
onOpen
|
||||
{
|
||||
play menu_open;
|
||||
setLocalVarInt ui_highlight 5;
|
||||
}
|
||||
onFocus
|
||||
{
|
||||
setdvar ui_menu_focused 1;
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
name "empty_text"
|
||||
text ""
|
||||
rect 10 20 180 24 1 2
|
||||
type 1
|
||||
visible 1
|
||||
forecolor 0.9 0.9 1 0.07
|
||||
dvar "ui_fallback_text"
|
||||
action
|
||||
{
|
||||
setItemColor empty_text borderColor 0.1 0.1 0.12 0.5;
|
||||
}
|
||||
exp material localvarstring("ui_material");
|
||||
}
|
||||
itemDef
|
||||
{
|
||||
name "server_list"
|
||||
rect 20 60 300 200 0 0
|
||||
type 6
|
||||
focusColor 0.1 0.2 0.3 0.4
|
||||
onListboxSelectionChange
|
||||
{
|
||||
setdvar ui_server_selected 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
loadMenu { "ui_mp/main.menu" }
|
||||
loadMenu { "ui_mp/popup.menu" }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
name "popup"
|
||||
rect 40 40 200 100 0 0
|
||||
popup
|
||||
visible when(partyismissingmappack());
|
||||
onESC
|
||||
{
|
||||
close self;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "Game/T4/Menu/MenuDumperT4.h"
|
||||
#include "Game/T4/Menu/MenuListDumperT4.h"
|
||||
#include "Game/T4/T4.h"
|
||||
#include "Linker.h"
|
||||
#include "OatTestPaths.h"
|
||||
#include "SearchPath/MockOutputPath.h"
|
||||
#include "SearchPath/MockSearchPath.h"
|
||||
#include "SystemTestsPaths.h"
|
||||
#include "ZoneLoading.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using namespace T4;
|
||||
using namespace std::literals;
|
||||
|
||||
namespace
|
||||
{
|
||||
TEST_CASE("Menu loading and dumping (T4)", "[t4][menu][system]")
|
||||
{
|
||||
const auto testDataPath = oat::paths::GetSystemTestsDirectory() / "Game/T4/MenuRoundTrip";
|
||||
const auto testDataPathString = testDataPath.string();
|
||||
const auto outputPath = oat::paths::GetTempDirectory("MenuRoundTripT4");
|
||||
const auto outputPathString = outputPath.string();
|
||||
|
||||
const char* arguments[]{
|
||||
"SystemTests",
|
||||
"--verbose",
|
||||
"--base-folder",
|
||||
outputPathString.c_str(),
|
||||
"--asset-search-path",
|
||||
testDataPathString.c_str(),
|
||||
"--source-search-path",
|
||||
testDataPathString.c_str(),
|
||||
"--output-folder",
|
||||
outputPathString.c_str(),
|
||||
"MenuRoundTripT4",
|
||||
};
|
||||
|
||||
LinkerArgs linkerArgs;
|
||||
auto shouldContinue = true;
|
||||
REQUIRE(linkerArgs.ParseArgs(std::size(arguments), arguments, shouldContinue));
|
||||
REQUIRE(shouldContinue);
|
||||
|
||||
const auto linker = Linker::Create(std::move(linkerArgs));
|
||||
REQUIRE(linker->Start());
|
||||
|
||||
const auto zonePath = outputPath / "MenuRoundTripT4.ff";
|
||||
auto maybeZone = ZoneLoading::LoadZone(zonePath.string(), std::nullopt);
|
||||
REQUIRE(maybeZone);
|
||||
auto zone = std::move(*maybeZone);
|
||||
|
||||
const auto* menuList = zone->m_pools.GetAsset<AssetMenuList>("ui_mp/menus.txt");
|
||||
const auto* mainMenu = zone->m_pools.GetAsset<AssetMenu>("main");
|
||||
const auto* popupMenu = zone->m_pools.GetAsset<AssetMenu>("popup");
|
||||
REQUIRE(menuList);
|
||||
REQUIRE(mainMenu);
|
||||
REQUIRE(popupMenu);
|
||||
REQUIRE(menuList->Asset()->menuCount == 2);
|
||||
REQUIRE(mainMenu->Asset()->visibleExp.numEntries == 3);
|
||||
REQUIRE(mainMenu->Asset()->window.dynamicFlags[0] & WINDOW_FLAG_NON_DEFAULT_FORECOLOR);
|
||||
REQUIRE(mainMenu->Asset()->onFocus == R"("setdvar" "ui_menu_focused" "1" ; )"s);
|
||||
REQUIRE(mainMenu->Asset()->items[0]->text != nullptr);
|
||||
REQUIRE(mainMenu->Asset()->items[0]->text == ""s);
|
||||
REQUIRE(mainMenu->Asset()->items[0]->window.dynamicFlags[0] & WINDOW_FLAG_NON_DEFAULT_FORECOLOR);
|
||||
REQUIRE(mainMenu->Asset()->items[0]->action == R"("setItemColor" "empty_text" "borderColor" "0.1" "0.1" "0.12" "0.5" ; )"s);
|
||||
REQUIRE(mainMenu->Asset()->items[1]->onListboxSelectionChange == R"("setdvar" "ui_server_selected" "1" ; )"s);
|
||||
REQUIRE(mainMenu->Asset()->items[1]->typeData.listBox->focusColor[2] == 0.3f);
|
||||
REQUIRE(popupMenu->Asset()->visibleExp.entries[0]->data.op == OP_PARTYISMISSINGMAPPACK);
|
||||
|
||||
MockSearchPath objPath;
|
||||
MockOutputPath dumpOutput;
|
||||
AssetDumpingContext dumpingContext(*zone, "", dumpOutput, objPath, std::nullopt);
|
||||
menu::MenuListDumperT4 menuListDumper;
|
||||
menuListDumper.Dump(dumpingContext);
|
||||
menu::MenuDumperT4 menuDumper;
|
||||
menuDumper.Dump(dumpingContext);
|
||||
|
||||
const auto* dumpedMenuList = dumpOutput.GetMockedFile("ui_mp/menus.txt");
|
||||
const auto* dumpedMainMenu = dumpOutput.GetMockedFile("ui_mp/main.menu");
|
||||
const auto* dumpedPopupMenu = dumpOutput.GetMockedFile("ui_mp/popup.menu");
|
||||
REQUIRE(dumpedMenuList);
|
||||
REQUIRE(dumpedMainMenu);
|
||||
REQUIRE(dumpedPopupMenu);
|
||||
REQUIRE(dumpedMenuList->AsString().find("loadMenu { \"ui_mp/main.menu\" }") != std::string::npos);
|
||||
REQUIRE(dumpedMenuList->AsString().find("loadMenu { \"ui_mp/popup.menu\" }") != std::string::npos);
|
||||
REQUIRE(dumpedMainMenu->AsString().find("text \"\"") != std::string::npos);
|
||||
REQUIRE(dumpedMainMenu->AsString().find("visible when(dvarbool(\"ui_show_main\"));") != std::string::npos);
|
||||
REQUIRE(dumpedMainMenu->AsString().find("setItemColor empty_text borderColor 0.1 0.1 0.12 0.5;") != std::string::npos);
|
||||
REQUIRE(dumpedMainMenu->AsString().find("onListboxSelectionChange") != std::string::npos);
|
||||
REQUIRE(dumpedMainMenu->AsString().find("focusColor 0.1 0.2 0.3 0.4") != std::string::npos);
|
||||
REQUIRE(dumpedPopupMenu->AsString().find("partyismissingmappack()") != std::string::npos);
|
||||
}
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user