Fix to creature name formatting and scrollarea maximum option

This commit is contained in:
Henrique Santiago 2012-08-09 21:36:52 -03:00
parent 96af3d3fcc
commit 47f0d7f3a6
5 changed files with 59 additions and 20 deletions

View File

@ -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

View File

@ -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)

View File

@ -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<bool>("g_game", "isCreatureNameFormatEnabled") && name.length() > 0)
formatedName[0] = stdext::upchar(formatedName[0]);
return formatedName;
}

View File

@ -268,6 +268,8 @@ public:
std::string getWorldName() { return m_worldName; }
std::vector<uint8> getGMActions() { return m_gmActions; }
std::string formatCreatureName(const std::string &name);
protected:
void enableBotCall() { m_denyBotCall = false; }
void disableBotCall() { m_denyBotCall = true; }

View File

@ -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<ItemPtr> 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<ItemPtr> 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;i<joinedPlayers;++i)
msg->getString(); // player name
g_game.formatCreatureName(msg->getString()); // player name
int invitedPlayers = msg->getU16();
for(int i=0;i<invitedPlayers;++i)
msg->getString(); // 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;