Improvements in textedit and hotkey manager

* Set textedit's cursor position to the end of text in some situations
* Send hotkey messages to the current channel instead of default channel
* Allow to overwrite sprites using otml and pngs
This commit is contained in:
Eduardo Bart
2013-01-24 18:36:04 -02:00
parent a8fbd6cdfc
commit d5b4e0929f
8 changed files with 38 additions and 17 deletions

View File

@@ -146,8 +146,10 @@ void ThingType::unserializeOtml(const OTMLNodePtr& node)
for(const OTMLNodePtr& node2 : node->children()) {
if(node2->tag() == "opacity")
m_opacity = node2->value<float>();
if(node2->tag() == "notprewalkable")
else if(node2->tag() == "notprewalkable")
m_attribs.set(ThingAttrNotPreWalkable, node2->value<bool>());
else if(node2->tag() == "image")
m_customImage = node2->value();
}
}
@@ -186,6 +188,10 @@ const TexturePtr& ThingType::getTexture(int animationPhase)
{
TexturePtr& animationPhaseTexture = m_textures[animationPhase];
if(!animationPhaseTexture) {
bool useCustomImage = false;
if(animationPhase == 0 && !m_customImage.empty())
useCustomImage = true;
// we don't need layers in common items, they will be pre-drawn
int textureLayers = 1;
int numLayers = m_layers;
@@ -197,7 +203,12 @@ const TexturePtr& ThingType::getTexture(int animationPhase)
int indexSize = textureLayers * m_numPatternX * m_numPatternY * m_numPatternZ;
Size textureSize = getBestTextureDimension(m_size.width(), m_size.height(), indexSize);
ImagePtr fullImage = ImagePtr(new Image(textureSize * Otc::TILE_PIXELS));
ImagePtr fullImage;
if(useCustomImage)
fullImage = Image::load(m_customImage);
else
fullImage = ImagePtr(new Image(textureSize * Otc::TILE_PIXELS));
m_texturesFramesRects[animationPhase].resize(indexSize);
m_texturesFramesOriginRects[animationPhase].resize(indexSize);
@@ -212,19 +223,21 @@ const TexturePtr& ThingType::getTexture(int animationPhase)
Point framePos = Point(frameIndex % (textureSize.width() / m_size.width()) * m_size.width(),
frameIndex / (textureSize.width() / m_size.width()) * m_size.height()) * Otc::TILE_PIXELS;
for(int h = 0; h < m_size.height(); ++h) {
for(int w = 0; w < m_size.width(); ++w) {
uint spriteIndex = getSpriteIndex(w, h, spriteMask ? 1 : l, x, y, z, animationPhase);
ImagePtr spriteImage = g_sprites.getSpriteImage(m_spritesIndex[spriteIndex]);
if(spriteImage) {
if(spriteMask) {
static Color maskColors[] = { Color::red, Color::green, Color::blue, Color::yellow };
spriteImage->overwriteMask(maskColors[l - 1]);
}
Point spritePos = Point(m_size.width() - w - 1,
m_size.height() - h - 1) * Otc::TILE_PIXELS;
if(!useCustomImage) {
for(int h = 0; h < m_size.height(); ++h) {
for(int w = 0; w < m_size.width(); ++w) {
uint spriteIndex = getSpriteIndex(w, h, spriteMask ? 1 : l, x, y, z, animationPhase);
ImagePtr spriteImage = g_sprites.getSpriteImage(m_spritesIndex[spriteIndex]);
if(spriteImage) {
if(spriteMask) {
static Color maskColors[] = { Color::red, Color::green, Color::blue, Color::yellow };
spriteImage->overwriteMask(maskColors[l - 1]);
}
Point spritePos = Point(m_size.width() - w - 1,
m_size.height() - h - 1) * Otc::TILE_PIXELS;
fullImage->blit(framePos + spritePos, spriteImage);
fullImage->blit(framePos + spritePos, spriteImage);
}
}
}
}

View File

@@ -202,6 +202,7 @@ private:
int m_layers;
int m_elevation;
float m_opacity;
std::string m_customImage;
std::vector<int> m_spritesIndex;
std::vector<TexturePtr> m_textures;

View File

@@ -33,6 +33,7 @@ public:
void poll();
void clearTexturesCache();
void preload(const std::string& fileName) { getTexture(fileName); }
TexturePtr getTexture(const std::string& fileName);
const TexturePtr& getEmptyTexture() { return m_emptyTexture; }

View File

@@ -294,6 +294,7 @@ void Application::registerLuaFunctions()
// Textures
g_lua.registerSingletonClass("g_textures");
g_lua.bindSingletonFunction("g_textures", "preload", &TextureManager::preload, &g_textures);
g_lua.bindSingletonFunction("g_textures", "clearTexturesCache", &TextureManager::clearTexturesCache, &g_textures);
// UI

View File

@@ -327,6 +327,9 @@ void UITextEdit::update(bool focusCursor)
void UITextEdit::setCursorPos(int pos)
{
if(pos < 0)
pos = m_text.length();
if(pos != m_cursorPos) {
if(pos < 0)
m_cursorPos = 0;