00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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);
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 }