Minimap Icons

Now server can call:
doPlayerAddMapMark(cid, pos, icon, description)
and it will be parsed.

TODO:
Adding map icons by rightclick on minimap menu.
Removing icons.

Needs to be tested when switching between different versions.
This commit is contained in:
Samuel 2012-10-11 17:36:00 +02:00
parent f48fb4343f
commit 3990ee76e7
5 changed files with 175 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -7,6 +7,8 @@ minimapWidget = nil
minimapButton = nil minimapButton = nil
minimapWindow = nil minimapWindow = nil
flagsPanel = nil
nextFlagId = 0
--[[ --[[
Known Issue (TODO): Known Issue (TODO):
If you move the minimap compass directions and If you move the minimap compass directions and
@ -16,8 +18,10 @@ function init()
connect(g_game, { connect(g_game, {
onGameStart = online, onGameStart = online,
onGameEnd = offline, onGameEnd = offline,
onAutomapFlag = addMapFlag
}) })
connect(LocalPlayer, { onPositionChange = center }) connect(LocalPlayer, { onPositionChange = center,
onPositionChange = updateMapFlags })
g_keyboard.bindKeyDown('Ctrl+M', toggle) g_keyboard.bindKeyDown('Ctrl+M', toggle)
@ -38,18 +42,27 @@ function init()
minimapWidget:setKeepAspectRatio(false) minimapWidget:setKeepAspectRatio(false)
minimapWidget.onMouseRelease = onMinimapMouseRelease minimapWidget.onMouseRelease = onMinimapMouseRelease
minimapWidget.onMouseWheel = onMinimapMouseWheel minimapWidget.onMouseWheel = onMinimapMouseWheel
flagsPanel = minimapWindow:recursiveGetChildById('flagsPanel')
reset() reset()
minimapWindow:setup() minimapWindow:setup()
loadMapFlags()
if g_game.isOnline() then
addEvent(function() updateMapFlags() end)
end
end end
function terminate() function terminate()
disconnect(g_game, { disconnect(g_game, {
onGameStart = online, onGameStart = online,
onGameEnd = offline, onGameEnd = offline,
onAutomapFlag = addMapFlag
}) })
disconnect(LocalPlayer, { onPositionChange = center }) disconnect(LocalPlayer, { onPositionChange = center,
onPositionChange = updateMapFlags })
saveMapFlags()
if g_game.isOnline() then if g_game.isOnline() then
saveMap() saveMap()
end end
@ -60,9 +73,122 @@ function terminate()
minimapWindow:destroy() minimapWindow:destroy()
end end
function loadMapFlags()
mapFlags = {}
local flagSettings = g_settings.getNode('MapFlags')
if flagSettings then
for i = 1, #flagSettings do
local flag = flagSettings[i]
addMapFlag(flag.position, flag.icon, flag.description, flag.id, flag.version)
if i == #flagSettings then
nextFlagId = flag.id + 1
end
end
end
end
function saveMapFlags()
local flagSettings = {}
for i = 1, flagsPanel:getChildCount() do
local child = flagsPanel:getChildByIndex(i)
table.insert(flagSettings, { position = child.position,
icon = child.icon,
description = child.description,
id = child.id,
version = child.version })
end
g_settings.setNode('MapFlags', flagSettings)
end
function getFlagIconClip(id)
return (((id)%10)*11) .. ' ' .. ((math.ceil(id/10+0.1)-1)*11) .. ' 11 11'
end
function addMapFlag(pos, icon, message, flagId, version)
if not(icon >= 1 and icon <= 20) or not pos then
return
end
version = version or g_game.getClientVersion()
-- Check if flag is set for that position
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 version == flag.version then
return
end
end
if not flagId then
flagId = nextFlagId
nextFlagId = nextFlagId + 1
end
local flagWidget = g_ui.createWidget('FlagWidget', flagsPanel)
flagWidget:setIconClip(getFlagIconClip(icon - 1))
flagWidget:setId('flag' .. flagId)
flagWidget.position = pos
flagWidget.icon = icon
flagWidget.description = message
flagWidget:setTooltip(tr(message))
flagWidget.id = flagId
flagWidget.version = version
updateMapFlag(flagId)
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.getClientVersion() and (minimapWidget:getZoom() >= 30 and minimapWidget:getZoom() <= 150) 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)
local firstPosition, lastPosition = getMapArea()
if not firstPosition or not lastPosition then
return
end
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))
else
flag:setVisible(false)
end
end
function updateMapFlags()
local firstPosition, lastPosition = getMapArea()
if not firstPosition or not lastPosition then
return
end
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))
else
flag:setVisible(false)
end
end
end
function online() function online()
reset() reset()
loadMap() loadMap()
updateMapFlags()
end end
function offline() function offline()
@ -133,6 +259,8 @@ function compassClick(self, mousePos, mouseButton, elapsed)
local cameraPos = minimapWidget:getCameraPosition() local cameraPos = minimapWidget:getCameraPosition()
local pos = {x = cameraPos.x + movex, y = cameraPos.y + movey, z = cameraPos.z} local pos = {x = cameraPos.x + movex, y = cameraPos.y + movey, z = cameraPos.z}
minimapWidget:setCameraPosition(pos) minimapWidget:setCameraPosition(pos)
updateMapFlags()
end end
function onButtonClick(id) function onButtonClick(id)
@ -153,6 +281,8 @@ function onButtonClick(id)
minimapWidget:setCameraPosition(pos) minimapWidget:setCameraPosition(pos)
end end
end end
updateMapFlags()
end end
function onMinimapMouseRelease(self, mousePosition, mouseButton) function onMinimapMouseRelease(self, mousePosition, mouseButton)
@ -179,6 +309,7 @@ function onMinimapMouseWheel(self, mousePos, direction)
else else
self:zoomOut() self:zoomOut()
end end
updateMapFlags()
end end
function onMiniWindowClose() function onMiniWindowClose()

