Add menu scopes to state before closing them

This commit is contained in:
Jan 2021-11-06 17:47:18 +01:00
parent bf19208351
commit 5af2e6da61
8 changed files with 50 additions and 18 deletions

View File

@ -5,6 +5,7 @@
#include "CommonItemDef.h"
#include "CommonMenuTypes.h"
#include "EventHandler/CommonEventHandlerSet.h"
#include "Expression/ICommonExpression.h"
namespace menu
@ -38,6 +39,11 @@ namespace menu
std::unique_ptr<ICommonExpression> m_rect_h_exp;
std::unique_ptr<ICommonExpression> m_open_sound_exp;
std::unique_ptr<ICommonExpression> m_close_sound_exp;
std::unique_ptr<CommonEventHandlerSet> m_on_open;
std::unique_ptr<CommonEventHandlerSet> m_on_close;
std::unique_ptr<CommonEventHandlerSet> m_on_request_close;
std::unique_ptr<CommonEventHandlerSet> m_on_esc;
std::map<int, std::unique_ptr<CommonEventHandlerSet>> m_key_handler;
bool m_full_screen;
bool m_screen_space;

View File

@ -10,6 +10,10 @@ MenuFileParserState::EventHandlerConditionState::EventHandlerConditionState(std:
MenuFileParserState::MenuFileParserState(const FeatureLevel featureLevel)
: m_feature_level(featureLevel),
m_in_global_scope(false)
m_in_global_scope(false),
m_current_function(nullptr),
m_current_menu(nullptr),
m_current_item(nullptr),
m_current_event_handler_set(nullptr)
{
}

View File

@ -1,6 +1,5 @@
#pragma once
#include <functional>
#include <map>
#include <memory>
#include <vector>
@ -36,12 +35,11 @@ namespace menu
std::map<std::string, CommonMenuDef*> m_menus_by_name;
bool m_in_global_scope;
std::unique_ptr<CommonFunctionDef> m_current_function;
std::unique_ptr<CommonMenuDef> m_current_menu;
std::unique_ptr<CommonItemDef> m_current_item;
std::unique_ptr<CommonEventHandlerSet> m_current_event_handler_set;
CommonFunctionDef* m_current_function;
CommonMenuDef* m_current_menu;
CommonItemDef* m_current_item;
CommonEventHandlerSet* m_current_event_handler_set;
std::function<void(MenuFileParserState* state, std::unique_ptr<CommonEventHandlerSet> value)> m_event_handler_set_callback;
std::ostringstream m_current_script;
std::stack<EventHandlerConditionState> m_current_condition;

View File

@ -29,8 +29,7 @@ namespace menu::function_scope_sequences
const auto existingFunction = state->m_functions_by_name.find(state->m_current_function->m_name);
if (existingFunction == state->m_functions_by_name.end())
{
state->m_functions_by_name.emplace(std::make_pair(state->m_current_function->m_name, state->m_current_function.get()));
state->m_functions.emplace_back(std::move(state->m_current_function));
state->m_functions_by_name.emplace(std::make_pair(state->m_current_function->m_name, state->m_current_function));
state->m_current_function = nullptr;
}
else

View File

@ -19,6 +19,10 @@ GenericMenuEventHandlerSetPropertySequence::GenericMenuEventHandlerSetPropertySe
void GenericMenuEventHandlerSetPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
{
state->m_current_event_handler_set = std::make_unique<CommonEventHandlerSet>();
state->m_event_handler_set_callback = m_set_callback;
if (m_set_callback)
{
auto newEventHandlerSet = std::make_unique<CommonEventHandlerSet>();
state->m_current_event_handler_set = newEventHandlerSet.get();
m_set_callback(state, std::move(newEventHandlerSet));
}
}

View File

@ -42,7 +42,9 @@ namespace menu::global_scope_sequences
protected:
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
{
state->m_current_function = std::make_unique<CommonFunctionDef>();
auto newFunction = std::make_unique<CommonFunctionDef>();
state->m_current_function = newFunction.get();
state->m_functions.emplace_back(std::move(newFunction));
}
};
@ -62,7 +64,9 @@ namespace menu::global_scope_sequences
protected:
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
{
state->m_current_menu = std::make_unique<CommonMenuDef>();
auto newMenu = std::make_unique<CommonMenuDef>();
state->m_current_menu = newMenu.get();
state->m_menus.emplace_back(std::move(newMenu));
}
};

View File

@ -29,7 +29,6 @@ namespace menu::item_scope_sequences
protected:
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
{
state->m_current_menu->m_items.emplace_back(std::move(state->m_current_item));
state->m_current_item = nullptr;
}
};

View File

@ -8,6 +8,7 @@
#include "Generic/GenericFloatingPointPropertySequence.h"
#include "Generic/GenericIntPropertySequence.h"
#include "Generic/GenericKeywordPropertySequence.h"
#include "Generic/GenericMenuEventHandlerSetPropertySequence.h"
#include "Generic/GenericStringPropertySequence.h"
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
#include "Parsing/Menu/Domain/CommonMenuTypes.h"
@ -40,8 +41,7 @@ namespace menu::menu_scope_sequences
const auto existingMenu = state->m_menus_by_name.find(state->m_current_menu->m_name);
if (existingMenu == state->m_menus_by_name.end())
{
state->m_menus_by_name.emplace(std::make_pair(state->m_current_menu->m_name, state->m_current_menu.get()));
state->m_menus.emplace_back(std::move(state->m_current_menu));
state->m_menus_by_name.emplace(std::make_pair(state->m_current_menu->m_name, state->m_current_menu));
state->m_current_menu = nullptr;
}
else
@ -71,7 +71,9 @@ namespace menu::menu_scope_sequences
protected:
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
{
state->m_current_item = std::make_unique<CommonItemDef>();
auto newItemDef = std::make_unique<CommonItemDef>();
state->m_current_item = newItemDef.get();
state->m_current_menu->m_items.emplace_back(std::move(newItemDef));
}
};
@ -271,4 +273,20 @@ void MenuScopeSequences::AddSequences(FeatureLevel featureLevel)
{
state->m_current_menu->m_rect_h_exp = std::move(value);
}));
AddSequence(std::make_unique<GenericMenuEventHandlerSetPropertySequence>("onOpen", [](const MenuFileParserState* state, std::unique_ptr<CommonEventHandlerSet> value)
{
state->m_current_menu->m_on_open = std::move(value);
}));
AddSequence(std::make_unique<GenericMenuEventHandlerSetPropertySequence>("onClose", [](const MenuFileParserState* state, std::unique_ptr<CommonEventHandlerSet> value)
{
state->m_current_menu->m_on_close = std::move(value);
}));
AddSequence(std::make_unique<GenericMenuEventHandlerSetPropertySequence>("onRequestClose", [](const MenuFileParserState* state, std::unique_ptr<CommonEventHandlerSet> value)
{
state->m_current_menu->m_on_request_close = std::move(value);
}));
AddSequence(std::make_unique<GenericMenuEventHandlerSetPropertySequence>("onESC", [](const MenuFileParserState* state, std::unique_ptr<CommonEventHandlerSet> value)
{
state->m_current_menu->m_on_esc = std::move(value);
}));
}