Allow building as monolithic app (no plugins) for easier developement.
[tagua/yd.git] / src / graphicalgame.h
blobcfb90a7886e0859f9f07dee0e371a80ef37f0a44
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef GRAPHICALGAME_H
12 #define GRAPHICALGAME_H
14 #include <QObject>
15 #include <QFlags>
16 #include <boost/weak_ptr.hpp>
17 #include "game.h"
18 #include "movelist_notifier.h"
20 class GraphicalSystem;
21 class CtrlAction;
22 class IMoveSerializer;
23 class UserEntity;
24 class GraphicalGame;
25 class ActionStateObserver;
26 namespace MoveList { class Table; }
28 class GraphicalGame : public QObject, public Game, public MoveList::Notifier {
29 Q_OBJECT
30 public:
31 /**
32 * @brief State of GUI actions associated to a game.
34 enum ActionStateFlag {
35 UNDO = 0x1,
36 REDO = 0x2,
37 BEGIN = 0x4,
38 BACK = 0x8,
39 FORWARD = 0x10,
40 END = 0x20
42 Q_DECLARE_FLAGS(ActionState, ActionStateFlag)
43 private:
44 GraphicalSystem* m_graphical;
45 MoveList::Table* m_movelist;
46 bool m_anim_sequence;
47 int m_anim_sequence_max;
49 IMoveSerializer* m_decorator;
51 boost::shared_ptr<CtrlAction> m_ctrl;
52 boost::weak_ptr<UserEntity> m_listener_entity;
53 boost::shared_ptr<ActionStateObserver> m_action_state_observer;
54 ActionState m_action_state;
55 void updateActionState();
57 private Q_SLOTS:
58 void settingsChanged();
60 public:
61 GraphicalGame(GraphicalSystem* graphical, MoveList::Table* m);
62 ~GraphicalGame();
64 void onAddedInternal(const Index& i, bool confirm_promotion = false);
65 virtual void onAdded(const Index& i);
66 virtual void onRemoved(const Index& i);
67 virtual void onEntryChanged(const Index& at, int propagate=1);
68 virtual void onPromoteVariation(const Index& i, int v);
69 virtual void onSetComment(const Index& i, const QString& s);
70 virtual void onSetVComment(const Index& i, int v, const QString& s);
71 virtual void onCurrentIndexChanged(const Index& old_c);
72 virtual void onAvailableUndo(bool e);
73 virtual void onAvailableRedo(bool e);
74 virtual void onUserSelectMove(const Index& i);
75 virtual void onUserSetComment(const Index& i, QString s);
76 virtual void onUserSetVComment(const Index& i, int v, QString s);
77 virtual void onUserClearVariations(const Index& i);
78 virtual void onUserTruncate(const Index& i);
79 virtual void onUserPromoteVariation(const Index& i);
80 virtual void onUserRemoveVariation(const Index& i);
81 virtual void onUserUndo();
82 virtual void onUserRedo();
83 virtual void onDetachNotifier();
85 virtual void createCtrlAction();
86 virtual void destroyCtrlAction();
88 void setEntity(const boost::shared_ptr<UserEntity>& entity) { m_listener_entity = entity; }
89 void detachEntity() { m_listener_entity.reset(); }
90 void setActionStateObserver(const boost::shared_ptr<ActionStateObserver>& obs);
91 void onActionStateChange();
94 Q_DECLARE_OPERATORS_FOR_FLAGS(GraphicalGame::ActionState)
97 /**
98 * @brief An observer that is notified of changes in the ActionState flags.
100 class ActionStateObserver {
101 public:
102 virtual ~ActionStateObserver();
104 virtual void notifyActionStateChange(GraphicalGame::ActionState state) = 0;
107 #endif //GRAPHICALGAME_H