Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/masterserverfix/src/modules/notifications/NotificationQueueCEGUI.cc @ 8933

Last change on this file since 8933 was 8858, checked in by landauf, 13 years ago

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
  • Property svn:eol-style set to native
File size: 15.0 KB
Line 
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
36#include <sstream>
37
38#include "core/CoreIncludes.h"
39#include "core/GameMode.h"
40#include "core/GUIManager.h"
41#include "core/LuaState.h"
42#include "core/XMLPort.h"
43#include "util/Convert.h"
44
45namespace orxonox
46{
47
48    CreateFactory(NotificationQueueCEGUI);
49
50    /*static*/ const std::string NotificationQueueCEGUI::NOTIFICATION_LAYER("NotificationLayer");
51
52    NotificationQueueCEGUI::NotificationQueueCEGUI(BaseObject* creator) : NotificationQueue(creator)
53    {
54        RegisterObject(NotificationQueueCEGUI);
55
56        this->initialize();
57        this->registerVariables();
58    }
59   
60    NotificationQueueCEGUI::~NotificationQueueCEGUI()
61    {
62        if(this->isRegistered() && GameMode::showsGraphics())
63            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() +  "\")");
64    }
65
66    /**
67    @brief
68        Initializes The NotificationQueueCEGUI.
69    */
70    void NotificationQueueCEGUI::initialize(void)
71    {
72        this->displaySize_ = Vector4(1.0, 0.0, 0.0, 0.0);
73        this->position_ = Vector4(0.0, 0.0, 0.0, 0.0);
74        this->alignment_ = "LeftAligned";
75        this->fontSize_ = 12;
76        this->fontColor_ = Vector4(1.0, 1.0, 1.0, 1.0);
77        this->fontColorStr_ = "FFFFFFFF";
78    }
79
80    void NotificationQueueCEGUI::XMLPort(Element& xmlelement, XMLPort::Mode mode)
81    {
82        SUPER(NotificationQueueCEGUI, XMLPort, xmlelement, mode);
83
84        XMLPortParam(NotificationQueueCEGUI, "position", setPosition, getPosition, xmlelement, mode);
85        XMLPortParam(NotificationQueueCEGUI, "fontSize", setFontSize, getFontSize, xmlelement, mode);
86        XMLPortParam(NotificationQueueCEGUI, "fontColor", setFontColor, getFontColor, xmlelement, mode);
87        XMLPortParam(NotificationQueueCEGUI, "alignment", setAlignment, getAlignment, xmlelement, mode);
88        XMLPortParam(NotificationQueueCEGUI, "displaySize", setDisplaySize, getDisplaySize, xmlelement, mode);
89    }
90   
91    void NotificationQueueCEGUI::registerVariables()
92    {
93        registerVariable( this->position_, VariableDirection::ToClient, new NetworkCallback<NotificationQueueCEGUI>(this, &NotificationQueueCEGUI::positionChanged));
94        registerVariable( this->fontSize_, VariableDirection::ToClient, new NetworkCallback<NotificationQueueCEGUI>(this, &NotificationQueueCEGUI::fontSizeChanged));
95        registerVariable( this->fontColor_, VariableDirection::ToClient, new NetworkCallback<NotificationQueueCEGUI>(this, &NotificationQueueCEGUI::fontColorChanged));
96        registerVariable( this->alignment_, VariableDirection::ToClient, new NetworkCallback<NotificationQueueCEGUI>(this, &NotificationQueueCEGUI::alignmentChanged));
97        registerVariable( this->displaySize_, VariableDirection::ToClient, new NetworkCallback<NotificationQueueCEGUI>(this, &NotificationQueueCEGUI::displaySizeChanged));
98    }
99
100    void NotificationQueueCEGUI::changedName(void)
101    {
102        SUPER(NotificationQueueCEGUI, changedName);
103
104        this->positionChanged();
105        this->fontSizeChanged();
106        this->fontColorChanged();
107        this->alignmentChanged();
108        this->displaySizeChanged();
109    }
110
111    /**
112    @brief
113        Destroys the NotificationQueueCEGUI.
114        Used in lua and NotificationManager.
115    @param noGraphics
116        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.
117    */
118    void NotificationQueueCEGUI::destroy(bool noGraphics)
119    {
120        // Remove the NotificationQueue in lua.
121        if(this->isRegistered() && GameMode::showsGraphics() && !noGraphics)
122            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() +  "\")");
123
124        NotificationQueue::destroy();
125    }
126
127    /**
128    @brief
129        Set the size of the window that displays the NotificationQueue.
130    @param size
131        The size is a vector with components:
132        - The relative width of the window. (A value between 0 and 1)
133        - The absolute width in pixels. (Additional to the relative width, can be negative)
134        - The relative height of the window. (A value between 0 and 1)
135        - The absolute height in pixels. (Additional to the relative width, can be negative.)
136        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).
137    */
138    void NotificationQueueCEGUI::setDisplaySize(const Vector4& size)
139    {
140        if(this->displaySize_ == size)
141            return;
142
143        if(size.x < 0.0 || size.x > 1.0 || size.z < 0.0 || size.z > 1.0)
144        {
145            orxout(internal_warning, context::notifications) << "The display size of the NotificationQueueCEGUI " << this->getName() << " was trying to be set, but the relative size was not in [0,1]. Aborting..." << endl;
146            return;
147        }
148
149        this->displaySize_ = size;
150        this->displaySizeChanged();
151    }
152
153    /**
154    @brief
155        Is called when the display size has changed.
156    */
157    void NotificationQueueCEGUI::displaySizeChanged(void)
158    {
159        if(this->isRegistered() && GameMode::showsGraphics())
160        {
161            if(this->displaySize_.z == 0.0 && this->displaySize_.w == 0.0)
162                GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ")");
163            else
164                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) + ")");
165        }
166    }
167
168    /**
169    @brief
170        Set the position of the window that displays the NotificationQueue.
171    @param position
172        The position is a vector with components:
173        - The relative x-position of the window. (A value between 0 and 1)
174        - The absolute x-position in pixels. (Additional to the relative x-position, can be negative)
175        - The relative y-position of the window. (A value between 0 and 1)
176        - The absolute y-position in pixels. (Additional to the relative y-position, can be negative.)
177    */
178    void NotificationQueueCEGUI::setPosition(const Vector4& position)
179    {
180        if(this->position_ == position)
181            return;
182
183        if(position.x < 0.0 || position.x > 1.0 || position.z < 0.0 || position.z > 1.0)
184        {
185            orxout(internal_warning, context::notifications) << "The position the NotificationQueueCEGUI " << this->getName() << " was trying to be set, but the relative position was not in [0,1]. Aborting..." << endl;
186            return;
187        }
188
189        this->position_ = position;
190        this->positionChanged();
191    }
192
193    /**
194    @brief
195        Is called when the NotificationQueue's position has changed.
196    */
197    void NotificationQueueCEGUI::positionChanged(void)
198    {
199        if(this->isRegistered() && GameMode::showsGraphics())
200            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) + ")");
201    }
202
203    /**
204    @brief
205        Set the horizontal alignment of the Notifications text.
206    @param alignment
207        The alignment of the Notifications, they are the possible string that the CEGUI Falagard StaticText HorzFormatting property can take.
208    @see http://cegui.org.uk/api_reference/classCEGUI_1_1FalagardStaticTextProperties_1_1HorzFormatting.html
209    */
210    void NotificationQueueCEGUI::setAlignment(const std::string& alignment)
211    {
212        if(this->alignment_ == alignment)
213            return;
214
215        // TODO: Check whether the alignment string is correct?
216        this->alignment_ = alignment;
217        this->alignmentChanged();
218    }
219
220    /**
221    @brief
222        Is called when the horizontal alignment of the Notifications text has changed.
223    */
224    void NotificationQueueCEGUI::alignmentChanged(void)
225    {
226        if(this->isRegistered() && GameMode::showsGraphics())
227            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueAlignment(\"" + this->getName() + "\", \"" + this->alignment_ + "\")");
228    }
229
230    /**
231    @brief
232        Set the font size of the text displayed by this NotificationQueue.
233    @param size
234        The font size.
235    */
236    void NotificationQueueCEGUI::setFontSize(unsigned int size)
237    {
238        if(this->fontSize_ == size)
239            return;
240
241        this->fontSize_ = size;
242        this->fontSizeChanged();
243    }
244
245    /**
246    @brief
247        Is called when the font size of the text displayed by this NotificationQueue has changed.
248    */
249    void NotificationQueueCEGUI::fontSizeChanged(void)
250    {
251        if(this->isRegistered() && GameMode::showsGraphics())
252            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueFontSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->fontSize_) + ")");
253    }
254
255    /**
256    @brief
257        Set the font color if the text displayed by this NotificationQueue.
258    @param color
259        The color is a vector with the components being RGBA and taking values from 0 to 1.
260    */
261    void NotificationQueueCEGUI::setFontColor(const Vector4& color)
262    {
263        if(this->fontColor_ == color)
264            return;
265
266        this->fontColor_ = color;
267        this->fontColorChanged();
268    }
269
270    /**
271    @brief
272        Is called when the font color if the text displayed by this NotificationQueue.
273    */
274    void NotificationQueueCEGUI::fontColorChanged(void)
275    {
276        // Convert to ARGB format.
277        std::stringstream stream;
278        for(unsigned int i = 0; i < 4; i++)
279            stream << std::hex << std::setw(2) << std::setfill('0') << int(this->fontColor_[(i+3)%4]*255);
280        this->fontColorStr_ = stream.str();
281
282        if(this->isRegistered() && GameMode::showsGraphics())
283            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueFontColor(\"" + this->getName() + "\", \"" + this->fontColorStr_ + "\")");
284    }
285
286    /**
287    @brief
288        Get the NotificationQueueCEGUI with the input name.
289    @param name
290        The name of the NotificationQueueCEGUI to be got.
291    @return
292        Returns a pointer to the NotificationQueueCEGUI, or NULL if it doesn't exist.
293    */
294    /*static*/ NotificationQueueCEGUI* NotificationQueueCEGUI::getQueue(const std::string& name)
295    {
296        NotificationQueue* queue = NotificationManager::getInstance().getQueue(name);
297        if(queue == NULL || !queue->isA(Class(NotificationQueueCEGUI)))
298            return NULL;
299        return static_cast<NotificationQueueCEGUI*>(queue);
300    }
301
302    /**
303    @brief
304        Is called by the NotificationQueue when a Notification was pushed.
305    @param notification
306        The Notification that was pushed.
307    */
308    void NotificationQueueCEGUI::notificationPushed(Notification* notification)
309    {
310         // Push the Notification to the GUI.
311        if(this->isRegistered() && GameMode::showsGraphics())
312            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
313    }
314
315    /**
316    @brief
317        Is called by the NotificationQueue when a Notification was popped.
318    */
319    void NotificationQueueCEGUI::notificationPopped(void)
320    {
321        // Pops the Notification from the GUI.
322        if(this->isRegistered() && GameMode::showsGraphics())
323            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".popNotification(\"" + this->getName() + "\")");
324    }
325
326    /**
327    @brief Is called when a notification was removed.
328    @param index The index the removed Notification was at.
329    */
330    void NotificationQueueCEGUI::notificationRemoved(unsigned int index)
331    {
332        // Removes the Notification from the GUI.
333        if(this->isRegistered() && GameMode::showsGraphics())
334            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
335    }
336
337    /**
338    @brief
339        Clears the NotificationQueue by removing all NotificationContainers.
340    @param noGraphics
341        If this is set to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.
342    */
343    void NotificationQueueCEGUI::clear(bool noGraphics)
344    {
345        NotificationQueue::clear(noGraphics);
346
347        // Clear the NotificationQueue in the GUI.
348        if(this->isRegistered() && GameMode::showsGraphics() && !noGraphics)
349            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".clearQueue(\"" + this->getName() + "\")");
350    }
351
352    /**
353    @brief
354        Creates the NotificationQueue in lua.
355    */
356    void NotificationQueueCEGUI::create(void)
357    {
358        if(this->isRegistered() && GameMode::showsGraphics())
359            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() +  "\")");
360       
361        this->NotificationQueue::create();
362       
363        if(this->isRegistered() && GameMode::showsGraphics())
364            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".createQueue(\"" + this->getName() +  "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
365    }
366
367}
368
Note: See TracBrowser for help on using the repository browser.