| 1 | |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 5 | |
|---|
| 6 | Copyright (C) 1004 orx |
|---|
| 7 | |
|---|
| 8 | This program is free software; you can redistribute it and/or modify |
|---|
| 9 | it under the terms of the GNU General Public License as published by |
|---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 11 | any later version. |
|---|
| 12 | |
|---|
| 13 | ### File Specific: |
|---|
| 14 | main-programmer std::string questName; |
|---|
| 15 | std::string questDescription; |
|---|
| 16 | std::string questPicture; |
|---|
| 17 | std::string questDifficulty; |
|---|
| 18 | std::string rewardDescription; |
|---|
| 19 | std::string rewardPicture;: Andreas Hejj |
|---|
| 20 | |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
|---|
| 25 | |
|---|
| 26 | #include "debug.h" |
|---|
| 27 | #include "quest_gui.h" |
|---|
| 28 | |
|---|
| 29 | #include "util/loading/load_param.h" |
|---|
| 30 | #include "util/loading/factory.h" |
|---|
| 31 | |
|---|
| 32 | #include "sound_engine.h" |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | #include "glgui.h" |
|---|
| 36 | #include "menu/glgui_imagebutton.h" |
|---|
| 37 | #include "glgui_multiline_text.h" |
|---|
| 38 | |
|---|
| 39 | #include "event_handler.h" |
|---|
| 40 | |
|---|
| 41 | #include "quest.h" |
|---|
| 42 | |
|---|
| 43 | ObjectListDefinition(QuestGUI); |
|---|
| 44 | CREATE_FACTORY(QuestGUI); |
|---|
| 45 | |
|---|
| 46 | #include "script_class.h" |
|---|
| 47 | CREATE_SCRIPTABLE_CLASS(QuestGUI, |
|---|
| 48 | addMethod("startGUI", Executor0<QuestGUI, lua_State*>(&QuestGUI::startGUI)) |
|---|
| 49 | ->addMethod("stopGUI", Executor0<QuestGUI, lua_State*>(&QuestGUI::stopGUI)) |
|---|
| 50 | ->addMethod("isActive", Executor0ret<QuestGUI, lua_State*,bool>(&QuestGUI::isActive)) |
|---|
| 51 | ); |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | QuestGUI::QuestGUI(const TiXmlElement* root) |
|---|
| 56 | { |
|---|
| 57 | this->questBox = NULL; |
|---|
| 58 | this->bKillGui = false; |
|---|
| 59 | this->bActive = false; |
|---|
| 60 | |
|---|
| 61 | if (root != NULL) |
|---|
| 62 | { |
|---|
| 63 | this->registerObject(this, QuestGUI::_objectList); |
|---|
| 64 | this->toList(OM_GROUP_00); |
|---|
| 65 | this->myQuest = new Quest(root); |
|---|
| 66 | |
|---|
| 67 | if(root) |
|---|
| 68 | this->loadParams( root); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | * deconstructor |
|---|
| 75 | */ |
|---|
| 76 | QuestGUI::~QuestGUI () |
|---|
| 77 | { |
|---|
| 78 | if( this->myQuest) |
|---|
| 79 | delete this->myQuest; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | /** |
|---|
| 83 | * loads the xml tagsthis->questDescription |
|---|
| 84 | * @param root: root xml tag for this element |
|---|
| 85 | */ |
|---|
| 86 | void QuestGUI::loadParams(const TiXmlElement* root) |
|---|
| 87 | { |
|---|
| 88 | WorldEntity::loadParams(root); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | /** |
|---|
| 94 | * initializes the gui |
|---|
| 95 | */ |
|---|
| 96 | void QuestGUI::startGUI() |
|---|
| 97 | { |
|---|
| 98 | this->bKillGui = false; |
|---|
| 99 | |
|---|
| 100 | if (questBox == NULL) |
|---|
| 101 | { |
|---|
| 102 | this->questBox= new OrxGui::GLGuiBox(OrxGui::Vertical); |
|---|
| 103 | questBox->setBorderTop(10); |
|---|
| 104 | questBox->setBorderRight(10); |
|---|
| 105 | questBox->setBorderLeft(10); |
|---|
| 106 | questBox->setBorderBottom(10); |
|---|
| 107 | this->questBox->setBackgroundTexture("textures/gui/gui_quest_border.png"); |
|---|
| 108 | |
|---|
| 109 | OrxGui::GLGuiBox* headerBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 110 | { |
|---|
| 111 | headerBox->setBackgroundTexture("textures/gui/gui_quest_border_low.png"); |
|---|
| 112 | OrxGui::GLGuiImage* questImage = new OrxGui::GLGuiImage(); |
|---|
| 113 | questImage->setWidgetSize(100, 100); |
|---|
| 114 | questImage->loadImageFromFile(this->myQuest->getQuestPicture()); |
|---|
| 115 | questImage->show(); |
|---|
| 116 | headerBox->pack(questImage); |
|---|
| 117 | |
|---|
| 118 | OrxGui::GLGuiBox* outlineBox = new OrxGui::GLGuiBox(OrxGui::Vertical); |
|---|
| 119 | { |
|---|
| 120 | OrxGui::GLGuiMultiLineText* questDetails = new OrxGui::GLGuiMultiLineText(); |
|---|
| 121 | questDetails->setText(this->myQuest->getQuestDifficulty()); |
|---|
| 122 | questDetails->append(this->myQuest->getQuestPersons()); |
|---|
| 123 | outlineBox->setBorderTop(0); |
|---|
| 124 | outlineBox->setBorderRight(0); |
|---|
| 125 | outlineBox->setBorderLeft(0); |
|---|
| 126 | outlineBox->setBorderBottom(10); |
|---|
| 127 | outlineBox->pack(questDetails); |
|---|
| 128 | } |
|---|
| 129 | headerBox->setBorderTop(0); |
|---|
| 130 | headerBox->setBorderRight(0); |
|---|
| 131 | headerBox->setBorderLeft(0); |
|---|
| 132 | headerBox->setBorderBottom(10); |
|---|
| 133 | headerBox->pack(outlineBox); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | OrxGui::GLGuiBox* labelBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 137 | { |
|---|
| 138 | labelBox->setBackgroundTexture("textures/gui/gui_quest_border_low.png"); |
|---|
| 139 | OrxGui::GLGuiMultiLineText* questTxt = new OrxGui::GLGuiMultiLineText(); |
|---|
| 140 | questTxt->setText(this->myQuest->getQuestDescription()); |
|---|
| 141 | labelBox->pack(questTxt); |
|---|
| 142 | |
|---|
| 143 | OrxGui::GLGuiImage* placeImage = new OrxGui::GLGuiImage(); |
|---|
| 144 | placeImage->setWidgetSize(85, 10); |
|---|
| 145 | placeImage->loadImageFromFile("textures/gui/gui_quest_black.png"); |
|---|
| 146 | placeImage->show(); |
|---|
| 147 | labelBox->pack(placeImage); |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | labelBox->setBorderTop(0); |
|---|
| 151 | labelBox->setBorderRight(0); |
|---|
| 152 | labelBox->setBorderLeft(55); |
|---|
| 153 | labelBox->setBorderBottom(10); |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | OrxGui::GLGuiBox* rewardBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 158 | { |
|---|
| 159 | rewardBox->setBackgroundTexture("textures/gui/gui_quest_border_low.png"); |
|---|
| 160 | OrxGui::GLGuiImage* rewardImage = new OrxGui::GLGuiImage(); |
|---|
| 161 | rewardImage->setWidgetSize(100, 100); |
|---|
| 162 | rewardImage->loadImageFromFile(this->myQuest->getRewardPicture()); |
|---|
| 163 | rewardImage->show(); |
|---|
| 164 | rewardBox->pack(rewardImage); |
|---|
| 165 | |
|---|
| 166 | OrxGui::GLGuiMultiLineText* rewardTxt = new OrxGui::GLGuiMultiLineText(); |
|---|
| 167 | rewardTxt->setText(this->myQuest->getRewardDescription()); |
|---|
| 168 | rewardBox->setBorderTop(0); |
|---|
| 169 | rewardBox->setBorderRight(0); |
|---|
| 170 | rewardBox->setBorderLeft(0); |
|---|
| 171 | rewardBox->setBorderBottom(10); |
|---|
| 172 | rewardBox->pack(rewardTxt); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | OrxGui::GLGuiBox* answerBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 176 | { |
|---|
| 177 | OrxGui::GLGuiImage* placeImage = new OrxGui::GLGuiImage(); |
|---|
| 178 | placeImage->setWidgetSize(20, 10); |
|---|
| 179 | placeImage->loadImageFromFile("textures/gui/gui_quest_black.png"); |
|---|
| 180 | placeImage->show(); |
|---|
| 181 | answerBox->pack(placeImage); |
|---|
| 182 | |
|---|
| 183 | OrxGui::GLGuiBox* acceptBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 184 | { |
|---|
| 185 | //acceptBox->setBackgroundTexture("maps/accept.png"); |
|---|
| 186 | acceptBox->setBackgroundTexture("textures/gui/gui_quest_accept.gif", OrxGui::Normal); |
|---|
| 187 | //acceptBox->setBackgroundTexture("maps/gui_quest_acceptrout.png", OrxGui::Selected); |
|---|
| 188 | OrxGui::GLGuiButton* acceptButton = new OrxGui::GLGuiPushButton(" "); |
|---|
| 189 | acceptButton->released.connect(this, &QuestGUI::accept); |
|---|
| 190 | acceptBox->setBorderTop(7); |
|---|
| 191 | acceptBox->setBorderRight(7); |
|---|
| 192 | acceptBox->setBorderLeft(7); |
|---|
| 193 | acceptBox->setBorderBottom(7); |
|---|
| 194 | acceptBox->pack(acceptButton); |
|---|
| 195 | } |
|---|
| 196 | answerBox->pack(acceptBox); |
|---|
| 197 | |
|---|
| 198 | OrxGui::GLGuiImage* placeImage2 = new OrxGui::GLGuiImage(); |
|---|
| 199 | placeImage2->setWidgetSize(300, 10); |
|---|
| 200 | placeImage2->loadImageFromFile("textures/gui/gui_quest_black.png"); |
|---|
| 201 | placeImage2->show(); |
|---|
| 202 | answerBox->pack(placeImage2); |
|---|
| 203 | |
|---|
| 204 | OrxGui::GLGuiBox* refuseBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 205 | { |
|---|
| 206 | refuseBox->setBackgroundTexture("textures/gui/gui_quest_refuserout.gif"); |
|---|
| 207 | OrxGui::GLGuiButton* refuseButton = new OrxGui::GLGuiPushButton(" "); |
|---|
| 208 | refuseButton->released.connect(this, &QuestGUI::refuse); |
|---|
| 209 | refuseBox->setBorderTop(7); |
|---|
| 210 | refuseBox->setBorderRight(7); |
|---|
| 211 | refuseBox->setBorderLeft(7); |
|---|
| 212 | refuseBox->setBorderBottom(7); |
|---|
| 213 | refuseBox->pack(refuseButton); |
|---|
| 214 | } |
|---|
| 215 | answerBox->setBorderTop(15); |
|---|
| 216 | answerBox->setBorderRight(0); |
|---|
| 217 | answerBox->setBorderLeft(0); |
|---|
| 218 | answerBox->setBorderBottom(20); |
|---|
| 219 | answerBox->pack(refuseBox); |
|---|
| 220 | } |
|---|
| 221 | this->questBox->pack(headerBox); |
|---|
| 222 | this->questBox->pack(labelBox); |
|---|
| 223 | this->questBox->pack(rewardBox); |
|---|
| 224 | this->questBox->pack(answerBox); |
|---|
| 225 | this->questBox->showAll(); |
|---|
| 226 | |
|---|
| 227 | this->questBox->setAbsCoor2D(300, 100); |
|---|
| 228 | |
|---|
| 229 | OrxGui::GLGuiHandler::getInstance()->activate(); |
|---|
| 230 | OrxGui::GLGuiHandler::getInstance()->activateCursor(); |
|---|
| 231 | EventHandler::getInstance()->pushState( ES_MENU); |
|---|
| 232 | } |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | void QuestGUI::stopGUI() |
|---|
| 236 | { |
|---|
| 237 | this->bKillGui = true; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | void QuestGUI::tick(float dt) |
|---|
| 242 | { |
|---|
| 243 | if( this->bKillGui) |
|---|
| 244 | this->killgui(); |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | void QuestGUI::accept() |
|---|
| 249 | { |
|---|
| 250 | this->myQuest->setQuestActive(); |
|---|
| 251 | this->bKillGui = true; |
|---|
| 252 | bActive=true; |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | void QuestGUI::refuse() |
|---|
| 256 | { |
|---|
| 257 | this->bKillGui = true; |
|---|
| 258 | bActive=false; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | void QuestGUI::killgui() |
|---|
| 262 | { |
|---|
| 263 | OrxGui::GLGuiHandler::getInstance()->deactivate(); |
|---|
| 264 | OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); |
|---|
| 265 | EventHandler::getInstance()->popState(); |
|---|
| 266 | delete this->questBox; |
|---|
| 267 | this->questBox = NULL; |
|---|
| 268 | this->bKillGui = false; |
|---|
| 269 | //this->bActive = false; |
|---|
| 270 | } |
|---|