From 47f0d7f3a6f7881157759dca86cc39aabb3b1bd7 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Thu, 9 Aug 2012 21:36:52 -0300 Subject: [PATCH] Fix to creature name formatting and scrollarea maximum option --- modules/corelib/ui/uiscrollarea.lua | 42 ++++++++++++++++++++++++----- modules/gamelib/game.lua | 5 ++++ src/otclient/game.cpp | 8 ++++++ src/otclient/game.h | 2 ++ src/otclient/protocolgameparse.cpp | 22 +++++++-------- 5 files changed, 59 insertions(+), 20 deletions(-) diff --git a/modules/corelib/ui/uiscrollarea.lua b/modules/corelib/ui/uiscrollarea.lua index 7e408ad1..baa7ca06 100644 --- a/modules/corelib/ui/uiscrollarea.lua +++ b/modules/corelib/ui/uiscrollarea.lua @@ -6,6 +6,7 @@ function UIScrollArea.create() local scrollarea = UIScrollArea.internalCreate() scrollarea:setClipping(true) scrollarea.inverted = false + scrollarea.alwaysScrollMaximum = false return scrollarea end @@ -21,34 +22,45 @@ function UIScrollArea:onStyleApply(styleName, styleNode) end) elseif name == 'inverted-scroll' then self:setInverted(value) + elseif name == 'always-scroll-maximum' then + self:setAlwaysScrollMaximum(value) end end end function UIScrollArea:updateScrollBars() - local offset = { x = 0, y = 0 } - local scrollheight = math.max(self:getChildrenRect().height - self:getPaddingRect().height, 0) - local scrollwidth = math.max(self:getChildrenRect().width - self:getPaddingRect().width, 0) + local scrollWidth = math.max(self:getChildrenRect().width - self:getPaddingRect().width, 0) + local scrollHeight = math.max(self:getChildrenRect().height - self:getPaddingRect().height, 0) local scrollbar = self.verticalScrollBar if scrollbar then if self.inverted then - scrollbar:setMinimum(-scrollheight) + scrollbar:setMinimum(-scrollHeight) scrollbar:setMaximum(0) else scrollbar:setMinimum(0) - scrollbar:setMaximum(scrollheight) + scrollbar:setMaximum(scrollHeight) end end local scrollbar = self.horizontalScrollBar if scrollbar then if self.inverted then - scrollbar:setMinimum(-scrollwidth) + scrollbar:setMinimum(-scrollWidth) else - scrollbar:setMaximum(scrollwidth) + scrollbar:setMaximum(scrollWidth) end end + + if self.lastScrollWidth ~= scrollWidth then + self:onScrollWidthChange() + end + if self.lastScrollHeight ~= scrollHeight then + self:onScrollHeightChange() + end + + self.lastScrollWidth = scrollWidth + self.lastScrollHeight = scrollHeight end function UIScrollArea:setVerticalScrollBar(scrollbar) @@ -70,6 +82,10 @@ function UIScrollArea:setInverted(inverted) self.inverted = inverted end +function UIScrollArea:setAlwaysScrollMaximum(value) + self.alwaysScrollMaximum = value +end + function UIScrollArea:onLayoutUpdate() self:updateScrollBars() end @@ -99,3 +115,15 @@ function UIScrollArea:onChildFocusChange(focusedChild, oldFocused, reason) end end end + +function UIScrollArea:onScrollWidthChange() + if self.alwaysScrollMaximum and self.horizontalScrollBar then + self.horizontalScrollBar:setValue(self.horizontalScrollBar:getMaximum()) + end +end + +function UIScrollArea:onScrollHeightChange() + if self.alwaysScrollMaximum and self.verticalScrollBar then + self.verticalScrollBar:setValue(self.verticalScrollBar:getMaximum()) + end +end diff --git a/modules/gamelib/game.lua b/modules/gamelib/game.lua index 7d83797d..d41dc008 100644 --- a/modules/gamelib/game.lua +++ b/modules/gamelib/game.lua @@ -1,9 +1,14 @@ local currentRsa +local enableCreatureNameFormat = true function g_game.getRsa() return currentRsa end +function g_game.isCreatureNameFormatEnabled() + return enableCreatureNameFormat +end + function g_game.chooseRsa(host) if host:match('.*\.tibia\.com') or host:match('.*\.cipsoft\.com') then g_game.setRsa(CIPSOFT_RSA) diff --git a/src/otclient/game.cpp b/src/otclient/game.cpp index fa1a8ce0..b914837e 100644 --- a/src/otclient/game.cpp +++ b/src/otclient/game.cpp @@ -1199,3 +1199,11 @@ void Game::setFollowingCreature(const CreaturePtr& creature) g_lua.callGlobalField("g_game", "onFollowingCreatureChange", creature, oldCreature); } + +std::string Game::formatCreatureName(const std::string& name) +{ + std::string formatedName = name; + if(g_lua.callGlobalField("g_game", "isCreatureNameFormatEnabled") && name.length() > 0) + formatedName[0] = stdext::upchar(formatedName[0]); + return formatedName; +} diff --git a/src/otclient/game.h b/src/otclient/game.h index 70861a67..cffadf98 100644 --- a/src/otclient/game.h +++ b/src/otclient/game.h @@ -268,6 +268,8 @@ public: std::string getWorldName() { return m_worldName; } std::vector getGMActions() { return m_gmActions; } + std::string formatCreatureName(const std::string &name); + protected: void enableBotCall() { m_denyBotCall = false; } void disableBotCall() { m_denyBotCall = true; } diff --git a/src/otclient/protocolgameparse.cpp b/src/otclient/protocolgameparse.cpp index b7355911..21f434e0 100644 --- a/src/otclient/protocolgameparse.cpp +++ b/src/otclient/protocolgameparse.cpp @@ -626,7 +626,7 @@ void ProtocolGame::parseCloseNpcTrade(const InputMessagePtr&) void ProtocolGame::parseOwnTrade(const InputMessagePtr& msg) { - std::string name = msg->getString(); + std::string name = g_game.formatCreatureName(msg->getString()); int count = msg->getU8(); std::vector items(count); @@ -638,7 +638,7 @@ void ProtocolGame::parseOwnTrade(const InputMessagePtr& msg) void ProtocolGame::parseCounterTrade(const InputMessagePtr& msg) { - std::string name = msg->getString(); + std::string name = g_game.formatCreatureName(msg->getString()); int count = msg->getU8(); std::vector items(count); @@ -962,7 +962,7 @@ void ProtocolGame::parseTalk(const InputMessagePtr& msg) { msg->getU32(); // channel statement guid - std::string name = msg->getString(); + std::string name = g_game.formatCreatureName(msg->getString()); int level = msg->getU16(); Otc::MessageMode mode = Proto::translateMessageModeFromServer(msg->getU8()); int channelId = 0; @@ -1025,10 +1025,10 @@ void ProtocolGame::parseOpenChannel(const InputMessagePtr& msg) if(g_game.getFeature(Otc::GameChannelPlayerList)) { int joinedPlayers = msg->getU16(); for(int i=0;igetString(); // player name + g_game.formatCreatureName(msg->getString()); // player name int invitedPlayers = msg->getU16(); for(int i=0;igetString(); // player name + g_game.formatCreatureName(msg->getString()); // player name } g_game.processOpenChannel(channelId, name); @@ -1036,7 +1036,7 @@ void ProtocolGame::parseOpenChannel(const InputMessagePtr& msg) void ProtocolGame::parseOpenPrivateChannel(const InputMessagePtr& msg) { - std::string name = msg->getString(); + std::string name = g_game.formatCreatureName(msg->getString()); g_game.processOpenPrivateChannel(name); } @@ -1226,7 +1226,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) void ProtocolGame::parseVipAdd(const InputMessagePtr& msg) { uint id = msg->getU32(); - std::string name = msg->getString(); + std::string name = g_game.formatCreatureName(msg->getString()); bool online = msg->getU8() != 0; g_game.processVipAdd(id, name, online); @@ -1289,7 +1289,7 @@ void ProtocolGame::parseQuestLine(const InputMessagePtr& msg) void ProtocolGame::parseChannelEvent(const InputMessagePtr& msg) { msg->getU16(); // channel id - msg->getString(); // player name + g_game.formatCreatureName(msg->getString()); // player name msg->getU8(); // event type } @@ -1517,11 +1517,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) creatureType = Proto::CreatureTypeNpc; } - std::string name = msg->getString(); - - // every creature name must start with a capital letter - if(name.length() > 0) - name[0] = toupper(name[0]); + std::string name = g_game.formatCreatureName(msg->getString()); if(id == m_localPlayer->getId()) creature = m_localPlayer;