[8446] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Damian 'Mozork' Frick |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file NotificationQueueCEGUI.cc |
---|
| 31 | @brief Implementation of the NotificationQueueCEGUI class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "NotificationQueueCEGUI.h" |
---|
| 35 | |
---|
[8448] | 36 | #include <sstream> |
---|
| 37 | |
---|
[8446] | 38 | #include "core/CoreIncludes.h" |
---|
| 39 | #include "core/GameMode.h" |
---|
| 40 | #include "core/GUIManager.h" |
---|
| 41 | #include "core/LuaState.h" |
---|
| 42 | #include "util/Convert.h" |
---|
| 43 | |
---|
[8448] | 44 | #include "ToluaBindNotifications.h" |
---|
| 45 | |
---|
[8446] | 46 | namespace orxonox |
---|
| 47 | { |
---|
| 48 | |
---|
[8636] | 49 | CreateFactory(NotificationQueueCEGUI); |
---|
| 50 | |
---|
[8448] | 51 | // Register tolua_open function when loading the library. |
---|
| 52 | DeclareToluaInterface(Notifications); |
---|
| 53 | |
---|
[8450] | 54 | /*static*/ const std::string NotificationQueueCEGUI::NOTIFICATION_LAYER("NotificationLayer"); |
---|
| 55 | |
---|
[8636] | 56 | NotificationQueueCEGUI::NotificationQueueCEGUI(BaseObject* creator) : NotificationQueue(creator) |
---|
[8446] | 57 | { |
---|
| 58 | RegisterObject(NotificationQueueCEGUI); |
---|
[8448] | 59 | |
---|
[8636] | 60 | this->initialize(); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | NotificationQueueCEGUI::~NotificationQueueCEGUI() |
---|
| 64 | { |
---|
| 65 | if(GameMode::showsGraphics()) |
---|
| 66 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() + "\")"); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | @brief |
---|
| 71 | Initializes The NotificationQueueCEGUI. |
---|
| 72 | */ |
---|
| 73 | void NotificationQueueCEGUI::initialize(void) |
---|
| 74 | { |
---|
[8448] | 75 | this->displaySize_ = Vector4(1.0, 0.0, 0.0, 0.0); |
---|
| 76 | this->position_ = Vector4(0.0, 0.0, 0.0, 0.0); |
---|
| 77 | this->alignment_ = "LeftAligned"; |
---|
| 78 | this->fontSize_ = 12; |
---|
| 79 | this->fontColor_ = Vector4(1.0, 1.0, 1.0, 1.0); |
---|
| 80 | this->fontColorStr_ = "FFFFFFFF"; |
---|
[8446] | 81 | } |
---|
[8636] | 82 | |
---|
| 83 | void NotificationQueueCEGUI::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[8446] | 84 | { |
---|
[8636] | 85 | SUPER(NotificationQueueCEGUI, XMLPort, xmlelement, mode); |
---|
| 86 | |
---|
| 87 | XMLPortParam(NotificationQueueCEGUI, "position", setPosition, getPosition, xmlelement, mode); |
---|
| 88 | XMLPortParam(NotificationQueueCEGUI, "fontSize", setFontSize, getFontSize, xmlelement, mode); |
---|
| 89 | XMLPortParam(NotificationQueueCEGUI, "fontColor", setFontColor, getFontColor, xmlelement, mode); |
---|
| 90 | XMLPortParam(NotificationQueueCEGUI, "alignment", setAlignment, getAlignment, xmlelement, mode); |
---|
| 91 | XMLPortParam(NotificationQueueCEGUI, "displaySize", setDisplaySize, getDisplaySize, xmlelement, mode); |
---|
[8446] | 92 | } |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | @brief |
---|
| 96 | Destroys the NotificationQueueCEGUI. |
---|
| 97 | Used in lua and NotificationManager. |
---|
| 98 | @param noGraphics |
---|
| 99 | If this is set to true (false is default), then the queue is not removed in lua. This is used to destroy the queue, after the GUIManager has been destroyed. |
---|
| 100 | */ |
---|
| 101 | void NotificationQueueCEGUI::destroy(bool noGraphics) |
---|
| 102 | { |
---|
| 103 | // Remove the NotificationQueue in lua. |
---|
| 104 | if(GameMode::showsGraphics() && !noGraphics) |
---|
[8450] | 105 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() + "\")"); |
---|
[8446] | 106 | |
---|
| 107 | NotificationQueue::destroy(); |
---|
| 108 | } |
---|
[8448] | 109 | |
---|
[8446] | 110 | /** |
---|
| 111 | @brief |
---|
[8448] | 112 | Set the size of the window that displays the NotificationQueue. |
---|
| 113 | @param size |
---|
| 114 | The size is a vector with components: |
---|
| 115 | - The relative width of the window. (A value between 0 and 1) |
---|
| 116 | - The absolute width in pixels. (Additional to the relative width, can be negative) |
---|
| 117 | - The relative height of the window. (A value between 0 and 1) |
---|
| 118 | - The absolute height in pixels. (Additional to the relative width, can be negative.) |
---|
| 119 | If both the 3rd and 4th component of size are set to 0 the height is set such that exactly as many Notifications fit as is the maximum size of the NotificationQueue (in terms of the number of Notifications). |
---|
| 120 | */ |
---|
| 121 | void NotificationQueueCEGUI::setDisplaySize(const Vector4& size) |
---|
| 122 | { |
---|
| 123 | if(this->displaySize_ == size) |
---|
| 124 | return; |
---|
| 125 | |
---|
| 126 | if(size.x < 0.0 || size.x > 1.0 || size.z < 0.0 || size.z > 1.0) |
---|
| 127 | { |
---|
| 128 | COUT(2) << "The display size of the NotificationQueueCEGUI " << this->getName() << " was trying to be set, but the relative size was not in [0,1]. Aborting..." << endl; |
---|
| 129 | return; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | this->displaySize_ = size; |
---|
| 133 | if(size.z == 0.0 && size.w == 0.0) |
---|
[8450] | 134 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ")"); |
---|
[8448] | 135 | else |
---|
[8450] | 136 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ", " + multi_cast<std::string>(this->displaySize_.z) + ", " + multi_cast<std::string>(this->displaySize_.w) + ")"); |
---|
[8448] | 137 | } |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | @brief |
---|
| 141 | Set the position of the window that displays the NotificationQueue. |
---|
| 142 | @param position |
---|
| 143 | The position is a vector with components: |
---|
| 144 | - The relative x-position of the window. (A value between 0 and 1) |
---|
| 145 | - The absolute x-position in pixels. (Additional to the relative x-position, can be negative) |
---|
| 146 | - The relative y-position of the window. (A value between 0 and 1) |
---|
| 147 | - The absolute y-position in pixels. (Additional to the relative y-position, can be negative.) |
---|
| 148 | */ |
---|
| 149 | void NotificationQueueCEGUI::setPosition(const Vector4& position) |
---|
| 150 | { |
---|
| 151 | if(this->position_ == position) |
---|
| 152 | return; |
---|
| 153 | |
---|
| 154 | if(position.x < 0.0 || position.x > 1.0 || position.z < 0.0 || position.z > 1.0) |
---|
| 155 | { |
---|
| 156 | COUT(2) << "The position the NotificationQueueCEGUI " << this->getName() << " was trying to be set, but the relative position was not in [0,1]. Aborting..." << endl; |
---|
| 157 | return; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | this->position_ = position; |
---|
[8450] | 161 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".moveQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->position_.x) + ", " + multi_cast<std::string>(this->position_.y) + ", " + multi_cast<std::string>(this->position_.z) + ", " + multi_cast<std::string>(this->position_.w) + ")"); |
---|
[8448] | 162 | } |
---|
| 163 | |
---|
| 164 | /** |
---|
| 165 | @brief |
---|
| 166 | Set the horizontal alignment of the Notifications text. |
---|
| 167 | @param alignment |
---|
| 168 | The alignment of the Notifications, they are the possible string that the CEGUI Falagard StaticText HorzFormatting property can take. |
---|
| 169 | @see http://cegui.org.uk/api_reference/classCEGUI_1_1FalagardStaticTextProperties_1_1HorzFormatting.html |
---|
| 170 | */ |
---|
| 171 | void NotificationQueueCEGUI::setAlignment(const std::string& alignment) |
---|
| 172 | { |
---|
| 173 | if(this->alignment_ == alignment) |
---|
| 174 | return; |
---|
| 175 | |
---|
| 176 | // TODO: Check whether the alignment string is correct? |
---|
| 177 | this->alignment_ = alignment; |
---|
[8450] | 178 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueAlignment(\"" + this->getName() + "\", \"" + this->alignment_ + "\")"); |
---|
[8448] | 179 | } |
---|
| 180 | |
---|
| 181 | /** |
---|
| 182 | @brief |
---|
| 183 | Set the font size of the text displayed by this NotificationQueue. |
---|
| 184 | @param size |
---|
| 185 | The font size. |
---|
| 186 | */ |
---|
| 187 | void NotificationQueueCEGUI::setFontSize(unsigned int size) |
---|
| 188 | { |
---|
| 189 | if(this->fontSize_ == size) |
---|
| 190 | return; |
---|
| 191 | |
---|
| 192 | this->fontSize_ = size; |
---|
[8450] | 193 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueFontSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->fontSize_) + ")"); |
---|
[8448] | 194 | } |
---|
| 195 | |
---|
| 196 | /** |
---|
| 197 | @brief |
---|
| 198 | Set the font color if the text displayed by this NotificationQueue. |
---|
| 199 | @param color |
---|
| 200 | The color is a vector with the components being RGBA and taking values from 0 to 1. |
---|
| 201 | */ |
---|
| 202 | void NotificationQueueCEGUI::setFontColor(const Vector4& color) |
---|
| 203 | { |
---|
| 204 | if(this->fontColor_ == color) |
---|
| 205 | return; |
---|
| 206 | |
---|
| 207 | this->fontColor_ = color; |
---|
| 208 | // Convert to ARGB format. |
---|
| 209 | std::stringstream stream; |
---|
| 210 | for(unsigned int i = 0; i < 4; i++) |
---|
| 211 | stream << std::hex << std::setw(2) << std::setfill('0') << int(this->fontColor_[(i+3)%4]*255); |
---|
| 212 | this->fontColorStr_ = stream.str(); |
---|
[8450] | 213 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueFontColor(\"" + this->getName() + "\", \"" + this->fontColorStr_ + "\")"); |
---|
[8448] | 214 | } |
---|
| 215 | |
---|
| 216 | /** |
---|
| 217 | @brief |
---|
| 218 | Get the NotificationQueueCEGUI with the input name. |
---|
| 219 | @param name |
---|
| 220 | The name of the NotificationQueueCEGUI to be got. |
---|
| 221 | @return |
---|
| 222 | Returns a pointer to the NotificationQueueCEGUI, or NULL if it doesn't exist. |
---|
| 223 | */ |
---|
| 224 | /*static*/ NotificationQueueCEGUI* NotificationQueueCEGUI::getQueue(const std::string& name) |
---|
| 225 | { |
---|
| 226 | NotificationQueue* queue = NotificationManager::getInstance().getQueue(name); |
---|
| 227 | if(queue == NULL || !queue->isA(Class(NotificationQueueCEGUI))) |
---|
| 228 | return NULL; |
---|
| 229 | return static_cast<NotificationQueueCEGUI*>(queue); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | /** |
---|
| 233 | @brief |
---|
[8446] | 234 | Is called by the NotificationQueue when a notification was pushed. |
---|
| 235 | @param notification |
---|
| 236 | The Notification that was pushed. |
---|
| 237 | */ |
---|
| 238 | void NotificationQueueCEGUI::notificationPushed(Notification* notification) |
---|
| 239 | { |
---|
| 240 | // Push the Notification to the GUI. |
---|
| 241 | if(GameMode::showsGraphics()) |
---|
[8450] | 242 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")"); |
---|
[8446] | 243 | } |
---|
[8448] | 244 | |
---|
[8446] | 245 | /** |
---|
| 246 | @brief |
---|
| 247 | Is called by the NotificationQueue when a notification was popped. |
---|
| 248 | */ |
---|
| 249 | void NotificationQueueCEGUI::notificationPopped(void) |
---|
| 250 | { |
---|
| 251 | // Pops the Notification from the GUI. |
---|
| 252 | if(GameMode::showsGraphics()) |
---|
[8450] | 253 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".popNotification(\"" + this->getName() + "\")"); |
---|
[8446] | 254 | } |
---|
[8448] | 255 | |
---|
[8446] | 256 | /** |
---|
| 257 | @brief Is called when a notification was removed. |
---|
| 258 | @param index The index the removed notification was at. |
---|
| 259 | */ |
---|
| 260 | void NotificationQueueCEGUI::notificationRemoved(unsigned int index) |
---|
| 261 | { |
---|
| 262 | // Removes the Notification from the GUI. |
---|
| 263 | if(GameMode::showsGraphics()) |
---|
[8450] | 264 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")"); |
---|
[8446] | 265 | } |
---|
[8448] | 266 | |
---|
[8446] | 267 | /** |
---|
| 268 | @brief |
---|
| 269 | Clears the NotificationQueue by removing all NotificationContainers. |
---|
| 270 | @param noGraphics |
---|
| 271 | If this is set to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally. |
---|
| 272 | */ |
---|
| 273 | void NotificationQueueCEGUI::clear(bool noGraphics) |
---|
| 274 | { |
---|
| 275 | NotificationQueue::clear(noGraphics); |
---|
[8448] | 276 | |
---|
[8446] | 277 | // Clear the NotificationQueue in the GUI. |
---|
| 278 | if(GameMode::showsGraphics() && !noGraphics) |
---|
[8450] | 279 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".clearQueue(\"" + this->getName() + "\")"); |
---|
[8446] | 280 | } |
---|
[8448] | 281 | |
---|
[8446] | 282 | /** |
---|
| 283 | @brief |
---|
| 284 | Creates the NotificationQueue in lua. |
---|
| 285 | */ |
---|
| 286 | void NotificationQueueCEGUI::create(void) |
---|
| 287 | { |
---|
[8636] | 288 | this->NotificationQueue::create(); |
---|
| 289 | |
---|
| 290 | if(this->isRegistered() && GameMode::showsGraphics()) |
---|
[8450] | 291 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")"); |
---|
[8446] | 292 | } |
---|
| 293 | |
---|
| 294 | } |
---|
| 295 | |
---|