[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 | |
---|
[8448] | 49 | // Register tolua_open function when loading the library. |
---|
| 50 | DeclareToluaInterface(Notifications); |
---|
| 51 | |
---|
[8450] | 52 | /*static*/ const std::string NotificationQueueCEGUI::NOTIFICATION_LAYER("NotificationLayer"); |
---|
| 53 | |
---|
[8446] | 54 | NotificationQueueCEGUI::NotificationQueueCEGUI(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime) : NotificationQueue(name, senders, size, displayTime) |
---|
| 55 | { |
---|
| 56 | RegisterObject(NotificationQueueCEGUI); |
---|
[8448] | 57 | |
---|
| 58 | this->displaySize_ = Vector4(1.0, 0.0, 0.0, 0.0); |
---|
| 59 | this->position_ = Vector4(0.0, 0.0, 0.0, 0.0); |
---|
| 60 | this->alignment_ = "LeftAligned"; |
---|
| 61 | this->fontSize_ = 12; |
---|
| 62 | this->fontColor_ = Vector4(1.0, 1.0, 1.0, 1.0); |
---|
| 63 | this->fontColorStr_ = "FFFFFFFF"; |
---|
[8446] | 64 | |
---|
| 65 | // Create the NotificationQueueCEGUI in lua. |
---|
| 66 | this->create(); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | NotificationQueueCEGUI::~NotificationQueueCEGUI() |
---|
| 70 | { |
---|
| 71 | |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | @brief |
---|
| 76 | Destroys the NotificationQueueCEGUI. |
---|
| 77 | Used in lua and NotificationManager. |
---|
| 78 | @param noGraphics |
---|
| 79 | 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. |
---|
| 80 | */ |
---|
| 81 | void NotificationQueueCEGUI::destroy(bool noGraphics) |
---|
| 82 | { |
---|
| 83 | // Remove the NotificationQueue in lua. |
---|
| 84 | if(GameMode::showsGraphics() && !noGraphics) |
---|
[8450] | 85 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() + "\")"); |
---|
[8446] | 86 | |
---|
| 87 | NotificationQueue::destroy(); |
---|
| 88 | } |
---|
[8448] | 89 | |
---|
[8446] | 90 | /** |
---|
| 91 | @brief |
---|
[8448] | 92 | Set the size of the window that displays the NotificationQueue. |
---|
| 93 | @param size |
---|
| 94 | The size is a vector with components: |
---|
| 95 | - The relative width of the window. (A value between 0 and 1) |
---|
| 96 | - The absolute width in pixels. (Additional to the relative width, can be negative) |
---|
| 97 | - The relative height of the window. (A value between 0 and 1) |
---|
| 98 | - The absolute height in pixels. (Additional to the relative width, can be negative.) |
---|
| 99 | 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). |
---|
| 100 | */ |
---|
| 101 | void NotificationQueueCEGUI::setDisplaySize(const Vector4& size) |
---|
| 102 | { |
---|
| 103 | if(this->displaySize_ == size) |
---|
| 104 | return; |
---|
| 105 | |
---|
| 106 | if(size.x < 0.0 || size.x > 1.0 || size.z < 0.0 || size.z > 1.0) |
---|
| 107 | { |
---|
| 108 | 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; |
---|
| 109 | return; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | this->displaySize_ = size; |
---|
| 113 | if(size.z == 0.0 && size.w == 0.0) |
---|
[8450] | 114 | 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] | 115 | else |
---|
[8450] | 116 | 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] | 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | @brief |
---|
| 121 | Set the position of the window that displays the NotificationQueue. |
---|
| 122 | @param position |
---|
| 123 | The position is a vector with components: |
---|
| 124 | - The relative x-position of the window. (A value between 0 and 1) |
---|
| 125 | - The absolute x-position in pixels. (Additional to the relative x-position, can be negative) |
---|
| 126 | - The relative y-position of the window. (A value between 0 and 1) |
---|
| 127 | - The absolute y-position in pixels. (Additional to the relative y-position, can be negative.) |
---|
| 128 | */ |
---|
| 129 | void NotificationQueueCEGUI::setPosition(const Vector4& position) |
---|
| 130 | { |
---|
| 131 | if(this->position_ == position) |
---|
| 132 | return; |
---|
| 133 | |
---|
| 134 | if(position.x < 0.0 || position.x > 1.0 || position.z < 0.0 || position.z > 1.0) |
---|
| 135 | { |
---|
| 136 | COUT(2) << "The position the NotificationQueueCEGUI " << this->getName() << " was trying to be set, but the relative position was not in [0,1]. Aborting..." << endl; |
---|
| 137 | return; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | this->position_ = position; |
---|
[8450] | 141 | 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] | 142 | } |
---|
| 143 | |
---|
| 144 | /** |
---|
| 145 | @brief |
---|
| 146 | Set the horizontal alignment of the Notifications text. |
---|
| 147 | @param alignment |
---|
| 148 | The alignment of the Notifications, they are the possible string that the CEGUI Falagard StaticText HorzFormatting property can take. |
---|
| 149 | @see http://cegui.org.uk/api_reference/classCEGUI_1_1FalagardStaticTextProperties_1_1HorzFormatting.html |
---|
| 150 | */ |
---|
| 151 | void NotificationQueueCEGUI::setAlignment(const std::string& alignment) |
---|
| 152 | { |
---|
| 153 | if(this->alignment_ == alignment) |
---|
| 154 | return; |
---|
| 155 | |
---|
| 156 | // TODO: Check whether the alignment string is correct? |
---|
| 157 | this->alignment_ = alignment; |
---|
[8450] | 158 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueAlignment(\"" + this->getName() + "\", \"" + this->alignment_ + "\")"); |
---|
[8448] | 159 | } |
---|
| 160 | |
---|
| 161 | /** |
---|
| 162 | @brief |
---|
| 163 | Set the font size of the text displayed by this NotificationQueue. |
---|
| 164 | @param size |
---|
| 165 | The font size. |
---|
| 166 | */ |
---|
| 167 | void NotificationQueueCEGUI::setFontSize(unsigned int size) |
---|
| 168 | { |
---|
| 169 | if(this->fontSize_ == size) |
---|
| 170 | return; |
---|
| 171 | |
---|
| 172 | this->fontSize_ = size; |
---|
[8450] | 173 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueFontSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->fontSize_) + ")"); |
---|
[8448] | 174 | } |
---|
| 175 | |
---|
| 176 | /** |
---|
| 177 | @brief |
---|
| 178 | Set the font color if the text displayed by this NotificationQueue. |
---|
| 179 | @param color |
---|
| 180 | The color is a vector with the components being RGBA and taking values from 0 to 1. |
---|
| 181 | */ |
---|
| 182 | void NotificationQueueCEGUI::setFontColor(const Vector4& color) |
---|
| 183 | { |
---|
| 184 | if(this->fontColor_ == color) |
---|
| 185 | return; |
---|
| 186 | |
---|
| 187 | this->fontColor_ = color; |
---|
| 188 | // Convert to ARGB format. |
---|
| 189 | std::stringstream stream; |
---|
| 190 | for(unsigned int i = 0; i < 4; i++) |
---|
| 191 | stream << std::hex << std::setw(2) << std::setfill('0') << int(this->fontColor_[(i+3)%4]*255); |
---|
| 192 | this->fontColorStr_ = stream.str(); |
---|
[8450] | 193 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueFontColor(\"" + this->getName() + "\", \"" + this->fontColorStr_ + "\")"); |
---|
[8448] | 194 | } |
---|
| 195 | |
---|
| 196 | /** |
---|
| 197 | @brief |
---|
| 198 | Get the NotificationQueueCEGUI with the input name. |
---|
| 199 | @param name |
---|
| 200 | The name of the NotificationQueueCEGUI to be got. |
---|
| 201 | @return |
---|
| 202 | Returns a pointer to the NotificationQueueCEGUI, or NULL if it doesn't exist. |
---|
| 203 | */ |
---|
| 204 | /*static*/ NotificationQueueCEGUI* NotificationQueueCEGUI::getQueue(const std::string& name) |
---|
| 205 | { |
---|
| 206 | NotificationQueue* queue = NotificationManager::getInstance().getQueue(name); |
---|
| 207 | if(queue == NULL || !queue->isA(Class(NotificationQueueCEGUI))) |
---|
| 208 | return NULL; |
---|
| 209 | return static_cast<NotificationQueueCEGUI*>(queue); |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | /** |
---|
| 213 | @brief |
---|
[8446] | 214 | Is called by the NotificationQueue when a notification was pushed. |
---|
| 215 | @param notification |
---|
| 216 | The Notification that was pushed. |
---|
| 217 | */ |
---|
| 218 | void NotificationQueueCEGUI::notificationPushed(Notification* notification) |
---|
| 219 | { |
---|
| 220 | // Push the Notification to the GUI. |
---|
| 221 | if(GameMode::showsGraphics()) |
---|
[8450] | 222 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")"); |
---|
[8446] | 223 | } |
---|
[8448] | 224 | |
---|
[8446] | 225 | /** |
---|
| 226 | @brief |
---|
| 227 | Is called by the NotificationQueue when a notification was popped. |
---|
| 228 | */ |
---|
| 229 | void NotificationQueueCEGUI::notificationPopped(void) |
---|
| 230 | { |
---|
| 231 | // Pops the Notification from the GUI. |
---|
| 232 | if(GameMode::showsGraphics()) |
---|
[8450] | 233 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".popNotification(\"" + this->getName() + "\")"); |
---|
[8446] | 234 | } |
---|
[8448] | 235 | |
---|
[8446] | 236 | /** |
---|
| 237 | @brief Is called when a notification was removed. |
---|
| 238 | @param index The index the removed notification was at. |
---|
| 239 | */ |
---|
| 240 | void NotificationQueueCEGUI::notificationRemoved(unsigned int index) |
---|
| 241 | { |
---|
| 242 | // Removes the Notification from the GUI. |
---|
| 243 | if(GameMode::showsGraphics()) |
---|
[8450] | 244 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")"); |
---|
[8446] | 245 | } |
---|
[8448] | 246 | |
---|
[8446] | 247 | /** |
---|
| 248 | @brief |
---|
| 249 | Clears the NotificationQueue by removing all NotificationContainers. |
---|
| 250 | @param noGraphics |
---|
| 251 | If this is set to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally. |
---|
| 252 | */ |
---|
| 253 | void NotificationQueueCEGUI::clear(bool noGraphics) |
---|
| 254 | { |
---|
| 255 | NotificationQueue::clear(noGraphics); |
---|
[8448] | 256 | |
---|
[8446] | 257 | // Clear the NotificationQueue in the GUI. |
---|
| 258 | if(GameMode::showsGraphics() && !noGraphics) |
---|
[8450] | 259 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".clearQueue(\"" + this->getName() + "\")"); |
---|
[8446] | 260 | } |
---|
[8448] | 261 | |
---|
[8446] | 262 | /** |
---|
| 263 | @brief |
---|
| 264 | Creates the NotificationQueue in lua. |
---|
| 265 | */ |
---|
| 266 | void NotificationQueueCEGUI::create(void) |
---|
| 267 | { |
---|
| 268 | if(GameMode::showsGraphics()) |
---|
[8450] | 269 | GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")"); |
---|
[8446] | 270 | } |
---|
| 271 | |
---|
| 272 | } |
---|
| 273 | |
---|