Minimap fix and remove option

This commit is contained in:
Henrique Santiago 2013-01-29 18:36:27 -02:00
parent ff9f82d0c8
commit 60986eb80f
6 changed files with 46 additions and 19 deletions

View File

@ -21,7 +21,8 @@ function init()
connect(g_game, {
onGameStart = online,
onGameEnd = offline,
onAutomapFlag = addMapFlag
onAddAutomapFlag = addMapFlag,
onRemoveAutomapFlag = removeMapFlag,
})
connect(LocalPlayer, { onPositionChange = center })
@ -65,7 +66,8 @@ function terminate()
disconnect(g_game, {
onGameStart = online,
onGameEnd = offline,
onAutomapFlag = addMapFlag
onAddAutomapFlag = addMapFlag,
onRemoveAutomapFlag = removeMapFlag,
})
disconnect(LocalPlayer, { onPositionChange = center })
@ -118,7 +120,7 @@ function showFlagDialog(position)
for i = 1, 20 do
local checkbox = flagWindow:getChildById('flag' .. i)
table.insert(flagCheckbox, checkbox)
checkbox.icon = i
checkbox.icon = i - 1
flagRadioGroup:addWidget(checkbox)
end
@ -174,7 +176,7 @@ function getFlagIconClip(id)
end
function addMapFlag(pos, icon, message, flagId, version)
if not(icon >= 1 and icon <= 20) or not pos then
if not (icon >= 0 and icon <= 19) or not pos then
return
end
@ -194,7 +196,7 @@ function addMapFlag(pos, icon, message, flagId, version)
end
local flagWidget = g_ui.createWidget('FlagWidget', flagsPanel)
flagWidget:setIconClip(getFlagIconClip(icon - 1))
flagWidget:setIconClip(getFlagIconClip(icon))
flagWidget:setId('flag' .. flagId)
flagWidget.position = pos
flagWidget.icon = icon
@ -208,13 +210,23 @@ function addMapFlag(pos, icon, message, flagId, version)
flagWidget.onMousePress = onFlagMousePress
end
function removeMapFlag(pos, icon, message)
for i=1, flagsPanel:getChildCount() do
local flag = flagsPanel:getChildByIndex(i)
if flag.position.x == pos.x and flag.position.y == pos.y and flag.position.z == pos.z and flag.icon == icon and flag.description == message then
flag:destroy()
break
end
end
end
function getMapArea()
return minimapWidget:getPosition( { x = 1 + minimapWidget:getX(), y = 1 + minimapWidget:getY() } ),
minimapWidget:getPosition( { x = -2 + minimapWidget:getWidth() + minimapWidget:getX(), y = -2 + minimapWidget:getHeight() + minimapWidget:getY() } )
end
function isFlagVisible(flag, firstPosition, lastPosition)
return flag.version == g_game.getProtocolVersion() and (minimapWidget:getZoom() >= 0 and minimapWidget:getZoom() <= 2) and flag.position.x >= firstPosition.x and flag.position.x <= lastPosition.x and flag.position.y >= firstPosition.y and flag.position.y <= lastPosition.y and flag.position.z == firstPosition.z
return flag.version == g_game.getProtocolVersion() and (minimapWidget:getZoom() >= -2 and minimapWidget:getZoom() <= 4) and flag.position.x >= firstPosition.x and flag.position.x <= lastPosition.x and flag.position.y >= firstPosition.y and flag.position.y <= lastPosition.y and flag.position.z == firstPosition.z
end
function updateMapFlag(id)
@ -226,8 +238,8 @@ function updateMapFlag(id)
local flag = flagsPanel:getChildById('flag' .. id)
if isFlagVisible(flag, firstPosition, lastPosition) then
flag:setVisible(true)
flag:setMarginLeft( -5 + (minimapWidget:getWidth() / (lastPosition.x - firstPosition.x)) * (flag.position.x - firstPosition.x))
flag:setMarginTop( -5 + (minimapWidget:getHeight() / (lastPosition.y - firstPosition.y)) * (flag.position.y - firstPosition.y))
flag:setMarginLeft(-5.5 + (minimapWidget:getWidth() / (lastPosition.x - firstPosition.x)) * (flag.position.x - firstPosition.x))
flag:setMarginTop(-5.5 + (minimapWidget:getHeight() / (lastPosition.y - firstPosition.y)) * (flag.position.y - firstPosition.y))
else
flag:setVisible(false)
end
@ -239,12 +251,12 @@ function updateMapFlags()
return
end
for i = 1, flagsPanel:getChildCount() do
for i=1, flagsPanel:getChildCount() do
local flag = flagsPanel:getChildByIndex(i)
if isFlagVisible(flag, firstPosition, lastPosition) then
flag:setVisible(true)
flag:setMarginLeft( -5 + (minimapWidget:getWidth() / (lastPosition.x - firstPosition.x)) * (flag.position.x - firstPosition.x))
flag:setMarginTop( -5 + (minimapWidget:getHeight() / (lastPosition.y - firstPosition.y)) * (flag.position.y - firstPosition.y))
flag:setMarginLeft(-5.5 + (minimapWidget:getWidth() / (lastPosition.x - firstPosition.x)) * (flag.position.x - firstPosition.x))
flag:setMarginTop(-5.5 + (minimapWidget:getHeight() / (lastPosition.y - firstPosition.y)) * (flag.position.y - firstPosition.y))
else
flag:setVisible(false)
end

