freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CursedScreen.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 /**\file CursedScreen.h
21  * \brief Provides curses (text-based graphics interface) screen for freg.*/
22 
23 #ifndef CURSEDSCREEN_H
24 #define CURSEDSCREEN_H
25 
26 #define NOX
27 
28 #include <QMutex>
29 
30 #ifdef Q_OS_WIN32
31 #define NCURSES_MOUSE_VERSION 2
32 #include "pdcurses/curses.h"
33 #else
34 #define _X_OPEN_SOURCE_EXTENDED
35 #include <ncursesw/ncurses.h>
36 #endif
37 #include "screens/VirtScreen.h"
38 
39 const int SCREEN_SIZE = 30;
40 
41 enum actions {
49 };
50 
55 };
56 
57 class IThread;
58 class Inventory;
59 class QFile;
60 class Block;
61 
62 class Screen final : public VirtScreen {
63  Q_OBJECT
64 public:
65  Screen(World *, Player *, int & error, bool ascii);
66  ~Screen() override;
67 
68  void ControlPlayer();
69  void ControlPlayer(int ch);
70 
71 public slots:
72  void Notify(QString) const override;
73  void PassString(QString &) const override;
74  void Update(int, int, int) override;
75  void UpdateAll() override;
76  void UpdatePlayer() override;
77  void UpdateAround(int, int, int, int) override;
78  void Move(int) override;
79  void DeathScreen();
80  void DisplayFile(QString path) override;
81  void ActionXyz(int * x, int * y, int * z) const override;
82 
83 private slots:
84  void Print() override;
85 
86 private:
87  Screen(const Screen &) = delete;
88  Screen & operator=(const Screen &) = delete;
89  char CharNumber(int z) const;
90  char CharNumberFront(int x, int y) const;
91  void Arrows(WINDOW *, int x, int y, dirs) const;
92  void HorizontalArrows(WINDOW *, int y, dirs) const;
93  void PrintNormal(WINDOW *, dirs) const;
94  /// Has two functions: first - when x == -1 - prints front,
95  /// second - otherwise - examines block at position x, y.
96  void PrintFront(dirs direction, int x = -1, int y = 0) const;
97  void PrintInv(WINDOW *, const Block *, const Inventory *) const;
98  /// Can print health, breath and other bars on hudWin.
99  void PrintBar(int x, int color, int ch, int percent,
100  bool value_position_right = true);
101  /// Returns false when file does not exist, otherwise true.
102  bool PrintFile(WINDOW *, QString const & file_name);
103  void PrintHUD();
104  void PrintMiniMap();
105  void PrintQuickInventory();
106  void CleanFileToShow();
107  void RePrint();
108  void InventoryAction(int num) const;
109  int Color(int kind, int sub) const;
110  int ColorShred(shred_type) const;
111  char PrintBlock(const Block &, WINDOW *) const;
112  void SetActionMode(actions mode);
113  void ProcessCommand(QString command);
114  void ProcessMouse();
115  void MovePlayer(dirs dir);
116  void MovePlayerDiag(dirs dir1, dirs dir2) const;
117  static bool IsScreenWide();
118  int RandomBlink() const;
119  bool RandomBit() const;
120  /// Returns nullptr if block is not player->Visible().
121  Block * GetFocusedBlock() const;
122  inline static void PrintVerticalDirection(WINDOW *, int y, int x, dirs);
123 
124  inline int GetNormalStartX() const;
125  inline int GetNormalStartY() const;
126  inline int GetMinimapStartX() const;
127  inline int GetMinimapStartY() const;
128  void ExamineOnNormalScreen(int x, int y, int z, int step) const;
129 
130  WINDOW * windows[6];
131  WINDOW *& leftWin = windows[0];
132  WINDOW *& rightWin = windows[1];
133  WINDOW *& notifyWin = windows[2];
134  WINDOW *& hudWin = windows[3]; // head-up display
135  WINDOW *& minimapWin = windows[4];
136  WINDOW *& actionWin = windows[5];
137  mutable QString lastNotification;
138  IThread * const input;
139  volatile bool updated;
140  FILE * const notifyLog;
142  /// Can be -1, 0, 1 for low, normal, and high focus.
144  QFile * fileToShow;
145  const bool beepOn, flashOn;
146  const bool ascii;
147  bool blinkOn;
148  const QChar arrows[WEST+1];
149  SCREEN * const screen;
150  mutable bool inputActive = false;
151  mutable int randomBlink;
152 };
153 
154 #endif // CURSEDSCREEN_H
int GetNormalStartY() const
void DisplayFile(QString path) override
Screen(World *, Player *, int &error, bool ascii)
IThread *const input
Definition: CursedScreen.h:138
void Print() override
int GetMinimapStartX() const
void UpdateAround(int, int, int, int) override
const bool beepOn
Definition: CursedScreen.h:145
void PrintNormal(WINDOW *, dirs) const
void DeathScreen()
bool PrintFile(WINDOW *, QString const &file_name)
Returns false when file does not exist, otherwise true.
const bool flashOn
Definition: CursedScreen.h:145
void PrintQuickInventory()
void ExamineOnNormalScreen(int x, int y, int z, int step) const
SCREEN *const screen
Definition: CursedScreen.h:149
World provides global physics and shred connection.
Definition: World.h:52
void ControlPlayer()
~Screen() override
volatile bool updated
Definition: CursedScreen.h:139
int shiftFocus
Can be -1, 0, 1 for low, normal, and high focus.
Definition: CursedScreen.h:143
void PrintHUD()
char PrintBlock(const Block &, WINDOW *) const
actions
Definition: CursedScreen.h:41
void PassString(QString &) const override
Block * GetFocusedBlock() const
Returns nullptr if block is not player->Visible().
WINDOW * windows[6]
Definition: CursedScreen.h:130
char CharNumber(int z) const
const QChar arrows[WEST+1]
Definition: CursedScreen.h:148
void PrintMiniMap()
void ProcessCommand(QString command)
char CharNumberFront(int x, int y) const
static void PrintVerticalDirection(WINDOW *, int y, int x, dirs)
FILE *const notifyLog
Definition: CursedScreen.h:140
int Color(int kind, int sub) const
int RandomBlink() const
void UpdatePlayer() override
Keyboard input thread for curses screen for freg.
Definition: IThread.h:33
void ActionXyz(int *x, int *y, int *z) const override
int GetNormalStartX() const
WINDOW *& minimapWin
Definition: CursedScreen.h:135
void SetActionMode(actions mode)
WINDOW *& rightWin
Definition: CursedScreen.h:132
void Move(int) override
int randomBlink
Definition: CursedScreen.h:151
shred_type
Definition: header.h:59
void ProcessMouse()
const int SCREEN_SIZE
Definition: CursedScreen.h:39
void HorizontalArrows(WINDOW *, int y, dirs) const
void RePrint()
void MovePlayerDiag(dirs dir1, dirs dir2) const
QString lastNotification
Definition: CursedScreen.h:137
bool RandomBit() const
void InventoryAction(int num) const
void UpdateAll() override
WINDOW *& leftWin
Definition: CursedScreen.h:131
WINDOW *& hudWin
Definition: CursedScreen.h:134
const bool ascii
Definition: CursedScreen.h:146
void PrintFront(dirs direction, int x=-1, int y=0) const
void Notify(QString) const override
void CleanFileToShow()
void Arrows(WINDOW *, int x, int y, dirs) const
void PrintBar(int x, int color, int ch, int percent, bool value_position_right=true)
Can print health, breath and other bars on hudWin.
int GetMinimapStartY() const
dirs
Definition: header.h:85
static bool IsScreenWide()
Provides block ability to contain other blocks inside.
Definition: Inventory.h:33
This class provides base for all screens for freg.
Definition: VirtScreen.h:104
bool inputActive
Definition: CursedScreen.h:150
bool blinkOn
Definition: CursedScreen.h:147
QFile * fileToShow
Definition: CursedScreen.h:144
int ColorShred(shred_type) const
void PrintInv(WINDOW *, const Block *, const Inventory *) const
actions actionMode
Definition: CursedScreen.h:141
WINDOW *& notifyWin
Definition: CursedScreen.h:133
Screen & operator=(const Screen &)=delete
void Update(int, int, int) override
This class contains information specific to player and interface for manipulating him...
Definition: Player.h:34
Block without special physics and attributes.
Definition: Block.h:89
5
Definition: header.h:92
WINDOW *& actionWin
Definition: CursedScreen.h:136
void MovePlayer(dirs dir)
screen_errors
Definition: CursedScreen.h:51