1 /*
2  * This file is part of EasyRPG Player.
3  *
4  * EasyRPG Player is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * EasyRPG Player is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef EP_SCENE_TITLE_H
19 #define EP_SCENE_TITLE_H
20 
21 // Headers
22 #include "scene.h"
23 #include "sprite.h"
24 #include "window_command.h"
25 #include "async_handler.h"
26 
27 
28 /**
29  * Scene Title class.
30  */
31 class Scene_Title : public Scene {
32 public:
33 	/**
34 	 * Constructor.
35 	 */
36 	Scene_Title();
37 
38 	void Start() override;
39 	void Continue(SceneType prev_scene) override;
40 	void TransitionIn(SceneType prev_scene) override;
41 	void Suspend(SceneType next_scene) override;
42 	void Update() override;
43 
44 	/**
45 	 * Creates the background graphic of the scene.
46 	 */
47 	void CreateTitleGraphic();
48 
49 	/**
50 	 * Creates the Window displaying the options.
51 	 */
52 	void CreateCommandWindow();
53 
54 	/**
55 	 * Creates the Window displaying available translations.
56 	 */
57 	void CreateTranslationWindow();
58 
59 	/**
60 	 * Creates the Help window and hides it
61 	 */
62 	void CreateHelpWindow();
63 
64 	/**
65 	 * Plays the title music.
66 	 */
67 	void PlayTitleMusic();
68 
69 	/**
70 	 * Checks if game or engine configuration requires usage of title
71 	 * graphic and music or not.
72 	 *
73 	 * @return true when graphic and music are shown
74 	 */
75 	bool CheckEnableTitleGraphicAndMusic();
76 
77 	/**
78 	 * Checks if there is a player start location.
79 	 *
80 	 * @return true if there is one, false otherwise.
81 	 */
82 	bool CheckValidPlayerLocation();
83 
84 	/**
85 	 * Option New Game.
86 	 * Starts a new game.
87 	 */
88 	void CommandNewGame();
89 
90 	/**
91 	 * Option Continue.
92 	 * Shows the Load-Screen (Scene_Load).
93 	 */
94 	void CommandContinue();
95 
96 	/**
97 	 * Option Import.
98 	 * Shows the Import screen, for use with multi-game save files.
99 	 */
100 	void CommandImport();
101 
102 	/**
103 	 * Option Translation.
104 	 * Shows the Translation menu, for picking between multiple languages or localizations
105 	 */
106 	void CommandTranslation();
107 
108 	/**
109 	 * Option Shutdown.
110 	 * Does a player shutdown.
111 	 */
112 	void CommandShutdown();
113 
114 	/**
115 	 * Invoked when a new game is started or a save game is loaded.
116 	 */
117 	void OnGameStart();
118 
119 private:
120 	void OnTitleSpriteReady(FileRequestResult* result);
121 
122 	/**
123 	 * Moves a window (typically the New/Continue/Quit menu) to the middle or bottom-center of the screen.
124 	 * @param window The window to resposition.
125 	 * @param center_vertical If true, the menu will be centered vertically. Otherwise, it will be at the bottom of the screen.
126 	 */
127 	void RepositionWindow(Window_Command& window, bool center_vertical);
128 
129 	/**
130 	 * Picks a new language based and switches to it.
131 	 * @param lang_str If the empty string, switches the game to 'No Translation'. Otherwise, switch to that translation by name.
132 	 */
133 	void ChangeLanguage(const std::string& lang_str);
134 
135 	void HideTranslationWindow();
136 
137 	/** Displays the options of the title scene. */
138 	std::unique_ptr<Window_Command> command_window;
139 
140 	/** Displays all available translations (languages). */
141 	std::unique_ptr<Window_Command> translate_window;
142 
143 	/** Displays help text for a given language **/
144 	std::unique_ptr<Window_Help> help_window;
145 
146 	/** Contains directory names for each language; entry 0 is resverd for the default (no) translation */
147 	std::vector<std::string> lang_dirs;
148 
149 	/** Contains help strings for each language; entry 0 is resverd for the default (no) translation */
150 	std::vector<std::string> lang_helps;
151 
152 	/** Background graphic. */
153 	std::unique_ptr<Sprite> title;
154 
155 	/**
156 	 * Current active window
157 	 *   0 = command
158 	 *   1 = translate
159 	 */
160 	int active_window = 0;
161 
162 	/**
163 	 * Offsets for each selection, in case "Import" or "Translate" is enabled.
164 	 *   Listed in the order they may appear; exit_index will always be last,
165 	 *   and import appears before translate, if it exists.
166 	 * Stored in a struct for easy resetting, as Scene_Title can be reused.
167 	 */
168 	struct CommandIndices {
169 		int new_game =  0;
170 		int continue_game =  1;
171 		int import = -1;
172 		int translate = -1;
173 		int exit =  2;
174 	};
175 	CommandIndices indices;
176 
177 	/** Contains the state of continue button. */
178 	bool continue_enabled = false;
179 
180 	bool restart_title_cache = false;
181 
182 	FileRequestBinding request_id;
183 };
184 
185 #endif
186