View File

@ -76,6 +76,7 @@ GameDiagonalAnimatedText = 34
GameLoginPending = 35
GameNewSpeedLaw = 36
GameForceFirstAutoWalkStep = 37
GameMinimapRemove = 38
TextColors = {
red = '#f55e5e', --'#c83200'

View File

@ -347,6 +347,7 @@ namespace Otc
GameLoginPending = 35,
GameNewSpeedLaw = 36,
GameForceFirstAutoWalkStep = 37,
GameMinimapRemove = 38,
// 51-100 reserved to be defined in lua
LastGameFeature = 101
};

View File

@ -371,9 +371,14 @@ void Game::processTutorialHint(int id)
g_lua.callGlobalField("g_game", "onTutorialHint", id);
}
void Game::processAutomapFlag(const Position& pos, int icon, const std::string& message)
void Game::processAddAutomapFlag(const Position& pos, int icon, const std::string& message)
{
g_lua.callGlobalField("g_game", "onAutomapFlag", pos, icon, message);
g_lua.callGlobalField("g_game", "onAddAutomapFlag", pos, icon, message);
}
void Game::processRemoveAutomapFlag(const Position& pos, int icon, const std::string& message)
{
g_lua.callGlobalField("g_game", "onRemoveAutomapFlag", pos, icon, message);
}
void Game::processOpenOutfitWindow(const Outfit& currentOufit, const std::vector<std::tuple<int, std::string, int> >& outfitList,

View File

@ -103,7 +103,8 @@ protected:
// tutorial hint
void processTutorialHint(int id);
void processAutomapFlag(const Position& pos, int icon, const std::string& message);
void processAddAutomapFlag(const Position& pos, int icon, const std::string& message);
void processRemoveAutomapFlag(const Position& pos, int icon, const std::string& message);
// outfit
void processOpenOutfitWindow(const Outfit& currentOufit, const std::vector<std::tuple<int, std::string, int> >& outfitList,

View File

@ -1406,17 +1406,24 @@ void ProtocolGame::parseVipLogout(const InputMessagePtr& msg)
void ProtocolGame::parseTutorialHint(const InputMessagePtr& msg)
{
int id = msg->getU8(); // tutorial id
int id = msg->getU8();
g_game.processTutorialHint(id);
}
void ProtocolGame::parseAutomapFlag(const InputMessagePtr& msg)
{
Position pos = getPosition(msg); // position
int icon = msg->getU8(); // icon
std::string description = msg->getString(); // message
Position pos = getPosition(msg);
int icon = msg->getU8();
std::string description = msg->getString();
g_game.processAutomapFlag(pos, icon, description);
bool remove = false;
if(g_game.getFeature(Otc::GameMinimapRemove))
remove = msg->getU8() != 0;
if(!remove)
g_game.processAddAutomapFlag(pos, icon, description);
else
g_game.processRemoveAutomapFlag(pos, icon, description);
}
void ProtocolGame::parseQuestLog(const InputMessagePtr& msg)