Allow message queue to be able to do linebreak
Also set "/" and "\" to be breakable
This commit is contained in:
parent
aecb1a97ce
commit
2660a5b332
@ -104,9 +104,10 @@ bool breakable (wchar_t c)
|
||||
if ((c > 12287 && c < 40960) || //Common CJK words
|
||||
(c > 44031 && c < 55204) || //Hangul
|
||||
(c > 63743 && c < 64256) || //More Chinese
|
||||
c == 173 || c == L' ' || c == 0) //Soft hyphen and white space
|
||||
return true;
|
||||
return false;
|
||||
c == 173 || c == L' ' || //Soft hyphen and white space
|
||||
c == 47 || c == 92) //Slash and blackslash
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
} // end namespace gui
|
||||
} // end namespace irr
|
||||
|
@ -20,19 +20,25 @@
|
||||
|
||||
#include "guiengine/message_queue.hpp"
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "guiengine/skin.hpp"
|
||||
#include "utils/synchronised.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
#include "IGUIElement.h"
|
||||
#include "IGUIEnvironment.h"
|
||||
#include "IGUIStaticText.h"
|
||||
|
||||
using namespace GUIEngine;
|
||||
|
||||
namespace MessageQueue
|
||||
{
|
||||
// ============================================================================
|
||||
/** The area which the message is drawn. */
|
||||
core::recti g_area;
|
||||
|
||||
// ============================================================================
|
||||
/** A small helper class to store and sort messages to be displayed. */
|
||||
class Message
|
||||
{
|
||||
@ -46,11 +52,15 @@ private:
|
||||
* or friend-message::neutral. */
|
||||
std::string m_render_type;
|
||||
|
||||
/** The text label, can do linebreak if needed. */
|
||||
gui::IGUIStaticText* m_text;
|
||||
|
||||
public:
|
||||
Message(MessageQueue::MessageType mt, const core::stringw &message)
|
||||
{
|
||||
m_message_type = mt;
|
||||
m_message = message;
|
||||
m_text = NULL;
|
||||
if(mt==MessageQueue::MT_ACHIEVEMENT)
|
||||
m_render_type = "achievement-message::neutral";
|
||||
else if (mt==MessageQueue::MT_ERROR)
|
||||
@ -61,6 +71,11 @@ public:
|
||||
m_render_type = "friend-message::neutral";
|
||||
} // Message
|
||||
// ------------------------------------------------------------------------
|
||||
~Message()
|
||||
{
|
||||
assert(m_text != NULL);
|
||||
m_text->drop();
|
||||
}
|
||||
/** Returns the message. */
|
||||
const core::stringw & getMessage() const { return m_message; }
|
||||
// ------------------------------------------------------------------------
|
||||
@ -73,6 +88,39 @@ public:
|
||||
{
|
||||
return m_render_type;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Init the message text, do linebreak as required. */
|
||||
void init()
|
||||
{
|
||||
const GUIEngine::BoxRenderParams &brp =
|
||||
GUIEngine::getSkin()->getBoxRenderParams(m_render_type);
|
||||
const unsigned width = irr_driver->getActualScreenSize().Width;
|
||||
const unsigned height = irr_driver->getActualScreenSize().Height;
|
||||
const unsigned max_width = width - (brp.m_left_border +
|
||||
brp.m_right_border);
|
||||
m_text =
|
||||
GUIEngine::getGUIEnv()->addStaticText(m_message.c_str(),
|
||||
core::recti(0, 0, max_width, height));
|
||||
m_text->setRightToLeft(translations->isRTLText(m_message));
|
||||
core::dimension2du dim(m_text->getTextWidth(),
|
||||
m_text->getTextHeight());
|
||||
dim.Width += brp.m_left_border + brp.m_right_border;
|
||||
int x = (width - dim.Width) / 2;
|
||||
int y = height - int(1.5f * dim.Height);
|
||||
g_area = irr::core::recti(x, y, x + dim.Width, y + dim.Height);
|
||||
m_text->setRelativePosition(g_area);
|
||||
m_text->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
|
||||
m_text->grab();
|
||||
m_text->remove();
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Draw the message. */
|
||||
void draw()
|
||||
{
|
||||
assert(m_text != NULL);
|
||||
m_text->draw();
|
||||
}
|
||||
|
||||
}; // class Message
|
||||
|
||||
// ============================================================================
|
||||
@ -103,26 +151,18 @@ float g_max_display_time = 5.0f;
|
||||
|
||||
/** The label widget used to show the current message. */
|
||||
SkinWidgetContainer *g_container = NULL;
|
||||
core::recti g_area;
|
||||
|
||||
// ============================================================================
|
||||
|
||||
void createLabel(const Message *message)
|
||||
void createLabel(Message *message)
|
||||
{
|
||||
if(!g_container)
|
||||
g_container = new SkinWidgetContainer();
|
||||
|
||||
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?
|
||||
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);
|
||||
message->init();
|
||||
} // createLabel
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -200,10 +240,7 @@ void update(float dt)
|
||||
|
||||
GUIEngine::getSkin()->drawMessage(g_container, g_area,
|
||||
current->getRenderType());
|
||||
gui::ScalableFont *font = GUIEngine::getFont();
|
||||
|
||||
video::SColor color(255, 0, 0, 0);
|
||||
font->draw(current->getMessage(), g_area, color, true, true);
|
||||
current->draw();
|
||||
|
||||
} // update
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user