View File

@ -8,6 +8,13 @@ MapControl < Button
$hover !pressed: $hover !pressed:
icon-clip: 0 16 16 16 icon-clip: 0 16 16 16
FlagWidget < UIWidget
size: 11 11
icon-clip: 0 0 11 11
icon-source: /game_minimap/images/mapflags.png
anchors.left: parent.left
anchors.top: parent.top
FloorUpControl < MapControl FloorUpControl < MapControl
icon-source: /game_minimap/images/floor_up.png icon-source: /game_minimap/images/floor_up.png
@ -26,6 +33,7 @@ MiniWindow
height: 150 height: 150
icon: minimap.png icon: minimap.png
@onClose: modules.game_minimap.onMiniWindowClose() @onClose: modules.game_minimap.onMiniWindowClose()
@onGeometryChange: updateMapFlags()
&save: true &save: true
Label Label
@ -43,6 +51,11 @@ MiniWindow
id: minimap id: minimap
anchors.fill: parent anchors.fill: parent
Panel
id: flagsPanel
anchors.fill: minimap
phantom: true
FloorUpControl FloorUpControl
id: floorUp id: floorUp
anchors.right: parent.right anchors.right: parent.right

View File

@ -359,6 +359,30 @@ namespace Otc
PATHFIND_ALLOW_NONPATHABLE = 4, PATHFIND_ALLOW_NONPATHABLE = 4,
PATHFIND_ALLOW_NONWALKABLE = 8 PATHFIND_ALLOW_NONWALKABLE = 8
}; };
enum AutomapFlags
{
MAPMARK_TICK = 0,
MAPMARK_QUESTION,
MAPMARK_EXCLAMATION,
MAPMARK_STAR,
MAPMARK_CROSS,
MAPMARK_TEMPLE,
MAPMARK_KISS,
MAPMARK_SHOVEL,
MAPMARK_SWORD,
MAPMARK_FLAG,
MAPMARK_LOCK,
MAPMARK_BAG,
MAPMARK_SKULL,
MAPMARK_DOLLAR,
MAPMARK_REDNORTH,
MAPMARK_REDSOUTH,
MAPMARK_REDEAST,
MAPMARK_REDWEST,
MAPMARK_GREENNORTH,
MAPMARK_GREENSOUTH
};
} }
#endif #endif

View File

@ -1288,10 +1288,11 @@ void ProtocolGame::parseTutorialHint(const InputMessagePtr& msg)
void ProtocolGame::parseAutomapFlag(const InputMessagePtr& msg) void ProtocolGame::parseAutomapFlag(const InputMessagePtr& msg)
{ {
// ignored Position pos = getPosition(msg); // position
getPosition(msg); // position int icon = msg->getU8(); // icon
msg->getU8(); // icon std::string description = msg->getString(); // message
msg->getString(); // message
g_game.processAutomapFlag(pos, icon, description);
} }
void ProtocolGame::parseQuestLog(const InputMessagePtr& msg) void ProtocolGame::parseQuestLog(const InputMessagePtr& msg)