diff --git a/modules/client_entergame/entergame.lua b/modules/client_entergame/entergame.lua index d9f1f227..b1f901c5 100644 --- a/modules/client_entergame/entergame.lua +++ b/modules/client_entergame/entergame.lua @@ -91,6 +91,7 @@ function EnterGame.init() if port == nil or port == 0 then port = 7171 end enterGame:getChildById('accountNameTextEdit'):setText(account) + enterGame:getChildById('accountNameTextEdit'):setCursorPos(-1) enterGame:getChildById('accountPasswordTextEdit'):setText(password) enterGame:getChildById('serverHostTextEdit'):setText(host) enterGame:getChildById('serverPortTextEdit'):setText(port) diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index 5038636a..605b283e 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -223,6 +223,7 @@ end function setTextEditText(text) consoleTextEdit:setText(text) + consoleTextEdit:setCursorPos(-1) end function openHelp() @@ -529,7 +530,7 @@ function sendMessage(message, tab) if chatCommandInitial == chatCommandEnd then chatCommandPrivateRepeat = false if chatCommandInitial == "*" then - consoleTextEdit:setText('*'.. chatCommandPrivate .. '* ') + setTextEditText('*'.. chatCommandPrivate .. '* ') end message = chatCommandMessage:trim() chatCommandPrivateReady = true @@ -615,7 +616,7 @@ function navigateMessageHistory(step) currentMessageIndex = math.min(math.max(currentMessageIndex + step, 0), numCommands) if currentMessageIndex > 0 then local command = messageHistory[numCommands - currentMessageIndex + 1] - consoleTextEdit:setText(command) + setTextEditText(command) else consoleTextEdit:clearText() end diff --git a/modules/game_hotkeys/hotkeys_manager.lua b/modules/game_hotkeys/hotkeys_manager.lua index 53716219..43b80701 100644 --- a/modules/game_hotkeys/hotkeys_manager.lua +++ b/modules/game_hotkeys/hotkeys_manager.lua @@ -289,7 +289,7 @@ function call(keyCombo) local hotKey = hotkeyList[keyCombo] if hotKey ~= nil and hotKey.itemId == nil and hotKey.value ~= '' then if hotKey.autoSend then - g_game.talk(hotKey.value) + modules.game_console.sendMessage(hotKey.value) else modules.game_console.setTextEditText(hotKey.value) end diff --git a/src/client/thingtype.cpp b/src/client/thingtype.cpp index 7a3a409a..e11ce909 100644 --- a/src/client/thingtype.cpp +++ b/src/client/thingtype.cpp @@ -146,8 +146,10 @@ void ThingType::unserializeOtml(const OTMLNodePtr& node) for(const OTMLNodePtr& node2 : node->children()) { if(node2->tag() == "opacity") m_opacity = node2->value(); - if(node2->tag() == "notprewalkable") + else if(node2->tag() == "notprewalkable") m_attribs.set(ThingAttrNotPreWalkable, node2->value()); + 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]); + 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); } - Point spritePos = Point(m_size.width() - w - 1, - m_size.height() - h - 1) * Otc::TILE_PIXELS; - - fullImage->blit(framePos + spritePos, spriteImage); } } } diff --git a/src/client/thingtype.h b/src/client/thingtype.h index 18cd9f92..61432c76 100644 --- a/src/client/thingtype.h +++ b/src/client/thingtype.h @@ -202,6 +202,7 @@ private: int m_layers; int m_elevation; float m_opacity; + std::string m_customImage; std::vector m_spritesIndex; std::vector m_textures; diff --git a/src/framework/graphics/texturemanager.h b/src/framework/graphics/texturemanager.h index a2e4bdc9..4997ea0a 100644 --- a/src/framework/graphics/texturemanager.h +++ b/src/framework/graphics/texturemanager.h @@ -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; } diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 11fab2fa..6edb9871 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -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 diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index 747659a9..93f7250e 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -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;