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