git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / client / dialogs / RulesDialog.cpp
blob2793b6d730b181df2c125d93264bc3d2bfbeeac1
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
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.
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()
38 if (!instance_)
40 instance_ = new RulesDialog();
42 return instance_;
45 RulesDialog::RulesDialog() :
46 GLWWindow("Rules", 0.0f, 0.0f, 740.0f, 480.0f, eSmallTitle,
47 "Shows the game rules for the game\n"
48 "in progress.")
50 needCentered_ = true;
51 okId_ = addWidget(new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 675, 10, 55, this,
52 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX))->getId();
53 motdTab_ = (GLWTab *)
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();
79 motdList_->clear();
80 rulesList_->clear();
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;
98 rulesList_->addLine(
99 S3D::formatStringBuffer("%s = %s%s",
100 entry->getName(),
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;
108 if (found)
110 while (found)
112 *found = '\0';
113 motdList_->addLine(start);
114 start = found;
115 start++;
116 *found = '\n';
118 found = strchr(start, '\n');
120 if (start[0] != '\0')
122 motdList_->addLine(start);
125 else
127 motdList_->addLine(text);
131 void RulesDialog::draw()
133 GLWWindow::draw();
135 if (rulesTab_->getDepressed())
137 drawRules();
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(
157 yellow,
159 left, top - 45.0f, 0.0f,
160 TYPE_LABEL);
162 LANG_RESOURCE_VAR_1(MOD_LABEL, "MOD_LABEL", "Mod : {0}",
163 ScorchedClient::instance()->getOptionsGame().getMod());
164 GLWFont::instance()->getGameFont()->draw(
165 yellow,
167 left, top - 75.0f, 0.0f,
168 MOD_LABEL);
170 LANG_RESOURCE_VAR_1(GAME_TYPE_LABEL, "GAME_TYPE_LABEL", "Game type : {0}",
171 ScorchedClient::instance()->getOptionsTransient().getGameType());
172 GLWFont::instance()->getGameFont()->draw(
173 yellow,
175 left, top - 90.0f, 0.0f,
176 GAME_TYPE_LABEL);
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(
182 yellow,
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(
191 yellow,
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(
200 yellow,
202 left, top - 150.0f, 0.0f,
203 (options.getBuyingTime() > 0)?BUYING_TIME_LABEL:BUYING_TIME_UNLIMITED);
206 void RulesDialog::buttonDown(unsigned int id)
208 if (id == okId_)
210 GLWWindowManager::instance()->hideWindow(id_);
214 void RulesDialog::display()
216 addMOTD(ScorchedClient::instance()->getOptionsGame().getMOTD());
218 GLWWindow::display();
221 void RulesDialog::hide()
223 GLWWindow::hide();
224 GLWWindowManager::instance()->showWindow(
225 PlayerDialog::instance()->getId());