GigaPasjans
Loading...
Searching...
No Matches
EnumComponent.h
1// Plik utworzony przez Piotra Chudzińskiego w dniu 11.04.2025
2#pragma once
3#include <game/Solitaire.h>
4
5
6#include "../SettingComponent.h"
7
8namespace Game
9{
10 using namespace Andromenda;
11
16 class EnumComponent : public SettingComponent
17 {
18 private:
20 Int2 getSize() override { return Int2{GetText().GetLength(), 1}; }
21
26 int32 m_CurrentIndex = 0;
27
28 public:
29 explicit EnumComponent(Phosphorus::BaseEnumParameter *parameter) : SettingComponent(parameter) {}
30
36 {
38 return FORMAT(L"{}: {}", std::wstring(RedactSettingName().Get()),
39 param->GetBinding(param->GetValue()).Get());
40 }
41
43 void ProvideActions(ActionRegistry &registry) override
44 {
46 registry.Register(
47 Keycode::Enter, L"Przełącz",
48 [param, this]
49 {
50 param->SetValue(m_CurrentIndex + 1 >= param->GetBindingCount() ? m_CurrentIndex = 0
51 : ++m_CurrentIndex);
52 Phosphorus::GetGameAs<Game::Solitaire>()->PlayOneShot("game_enter.wav");
54 },
55 MouseButton::Left);
56 }
57
59 void Draw(DrawContext &context) override
60 {
61 context.StyleStack.Push(TerminalStyle{Color::White, m_IsActive ? Color::Green : Color::Black});
62 context.Put(GetText(), GetBounds().GetPosition());
63 context.StyleStack.Pop();
64 }
65 };
66} // 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
void Draw(DrawContext &context) override
Draws self.
Definition EnumComponent.h:59
WideString GetText()
Returns text that should be drawed on screen.
Definition EnumComponent.h:35
void ProvideActions(ActionRegistry &registry) override
Provides own actions to the ActionRegistry.
Definition EnumComponent.h:43
T * As()
Returns casted parameter to T.
Definition SettingComponent.h:50
Enum based parameter. Stored as 32bit signed integer.
Definition GameObject.h:168
int32 GetBindingCount() const
Returns binding count.
Definition GameObject.h:206
WideString GetBinding(int32 index) const
Returns bound name for enum value.
Definition GameObject.h:199
T GetValue() const
Returns value.
Definition GameObject.h:134
void SetValue(const T &value)
Sets value.
Definition GameObject.h:127
Represents a mutable sequence of utf-16 characters, providing various member functions for string man...
Definition WideString.h:14
wchar_t * Get() const
Gets a raw char sequence.
Definition WideString.h:177
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