3 #include <BLIB/Engine.hpp>
4 #include <BLIB/Logging.hpp>
5 #include <BLIB/Util/FileUtil.hpp>
23 :
State(systems,
bl::engine::StateMask::Menu)
31 if (!backgroundTxtr) {
33 using bl::menu::TextItem;
36 engine.renderer().getObserver(),
37 bl::menu::ArrowSelector::create(14.f, sf::Color::Black));
38 backgroundTxtr = engine.renderer().texturePool().getOrLoadTexture(
40 background.create(engine, backgroundTxtr);
42 newGame = TextItem::create(
44 newGame->getSignal(Item::Activated).willCall([
this]() {
45 BL_LOG_INFO <<
"New Game selected";
49 loadGame = TextItem::create(
51 loadGame->getSignal(Item::Activated).willCall([
this]() {
52 BL_LOG_INFO <<
"Load Game selected";
56 settings = TextItem::create(
58 settings->getSignal(Item::Activated).willCall([
this]() {
59 BL_LOG_INFO <<
"Settings selected";
63 quit = TextItem::create(
65 quit->getSignal(Item::Activated).willCall([
this]() {
66 BL_LOG_INFO <<
"Quit selected";
67 this->
systems.
engine().flags().set(bl::engine::Flags::PopState);
70 menu.setRootItem(newGame);
71 menu.addItem(loadGame, newGame.get(), Item::Bottom);
72 menu.addItem(settings, loadGame.get(), Item::Bottom);
73 menu.addItem(quit, settings.get(), Item::Bottom);
74 menu.setMinHeight(38.f);
75 menu.setSelectedItem(newGame.get());
81 const glm::vec2 HintPadding{4.f, 4.f};
83 const sf::Color controlColor(3, 146, 168);
90 hint.addSection(
"\nMove up:", 16, sf::Color::Black);
91 hint.addSection(a.getKBMTriggerControl(
Control::MoveUp).toString(), 16, controlColor);
92 hint.addSection(
"\nMove right:", 16, sf::Color::Black);
93 hint.addSection(a.getKBMTriggerControl(
Control::MoveRight).toString(), 16, controlColor);
94 hint.addSection(
"\nMove down:", 16, sf::Color::Black);
95 hint.addSection(a.getKBMTriggerControl(
Control::MoveDown).toString(), 16, controlColor);
96 hint.addSection(
"\nMove left:", 16, sf::Color::Black);
97 hint.addSection(a.getKBMTriggerControl(
Control::MoveLeft).toString(), 16, controlColor);
98 hint.addSection(
"\nSprint:", 16, sf::Color::Black);
99 hint.addSection(a.getKBMTriggerControl(
Control::Sprint).toString(), 16, controlColor);
100 hint.addSection(
"\nInteract:", 16, sf::Color::Black);
101 hint.addSection(a.getKBMTriggerControl(
Control::Interact).toString(), 16, controlColor);
102 hint.addSection(
"\nBack:", 16, sf::Color::Black);
103 hint.addSection(a.getKBMTriggerControl(
Control::Back).toString(), 16, controlColor);
104 hint.addSection(
"\nPause:", 16, sf::Color::Black);
105 hint.addSection(a.getKBMTriggerControl(
Control::Pause).toString(), 16, controlColor);
107 hint.getTransform().setPosition(HintPadding);
108 const sf::FloatRect hintBounds = hint.getLocalBounds();
109 const glm::vec2 hintSize(hintBounds.width + hintBounds.left,
110 hintBounds.height + hintBounds.top);
112 hintBox.create(engine, hintSize + HintPadding * 2.f);
113 hintBox.getOverlayScaler().positionInParentSpace({0.15f, 0.63f});
114 hintBox.setFillColor(sf::Color(252, 248, 212));
115 hintBox.setOutlineColor(sf::Color::Black);
116 hintBox.setOutlineThickness(2.f);
117 hint.setParent(hintBox);
118 hintBox.setParent(background);
121 inputDriver.drive(&menu);
122 systems.
engine().inputSystem().getActor().addListener(*
this);
124 hintBox.setHidden(
true);
126 auto overlay = engine.renderer().getObserver().pushScene<bl::rc::Overlay>();
127 background.addToScene(overlay, bl::rc::UpdateSpeed::Static);
128 hintBox.addToScene(overlay, bl::rc::UpdateSpeed::Static);
129 hint.addToScene(overlay, bl::rc::UpdateSpeed::Static);
130 menu.addToOverlay(background.entity());
134 engine.renderer().getObserver().popScene();
135 systems.
engine().inputSystem().getActor().removeListener(*
this);
140 if (hintTimer >= 5.f) { hintBox.setHidden(
false); }
143 bool MainMenu::observe(
const bl::input::Actor&,
unsigned int activatedControl,
144 bl::input::DispatchType,
bool eventTriggered) {
145 inputDriver.sendControl(activatedControl, eventTriggered);
147 hintBox.setHidden(
true);
Peoplemon specific input functionality around the BLIB input system.
Parent namespace for all functionality unique to the game.
static const sf::VulkanFont & MenuFont()
static const std::string & MenuImagePath()
static sf::Vector2f WindowSize()
Owns all primary systems and a reference to the engine.
const bl::engine::Engine & engine() const
Const accessor for the Engine.
static bl::engine::State::Ptr create(core::system::Systems &systems)
Creates the load game state.
Provides the main menu as an engine state.
virtual void deactivate(bl::engine::Engine &engine) override
Unsubscribes the menu to the engine event bus.
virtual void update(bl::engine::Engine &, float dt, float) override
Does nothing.
virtual const char * name() const override
Returns "MainMenu";.
static bl::engine::State::Ptr create(core::system::Systems &systems)
Creates a new MainMenu state.
virtual void activate(bl::engine::Engine &engine) override
Subscribes the menu to the engine event bus.
static bl::engine::State::Ptr create(core::system::Systems &systems)
Creates the new game state.
static bl::engine::State::Ptr create(core::system::Systems &systems)
Creates the settings menu state.
Parent to all game states. Provides some commonly required data like core game systems.
core::system::Systems & systems