| 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 "event_handler.h" | 
|---|
| 30 |  | 
|---|
| 31 | #include "state.h" | 
|---|
| 32 |  | 
|---|
| 33 | #include "util/loading/load_param.h" | 
|---|
| 34 | #include "util/loading/factory.h" | 
|---|
| 35 |  | 
|---|
| 36 | #include "graphics_engine.h" | 
|---|
| 37 | #include "camera.h" | 
|---|
| 38 | #include "sound_engine.h" | 
|---|
| 39 |  | 
|---|
| 40 | #include "sound_source.h" | 
|---|
| 41 |  | 
|---|
| 42 | #include "glgui_widget.h" | 
|---|
| 43 | #include "glgui.h" | 
|---|
| 44 | #include "menu/glgui_imagebutton.h" | 
|---|
| 45 | #include "glgui_multiline_text.h" | 
|---|
| 46 | #include <glgui_image.h> | 
|---|
| 47 |  | 
|---|
| 48 |  | 
|---|
| 49 | #include "quest.h" | 
|---|
| 50 |  | 
|---|
| 51 | #include "shell_command.h" | 
|---|
| 52 |  | 
|---|
| 53 | ObjectListDefinition(QuestGUI); | 
|---|
| 54 |  | 
|---|
| 55 | CREATE_FACTORY(QuestGUI); | 
|---|
| 56 | SHELL_COMMAND(gui, QuestGUI, guiInit); | 
|---|
| 57 |  | 
|---|
| 58 |  | 
|---|
| 59 | #include "script_class.h" | 
|---|
| 60 | CREATE_SCRIPTABLE_CLASS(QuestGUI, | 
|---|
| 61 |                         addMethod("guiInit", Executor0<QuestGUI, lua_State*>(&QuestGUI::guiInit)) | 
|---|
| 62 |                         ->addMethod("isActive", Executor0ret<QuestGUI, lua_State*,bool>(&QuestGUI::isActive)) | 
|---|
| 63 |                        ); | 
|---|
| 64 |  | 
|---|
| 65 |  | 
|---|
| 66 |  | 
|---|
| 67 | QuestGUI::QuestGUI(const TiXmlElement* root) | 
|---|
| 68 | { | 
|---|
| 69 |   if (root != NULL) | 
|---|
| 70 |   { | 
|---|
| 71 |   this->registerObject(this, QuestGUI::_objectList); | 
|---|
| 72 |  | 
|---|
| 73 |   this->toList(OM_GROUP_00); | 
|---|
| 74 |  | 
|---|
| 75 |   this->questBox = NULL; | 
|---|
| 76 |  | 
|---|
| 77 |   this->bKillGui = false; | 
|---|
| 78 |  | 
|---|
| 79 |   this->bActive = false; | 
|---|
| 80 |  | 
|---|
| 81 |   this->myQuest = new Quest(root); | 
|---|
| 82 |   if(root) | 
|---|
| 83 |     this->loadParams( root); | 
|---|
| 84 |   } | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 |  | 
|---|
| 88 | /** | 
|---|
| 89 |  * deconstructor | 
|---|
| 90 |  */ | 
|---|
| 91 | QuestGUI::~QuestGUI () | 
|---|
| 92 | { | 
|---|
| 93 |   if( this->myQuest) | 
|---|
| 94 |     delete this->myQuest; | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | /** | 
|---|
| 98 |  * loads the xml tagsthis->questDescription | 
|---|
| 99 |  * @param root: root xml tag for this element | 
|---|
| 100 |  */ | 
|---|
| 101 | void QuestGUI::loadParams(const TiXmlElement* root) | 
|---|
| 102 | { | 
|---|
| 103 |   WorldEntity::loadParams(root); | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 |  | 
|---|
| 107 |  | 
|---|
| 108 | /** | 
|---|
| 109 |  * initializes the gui | 
|---|
| 110 |  */ | 
|---|
| 111 | void QuestGUI::guiInit() | 
|---|
| 112 | { | 
|---|
| 113 |   if (questBox == NULL) | 
|---|
| 114 |   { | 
|---|
| 115 |     this->questBox= new OrxGui::GLGuiBox(OrxGui::Vertical); | 
|---|
| 116 |     questBox->setBorderTop(10); | 
|---|
| 117 |     questBox->setBorderRight(10); | 
|---|
| 118 |     questBox->setBorderLeft(10); | 
|---|
| 119 |     questBox->setBorderBottom(10); | 
|---|
| 120 |     this->questBox->setBackgroundTexture("textures/gui/gui_quest_border.png"); | 
|---|
| 121 |     this->bKillGui = false; | 
|---|
| 122 |  | 
|---|
| 123 |     OrxGui::GLGuiBox* headerBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); | 
|---|
| 124 |     { | 
|---|
| 125 |       headerBox->setBackgroundTexture("textures/gui/gui_quest_border_low.png"); | 
|---|
| 126 |       OrxGui::GLGuiImage* questImage = new OrxGui::GLGuiImage(); | 
|---|
| 127 |       questImage->setWidgetSize(100, 100); | 
|---|
| 128 |       questImage->loadImageFromFile(this->myQuest->getQuestPicture()); | 
|---|
| 129 |       questImage->show(); | 
|---|
| 130 |       headerBox->pack(questImage); | 
|---|
| 131 |  | 
|---|
| 132 |       OrxGui::GLGuiBox* outlineBox = new OrxGui::GLGuiBox(OrxGui::Vertical); | 
|---|
| 133 |       { | 
|---|
| 134 |         OrxGui::GLGuiMultiLineText* questDetails = new OrxGui::GLGuiMultiLineText(); | 
|---|
| 135 |         questDetails->setText(this->myQuest->getQuestDifficulty()); | 
|---|
| 136 |         questDetails->append(this->myQuest->getQuestPersons()); | 
|---|
| 137 |         outlineBox->setBorderTop(0); | 
|---|
| 138 |         outlineBox->setBorderRight(0); | 
|---|
| 139 |         outlineBox->setBorderLeft(0); | 
|---|
| 140 |         outlineBox->setBorderBottom(10); | 
|---|
| 141 |         outlineBox->pack(questDetails); | 
|---|
| 142 |       } | 
|---|
| 143 |       headerBox->setBorderTop(0); | 
|---|
| 144 |       headerBox->setBorderRight(0); | 
|---|
| 145 |       headerBox->setBorderLeft(0); | 
|---|
| 146 |       headerBox->setBorderBottom(10); | 
|---|
| 147 |       headerBox->pack(outlineBox); | 
|---|
| 148 |     } | 
|---|
| 149 |  | 
|---|
| 150 |     OrxGui::GLGuiBox* labelBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); | 
|---|
| 151 |     { | 
|---|
| 152 |       labelBox->setBackgroundTexture("textures/gui/gui_quest_border_low.png"); | 
|---|
| 153 |       OrxGui::GLGuiMultiLineText* questTxt = new OrxGui::GLGuiMultiLineText(); | 
|---|
| 154 |       questTxt->setText(this->myQuest->getQuestDescription()); | 
|---|
| 155 |       labelBox->pack(questTxt); | 
|---|
| 156 |  | 
|---|
| 157 |       OrxGui::GLGuiImage* placeImage = new OrxGui::GLGuiImage(); | 
|---|
| 158 |       placeImage->setWidgetSize(85, 10); | 
|---|
| 159 |       placeImage->loadImageFromFile("maps/schwarz.png"); | 
|---|
| 160 |       placeImage->show(); | 
|---|
| 161 |       labelBox->pack(placeImage); | 
|---|
| 162 |  | 
|---|
| 163 |  | 
|---|
| 164 |       labelBox->setBorderTop(0); | 
|---|
| 165 |       labelBox->setBorderRight(0); | 
|---|
| 166 |       labelBox->setBorderLeft(55); | 
|---|
| 167 |       labelBox->setBorderBottom(10); | 
|---|
| 168 |     } | 
|---|
| 169 |  | 
|---|
| 170 |  | 
|---|
| 171 |     OrxGui::GLGuiBox* rewardBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); | 
|---|
| 172 |     { | 
|---|
| 173 |       rewardBox->setBackgroundTexture("textures/gui/gui_quest_border_low.png"); | 
|---|
| 174 |       OrxGui::GLGuiImage* rewardImage = new OrxGui::GLGuiImage(); | 
|---|
| 175 |       rewardImage->setWidgetSize(100, 100); | 
|---|
| 176 |       rewardImage->loadImageFromFile(this->myQuest->getRewardPicture()); | 
|---|
| 177 |       rewardImage->show(); | 
|---|
| 178 |       rewardBox->pack(rewardImage); | 
|---|
| 179 |  | 
|---|
| 180 |       OrxGui::GLGuiMultiLineText* rewardTxt = new OrxGui::GLGuiMultiLineText(); | 
|---|
| 181 |       rewardTxt->setText(this->myQuest->getRewardDescription()); | 
|---|
| 182 |       rewardBox->setBorderTop(0); | 
|---|
| 183 |       rewardBox->setBorderRight(0); | 
|---|
| 184 |       rewardBox->setBorderLeft(0); | 
|---|
| 185 |       rewardBox->setBorderBottom(10); | 
|---|
| 186 |       rewardBox->pack(rewardTxt); | 
|---|
| 187 |     } | 
|---|
| 188 |  | 
|---|
| 189 |     OrxGui::GLGuiBox* answerBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); | 
|---|
| 190 |     { | 
|---|
| 191 |       OrxGui::GLGuiImage* placeImage = new OrxGui::GLGuiImage(); | 
|---|
| 192 |       placeImage->setWidgetSize(20, 10); | 
|---|
| 193 |       placeImage->loadImageFromFile("maps/schwarz.png"); | 
|---|
| 194 |       placeImage->show(); | 
|---|
| 195 |       answerBox->pack(placeImage); | 
|---|
| 196 |  | 
|---|
| 197 |       OrxGui::GLGuiBox* acceptBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); | 
|---|
| 198 |       { | 
|---|
| 199 |         //acceptBox->setBackgroundTexture("maps/accept.png"); | 
|---|
| 200 |         acceptBox->setBackgroundTexture("textures/gui/gui_quest_accept.jpg", OrxGui::Normal); | 
|---|
| 201 |         //acceptBox->setBackgroundTexture("maps/gui_quest_acceptrout.png", OrxGui::Selected); | 
|---|
| 202 |         OrxGui::GLGuiButton* acceptButton = new OrxGui::GLGuiPushButton("        "); | 
|---|
| 203 |         acceptButton->released.connect(this, &QuestGUI::accept); | 
|---|
| 204 |         acceptBox->setBorderTop(7); | 
|---|
| 205 |         acceptBox->setBorderRight(7); | 
|---|
| 206 |         acceptBox->setBorderLeft(7); | 
|---|
| 207 |         acceptBox->setBorderBottom(7); | 
|---|
| 208 |         acceptBox->pack(acceptButton); | 
|---|
| 209 |       } | 
|---|
| 210 |       answerBox->pack(acceptBox); | 
|---|
| 211 |  | 
|---|
| 212 |       OrxGui::GLGuiImage* placeImage2 = new OrxGui::GLGuiImage(); | 
|---|
| 213 |       placeImage2->setWidgetSize(300, 10); | 
|---|
| 214 |       placeImage2->loadImageFromFile("textures/gui/gui_quest_black.png"); | 
|---|
| 215 |       placeImage2->show(); | 
|---|
| 216 |       answerBox->pack(placeImage2); | 
|---|
| 217 |  | 
|---|
| 218 |       OrxGui::GLGuiBox* refuseBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); | 
|---|
| 219 |       { | 
|---|
| 220 |         refuseBox->setBackgroundTexture("textures/gui/gui_quest_refuserout.gif"); | 
|---|
| 221 |         OrxGui::GLGuiButton* refuseButton = new OrxGui::GLGuiPushButton("        "); | 
|---|
| 222 |         refuseButton->released.connect(this, &QuestGUI::refuse); | 
|---|
| 223 |         refuseBox->setBorderTop(7); | 
|---|
| 224 |         refuseBox->setBorderRight(7); | 
|---|
| 225 |         refuseBox->setBorderLeft(7); | 
|---|
| 226 |         refuseBox->setBorderBottom(7); | 
|---|
| 227 |         refuseBox->pack(refuseButton); | 
|---|
| 228 |       } | 
|---|
| 229 |       answerBox->setBorderTop(15); | 
|---|
| 230 |       answerBox->setBorderRight(0); | 
|---|
| 231 |       answerBox->setBorderLeft(0); | 
|---|
| 232 |       answerBox->setBorderBottom(20); | 
|---|
| 233 |       answerBox->pack(refuseBox); | 
|---|
| 234 |     } | 
|---|
| 235 |     this->questBox->pack(headerBox); | 
|---|
| 236 |     this->questBox->pack(labelBox); | 
|---|
| 237 |     this->questBox->pack(rewardBox); | 
|---|
| 238 |     this->questBox->pack(answerBox); | 
|---|
| 239 |     this->questBox->showAll(); | 
|---|
| 240 |  | 
|---|
| 241 |     this->questBox->setAbsCoor2D(300, 100); | 
|---|
| 242 |     OrxGui::GLGuiHandler::getInstance()->activate(); | 
|---|
| 243 |     OrxGui::GLGuiHandler::getInstance()->activateCursor(); | 
|---|
| 244 |   } | 
|---|
| 245 |   else | 
|---|
| 246 |   { | 
|---|
| 247 |     this->bKillGui = true; | 
|---|
| 248 |   } | 
|---|
| 249 |  | 
|---|
| 250 | } | 
|---|
| 251 |  | 
|---|
| 252 |  | 
|---|
| 253 | void QuestGUI::tick(float dt) | 
|---|
| 254 | { | 
|---|
| 255 |   if( this->bKillGui) | 
|---|
| 256 |     this->killgui(); | 
|---|
| 257 | } | 
|---|
| 258 |  | 
|---|
| 259 |  | 
|---|
| 260 | void QuestGUI::accept() | 
|---|
| 261 | { | 
|---|
| 262 |   this->myQuest->setQuestActive(); | 
|---|
| 263 |   this->bKillGui = true; | 
|---|
| 264 |   bActive=true; | 
|---|
| 265 | } | 
|---|
| 266 |  | 
|---|
| 267 | void QuestGUI::refuse() | 
|---|
| 268 | { | 
|---|
| 269 |   this->bKillGui = true; | 
|---|
| 270 |   bActive=false; | 
|---|
| 271 | } | 
|---|
| 272 |  | 
|---|
| 273 | void QuestGUI::killgui() | 
|---|
| 274 | { | 
|---|
| 275 |   OrxGui::GLGuiHandler::getInstance()->deactivate(); | 
|---|
| 276 |   OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); | 
|---|
| 277 |   delete this->questBox; | 
|---|
| 278 |   this->questBox = NULL; | 
|---|
| 279 |   this->bKillGui = false; | 
|---|
| 280 | } | 
|---|