1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
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.
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.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <dialogs/RulesDialog.h>
22 #include <dialogs/PlayerDialog.h>
23 #include <GLW/GLWTextButton.h>
24 #include <GLW/GLWFont.h>
25 #include <GLW/GLWWindowManager.h>
26 #include <tank/TankContainer.h>
27 #include <client/ClientParams.h>
28 #include <common/OptionsScorched.h>
29 #include <common/OptionsTransient.h>
30 #include <common/Defines.h>
31 #include <client/ScorchedClient.h>
32 #include <lang/LangResource.h>
34 RulesDialog
*RulesDialog::instance_
= 0;
36 RulesDialog
*RulesDialog::instance()
40 instance_
= new RulesDialog();
45 RulesDialog::RulesDialog() :
46 GLWWindow("Rules", 0.0f
, 0.0f
, 740.0f
, 480.0f
, eSmallTitle
,
47 "Shows the game rules for the game\n"
51 okId_
= addWidget(new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 675, 10, 55, this,
52 GLWButton::ButtonFlagCancel
| GLWButton::ButtonFlagOk
| GLWButton::ButtonFlagCenterX
))->getId();
54 addWidget(new GLWTab("MoTD", LANG_RESOURCE("MOTD_TAB", "MoTD"), 10, 40, 720, 400));
55 rulesTab_
= (GLWTab
*)
56 addWidget(new GLWTab("Rules", LANG_RESOURCE("RULES_TAB", "Rules"), 10, 40, 720, 400));
58 motdList_
= (GLWListView
*) motdTab_
->
59 addWidget(new GLWListView(10, 10, 700, 325, 100));
60 rulesList_
= (GLWListView
*) rulesTab_
->
61 addWidget(new GLWListView(10, 10, 700, 215, 500));
62 icon_
= (GLWIcon
*) motdTab_
->
63 addWidget(new GLWIcon(165, 340, 390, 50));
66 RulesDialog::~RulesDialog()
70 void RulesDialog::addIcon(GLTexture
*texture
)
72 delete icon_
->getTexture();
73 icon_
->setTexture(texture
);
76 void RulesDialog::addMOTD(const char *text
)
78 motdTab_
->setDepressed();
82 // Add all the server rules
83 std::list
<OptionEntry
*> &leveloptions
=
84 ScorchedClient::instance()->getOptionsGame().getLevelOptions().getOptions();
85 std::list
<OptionEntry
*> &mainoptions
=
86 ScorchedClient::instance()->getOptionsGame().getMainOptions().getOptions();
87 std::list
<OptionEntry
*>::iterator mainitor
;
88 std::list
<OptionEntry
*>::iterator levelitor
;
89 for (mainitor
= mainoptions
.begin(), levelitor
= leveloptions
.begin();
90 mainitor
!= mainoptions
.end() && levelitor
!= leveloptions
.end();
91 mainitor
++, levelitor
++)
93 OptionEntry
*mainentry
= (*mainitor
);
94 OptionEntry
*levelentry
= (*levelitor
);
95 OptionEntry
*entry
= mainentry
;
96 if (levelentry
->isChangedValue()) entry
= levelentry
;
99 S3D::formatStringBuffer("%s = %s%s",
101 entry
->getValueAsString(),
102 ((entry
== levelentry
)?" L":(entry
->isDefaultValue()?"":"*"))));
105 // Add single or multiple lines
106 char *found
= (char *) strchr(text
, '\n');
107 char *start
= (char *) text
;
113 motdList_
->addLine(start
);
118 found
= strchr(start
, '\n');
120 if (start
[0] != '\0')
122 motdList_
->addLine(start
);
127 motdList_
->addLine(text
);
131 void RulesDialog::draw()
135 if (rulesTab_
->getDepressed())
141 void RulesDialog::drawRules()
143 OptionsTransient
&optionsT
= ScorchedClient::instance()->getOptionsTransient();
144 OptionsScorched
&options
= ScorchedClient::instance()->getOptionsGame();
146 GLState
newState(GLState::TEXTURE_OFF
| GLState::DEPTH_OFF
);
148 float top
= y_
+ h_
- 40.0f
;
149 float left
= x_
+ 22.0f
;
150 Vector
yellow(0.3f
, 0.3f
, 0.3f
); // Hmm, thats not yellow
152 const char *type
= "Annihilate free for all";
153 if (options
.getTeams() > 1) type
= "Annihilate opposing team(s)";
155 LANG_RESOURCE_VAR_1(TYPE_LABEL
, "TYPE_LABEL", "Type : {0}", type
);
156 GLWFont::instance()->getGameFont()->draw(
159 left
, top
- 45.0f
, 0.0f
,
162 LANG_RESOURCE_VAR_1(MOD_LABEL
, "MOD_LABEL", "Mod : {0}",
163 ScorchedClient::instance()->getOptionsGame().getMod());
164 GLWFont::instance()->getGameFont()->draw(
167 left
, top
- 75.0f
, 0.0f
,
170 LANG_RESOURCE_VAR_1(GAME_TYPE_LABEL
, "GAME_TYPE_LABEL", "Game type : {0}",
171 ScorchedClient::instance()->getOptionsTransient().getGameType());
172 GLWFont::instance()->getGameFont()->draw(
175 left
, top
- 90.0f
, 0.0f
,
178 LANG_RESOURCE_VAR_1(TEAMS_LABEL
, "TEAMS_LABEL", "Teams : {0}",
179 S3D::formatStringBuffer("%i", options
.getTeams()));
180 LANG_RESOURCE_VAR(TEAMS_NONE
, "TEAMS_NONE", "Teams : None");
181 GLWFont::instance()->getGameFont()->draw(
184 left
, top
- 105.0f
, 0.0f
,
185 (options
.getTeams() > 1)?TEAMS_LABEL
:TEAMS_NONE
);
187 LANG_RESOURCE_VAR_1(SHOT_TIME_LABEL
, "SHOT_TIME_LABEL", "Shot Time : {0}",
188 S3D::formatStringBuffer("%i", options
.getShotTime()));
189 LANG_RESOURCE_VAR(SHOT_TIME_UNLIMITED
, "SHOT_TIME_UNLIMITED", "Shot time : Unlimited");
190 GLWFont::instance()->getGameFont()->draw(
193 left
, top
- 135.0f
, 0.0f
,
194 (options
.getShotTime() > 0)?SHOT_TIME_LABEL
:SHOT_TIME_UNLIMITED
);
196 LANG_RESOURCE_VAR_1(BUYING_TIME_LABEL
, "BUYING_TIME_LABEL", "Buying Time : {0}",
197 S3D::formatStringBuffer("%i", options
.getShotTime()));
198 LANG_RESOURCE_VAR(BUYING_TIME_UNLIMITED
, "BUYING_TIME_UNLIMITED", "Buying time : Unlimited");
199 GLWFont::instance()->getGameFont()->draw(
202 left
, top
- 150.0f
, 0.0f
,
203 (options
.getBuyingTime() > 0)?BUYING_TIME_LABEL
:BUYING_TIME_UNLIMITED
);
206 void RulesDialog::buttonDown(unsigned int id
)
210 GLWWindowManager::instance()->hideWindow(id_
);
214 void RulesDialog::display()
216 addMOTD(ScorchedClient::instance()->getOptionsGame().getMOTD());
218 GLWWindow::display();
221 void RulesDialog::hide()
224 GLWWindowManager::instance()->showWindow(
225 PlayerDialog::instance()->getId());