freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
VirtScreen.h
Go to the documentation of this file.
1  /* freg, Free-Roaming Elementary Game with open and interactive world
2  * Copyright (C) 2012-2014 Alexander 'mmaulwurff' Kromm
3  * mmaulwurff@gmail.com
4  *
5  * This file is part of FREG.
6  *
7  * FREG is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * FREG is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with FREG. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #ifndef VIRTSCREEN_H
21 #define VIRTSCREEN_H
22 
23 #include <QObject>
24 #include <QSettings>
25 #include <QString>
26 #include "World.h"
27 
28 class Player;
29 
30 enum color_pairs { // do not change colors order! // foreground_background
39  //
48  //
57  //
66  //
75  //
84  //
93  //
102 }; // enum color_pairs
103 
104 class VirtScreen : public QObject {
105  /** \class VirtScreen VirtScreen.h
106  * \brief This class provides base for all screens for freg.
107  *
108  * It provides interface for world-screen and player-screen
109  * communications by its slots and signals. */
110  Q_OBJECT
111 
112 public:
113  /// Constructor makes player and world connections.
114  /** Constructor of non-virtual screen should contain this code
115  * to connect to player for sending input:
116  * connect(this, SIGNAL(InputReceived(int, int)),
117  * player, SLOT(Act(int, int)),
118  * Qt::DirectConnection); */
119  VirtScreen(World *, Player *);
120  VirtScreen(VirtScreen &) = delete;
121  virtual ~VirtScreen();
122 
123  static char CharName(int kind, int sub);
124  static int Color (int kind, int sub);
125 
126 signals:
127  /// This is emitted when input receives exit key.
128  /** This is connected to application exit. */
129  void ExitReceived();
130 
131 public slots:
132  /// This is called for a notification to be displayed.
133  virtual void Notify(QString) const = 0;
134 
135  /// This is called when string is needed to be received from input.
136  /** It is connected to world in constructor. */
137  virtual void PassString(QString &) const = 0;
138 
139  /// This is called when block at (x, y, z) should be updated in screen.
140  /** When implemented, this should work fast.
141  * It is connected to world in constructor. */
142  virtual void Update(int x, int y, int z) = 0;
143 
144  /// This is called when all world should be updated in sceen.
145  /** When implemented, this should work fast.
146  * It is connected to world in constructor. */
147  virtual void UpdateAll() = 0;
148 
149  /// Called when world loaded zone is moved to update world in screen.
150  /** When implemented, this should work fast.
151  * It is connected to world in constructor. */
152  virtual void Move(int) = 0;
153 
154  /// Called when some player property needs to be updated in screen.
155  /** When implemented, this should work fast.
156  * It is connected to world in constructor. */
157  virtual void UpdatePlayer() = 0;
158 
159  /// Called when area around xyz with range needs to be updated.
160  /** When implemented, this should work fast.
161  * It is connected to world in constructor. */
162  virtual void UpdateAround(int x, int y, int z, int rng) = 0;
163 
164  /// This is called when current group of updates is ended.
165  /** This is called from world when pack of world changing is ended.
166  * ( Can be used in screen optimization. ) */
167  virtual void UpdatesEnd();
168 
169  /// This is called when player is dead, and displayed until respawn.
170  void DeathScreen(); // virtual ?
171 
172  /// Used to get player focus coordinates from screen.
173  /** x, y, z are coordinates where player will make action.
174  * May be reimplemented in derivative class to get xyz other than
175  * world direction-based focus. */
176  virtual void ActionXyz(int * x, int * y, int * z) const;
177 
178  /// This shows a file by path.
179  /** Standard (non-reimpemented) version does nothing. */
180  virtual void DisplayFile(QString path);
181 
182 private slots:
183  /// Prints world. Should not be called not within screen.
184  virtual void Print() = 0;
185 
186 protected:
187  World * GetWorld() const;
188 
189  World * const w;
190  Player * const player;
191  QSettings settings;
193 
194 private:
195  VirtScreen(const VirtScreen &) = delete;
196  VirtScreen & operator=(const VirtScreen &) = delete;
197 };
198 
199 #endif // VIRTSCREEN_H
QString previousCommand
Definition: VirtScreen.h:192
virtual void Update(int x, int y, int z)=0
This is called when block at (x, y, z) should be updated in screen.
Definition: VirtScreen.cpp:195
static char CharName(int kind, int sub)
Definition: VirtScreen.cpp:131
virtual void ActionXyz(int *x, int *y, int *z) const
Used to get player focus coordinates from screen.
Definition: VirtScreen.cpp:70
Player *const player
Definition: VirtScreen.h:190
VirtScreen & operator=(const VirtScreen &)=delete
World provides global physics and shred connection.
Definition: World.h:52
World * GetWorld() const
Definition: VirtScreen.cpp:74
color_pairs
Definition: VirtScreen.h:30
static int Color(int kind, int sub)
Definition: VirtScreen.cpp:76
World *const w
Definition: VirtScreen.h:189
virtual void UpdateAll()=0
This is called when all world should be updated in sceen.
Definition: VirtScreen.cpp:196
virtual void UpdateAround(int x, int y, int z, int rng)=0
Called when area around xyz with range needs to be updated.
Definition: VirtScreen.cpp:199
virtual void Notify(QString) const =0
This is called for a notification to be displayed.
Definition: VirtScreen.cpp:201
QSettings settings
Definition: VirtScreen.h:191
virtual void UpdatePlayer()=0
Called when some player property needs to be updated in screen.
Definition: VirtScreen.cpp:198
void ExitReceived()
This is emitted when input receives exit key.
virtual void UpdatesEnd()
This is called when current group of updates is ended.
Definition: VirtScreen.cpp:26
virtual void PassString(QString &) const =0
This is called when string is needed to be received from input.
Definition: VirtScreen.cpp:202
VirtScreen(World *, Player *)
Constructor makes player and world connections.
Definition: VirtScreen.cpp:29
This class provides base for all screens for freg.
Definition: VirtScreen.h:104
virtual void DisplayFile(QString path)
This shows a file by path.
Definition: VirtScreen.cpp:68
virtual ~VirtScreen()
Definition: VirtScreen.cpp:66
void DeathScreen()
This is called when player is dead, and displayed until respawn.
Definition: VirtScreen.cpp:27
virtual void Print()=0
Prints world. Should not be called not within screen.
Definition: VirtScreen.cpp:200
This class contains information specific to player and interface for manipulating him...
Definition: Player.h:34
virtual void Move(int)=0
Called when world loaded zone is moved to update world in screen.
Definition: VirtScreen.cpp:197