00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <dialogs/StartDialog.h>
00022 #include <dialogs/ModSelectDialog.h>
00023 #include <dialogs/ModSubSelectDialog.h>
00024 #include <dialogs/SaveSelectDialog.h>
00025 #include <dialogs/NetworkSelectDialog.h>
00026 #include <dialogs/SettingsSelectDialog.h>
00027 #include <dialogs/SettingsSubSelectDialog.h>
00028 #include <client/ScorchedClient.h>
00029 #include <client/ClientParams.h>
00030 #include <client/ClientMain.h>
00031 #include <engine/GameState.h>
00032 #include <engine/MainLoop.h>
00033 #include <GLW/GLWColors.h>
00034 #include <GLW/GLWFont.h>
00035 #include <GLW/GLWTranslate.h>
00036 #include <GLW/GLWWindowManager.h>
00037 #include <lang/LangResource.h>
00038
00039 StartDialog *StartDialog::instance_ = 0;
00040
00041 StartDialog *StartDialog::instance()
00042 {
00043 if (!instance_)
00044 {
00045 instance_ = new StartDialog;
00046 }
00047 return instance_;
00048 }
00049
00050 StartDialog::StartDialog() :
00051 GLWWindow("", 10.0f, 10.0f, 640.0f, 480.0f, eNoTitle),
00052 selected_(-1)
00053 {
00054 OptionDefinition defs[] =
00055 {
00056 LANG_RESOURCE("TUTORIAL", "Tutorial"), "- Start the tutorial to learn how to play.", 50.0f, 60.0f, 0.0f,
00057 LANG_RESOURCE("LOCAL_GAME", "Local Game"), "- Play a game against the computer or other local players.", 50.0f, 100.0f, 0.0f,
00058 LANG_RESOURCE("Network Game", "Network Game"), "- Play an online game against remote players.", 50.0f, 140.0f, 0.0f,
00059 LANG_RESOURCE("LOAD SAVE", "Load Save"), "- Continue playing a saved game.", 50.0f, 180.0f, 0.0f,
00060 LANG_RESOURCE("HELP", "Help"), "- View the online help.", 50.0f, 250.0f, 0.0f,
00061 LANG_RESOURCE("DONATE", "Donate"), "- Show support for Scorched3D.", 50.0f, 290.0f, 0.0f,
00062 LANG_RESOURCE("QUIT", "Quit"), "- Exit the game.", 50.0f, 360.0f, 0.0f
00063 };
00064 for (int i=0; i<sizeof(defs) / sizeof(OptionDefinition); i++)
00065 {
00066 definitions_.push_back(defs[i]);
00067 }
00068 }
00069
00070 StartDialog::~StartDialog()
00071 {
00072 }
00073
00074 void StartDialog::draw()
00075 {
00076 int mouseX = ScorchedClient::instance()->getGameState().getMouseX();
00077 int mouseY = ScorchedClient::instance()->getGameState().getMouseY();
00078
00079 GLState state(GLState::DEPTH_OFF);
00080
00081 selected_ = -1;
00082 float size = 18.0f;
00083 float smallSize = 14.0f;
00084 Vector white(0.8f, 0.8f, 0.8f);
00085 for (int i=0; i<(int) definitions_.size(); i++)
00086 {
00087 OptionDefinition &definition = definitions_[i];
00088
00089
00090 GLWFont::instance()->getNormalShadowFont()->draw(
00091 GLWColors::black, size,
00092 definition.x - 2, h_ - definition.y + 2, 0.0f,
00093 definition.option);
00094
00095
00096 Vector *color = &white;
00097 if (inBox(
00098 mouseX - GLWTranslate::getPosX(),
00099 mouseY - GLWTranslate::getPosY(),
00100 definition.x, (h_ - definition.y),
00101 definition.width, 20.0f))
00102 {
00103 color = &GLWColors::white;
00104 selected_ = i;
00105 }
00106
00107
00108 GLWFont::instance()->getNormalFont()->draw(
00109 *color, size,
00110 definition.x, h_ - definition.y, 0.0f,
00111 definition.option);
00112 definition.width =
00113 GLWFont::instance()->getNormalFont()->getWidth(
00114 size, definition.option);
00115
00116
00117 if (selected_ == i)
00118 {
00119 GLWFont::instance()->getNormalShadowFont()->draw(
00120 GLWColors::black, smallSize,
00121 definition.x + 200.0f - 1.5f, h_ - definition.y + 1.5f, 0.0f,
00122 definition.description);
00123
00124 GLWFont::instance()->getNormalFont()->draw(
00125 *color, smallSize,
00126 definition.x + 200.0f, h_ - definition.y, 0.0f,
00127 definition.description);
00128 }
00129 }
00130 }
00131
00132 void StartDialog::mouseDown(int button, float x, float y, bool &skipRest)
00133 {
00134 if (selected_ != -1)
00135 {
00136 skipRest = true;
00137
00138
00139 GLWWindowManager::instance()->hideWindow(
00140 ModSelectDialog::instance()->getId());
00141 GLWWindowManager::instance()->hideWindow(
00142 ModSubSelectDialog::instance()->getId());
00143 GLWWindowManager::instance()->hideWindow(
00144 SaveSelectDialog::instance()->getId());
00145 GLWWindowManager::instance()->hideWindow(
00146 NetworkSelectDialog::instance()->getId());
00147 GLWWindowManager::instance()->hideWindow(
00148 SettingsSelectDialog::instance()->getId());
00149 GLWWindowManager::instance()->hideWindow(
00150 SettingsSubSelectDialog::instance()->getId());
00151 }
00152
00153 switch (selected_)
00154 {
00155 case 0:
00156 {
00157 std::string targetFilePath = S3D::getDataFile("data/singletutorial.xml");
00158 ClientParams::instance()->reset();
00159 ClientParams::instance()->setClientFile(targetFilePath.c_str());
00160 ClientMain::startClient();
00161 }
00162 break;
00163 case 1:
00164 GLWWindowManager::instance()->showWindow(
00165 ModSelectDialog::instance()->getId());
00166 break;
00167 case 2:
00168 GLWWindowManager::instance()->showWindow(
00169 NetworkSelectDialog::instance()->getId());
00170 break;
00171 case 3:
00172 GLWWindowManager::instance()->showWindow(
00173 SaveSelectDialog::instance()->getId());
00174 break;
00175 case 4:
00176 {
00177 S3D::showURL("http://www.scorched3d.co.uk/wiki");
00178 }
00179 break;
00180 case 5:
00181 {
00182 const char *exec =
00183 "\"https://www.paypal.com/xclick/business=donations%40"
00184 "scorched3d.co.uk&item_name=Scorched3D&no_note=1&tax=0¤cy_code=GBP\"";
00185 S3D::showURL(exec);
00186 }
00187 break;
00188 case 6:
00189 ScorchedClient::instance()->getMainLoop().exitLoop();
00190 break;
00191 }
00192 }