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. */
core::stringw m_message;
/** The render type of the message: either achievement-message::neutral
* or friend-message::neutral. */
std::string m_render_type;
public:
Message(MessageQueue::MessageType mt, const core::stringw &message)
{
m_message_type = mt;
m_message = message;
if(mt==MessageQueue::MT_ACHIEVEMENT)
m_render_type = "achievement-message::neutral";
else
m_render_type = "friend-message::neutral";
} // Message
// --------------------------------------------------------------------
bool operator<(const Message &rhs) const
{
return m_message_type < rhs.m_message_type;
} // operator()
// --------------------------------------------------------------------
// ------------------------------------------------------------------------
/** Returns the 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; }
// ------------------------------------------------------------------------
/** 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
// ============================================================================
@ -64,9 +75,12 @@ public:
class CompareMessages
{
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
{
return a->getMessageType() > b->getMessageType();
return a->getMessageType() < b->getMessageType();
} // operator ()
}; // operator()
@ -76,7 +90,8 @@ public:
std::priority_queue<Message*, std::vector<Message*>,
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;
/** How long the current message should be displaed. */
@ -95,10 +110,12 @@ void createLabel(const Message *message)
gui::ScalableFont *font = GUIEngine::getFont();
core::dimension2du dim = font->getDimension(message->getMessage().c_str());
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;
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 y = UserConfigParams::m_height - int(1.5f*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);
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);
} // add
@ -133,22 +152,22 @@ void update(float dt)
g_current_display_time += dt;
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();
delete last;
if(g_all_messages.size()==0) return;
g_current_display_time = -1.0f;
}
if(g_all_messages.size()==0)
{
return;
}
// Create new data for the display.
if(g_current_display_time < 0)
{
createLabel(g_all_messages.top());
}
Message *current = g_all_messages.top();
std::string type = current->getMessageType() == MT_ACHIEVEMENT
? "achievement-message"
: "friend-message";
GUIEngine::getSkin()->drawMessage(g_container, g_area, type);
GUIEngine::getSkin()->drawMessage(g_container, g_area,
current->getRenderType());
gui::ScalableFont *font = GUIEngine::getFont();
video::SColor color(255, 0, 0, 0);

View File

@ -31,8 +31,10 @@ using namespace irr;
namespace MessageQueue
{
/** The various message type which can be shown (which might use a
* different look. */
enum MessageType {MT_ACHIEVEMENT, MT_FRIEND};
* different look. This type is used to sort the messages, so it is
* 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 update(float dt);

View File

@ -373,6 +373,15 @@ void Skin::drawBgImage()
irr_driver->getVideoDriver()->enableMaterial2D(false);
} // 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
* be an achievement, or friends comming online.
@ -383,8 +392,7 @@ void Skin::drawBgImage()
void Skin::drawMessage(SkinWidgetContainer* w, const core::recti &dest,
const std::string &type)
{
drawBoxFromStretchableTexture(w, dest,
SkinConfig::m_render_params[type+"::neutral"]);
drawBoxFromStretchableTexture(w, dest, SkinConfig::m_render_params[type]);
} // drawMessage
// ----------------------------------------------------------------------------

View File

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