2022-08-20 14:09:46 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-01-04 20:41:02 -05:00
|
|
|
#include <AK/Error.h>
|
2022-09-28 12:13:00 +01:00
|
|
|
#include <LibCards/CardStack.h>
|
2022-08-20 14:09:46 +01:00
|
|
|
#include <LibConfig/Listener.h>
|
2023-01-04 20:41:02 -05:00
|
|
|
#include <LibGUI/Forward.h>
|
2022-08-20 14:09:46 +01:00
|
|
|
#include <LibGUI/Frame.h>
|
|
|
|
|
|
|
|
|
|
namespace Cards {
|
|
|
|
|
|
2023-01-04 20:41:02 -05:00
|
|
|
ErrorOr<NonnullRefPtr<GUI::Action>> make_cards_settings_action(GUI::Window* parent = nullptr);
|
|
|
|
|
|
2022-08-20 14:09:46 +01:00
|
|
|
class CardGame
|
|
|
|
|
: public GUI::Frame
|
|
|
|
|
, public Config::Listener {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~CardGame() = default;
|
|
|
|
|
|
|
|
|
|
Gfx::Color background_color() const;
|
2022-12-06 19:43:46 +00:00
|
|
|
void set_background_color(Gfx::Color);
|
2022-08-20 14:09:46 +01:00
|
|
|
|
2023-03-06 14:17:01 +01:00
|
|
|
Vector<NonnullRefPtr<CardStack>>& stacks() { return m_stacks; }
|
|
|
|
|
Vector<NonnullRefPtr<CardStack>> const& stacks() const { return m_stacks; }
|
2022-09-28 12:13:00 +01:00
|
|
|
CardStack& stack_at_location(int location) { return m_stacks[location]; }
|
2023-01-05 17:24:27 +00:00
|
|
|
|
|
|
|
|
template<class... Args>
|
|
|
|
|
ErrorOr<void> add_stack(Args&&... args)
|
|
|
|
|
{
|
|
|
|
|
auto stack = TRY(try_make_ref_counted<CardStack>(forward<Args>(args)...));
|
|
|
|
|
return m_stacks.try_append(move(stack));
|
|
|
|
|
}
|
2022-09-28 14:18:44 +01:00
|
|
|
void mark_intersecting_stacks_dirty(Card const& intersecting_card);
|
2022-09-28 12:13:00 +01:00
|
|
|
|
2022-09-28 17:05:34 +01:00
|
|
|
bool is_moving_cards() const { return !m_moving_cards.is_empty(); }
|
2023-03-06 14:17:01 +01:00
|
|
|
Vector<NonnullRefPtr<Card>>& moving_cards() { return m_moving_cards; }
|
|
|
|
|
Vector<NonnullRefPtr<Card>> const& moving_cards() const { return m_moving_cards; }
|
2022-09-28 17:05:34 +01:00
|
|
|
Gfx::IntRect moving_cards_bounds() const;
|
|
|
|
|
RefPtr<CardStack> moving_cards_source_stack() const { return m_moving_cards_source_stack; }
|
2023-01-20 13:33:30 +00:00
|
|
|
ErrorOr<void> pick_up_cards_from_stack(CardStack&, Gfx::IntPoint click_location, CardStack::MovementRule);
|
2023-02-19 23:30:58 +01:00
|
|
|
RefPtr<CardStack> find_stack_to_drop_on(CardStack::MovementRule);
|
2023-01-22 21:28:28 +00:00
|
|
|
ErrorOr<void> drop_cards_on_stack(CardStack&, CardStack::MovementRule);
|
2022-09-28 17:05:34 +01:00
|
|
|
void clear_moving_cards();
|
|
|
|
|
|
2023-01-06 08:25:38 -05:00
|
|
|
bool is_previewing_card() const { return !m_previewed_card_stack.is_null(); }
|
|
|
|
|
void preview_card(CardStack&, Gfx::IntPoint click_location);
|
|
|
|
|
void clear_card_preview();
|
|
|
|
|
|
2022-09-28 12:13:00 +01:00
|
|
|
void dump_layout() const;
|
|
|
|
|
|
2022-08-20 14:09:46 +01:00
|
|
|
protected:
|
|
|
|
|
CardGame();
|
|
|
|
|
|
|
|
|
|
private:
|
2023-06-26 21:05:53 +02:00
|
|
|
virtual void config_string_did_change(StringView domain, StringView group, StringView key, StringView value) override;
|
2022-09-28 12:13:00 +01:00
|
|
|
|
2023-03-06 14:17:01 +01:00
|
|
|
Vector<NonnullRefPtr<CardStack>> m_stacks;
|
2022-09-28 17:05:34 +01:00
|
|
|
|
2023-03-06 14:17:01 +01:00
|
|
|
Vector<NonnullRefPtr<Card>> m_moving_cards;
|
2022-09-28 17:05:34 +01:00
|
|
|
RefPtr<CardStack> m_moving_cards_source_stack;
|
2023-01-06 08:25:38 -05:00
|
|
|
RefPtr<CardStack> m_previewed_card_stack;
|
2022-08-20 14:09:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|