GigaPasjans
Loading...
Searching...
No Matches
FragmentComponent.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 FragmentComponent : public Andromenda::Component
17 {
18 private:
20 Int2 getSize() override { return CardConstants::CardSize; }
21
22 public:
28
29 explicit FragmentComponent(CardStack *stack) : Stack(stack) {}
30
32 bool IsSelectable() const override { return true; }
33
36 {
38 return;
39
41 registry.Register(
42 Keycode::D, _TW("card.drop.plural"),
44 MouseButton::Right);
45
47 registry.Register(
48 Keycode::D, _TW("card.drop"),
49 [this] { InteractionManager::MoveCard(CardInteraction::Grabbed, Stack); }, MouseButton::Right);
50 }
51
53 void Draw(Andromenda::DrawContext &context) override
54 {
55 Int2 size = {GetBounds().Width, GetBounds().Height};
56
57 context.StyleStack.Push({Color::Black, Color::Black});
58 context.Fill({m_Position, size});
59 context.StyleStack.Pop();
60
61 context.StyleStack.Push({m_IsActive ? Color::Green : Color::White, Color::Black});
62 context.Border({m_Position, size});
63 context.StyleStack.Pop();
64
65 Andromenda::ScopeStyle scope({Color::Purple, Color::Black}, context.StyleStack);
66
67 context.Put(L"F", m_Position + Int2{2, 1}, true);
68
69 int xOffset = 3;
70 context.Put(L"F", m_Position + Int2{size.X - xOffset, size.Y - 2}, true);
71 context.Put(L"F", m_Position + Int2{size.X - 3, 1}, true);
72 context.Put(L"F", m_Position + Int2{2, size.Y - 2}, true);
73 context.Put(L"F", m_Position + size / 2, true);
74 }
75 };
76} // 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 stack of cards in the game.
Definition Deck.h:14
void ProvideActions(Andromenda::ActionRegistry &registry) override
Provides own actions to the ActionRegistry.
Definition FragmentComponent.h:35
bool IsSelectable() const override
Returns value indicating, whether component is selectable.
Definition FragmentComponent.h:32
void Draw(Andromenda::DrawContext &context) override
Draws self.
Definition FragmentComponent.h:53
CardStack * Stack
Stack where to render.
Definition FragmentComponent.h:27
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
static void MoveCards(const std::vector< Card * > &cards, CardStack *targetStack)
Moves a group of cards to the given target stack.
Definition InteractionManager.cpp:213
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