GigaPasjans
Loading...
Searching...
No Matches
FoundationComponent.h
1// Plik utworzony przez Piotra ChudziƄskiego w dniu 13.04.2025
2#pragma once
3
4#include <andromenda/Component.h>
5#include <phosphorus/Languages.h>
6#include "Card.h"
7#include "CardConstants.h"
8#include "Deck.h"
9#include "game/InteractionManager.h"
10
11namespace Game
12{
16 class FoundationComponent : public Andromenda::Component
17 {
18 private:
20 Int2 getSize() override { return CardConstants::CardSize; }
21
22 public:
28
29 explicit FoundationComponent(CardStack *stack) : Stack(stack) {}
30
32 bool IsSelectable() const override { return true; }
33
36 {
38 return;
39
40 if (Stack->GetSize() > 0)
41 registry.Register(
42 Keycode::Q, _TW("card.grab"), [this] { CardInteraction::Grabbed = Stack->Top(); },
43 MouseButton::Middle);
44
46 registry.Register(
47 Keycode::D, _TW("card.drop"),
48 [this] { InteractionManager::MoveCard(CardInteraction::Grabbed, Stack); }, MouseButton::Right);
50 registry.Register(Keycode::D, _TW("card.no_drop_foundation.plural"), [this] {});
51 }
52
54 void Draw(Andromenda::DrawContext &context) override
55 {
56 const Card *card = Stack->Top();
57 Int2 size = {GetBounds().Width, GetBounds().Height};
58
59 context.StyleStack.Push({Color::Black, Color::Black});
60 context.Fill({m_Position, size});
61 context.StyleStack.Pop();
62
63 context.StyleStack.Push({m_IsActive || (Stack->GetSize() != 0 && Stack->Top() == CardInteraction::Grabbed)
64 ? Color::Green
65 : Color::White,
66 Color::Black});
67 context.Border({m_Position, size});
68 context.StyleStack.Pop();
69
70 if (!card)
71 return;
72
73 Andromenda::ScopeStyle scope({card->GetTint(), Color::Black}, context.StyleStack);
74
75 WideString numberString;
76 if (card->Type.GetEnum() == CardType::N10)
77 numberString = L"10";
78 else
79 numberString = WideString(card->Type.GetValue());
80
81 wchar_t colorChar = card->Color.GetValue();
82
83 context.Put(numberString, m_Position + Int2{2, 1}, true);
84
85 int xOffset = (card->Type.GetEnum() == CardType::N10) ? 4 : 3;
86 context.Put(numberString, m_Position + Int2{size.X - xOffset, size.Y - 2}, true);
87 context.Put(WideString(colorChar), m_Position + Int2{size.X - 3, 1}, true);
88 context.Put(WideString(colorChar), m_Position + Int2{2, size.Y - 2}, true);
89 context.Put(WideString(colorChar), m_Position + size / 2, true);
90 }
91 };
92} // 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
Represents a renderable identified object.
Definition Component.h:23
bool m_IsActive
A value indicating, whether object is being pointed by pointer.
Definition Component.h:32
Int2 m_Position
Component position.
Definition Component.h:61
Box GetBounds()
Returns Component bounds. Position is already aligned.
Definition Components.cpp:27
Applies given style to the stack when constructed and pops when destroyed.
Definition Terminal.h:185
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
Represents a playing card in a game. This class defines a card with properties such as color,...
Definition Card.h:61
enum Color GetTint() const
Gets the tint color of the card.
Definition Card.cpp:63
Phosphorus::EnumParameter< CardType > Type
The card's type.
Definition Card.h:96
Phosphorus::EnumParameter< CardColor > Color
The card's color.
Definition Card.h:91
Represents a stack of cards in the game.
Definition Deck.h:14
CardStack * Stack
Stack to render.
Definition FoundationComponent.h:27
void Draw(Andromenda::DrawContext &context) override
Draws self.
Definition FoundationComponent.h:54
bool IsSelectable() const override
Returns value indicating, whether component is selectable.
Definition FoundationComponent.h:32
void ProvideActions(Andromenda::ActionRegistry &registry) override
Provides own actions to the ActionRegistry.
Definition FoundationComponent.h:35
static bool ProvideActions(Andromenda::ActionRegistry &registry)
Registers actions in the provided action registry.
Definition InteractionManager.cpp:286
static void MoveCard(Card *card, CardStack *targetStack, bool authorizedMove=false)
Moves a single card to the given target stack.
Definition InteractionManager.cpp:197
T GetEnum() const
Casts integer to enum and returns.
Definition GameObject.h:242
T GetValue() const
Returns value.
Definition GameObject.h:134
static FORCE_INLINE R Size(const std::vector< T > &vector)
Returns size of given list.
Definition Collections.h:107
Represents a mutable sequence of utf-16 characters, providing various member functions for string man...
Definition WideString.h:14
A utility which contains all essential class instances and functions for rendering objects.
Definition DrawContext.h:14
void Border(const Box &box)
Draws an rounded border at given position.
Definition DrawContext.cpp:58
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
void Fill(const Box &box)
Draws an rectangle at given position.
Definition DrawContext.cpp:43
static std::vector< Card * > GrabbedCards
Cards currently being moved (global state).
Definition InteractionManager.h:184
static Card * Grabbed
Currently selected card (global state).
Definition InteractionManager.h:242
Represents a two component vector. Components are 32-bit and they are signed.
Definition Int2.h:11