RulesDialog.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <dialogs/RulesDialog.h>
00022 #include <dialogs/PlayerDialog.h>
00023 #include <GLW/GLWTextButton.h>
00024 #include <GLW/GLWFont.h>
00025 #include <GLW/GLWWindowManager.h>
00026 #include <tank/TankContainer.h>
00027 #include <client/ClientParams.h>
00028 #include <common/OptionsScorched.h>
00029 #include <common/OptionsTransient.h>
00030 #include <common/Defines.h>
00031 #include <client/ScorchedClient.h>
00032 #include <lang/LangResource.h>
00033 
00034 RulesDialog *RulesDialog::instance_ = 0;
00035 
00036 RulesDialog *RulesDialog::instance()
00037 {
00038         if (!instance_)
00039         {
00040                 instance_ = new RulesDialog();
00041         }
00042         return instance_;
00043 }
00044 
00045 RulesDialog::RulesDialog() : 
00046         GLWWindow("Rules", 0.0f, 0.0f, 740.0f, 480.0f, eSmallTitle,
00047                 "Shows the game rules for the game\n"
00048                 "in progress.")
00049 {
00050         needCentered_ = true;
00051         okId_ = addWidget(new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 675, 10, 55, this, 
00052                 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX))->getId();
00053         motdTab_ = (GLWTab *)
00054                 addWidget(new GLWTab("MoTD", LANG_RESOURCE("MOTD_TAB", "MoTD"), 10, 40, 720, 400));
00055         rulesTab_ = (GLWTab *)
00056                 addWidget(new GLWTab("Rules", LANG_RESOURCE("RULES_TAB", "Rules"), 10, 40, 720, 400));
00057 
00058         motdList_ = (GLWListView *) motdTab_->
00059                 addWidget(new GLWListView(10, 10, 700, 325, 100));
00060         rulesList_ = (GLWListView *) rulesTab_->
00061                 addWidget(new GLWListView(10, 10, 700, 215, 500));
00062         icon_ = (GLWIcon *) motdTab_->
00063                 addWidget(new GLWIcon(165, 340, 390, 50));
00064 }
00065 
00066 RulesDialog::~RulesDialog()
00067 {
00068 }
00069 
00070 void RulesDialog::addIcon(GLTexture *texture)
00071 {
00072         delete icon_->getTexture();
00073         icon_->setTexture(texture);
00074 }
00075 
00076 void RulesDialog::addMOTD(const char *text)
00077 {
00078         motdTab_->setDepressed();
00079         motdList_->clear();
00080         rulesList_->clear();
00081 
00082         // Add all the server rules
00083         std::list<OptionEntry *> &leveloptions = 
00084                 ScorchedClient::instance()->getOptionsGame().getLevelOptions().getOptions();
00085         std::list<OptionEntry *> &mainoptions =
00086                 ScorchedClient::instance()->getOptionsGame().getMainOptions().getOptions();
00087         std::list<OptionEntry *>::iterator mainitor;
00088         std::list<OptionEntry *>::iterator levelitor;
00089         for (mainitor = mainoptions.begin(), levelitor = leveloptions.begin();
00090                 mainitor != mainoptions.end() && levelitor != leveloptions.end();
00091                 mainitor++, levelitor++)
00092         {
00093                 OptionEntry *mainentry = (*mainitor);
00094                 OptionEntry *levelentry = (*levelitor);
00095                 OptionEntry *entry = mainentry;
00096                 if (levelentry->isChangedValue()) entry = levelentry;
00097 
00098                 rulesList_->addLine(
00099                         S3D::formatStringBuffer("%s = %s%s",
00100                                 entry->getName(),
00101                                 entry->getValueAsString(),
00102                                 ((entry == levelentry)?" L":(entry->isDefaultValue()?"":"*"))));
00103         }
00104 
00105         // Add single or multiple lines
00106         char *found = (char *) strchr(text, '\n');
00107         char *start = (char *) text;
00108         if (found)
00109         {
00110                 while (found)
00111                 {
00112                         *found = '\0';
00113                         motdList_->addLine(start);
00114                         start = found;
00115                         start++;
00116                         *found = '\n';
00117 
00118                         found = strchr(start, '\n');
00119                 }
00120                 if (start[0] != '\0')
00121                 {
00122                         motdList_->addLine(start);
00123                 }
00124         }
00125         else
00126         {
00127                 motdList_->addLine(text);
00128         }
00129 }
00130 
00131 void RulesDialog::draw()
00132 {
00133         GLWWindow::draw();
00134 
00135         if (rulesTab_->getDepressed())
00136         {
00137                 drawRules();
00138         }
00139 }
00140 
00141 void RulesDialog::drawRules()
00142 {
00143         OptionsTransient &optionsT = ScorchedClient::instance()->getOptionsTransient();
00144         OptionsScorched &options = ScorchedClient::instance()->getOptionsGame();
00145 
00146         GLState newState(GLState::TEXTURE_OFF | GLState::DEPTH_OFF);
00147 
00148         float top = y_ + h_ - 40.0f;
00149         float left = x_ + 22.0f;
00150         Vector yellow(0.3f, 0.3f, 0.3f); // Hmm, thats not yellow
00151 
00152         const char *type = "Annihilate free for all";
00153         if (options.getTeams() > 1) type = "Annihilate opposing team(s)";
00154 
00155         LANG_RESOURCE_VAR_1(TYPE_LABEL, "TYPE_LABEL", "Type : {0}", type);
00156         GLWFont::instance()->getGameFont()->draw(
00157                 yellow,
00158                 12,
00159                 left, top - 45.0f, 0.0f,
00160                 TYPE_LABEL);
00161 
00162         LANG_RESOURCE_VAR_1(MOD_LABEL, "MOD_LABEL", "Mod : {0}", 
00163                 ScorchedClient::instance()->getOptionsGame().getMod());
00164         GLWFont::instance()->getGameFont()->draw(
00165                 yellow,
00166                 12,
00167                 left, top - 75.0f, 0.0f,
00168                 MOD_LABEL);
00169 
00170         LANG_RESOURCE_VAR_1(GAME_TYPE_LABEL, "GAME_TYPE_LABEL", "Game type : {0}", 
00171                 ScorchedClient::instance()->getOptionsTransient().getGameType());
00172         GLWFont::instance()->getGameFont()->draw(
00173                 yellow,
00174                 12,
00175                 left, top - 90.0f, 0.0f,
00176                 GAME_TYPE_LABEL);
00177 
00178         LANG_RESOURCE_VAR_1(TEAMS_LABEL, "TEAMS_LABEL", "Teams : {0}", 
00179                 S3D::formatStringBuffer("%i", options.getTeams()));
00180         LANG_RESOURCE_VAR(TEAMS_NONE, "TEAMS_NONE", "Teams : None");
00181         GLWFont::instance()->getGameFont()->draw(
00182                 yellow,
00183                 12,
00184                 left, top - 105.0f, 0.0f,
00185                 (options.getTeams() > 1)?TEAMS_LABEL:TEAMS_NONE);
00186 
00187         LANG_RESOURCE_VAR_1(SHOT_TIME_LABEL, "SHOT_TIME_LABEL", "Shot Time : {0}", 
00188                 S3D::formatStringBuffer("%i", options.getShotTime()));
00189         LANG_RESOURCE_VAR(SHOT_TIME_UNLIMITED, "SHOT_TIME_UNLIMITED", "Shot time : Unlimited");
00190         GLWFont::instance()->getGameFont()->draw(
00191                 yellow,
00192                 12,
00193                 left, top - 135.0f, 0.0f,
00194                 (options.getShotTime() > 0)?SHOT_TIME_LABEL:SHOT_TIME_UNLIMITED);
00195 
00196         LANG_RESOURCE_VAR_1(BUYING_TIME_LABEL, "BUYING_TIME_LABEL", "Buying Time : {0}", 
00197                 S3D::formatStringBuffer("%i", options.getShotTime()));
00198         LANG_RESOURCE_VAR(BUYING_TIME_UNLIMITED, "BUYING_TIME_UNLIMITED", "Buying time : Unlimited");
00199         GLWFont::instance()->getGameFont()->draw(
00200                 yellow,
00201                 12,
00202                 left, top - 150.0f, 0.0f,
00203                 (options.getBuyingTime() > 0)?BUYING_TIME_LABEL:BUYING_TIME_UNLIMITED);
00204 }
00205 
00206 void RulesDialog::buttonDown(unsigned int id)
00207 {
00208         if (id == okId_)
00209         {
00210                 GLWWindowManager::instance()->hideWindow(id_);  
00211         }
00212 }
00213 
00214 void RulesDialog::display()
00215 {
00216         addMOTD(ScorchedClient::instance()->getOptionsGame().getMOTD());
00217 
00218         GLWWindow::display();
00219 }
00220 
00221 void RulesDialog::hide()
00222 {
00223         GLWWindow::hide();
00224         GLWWindowManager::instance()->showWindow(
00225                 PlayerDialog::instance()->getId());     
00226 }

Generated on Mon Feb 16 15:14:37 2009 for Scorched3D by  doxygen 1.5.3