00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <dialogs/ModSelectDialog.h>
00022 #include <dialogs/ModSubSelectDialog.h>
00023 #include <dialogs/SettingsSelectDialog.h>
00024 #include <GLW/GLWTextButton.h>
00025 #include <GLW/GLWLabel.h>
00026 #include <GLW/GLWWindowManager.h>
00027 #include <GLW/GLWFont.h>
00028 #include <GLW/GLWTranslate.h>
00029 #include <graph/TextureStore.h>
00030 #include <engine/ModDirs.h>
00031 #include <common/Defines.h>
00032
00033 GLWIconListModItem::GLWIconListModItem(ModInfo &modInfo) :
00034 modInfo_(modInfo),
00035 tip_(ToolTip::ToolTipHelp,
00036 LANG_STRING(modInfo.getShortDescription()),
00037 LANG_STRING(modInfo.getDescription())),
00038 icon_(0.0f, 0.0f, 40.0f, 40.0f)
00039 {
00040 if (S3D::fileExists(modInfo_.getIcon()))
00041 {
00042 GLTexture *texture = TextureStore::instance()->loadTexture(
00043 modInfo_.getIcon());
00044 icon_.setTexture(texture);
00045 }
00046 }
00047
00048 GLWIconListModItem::~GLWIconListModItem()
00049 {
00050 }
00051
00052 void GLWIconListModItem::draw(float x, float y, float w)
00053 {
00054 icon_.setX(x + 2.0f);
00055 icon_.setY(y + 2.0f);
00056 icon_.draw();
00057
00058 GLWToolTip::instance()->addToolTip(&tip_,
00059 GLWTranslate::getPosX() + x,
00060 GLWTranslate::getPosY() + y, w, 50.0f);
00061
00062 GLWFont::instance()->getGameFont()->drawWidth(
00063 w - 50.0f,
00064 GLWFont::widgetFontColor,
00065 10.0f, x + 50.0f, y + 18.0f, 0.0f,
00066 modInfo_.getShortDescription());
00067 }
00068
00069 ModSelectDialog *ModSelectDialog::instance_ = 0;
00070
00071 ModSelectDialog *ModSelectDialog::instance()
00072 {
00073 if (!instance_)
00074 {
00075 instance_ = new ModSelectDialog;
00076 }
00077 return instance_;
00078 }
00079
00080 ModSelectDialog::ModSelectDialog() :
00081 GLWWindow("", 300.0f, 410.0f, 0, "")
00082 {
00083 iconList_ = new GLWIconList(10.0f, 40.0f, 280.0f, 360.0f, 50.0f);
00084 addWidget(iconList_);
00085
00086 okId_ = addWidget(new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 235, 10, 55, this,
00087 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX))->getId();
00088 cancelId_ = addWidget(new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 120, 10, 105, this,
00089 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX))->getId();
00090
00091 iconList_->setHandler(this);
00092 }
00093
00094 ModSelectDialog::~ModSelectDialog()
00095 {
00096
00097 }
00098
00099 void ModSelectDialog::display()
00100 {
00101 iconList_->clear();
00102
00103 ModDirs modDirs;
00104 if (!modDirs.loadModDirs())
00105 {
00106 S3D::dialogExit("ModSelectDialog", "Failed to load mod dirs");
00107 }
00108
00109 std::list<ModInfo>::iterator itor;
00110 for (itor = modDirs.getDirs().begin();
00111 itor != modDirs.getDirs().end();
00112 itor++)
00113 {
00114 ModInfo &info = (*itor);
00115 if (!info.getMenuEntries().empty())
00116 {
00117 GLWIconListModItem *item = new GLWIconListModItem(info);
00118 iconList_->addItem(item);
00119 }
00120 }
00121
00122
00123 {
00124 ModInfo customInfo("Custom");
00125 customInfo.parse(S3D::getDataFile("data/custominfo.xml"));
00126 GLWIconListModItem *item = new GLWIconListModItem(customInfo);
00127 iconList_->addItem(item);
00128 }
00129 }
00130
00131 void ModSelectDialog::selected(unsigned int id, int position)
00132 {
00133 }
00134
00135 void ModSelectDialog::chosen(unsigned int id, int position)
00136 {
00137 buttonDown(okId_);
00138 }
00139
00140 void ModSelectDialog::buttonDown(unsigned int id)
00141 {
00142 if (id == okId_)
00143 {
00144 GLWIconListModItem *selected =
00145 (GLWIconListModItem *) iconList_->getSelected();
00146 if (selected)
00147 {
00148 if (0 == strcmp("Custom", selected->getModInfo().getName()))
00149 {
00150 GLWWindowManager::instance()->showWindow(
00151 SettingsSelectDialog::instance()->getId());
00152 }
00153 else
00154 {
00155 ModSubSelectDialog::instance()->setModInfo(selected->getModInfo());
00156 GLWWindowManager::instance()->showWindow(
00157 ModSubSelectDialog::instance()->getId());
00158 }
00159 }
00160 }
00161 else if (id == cancelId_)
00162 {
00163 GLWWindowManager::instance()->hideWindow(id_);
00164 }
00165 }