1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #include <dialogs/StartDialog.h>
22 #include <dialogs/ModSelectDialog.h>
23 #include <dialogs/ModSubSelectDialog.h>
24 #include <dialogs/SaveSelectDialog.h>
25 #include <dialogs/NetworkSelectDialog.h>
26 #include <dialogs/SettingsSelectDialog.h>
27 #include <dialogs/SettingsSubSelectDialog.h>
28 #include <dialogs/QuitDialog.h>
29 #include <client/ScorchedClient.h>
30 #include <client/ClientParams.h>
31 #include <client/ClientMain.h>
32 #include <engine/GameState.h>
33 #include <engine/MainLoop.h>
34 #include <GLW/GLWColors.h>
35 #include <GLW/GLWFont.h>
36 #include <GLW/GLWTranslate.h>
37 #include <GLW/GLWWindowManager.h>
38 #include <lang/LangResource.h>
39 
40 StartDialog *StartDialog::instance_ = 0;
41 
instance()42 StartDialog *StartDialog::instance()
43 {
44 	if (!instance_)
45 	{
46 		instance_ = new StartDialog;
47 	}
48 	return instance_;
49 }
50 
StartDialog()51 StartDialog::StartDialog() :
52 	GLWWindow("Start", 10.0f, 10.0f, 640.0f, 480.0f, eNoTitle | eHideName),
53 	selected_(-1)
54 {
55 	OptionDefinition defs[] =
56 	{
57 		LANG_RESOURCE("TUTORIAL", "Tutorial"), "- Start the tutorial to learn how to play.", 50.0f, 60.0f, 0.0f,
58 		LANG_RESOURCE("PLAY_GAME", "Play Game"), "- Play a game against the computer or other local players.", 50.0f, 100.0f, 0.0f,
59 		LANG_RESOURCE("PLAY_ONLINE", "Play Online"), "- Play online game against other players, gain stats and win awards.", 50.0f, 140.0f, 0.0f,
60 		LANG_RESOURCE("LOAD SAVE", "Load Save"), "- Continue playing a saved game.", 50.0f, 180.0f, 0.0f,
61 		LANG_RESOURCE("HELP", "Help"), "- View the online help.", 50.0f, 250.0f, 0.0f,
62 		LANG_RESOURCE("DONATE", "Donate"), "- Show support for Scorched3D.", 50.0f, 290.0f, 0.0f,
63 		LANG_RESOURCE("QUIT", "Quit"), "- Exit the game.", 50.0f, 360.0f, 0.0f
64 	};
65 	for (int i=0; i<sizeof(defs) / sizeof(OptionDefinition); i++)
66 	{
67 		definitions_.push_back(defs[i]);
68 	}
69 }
70 
~StartDialog()71 StartDialog::~StartDialog()
72 {
73 }
74 
draw()75 void StartDialog::draw()
76 {
77 	int mouseX = ScorchedClient::instance()->getGameState().getMouseX();
78 	int mouseY = ScorchedClient::instance()->getGameState().getMouseY();
79 
80 	GLState state(GLState::DEPTH_OFF);
81 
82 	selected_ = -1;
83 	float size = 18.0f;
84 	float smallSize = 14.0f;
85 	Vector white(0.8f, 0.8f, 0.8f);
86 	for (int i=0; i<(int) definitions_.size(); i++)
87 	{
88 		OptionDefinition &definition = definitions_[i];
89 
90 		// Draw shadow
91 		GLWFont::instance()->getNormalShadowFont()->draw(
92 			GLWColors::black, size,
93 			definition.x - 2, h_ - definition.y + 2, 0.0f,
94 			definition.option);
95 
96 		// Check if option is selected
97 		Vector *color = &white;
98 		if (inBox(
99 			mouseX - GLWTranslate::getPosX(),
100 			mouseY - GLWTranslate::getPosY(),
101 			definition.x, (h_ - definition.y),
102 			definition.width, 20.0f))
103 		{
104 			color = &GLWColors::white;
105 			selected_ = i;
106 		}
107 
108 		// Draw Option
109 		GLWFont::instance()->getNormalFont()->draw(
110 			*color, size,
111 			definition.x, h_ - definition.y, 0.0f,
112 			definition.option);
113 		definition.width =
114 			GLWFont::instance()->getNormalFont()->getWidth(
115 			size, definition.option);
116 
117 		// Draw Description
118 		if (selected_ == i)
119 		{
120 			GLWFont::instance()->getNormalShadowFont()->draw(
121 				GLWColors::black, smallSize,
122 				definition.x + 200.0f - 1.5f, h_ - definition.y + 1.5f, 0.0f,
123 				definition.description);
124 
125 			GLWFont::instance()->getNormalFont()->draw(
126 				*color, smallSize,
127 				definition.x + 200.0f, h_ - definition.y, 0.0f,
128 				definition.description);
129 		}
130 	}
131 }
132 
mouseDown(int button,float x,float y,bool & skipRest)133 void StartDialog::mouseDown(int button, float x, float y, bool &skipRest)
134 {
135 	if (selected_ != -1)
136 	{
137 		skipRest = true;
138 
139 		// Make sure all other options are hidden
140 		GLWWindowManager::instance()->hideWindow(
141 			ModSelectDialog::instance()->getId());
142 		GLWWindowManager::instance()->hideWindow(
143 			ModSubSelectDialog::instance()->getId());
144 		GLWWindowManager::instance()->hideWindow(
145 			SaveSelectDialog::instance()->getId());
146 		GLWWindowManager::instance()->hideWindow(
147 			NetworkSelectDialog::instance()->getId());
148 		GLWWindowManager::instance()->hideWindow(
149 			SettingsSelectDialog::instance()->getId());
150 		GLWWindowManager::instance()->hideWindow(
151 			SettingsSubSelectDialog::instance()->getId());
152 	}
153 
154 	switch (selected_)
155 	{
156 	case 0:
157 		{
158 		std::string targetFilePath = S3D::getDataFile("data/singletutorial.xml");
159 		ClientParams::instance()->reset();
160 		ClientParams::instance()->setClientFile(targetFilePath.c_str());
161 		ClientMain::startClient();
162 		}
163 		break;
164 	case 1:
165 		GLWWindowManager::instance()->showWindow(
166 			ModSelectDialog::instance()->getId());
167 		break;
168 	case 2:
169 		GLWWindowManager::instance()->showWindow(
170 			NetworkSelectDialog::instance()->getId());
171 		break;
172 	case 3:
173 		GLWWindowManager::instance()->showWindow(
174 			SaveSelectDialog::instance()->getId());
175 		break;
176 	case 4:
177 		{
178 		S3D::showURL("http://www.scorched3d.co.uk/wiki");
179 		}
180 		break;
181 	case 5:
182 		{
183 		const char *exec =
184 			"\"https://www.paypal.com/xclick/business=donations%40"
185 			"scorched3d.co.uk&item_name=Scorched3D&no_note=1&tax=0&currency_code=GBP\"";
186 		S3D::showURL(exec);
187 		}
188 		break;
189 	case 6:
190 		GLWWindowManager::instance()->showWindow(
191 			QuitDialog::instance()->getId());
192 		break;
193 	}
194 }
195