Adjust the text width computation to take the left/right border of

the achievement background into account.
This commit is contained in:
hiker 2014-06-23 17:24:07 +10:00
parent 299816ac6f
commit 01a3a446bb
4 changed files with 58 additions and 28 deletions

View File

@ -41,22 +41,33 @@ private:
/** The message. */ /** The message. */
core::stringw m_message; core::stringw m_message;
/** The render type of the message: either achievement-message::neutral
* or friend-message::neutral. */
std::string m_render_type;
public: public:
Message(MessageQueue::MessageType mt, const core::stringw &message) Message(MessageQueue::MessageType mt, const core::stringw &message)
{ {
m_message_type = mt; m_message_type = mt;
m_message = message; m_message = message;
if(mt==MessageQueue::MT_ACHIEVEMENT)
m_render_type = "achievement-message::neutral";
else
m_render_type = "friend-message::neutral";
} // Message } // Message
// -------------------------------------------------------------------- // ------------------------------------------------------------------------
bool operator<(const Message &rhs) const
{
return m_message_type < rhs.m_message_type;
} // operator()
// --------------------------------------------------------------------
/** Returns the message. */ /** Returns the message. */
const core::stringw & getMessage() const { return m_message; } const core::stringw & getMessage() const { return m_message; }
// -------------------------------------------------------------------- // ------------------------------------------------------------------------
/** Returns the type of the message (achievement or friend). */
MessageQueue::MessageType getMessageType() const { return m_message_type; } MessageQueue::MessageType getMessageType() const { return m_message_type; }
// ------------------------------------------------------------------------
/** Returns the render type: either achievement-message::neutral or
* friend-message::neutral (see skin for details). */
const std::string &getRenderType() const
{
return m_render_type;
}
}; // class Message }; // class Message
// ============================================================================ // ============================================================================
@ -64,9 +75,12 @@ public:
class CompareMessages class CompareMessages
{ {
public: public:
/** Used to sort messages by priority in the priority queue. Achievement
* messages (1) need to have a higher priority than friend messages
* (value 0). */
bool operator() (const Message *a, const Message *b) const bool operator() (const Message *a, const Message *b) const
{ {
return a->getMessageType() > b->getMessageType(); return a->getMessageType() < b->getMessageType();
} // operator () } // operator ()
}; // operator() }; // operator()
@ -76,7 +90,8 @@ public:
std::priority_queue<Message*, std::vector<Message*>, std::priority_queue<Message*, std::vector<Message*>,
CompareMessages> g_all_messages; CompareMessages> g_all_messages;
/** How long the current message has been displayed. */ /** How long the current message has been displayed. The special value
* -1 indicates that a new message was added when the queue was empty. */
float g_current_display_time = -1.0f; float g_current_display_time = -1.0f;
/** How long the current message should be displaed. */ /** How long the current message should be displaed. */
@ -95,10 +110,12 @@ void createLabel(const Message *message)
gui::ScalableFont *font = GUIEngine::getFont(); gui::ScalableFont *font = GUIEngine::getFont();
core::dimension2du dim = font->getDimension(message->getMessage().c_str()); core::dimension2du dim = font->getDimension(message->getMessage().c_str());
g_current_display_time = 0.0f; g_current_display_time = 0.0f;
// Maybe make this time dependent on message length as well? // Maybe make this time dependent on message length as well?
g_max_display_time = 5.0f; g_max_display_time = 5.0f;
const GUIEngine::BoxRenderParams &brp =
GUIEngine::getSkin()->getBoxRenderParams(message->getRenderType());
dim.Width +=brp.m_left_border + brp.m_right_border;
int x = (UserConfigParams::m_width - dim.Width) / 2; int x = (UserConfigParams::m_width - dim.Width) / 2;
int y = UserConfigParams::m_height - int(1.5f*dim.Height); int y = UserConfigParams::m_height - int(1.5f*dim.Height);
g_area = irr::core::recti(x, y, x+dim.Width, y+dim.Height); g_area = irr::core::recti(x, y, x+dim.Width, y+dim.Height);
@ -114,7 +131,9 @@ void add(MessageType mt, const irr::core::stringw &message)
Message *m = new Message(mt, message); Message *m = new Message(mt, message);
if(g_all_messages.size()==0) if(g_all_messages.size()==0)
{ {
createLabel(m); // Indicate that there is a new message, which should
// which needs a new label etc. to be computed.
g_current_display_time =-1.0f;
} }
g_all_messages.push(m); g_all_messages.push(m);
} // add } // add
@ -133,22 +152,22 @@ void update(float dt)
g_current_display_time += dt; g_current_display_time += dt;
if(g_current_display_time > g_max_display_time) if(g_current_display_time > g_max_display_time)
{ {
Message *last= g_all_messages.top(); Message *last = g_all_messages.top();
g_all_messages.pop(); g_all_messages.pop();
delete last; delete last;
if(g_all_messages.size()==0) return;
g_current_display_time = -1.0f;
}
if(g_all_messages.size()==0) // Create new data for the display.
{ if(g_current_display_time < 0)
return; {
}
createLabel(g_all_messages.top()); createLabel(g_all_messages.top());
} }
Message *current = g_all_messages.top(); Message *current = g_all_messages.top();
std::string type = current->getMessageType() == MT_ACHIEVEMENT GUIEngine::getSkin()->drawMessage(g_container, g_area,
? "achievement-message" current->getRenderType());
: "friend-message";
GUIEngine::getSkin()->drawMessage(g_container, g_area, type);
gui::ScalableFont *font = GUIEngine::getFont(); gui::ScalableFont *font = GUIEngine::getFont();
video::SColor color(255, 0, 0, 0); video::SColor color(255, 0, 0, 0);

View File

@ -31,8 +31,10 @@ using namespace irr;
namespace MessageQueue namespace MessageQueue
{ {
/** The various message type which can be shown (which might use a /** The various message type which can be shown (which might use a
* different look. */ * different look. This type is used to sort the messages, so it is
enum MessageType {MT_ACHIEVEMENT, MT_FRIEND}; * important that messages that need to be shown as early as possible
* will be listed last (i.e. have highest priority). */
enum MessageType {MT_FRIEND, MT_ACHIEVEMENT};
void add(MessageType mt, const core::stringw &message); void add(MessageType mt, const core::stringw &message);
void update(float dt); void update(float dt);

View File

@ -373,6 +373,15 @@ void Skin::drawBgImage()
irr_driver->getVideoDriver()->enableMaterial2D(false); irr_driver->getVideoDriver()->enableMaterial2D(false);
} // drawBgImage } // drawBgImage
// ----------------------------------------------------------------------------
/** Returns the BoxRenderParams data structure for a given type.
* \param type The type name of the box render param to get.
*/
const BoxRenderParams& Skin::getBoxRenderParams(const std::string &type)
{
return SkinConfig::m_render_params[type];
} // getBoxRenderParams
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Draws a background box for an in-game notification message. Example would /** Draws a background box for an in-game notification message. Example would
* be an achievement, or friends comming online. * be an achievement, or friends comming online.
@ -383,8 +392,7 @@ void Skin::drawBgImage()
void Skin::drawMessage(SkinWidgetContainer* w, const core::recti &dest, void Skin::drawMessage(SkinWidgetContainer* w, const core::recti &dest,
const std::string &type) const std::string &type)
{ {
drawBoxFromStretchableTexture(w, dest, drawBoxFromStretchableTexture(w, dest, SkinConfig::m_render_params[type]);
SkinConfig::m_render_params[type+"::neutral"]);
} // drawMessage } // drawMessage
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -395,9 +395,10 @@ namespace GUIEngine
getDefaultText(gui::EGUI_DEFAULT_TEXT text) const; getDefaultText(gui::EGUI_DEFAULT_TEXT text) const;
virtual gui::IGUIFont* getFont(gui::EGUI_DEFAULT_FONT which= virtual gui::IGUIFont* getFont(gui::EGUI_DEFAULT_FONT which=
gui::EGDF_DEFAULT) const; gui::EGDF_DEFAULT) const;
virtual u32 getIcon (gui::EGUI_DEFAULT_ICON icon) const ; virtual u32 getIcon (gui::EGUI_DEFAULT_ICON icon) const;
virtual s32 getSize (gui::EGUI_DEFAULT_SIZE size) const ; virtual s32 getSize (gui::EGUI_DEFAULT_SIZE size) const;
virtual gui::IGUISpriteBank * getSpriteBank () const ; const BoxRenderParams& getBoxRenderParams(const std::string &type);
virtual gui::IGUISpriteBank * getSpriteBank () const;
virtual void setColor (gui::EGUI_DEFAULT_COLOR which, virtual void setColor (gui::EGUI_DEFAULT_COLOR which,
video::SColor newColor); video::SColor newColor);
virtual void setDefaultText (gui::EGUI_DEFAULT_TEXT which, virtual void setDefaultText (gui::EGUI_DEFAULT_TEXT which,