1 /**********************************************************************
2  *
3  *   FreeDoko a Doppelkopf-Game
4  *
5  *   Copyright (C) 2001 – 2018 by Diether Knof and Borg Enders
6  *
7  *   This program is free software; you can redistribute it and/or
8  *   modify it under the terms of the GNU General Public License as
9  *   published by the Free Software Foundation; either version 2 of
10  *   the License, or (at your option) any later version.
11  *
12  *   This program 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  *   You can find this license in the file 'gpl.txt'.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with this program; if not, write to the Free Software
20  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  *   MA  02111-1307  USA
22  *
23  *  Contact:
24  *    Diether Knof dknof@posteo.de
25  *
26  **********************************************************************/
27 
28 #ifdef USE_UI_TEXT
29 
30 #pragma once
31 
32 #include "../ui.h"
33 
34 namespace UI_TEXT_NS {
35 
36   /**
37    ** @brief	the UI, a simple text interface
38    **
39    ** @author	Diether Knof
40    **
41    ** @todo	(nearly) all
42    **/
43   class UI_Text : public UI {
44     public:
45       class General;
46       class Help;
47       class BugReport;
48       class Settings;
49       class Party;
50 
51       friend class General;
52       friend class Help;
53       friend class BugReport;
54       friend class Settings;
55       friend class Party;
56     public:
57       UI_Text();
58       virtual ~UI_Text();
59 
60       // the output stream
61       virtual ostream& ostr();
62       // the input stream
63       virtual istream& istr();
64 
65       // initialize the ui
66       virtual void init(int& argc, char**& argv);
67 
68       // sleeps 'sleep_usec' thousands of seconds
69       // (< 0 for infinity)
70       virtual void sleep(unsigned const sleep_usec);
71 
72       // the parts of a party
73       virtual void party_open();
74       virtual void party_get_settings();
75       virtual void party_start();
76       virtual void party_finish();
77       virtual void party_close();
78 
79       // the parts of a game
80       virtual void game_open();
81       Reservation reservation_get(Player const& player);
82       virtual void game_start();
83       virtual void game_finish();
84       virtual void game_close();
85 
86       // the parts of a trick
87       virtual void trick_open();
88       virtual void trick_full(Trick const& trick);
89       virtual void trick_move_in_pile(Trick const& trick);
90       virtual void trick_close();
91       // get a card
92       HandCard card_get(Player const& player);
93       // the card is played
94       virtual void card_played(Card const& card, Player const& player);
95       // an announcement is made
96       virtual void announcement_made(Announcement const& announcement,
97                                      Player const& player);
98       // the player has swines
99       virtual void swines_announced(Player const& player);
100       // the player has hyperswines
101       virtual void hyperswines_announced(Player const& player);
102 
103       // 'player' shifts 'cardno' cards
104       virtual void poverty_shift(Player const& player, unsigned const cardno);
105       // ask 'player' whether to accept the poverty
106       virtual void poverty_ask(Player const& player, unsigned const cardno);
107       // the player 'player' has denied the poverty trumps
108       virtual void poverty_take_denied(Player const& player);
109       // all players have denied to take the cards
110       virtual void poverty_take_denied_by_all();
111       // the player 'player' has accepted the poverty trumps
112       // and has returned 'cardno' cards with 'trumpno' trumps
113       virtual void poverty_take_accepted(Player const& player,
114                                          unsigned const cardno,
115                                          unsigned const trumpno);
116       // 'player' shifts cards
117       virtual HandCards poverty_shift(Player& player);
118       // returns whether 'player' accepts the poverty
119       virtual bool poverty_take_accept(Player& player,
120                                        unsigned const cardno);
121       // the player changes the cards of the poverty
122       virtual HandCards poverty_cards_change(Player& player,
123                                              HandCards const& cards);
124       // the poverty player 'player' gets 'cards'
125       virtual void poverty_cards_get_back(Player& player,
126                                           Hand const& cards);
127 
128       // return a partner for a genscher
129       virtual Player const* genscher_partner();
130       // a player has announced a genscher
131       virtual void genscher(Player const& genscher, Player const& partner);
132 
133       // redrawing
134       virtual void redraw_all();
135       virtual void gametype_update();
136       virtual void trick_update();
137       virtual void name_update(Player const& player);
138       virtual void hand_update(Player const& player);
139       virtual void trick_pile_update(Player const& player);
140       virtual void teaminfo_update(Player const& player);
141       virtual void announcement_update(Player const& player);
142 
143 
144       // change of the rules
145       virtual void rule_update(int const type, void const* const old_value);
146       // changes of the settings
147       virtual void preference_update(int const type, void const* const old_value);
148 
149       // load the help page
150       virtual void help_load(string const& page);
151 
152     private:
153       // reads a line from the input stream
154       virtual void getline(string const& default_command = "");
155       // interprets the line (non special commands)
156       virtual bool interpret_line();
157       // test, whether the read line is the keyword
158       virtual bool iskeyword(string const& keyword) const;
159       // test, whether 'text' is the keyword
160       virtual bool iskeyword(string const& text, string const& keyword) const;
161       // test, whether the first word is the keyword
162       virtual bool first_iskeyword(string const& keyword) const;
163       // test, whether the first word of 'text' is the keyword
164       virtual bool first_iskeyword(string const& text,
165                                    string const& keyword) const;
166 
167     private:
168       // input and output stream
169       istream* istr_;
170       ostream* ostr_;
171     protected:
172       // the prompt
173       string prompt;
174       // read line
175       string line;
176       // name part of the line
177       string line_name;
178       // value part of the line
179       string line_value;
180 
181     private:
182       General* general;
183       Help* help;
184       BugReport* bug_report;
185       Settings* settings;
186       Party* party;
187 
188     private: // unused
189       UI_Text(UI_Text const& ui);
190       UI_Text& operator=(UI_Text const& ui);
191   }; // class UI_Text : public UI
192 
193 } // namespace UI_TEXT_NS
194 using UI_TEXT_NS::UI_Text;
195 
196 #endif // #ifdef USE_UI_TEXT
197