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:
parent
a8fbd6cdfc
commit
d5b4e0929f
|
@ -91,6 +91,7 @@ function EnterGame.init()
|
||||||
if port == nil or port == 0 then port = 7171 end
|
if port == nil or port == 0 then port = 7171 end
|
||||||
|
|
||||||
enterGame:getChildById('accountNameTextEdit'):setText(account)
|
enterGame:getChildById('accountNameTextEdit'):setText(account)
|
||||||
|
enterGame:getChildById('accountNameTextEdit'):setCursorPos(-1)
|
||||||
enterGame:getChildById('accountPasswordTextEdit'):setText(password)
|
enterGame:getChildById('accountPasswordTextEdit'):setText(password)
|
||||||
enterGame:getChildById('serverHostTextEdit'):setText(host)
|
enterGame:getChildById('serverHostTextEdit'):setText(host)
|
||||||
enterGame:getChildById('serverPortTextEdit'):setText(port)
|
enterGame:getChildById('serverPortTextEdit'):setText(port)
|
||||||
|
|
|
@ -223,6 +223,7 @@ end
|
||||||
|
|
||||||
function setTextEditText(text)
|
function setTextEditText(text)
|
||||||
consoleTextEdit:setText(text)
|
consoleTextEdit:setText(text)
|
||||||
|
consoleTextEdit:setCursorPos(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function openHelp()
|
function openHelp()
|
||||||
|
@ -529,7 +530,7 @@ function sendMessage(message, tab)
|
||||||
if chatCommandInitial == chatCommandEnd then
|
if chatCommandInitial == chatCommandEnd then
|
||||||
chatCommandPrivateRepeat = false
|
chatCommandPrivateRepeat = false
|
||||||
if chatCommandInitial == "*" then
|
if chatCommandInitial == "*" then
|
||||||
consoleTextEdit:setText('*'.. chatCommandPrivate .. '* ')
|
setTextEditText('*'.. chatCommandPrivate .. '* ')
|
||||||
end
|
end
|
||||||
message = chatCommandMessage:trim()
|
message = chatCommandMessage:trim()
|
||||||
chatCommandPrivateReady = true
|
chatCommandPrivateReady = true
|
||||||
|
@ -615,7 +616,7 @@ function navigateMessageHistory(step)
|
||||||
currentMessageIndex = math.min(math.max(currentMessageIndex + step, 0), numCommands)
|
currentMessageIndex = math.min(math.max(currentMessageIndex + step, 0), numCommands)
|
||||||
if currentMessageIndex > 0 then
|
if currentMessageIndex > 0 then
|
||||||
local command = messageHistory[numCommands - currentMessageIndex + 1]
|
local command = messageHistory[numCommands - currentMessageIndex + 1]
|
||||||
consoleTextEdit:setText(command)
|
setTextEditText(command)
|
||||||
else
|
else
|
||||||
consoleTextEdit:clearText()
|
consoleTextEdit:clearText()
|
||||||
end
|
end
|
||||||
|
|
|
@ -289,7 +289,7 @@ function call(keyCombo)
|
||||||
local hotKey = hotkeyList[keyCombo]
|
local hotKey = hotkeyList[keyCombo]
|
||||||
if hotKey ~= nil and hotKey.itemId == nil and hotKey.value ~= '' then
|
if hotKey ~= nil and hotKey.itemId == nil and hotKey.value ~= '' then
|
||||||
if hotKey.autoSend then
|
if hotKey.autoSend then
|
||||||
g_game.talk(hotKey.value)
|
modules.game_console.sendMessage(hotKey.value)
|
||||||
else
|
else
|
||||||
modules.game_console.setTextEditText(hotKey.value)
|
modules.game_console.setTextEditText(hotKey.value)
|
||||||
end
|
end
|
||||||
|
|
|
@ -146,8 +146,10 @@ void ThingType::unserializeOtml(const OTMLNodePtr& node)
|
||||||
for(const OTMLNodePtr& node2 : node->children()) {
|
for(const OTMLNodePtr& node2 : node->children()) {
|
||||||
if(node2->tag() == "opacity")
|
if(node2->tag() == "opacity")
|
||||||
m_opacity = node2->value<float>();
|
m_opacity = node2->value<float>();
|
||||||
if(node2->tag() == "notprewalkable")
|
else if(node2->tag() == "notprewalkable")
|
||||||
m_attribs.set(ThingAttrNotPreWalkable, node2->value<bool>());
|
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];
|
TexturePtr& animationPhaseTexture = m_textures[animationPhase];
|
||||||
if(!animationPhaseTexture) {
|
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
|
// we don't need layers in common items, they will be pre-drawn
|
||||||
int textureLayers = 1;
|
int textureLayers = 1;
|
||||||
int numLayers = m_layers;
|
int numLayers = m_layers;
|
||||||
|
@ -197,7 +203,12 @@ const TexturePtr& ThingType::getTexture(int animationPhase)
|
||||||
|
|
||||||
int indexSize = textureLayers * m_numPatternX * m_numPatternY * m_numPatternZ;
|
int indexSize = textureLayers * m_numPatternX * m_numPatternY * m_numPatternZ;
|
||||||
Size textureSize = getBestTextureDimension(m_size.width(), m_size.height(), indexSize);
|
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_texturesFramesRects[animationPhase].resize(indexSize);
|
||||||
m_texturesFramesOriginRects[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(),
|
Point framePos = Point(frameIndex % (textureSize.width() / m_size.width()) * m_size.width(),
|
||||||
frameIndex / (textureSize.width() / m_size.width()) * m_size.height()) * Otc::TILE_PIXELS;
|
frameIndex / (textureSize.width() / m_size.width()) * m_size.height()) * Otc::TILE_PIXELS;
|
||||||
|
|
||||||
for(int h = 0; h < m_size.height(); ++h) {
|
if(!useCustomImage) {
|
||||||
for(int w = 0; w < m_size.width(); ++w) {
|
for(int h = 0; h < m_size.height(); ++h) {
|
||||||
uint spriteIndex = getSpriteIndex(w, h, spriteMask ? 1 : l, x, y, z, animationPhase);
|
for(int w = 0; w < m_size.width(); ++w) {
|
||||||
ImagePtr spriteImage = g_sprites.getSpriteImage(m_spritesIndex[spriteIndex]);
|
uint spriteIndex = getSpriteIndex(w, h, spriteMask ? 1 : l, x, y, z, animationPhase);
|
||||||
if(spriteImage) {
|
ImagePtr spriteImage = g_sprites.getSpriteImage(m_spritesIndex[spriteIndex]);
|
||||||
if(spriteMask) {
|
if(spriteImage) {
|
||||||
static Color maskColors[] = { Color::red, Color::green, Color::blue, Color::yellow };
|
if(spriteMask) {
|
||||||
spriteImage->overwriteMask(maskColors[l - 1]);
|
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;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,6 +202,7 @@ private:
|
||||||
int m_layers;
|
int m_layers;
|
||||||
int m_elevation;
|
int m_elevation;
|
||||||
float m_opacity;
|
float m_opacity;
|
||||||
|
std::string m_customImage;
|
||||||
|
|
||||||
std::vector<int> m_spritesIndex;
|
std::vector<int> m_spritesIndex;
|
||||||
std::vector<TexturePtr> m_textures;
|
std::vector<TexturePtr> m_textures;
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
void poll();
|
void poll();
|
||||||
|
|
||||||
void clearTexturesCache();
|
void clearTexturesCache();
|
||||||
|
void preload(const std::string& fileName) { getTexture(fileName); }
|
||||||
TexturePtr getTexture(const std::string& fileName);
|
TexturePtr getTexture(const std::string& fileName);
|
||||||
const TexturePtr& getEmptyTexture() { return m_emptyTexture; }
|
const TexturePtr& getEmptyTexture() { return m_emptyTexture; }
|
||||||
|
|
||||||
|
|
|
@ -294,6 +294,7 @@ void Application::registerLuaFunctions()
|
||||||
|
|
||||||
// Textures
|
// Textures
|
||||||
g_lua.registerSingletonClass("g_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);
|
g_lua.bindSingletonFunction("g_textures", "clearTexturesCache", &TextureManager::clearTexturesCache, &g_textures);
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
|
|
|
@ -327,6 +327,9 @@ void UITextEdit::update(bool focusCursor)
|
||||||
|
|
||||||
void UITextEdit::setCursorPos(int pos)
|
void UITextEdit::setCursorPos(int pos)
|
||||||
{
|
{
|
||||||
|
if(pos < 0)
|
||||||
|
pos = m_text.length();
|
||||||
|
|
||||||
if(pos != m_cursorPos) {
|
if(pos != m_cursorPos) {
|
||||||
if(pos < 0)
|
if(pos < 0)
|
||||||
m_cursorPos = 0;
|
m_cursorPos = 0;
|
||||||
|
|
Loading…
Reference in New Issue