Accessory sorting due to price.
[scorched3d.git] / src / client / dialogs / ModSelectDialog.cpp
blobf45c90f0edd06c71967d938a1415a17914688a89
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/ModSelectDialog.h>
22 #include <dialogs/ModSubSelectDialog.h>
23 #include <dialogs/SettingsSelectDialog.h>
24 #include <GLW/GLWTextButton.h>
25 #include <GLW/GLWLabel.h>
26 #include <GLW/GLWWindowManager.h>
27 #include <GLW/GLWFont.h>
28 #include <GLW/GLWTranslate.h>
29 #include <graph/TextureStore.h>
30 #include <engine/ModDirs.h>
31 #include <common/Defines.h>
33 GLWIconListModItem::GLWIconListModItem(ModInfo &modInfo) :
34 modInfo_(modInfo),
35 tip_(ToolTip::ToolTipHelp,
36 LANG_STRING(modInfo.getShortDescription()),
37 LANG_STRING(modInfo.getDescription())),
38 icon_(0.0f, 0.0f, 40.0f, 40.0f)
40 if (S3D::fileExists(modInfo_.getIcon()))
42 GLTexture *texture = TextureStore::instance()->loadTexture(
43 modInfo_.getIcon());
44 icon_.setTexture(texture);
48 GLWIconListModItem::~GLWIconListModItem()
52 void GLWIconListModItem::draw(float x, float y, float w)
54 icon_.setX(x + 2.0f);
55 icon_.setY(y + 2.0f);
56 icon_.draw();
58 GLWToolTip::instance()->addToolTip(&tip_,
59 GLWTranslate::getPosX() + x,
60 GLWTranslate::getPosY() + y, w, 50.0f);
62 GLWFont::instance()->getGameFont()->drawWidth(
63 w - 50.0f,
64 GLWFont::widgetFontColor,
65 10.0f, x + 50.0f, y + 18.0f, 0.0f,
66 modInfo_.getShortDescription());
69 ModSelectDialog *ModSelectDialog::instance_ = 0;
71 ModSelectDialog *ModSelectDialog::instance()
73 if (!instance_)
75 instance_ = new ModSelectDialog;
77 return instance_;
80 ModSelectDialog::ModSelectDialog() :
81 GLWWindow("", 300.0f, 410.0f, 0, "")
83 iconList_ = new GLWIconList(10.0f, 40.0f, 280.0f, 360.0f, 50.0f);
84 addWidget(iconList_);
86 okId_ = addWidget(new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 235, 10, 55, this,
87 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX))->getId();
88 cancelId_ = addWidget(new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 120, 10, 105, this,
89 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX))->getId();
91 iconList_->setHandler(this);
94 ModSelectDialog::~ModSelectDialog()
99 void ModSelectDialog::display()
101 iconList_->clear();
103 ModDirs modDirs;
104 if (!modDirs.loadModDirs())
106 S3D::dialogExit("ModSelectDialog", "Failed to load mod dirs");
109 std::list<ModInfo>::iterator itor;
110 for (itor = modDirs.getDirs().begin();
111 itor != modDirs.getDirs().end();
112 itor++)
114 ModInfo &info = (*itor);
115 if (!info.getMenuEntries().empty())
117 GLWIconListModItem *item = new GLWIconListModItem(info);
118 iconList_->addItem(item);
122 // Add the info that represents a custom game
124 ModInfo customInfo("Custom");
125 customInfo.parse(S3D::getDataFile("data/custominfo.xml"));
126 GLWIconListModItem *item = new GLWIconListModItem(customInfo);
127 iconList_->addItem(item);
131 void ModSelectDialog::selected(unsigned int id, int position)
135 void ModSelectDialog::chosen(unsigned int id, int position)
137 buttonDown(okId_);
140 void ModSelectDialog::buttonDown(unsigned int id)
142 if (id == okId_)
144 GLWIconListModItem *selected =
145 (GLWIconListModItem *) iconList_->getSelected();
146 if (selected)
148 if (0 == strcmp("Custom", selected->getModInfo().getName()))
150 GLWWindowManager::instance()->showWindow(
151 SettingsSelectDialog::instance()->getId());
153 else
155 ModSubSelectDialog::instance()->setModInfo(selected->getModInfo());
156 GLWWindowManager::instance()->showWindow(
157 ModSubSelectDialog::instance()->getId());
161 else if (id == cancelId_)
163 GLWWindowManager::instance()->hideWindow(id_);