| 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 | //SHELL_COMMAND(cancel, QuestGUI, guiDestruct); |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | #include "script_class.h" |
|---|
| 61 | CREATE_SCRIPTABLE_CLASS(QuestGUI, |
|---|
| 62 | addMethod("guiInit", Executor0<QuestGUI, lua_State*>(&QuestGUI::guiInit)) |
|---|
| 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->background = "maps/rand2.png"; |
|---|
| 80 | |
|---|
| 81 | this->backgroundBottom = "maps/rand-untent.png"; |
|---|
| 82 | |
|---|
| 83 | this->myQuest = new Quest(root); |
|---|
| 84 | if(root) |
|---|
| 85 | this->loadParams( root); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | /** |
|---|
| 91 | * deconstructor |
|---|
| 92 | */ |
|---|
| 93 | QuestGUI::~QuestGUI () |
|---|
| 94 | { |
|---|
| 95 | if( this->myQuest) |
|---|
| 96 | delete this->myQuest; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | /** |
|---|
| 100 | * loads the xml tagsthis->questDescription |
|---|
| 101 | * @param root: root xml tag for this element |
|---|
| 102 | */ |
|---|
| 103 | void QuestGUI::loadParams(const TiXmlElement* root) |
|---|
| 104 | { |
|---|
| 105 | WorldEntity::loadParams(root); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | /** |
|---|
| 111 | * initializes the gui |
|---|
| 112 | */ |
|---|
| 113 | void QuestGUI::guiInit() |
|---|
| 114 | { |
|---|
| 115 | if (questBox == NULL) |
|---|
| 116 | { |
|---|
| 117 | this->questBox= new OrxGui::GLGuiBox(OrxGui::Vertical); |
|---|
| 118 | questBox->setBorderTop(10); |
|---|
| 119 | questBox->setBorderRight(10); |
|---|
| 120 | questBox->setBorderLeft(10); |
|---|
| 121 | questBox->setBorderBottom(10); |
|---|
| 122 | this->questBox->setBackgroundTexture(background); |
|---|
| 123 | this->bKillGui = false; |
|---|
| 124 | |
|---|
| 125 | OrxGui::GLGuiBox* headerBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 126 | { |
|---|
| 127 | headerBox->setBackgroundTexture(backgroundBottom); |
|---|
| 128 | OrxGui::GLGuiImage* questImage = new OrxGui::GLGuiImage(); |
|---|
| 129 | questImage->setWidgetSize(100, 100); |
|---|
| 130 | questImage->loadImageFromFile(this->myQuest->getQuestPicture()); |
|---|
| 131 | questImage->show(); |
|---|
| 132 | headerBox->pack(questImage); |
|---|
| 133 | |
|---|
| 134 | OrxGui::GLGuiBox* outlineBox = new OrxGui::GLGuiBox(OrxGui::Vertical); |
|---|
| 135 | { |
|---|
| 136 | OrxGui::GLGuiMultiLineText* questDetails = new OrxGui::GLGuiMultiLineText(); |
|---|
| 137 | questDetails->setText(this->myQuest->getQuestDifficulty()); |
|---|
| 138 | questDetails->append(this->myQuest->getQuestPersons()); |
|---|
| 139 | outlineBox->setBorderTop(0); |
|---|
| 140 | outlineBox->setBorderRight(0); |
|---|
| 141 | outlineBox->setBorderLeft(0); |
|---|
| 142 | outlineBox->setBorderBottom(10); |
|---|
| 143 | outlineBox->pack(questDetails); |
|---|
| 144 | } |
|---|
| 145 | headerBox->setBorderTop(0); |
|---|
| 146 | headerBox->setBorderRight(0); |
|---|
| 147 | headerBox->setBorderLeft(0); |
|---|
| 148 | headerBox->setBorderBottom(10); |
|---|
| 149 | headerBox->pack(outlineBox); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | OrxGui::GLGuiBox* labelBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 153 | { |
|---|
| 154 | labelBox->setWidgetSize(500,500); |
|---|
| 155 | labelBox->setBackgroundTexture(backgroundBottom); |
|---|
| 156 | OrxGui::GLGuiMultiLineText* questTxt = new OrxGui::GLGuiMultiLineText(); |
|---|
| 157 | questTxt->setText(this->myQuest->getQuestDescription()); |
|---|
| 158 | //questTxt->setLineWidth( 400); |
|---|
| 159 | labelBox->pack(questTxt); |
|---|
| 160 | labelBox->setBorderTop(0); |
|---|
| 161 | labelBox->setBorderRight(0); |
|---|
| 162 | labelBox->setBorderLeft(40); |
|---|
| 163 | labelBox->setBorderBottom(10); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | OrxGui::GLGuiBox* rewardBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 168 | { |
|---|
| 169 | OrxGui::GLGuiImage* rewardImage = new OrxGui::GLGuiImage(); |
|---|
| 170 | rewardImage->setWidgetSize(100, 100); |
|---|
| 171 | rewardImage->loadImageFromFile(this->myQuest->getRewardPicture()); |
|---|
| 172 | rewardImage->show(); |
|---|
| 173 | rewardBox->pack(rewardImage); |
|---|
| 174 | |
|---|
| 175 | OrxGui::GLGuiMultiLineText* rewardTxt = new OrxGui::GLGuiMultiLineText(); |
|---|
| 176 | rewardTxt->setText(this->myQuest->getRewardDescription()); |
|---|
| 177 | rewardBox->setBorderTop(0); |
|---|
| 178 | rewardBox->setBorderRight(0); |
|---|
| 179 | rewardBox->setBorderLeft(0); |
|---|
| 180 | rewardBox->setBorderBottom(10); |
|---|
| 181 | rewardBox->pack(rewardTxt); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | OrxGui::GLGuiBox* answerBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 185 | { |
|---|
| 186 | OrxGui::GLGuiBox* acceptBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 187 | { |
|---|
| 188 | OrxGui::GLGuiButton* acceptButton = new OrxGui::GLGuiPushButton("Accept"); |
|---|
| 189 | acceptButton->released.connect(this, &QuestGUI::accept); |
|---|
| 190 | acceptBox->setBorderLeft(50); |
|---|
| 191 | acceptBox->setBorderRight(150); |
|---|
| 192 | acceptBox->pack(acceptButton); |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | OrxGui::GLGuiBox* refuseBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
|---|
| 196 | { |
|---|
| 197 | OrxGui::GLGuiButton* refuseButton = new OrxGui::GLGuiPushButton("Refuse"); |
|---|
| 198 | refuseButton->released.connect(this, &QuestGUI::refuse); |
|---|
| 199 | refuseBox->setBorderLeft(0); |
|---|
| 200 | refuseBox->pack(refuseButton); |
|---|
| 201 | } |
|---|
| 202 | answerBox->setBorderTop(0); |
|---|
| 203 | answerBox->setBorderRight(0); |
|---|
| 204 | answerBox->setBorderLeft(0); |
|---|
| 205 | answerBox->setBorderBottom(0); |
|---|
| 206 | answerBox->pack(acceptBox); |
|---|
| 207 | answerBox->pack(refuseBox); |
|---|
| 208 | } |
|---|
| 209 | this->questBox->pack(headerBox); |
|---|
| 210 | this->questBox->pack(labelBox); |
|---|
| 211 | this->questBox->pack(rewardBox); |
|---|
| 212 | this->questBox->pack(answerBox); |
|---|
| 213 | this->questBox->showAll(); |
|---|
| 214 | |
|---|
| 215 | this->questBox->setAbsCoor2D(300, 100); |
|---|
| 216 | OrxGui::GLGuiHandler::getInstance()->activate(); |
|---|
| 217 | OrxGui::GLGuiHandler::getInstance()->activateCursor(); |
|---|
| 218 | } |
|---|
| 219 | else |
|---|
| 220 | { |
|---|
| 221 | this->bKillGui = true; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | void QuestGUI::tick(float dt) |
|---|
| 228 | { |
|---|
| 229 | if( this->bKillGui) |
|---|
| 230 | this->killgui(); |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | void QuestGUI::accept() |
|---|
| 235 | { |
|---|
| 236 | this->myQuest->setQuestActive(); |
|---|
| 237 | this->bKillGui = true; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | void QuestGUI::refuse() |
|---|
| 241 | { |
|---|
| 242 | this->bKillGui = true; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | void QuestGUI::killgui() |
|---|
| 246 | { |
|---|
| 247 | OrxGui::GLGuiHandler::getInstance()->deactivate(); |
|---|
| 248 | OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); |
|---|
| 249 | delete this->questBox; |
|---|
| 250 | this->questBox = NULL; |
|---|
| 251 | } |
|---|