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
|
if ((c > 12287 && c < 40960) || //Common CJK words
|
||||||
(c > 44031 && c < 55204) || //Hangul
|
(c > 44031 && c < 55204) || //Hangul
|
||||||
(c > 63743 && c < 64256) || //More Chinese
|
(c > 63743 && c < 64256) || //More Chinese
|
||||||
c == 173 || c == L' ' || c == 0) //Soft hyphen and white space
|
c == 173 || c == L' ' || //Soft hyphen and white space
|
||||||
return true;
|
c == 47 || c == 92) //Slash and blackslash
|
||||||
return false;
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} // end namespace gui
|
} // end namespace gui
|
||||||
} // end namespace irr
|
} // end namespace irr
|
||||||
|
@ -20,19 +20,25 @@
|
|||||||
|
|
||||||
#include "guiengine/message_queue.hpp"
|
#include "guiengine/message_queue.hpp"
|
||||||
|
|
||||||
#include "config/user_config.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
#include "guiengine/engine.hpp"
|
#include "guiengine/engine.hpp"
|
||||||
#include "guiengine/scalable_font.hpp"
|
|
||||||
#include "guiengine/skin.hpp"
|
#include "guiengine/skin.hpp"
|
||||||
#include "utils/synchronised.hpp"
|
#include "utils/synchronised.hpp"
|
||||||
|
#include "utils/translation.hpp"
|
||||||
|
|
||||||
#include "IGUIElement.h"
|
#include "IGUIElement.h"
|
||||||
|
#include "IGUIEnvironment.h"
|
||||||
|
#include "IGUIStaticText.h"
|
||||||
|
|
||||||
using namespace GUIEngine;
|
using namespace GUIEngine;
|
||||||
|
|
||||||
namespace MessageQueue
|
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. */
|
/** A small helper class to store and sort messages to be displayed. */
|
||||||
class Message
|
class Message
|
||||||
{
|
{
|
||||||
@ -46,11 +52,15 @@ private:
|
|||||||
* or friend-message::neutral. */
|
* or friend-message::neutral. */
|
||||||
std::string m_render_type;
|
std::string m_render_type;
|
||||||
|
|
||||||
|
/** The text label, can do linebreak if needed. */
|
||||||
|
gui::IGUIStaticText* m_text;
|
||||||
|
|
||||||
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;
|
||||||
|
m_text = NULL;
|
||||||
if(mt==MessageQueue::MT_ACHIEVEMENT)
|
if(mt==MessageQueue::MT_ACHIEVEMENT)
|
||||||
m_render_type = "achievement-message::neutral";
|
m_render_type = "achievement-message::neutral";
|
||||||
else if (mt==MessageQueue::MT_ERROR)
|
else if (mt==MessageQueue::MT_ERROR)
|
||||||
@ -61,6 +71,11 @@ public:
|
|||||||
m_render_type = "friend-message::neutral";
|
m_render_type = "friend-message::neutral";
|
||||||
} // Message
|
} // Message
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
~Message()
|
||||||
|
{
|
||||||
|
assert(m_text != NULL);
|
||||||
|
m_text->drop();
|
||||||
|
}
|
||||||
/** Returns the message. */
|
/** Returns the message. */
|
||||||
const core::stringw & getMessage() const { return m_message; }
|
const core::stringw & getMessage() const { return m_message; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -73,6 +88,39 @@ public:
|
|||||||
{
|
{
|
||||||
return m_render_type;
|
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
|
}; // class Message
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@ -103,26 +151,18 @@ float g_max_display_time = 5.0f;
|
|||||||
|
|
||||||
/** The label widget used to show the current message. */
|
/** The label widget used to show the current message. */
|
||||||
SkinWidgetContainer *g_container = NULL;
|
SkinWidgetContainer *g_container = NULL;
|
||||||
core::recti g_area;
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
void createLabel(const Message *message)
|
void createLabel(Message *message)
|
||||||
{
|
{
|
||||||
if(!g_container)
|
if(!g_container)
|
||||||
g_container = new SkinWidgetContainer();
|
g_container = new SkinWidgetContainer();
|
||||||
|
|
||||||
gui::ScalableFont *font = GUIEngine::getFont();
|
|
||||||
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 =
|
message->init();
|
||||||
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);
|
|
||||||
} // createLabel
|
} // createLabel
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -200,10 +240,7 @@ void update(float dt)
|
|||||||
|
|
||||||
GUIEngine::getSkin()->drawMessage(g_container, g_area,
|
GUIEngine::getSkin()->drawMessage(g_container, g_area,
|
||||||
current->getRenderType());
|
current->getRenderType());
|
||||||
gui::ScalableFont *font = GUIEngine::getFont();
|
current->draw();
|
||||||
|
|
||||||
video::SColor color(255, 0, 0, 0);
|
|
||||||
font->draw(current->getMessage(), g_area, color, true, true);
|
|
||||||
|
|
||||||
} // update
|
} // update
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user