GigaPasjans
Loading...
Searching...
No Matches
BooleanComponent.h
1// Plik utworzony przez Piotra ChudziƄskiego w dniu 11.04.2025
2#pragma once
3#include <game/InteractionManager.h>
4#include <game/Solitaire.h>
5#include <phosphorus/Languages.h>
6#include "../SettingComponent.h"
7
8namespace Game
9{
10 using namespace Andromenda;
11
12#define REGISTER_EASY_STATE(keycode, text, state) \
13 registry.Register(keycode, text, \
14 [param, this] \
15 { \
16 param->SetValue(state); \
17 Phosphorus::GetGameAs<Game::Solitaire>()->PlayOneShot("game_enter.wav"); \
18 \
19 markAsDirty(); \
20 });
21
26 class BooleanComponent : public SettingComponent
27 {
28 private:
30 Int2 getSize() override { return Int2{GetText().GetLength(), 1}; }
31
32 public:
33 explicit BooleanComponent(Phosphorus::BoolParameter *parameter) : SettingComponent(parameter) {}
34
40 {
41 Phosphorus::BoolParameter *param = As<Phosphorus::BoolParameter>();
42 return FORMAT("{}: {}", RedactSettingName(),
43 param->GetValue() ? _T("settings.true") : _T("settings.false"));
44 }
45
47 void ProvideActions(ActionRegistry &registry) override
48 {
49 Phosphorus::BoolParameter *param = As<Phosphorus::BoolParameter>();
50 registry.Register(Keycode::Enter, _TW("settings.switch"),
51 [param, this]
52 {
53 param->SetValue(!param->GetValue());
54 Phosphorus::GetGameAs<Game::Solitaire>()->PlayOneShot("game_enter.wav");
55
57 });
58
59 REGISTER_EASY_STATE(Keycode::T, _TW("settings.set_true"), true);
60 REGISTER_EASY_STATE(Keycode::N, _TW("settings.set_false"), false);
61 }
62
64 void Draw(DrawContext &context) override
65 {
66 context.StyleStack.Push(TerminalStyle{Color::White, m_IsActive ? Color::Green : Color::Black});
67 context.Put(GetText(), GetBounds().GetPosition());
68 context.StyleStack.Pop();
69 }
70 };
71} // namespace Game
Represent registry of Action objects.
Definition ActionRegistry.h:74
void Register(const Keycode &keycode, const WideString &actionText, const Callback &callback, MouseButton button=MouseButton::None)
Registers given text and callback to given key.
Definition ActionRegistry.cpp:18
bool m_IsActive
A value indicating, whether object is being pointed by pointer.
Definition Component.h:32
Box GetBounds()
Returns Component bounds. Position is already aligned.
Definition Components.cpp:27
void markAsDirty()
Sets m_Dirty to true.
Definition Components.cpp:32
void Pop()
Pops style at the top.
Definition TerminalBase.cpp:45
void Push(const TerminalStyle &style)
Pushes given style to the top.
Definition TerminalBase.cpp:43
String GetText()
Returns text that should be drawed on screen.
Definition BooleanComponent.h:39
void ProvideActions(ActionRegistry &registry) override
Provides own actions to the ActionRegistry.
Definition BooleanComponent.h:47
void Draw(DrawContext &context) override
Draws self.
Definition BooleanComponent.h:64
T * As()
Returns casted parameter to T.
Definition SettingComponent.h:50
Represents a mutable sequence of characters, providing various member functions for string manipulati...
Definition String.h:16
A utility which contains all essential class instances and functions for rendering objects.
Definition DrawContext.h:14
void Put(const String &text, Int2 position)
Puts a UTF-8 text at given position and with given text.
Definition DrawContext.cpp:7
StyleStack StyleStack
Style stack.
Definition DrawContext.h:31
Represents terminal text style, described by background and foreground color.
Definition Terminal.h:20
Represents a two component vector. Components are 32-bit and they are signed.
Definition Int2.h:11