experimental minimap

* a lot of rework in MapView
* new APIs for UIMap
This commit is contained in:
Eduardo Bart
2012-04-06 20:12:46 -03:00
parent fba5f188d7
commit 2835a66bab
18 changed files with 583 additions and 185 deletions

View File

@@ -20,6 +20,7 @@ Module
- game_containers
- game_viplist
- game_battle
- game_minimap
- game_hotkeys
@onLoad: |

View File

@@ -2,6 +2,8 @@ UIGameMap = extends(UIMap)
function UIGameMap.create()
local gameMap = UIGameMap.internalCreate()
gameMap:setKeepAspectRatio(true)
gameMap:setVisibleDimension({width = 15, height = 11})
return gameMap
end

View File

@@ -0,0 +1,64 @@
Minimap = {}
-- private variables
local minimapWidget
local minimapButton
-- private functions
function onMinimapMouseRelease(self, mousePosition, mouseButton)
local tile = self:getTile(mousePosition)
if tile and mouseButton == MouseLeftButton and self:isPressed() then
local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), tile:getPosition(), 255)
if #dirs == 0 then
TextMessage.displayStatus('There is no way.')
return true
end
g_game.autoWalk(dirs)
return true
end
return false
end
function onMinimapMouseWheel(self, mousePos, direction)
if direction == MouseWheelUp then
self:zoomIn()
else
self:zoomOut()
end
end
-- public functions
function Minimap.init()
connect(g_game, { onLogin = Minimap.reset })
Keyboard.bindKeyDown('Ctrl+M', Minimap.toggle)
minimapButton = TopMenu.addGameToggleButton('minimapButton', 'Minimap (Ctrl+M)', 'minimap.png', Minimap.toggle)
minimapButton:setOn(true)
minimapWidget = loadUI('minimap.otui', GameInterface.getMapPanel())
minimapWidget.onMouseRelease = onMinimapMouseRelease
minimapWidget.onMouseWheel = onMinimapMouseWheel
end
function Minimap.terminate()
Keyboard.unbindKeyDown('Ctrl+M')
disconnect(g_game, { onLogin = Minimap.reset })
minimapWidget:destroy()
minimapWidget = nil
minimapButton:destroy()
minimapButton = nil
end
function Minimap.toggle()
local visible = not minimapWidget:isExplicitlyVisible()
minimapWidget:setVisible(visible)
minimapButton:setOn(visible)
end
function Minimap.reset()
minimapWidget:followCreature(g_game.getLocalPlayer())
for i=1,10 do minimapWidget:zoomOut() end
end

View File

@@ -0,0 +1,15 @@
Module
name: game_minimap
description: Manage minimap
author: OTClient team
website: https://github.com/edubart/otclient
dependecies:
- game
@onLoad: |
dofile 'minimap'
Minimap.init()
@onUnload:
Minimap.terminate()

View File

@@ -0,0 +1,21 @@
UIMap
id: minimap
anchors.top: parent.top
anchors.right: parent.right
size: 256 192
margin-top: 2
margin-right: 2
border-width: 1
border-color: #888888
padding: 1
//draw-minimap-colors: true
multifloor: false
draw-texts: false
CheckBox
anchors.top: parent.top
anchors.right: parent.right
margin-top: 2
margin-right: 2
size: 16 16
@onCheckChange: self:getParent():setDrawMinimapColors(self:isChecked())

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 B

View File

@@ -3,8 +3,84 @@ uniform vec4 color; // painter color
uniform float time; // time in seconds since shader linkage
uniform sampler2D texture; // map texture
varying vec2 textureCoords; // map texture coords
//uniform vec4 awareArea;
void main()
{
gl_FragColor = texture2D(texture, textureCoords);
}
/*
vec4 grayScale(vec4 color, float factor)
{
float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
return vec4(gray*factor + (1-factor)*color.r,
gray*factor + (1-factor)*color.g,
gray*factor + (1-factor)*color.b, 1);
}
// grayscale fog
void main()
{
vec4 color = texture2D(texture, textureCoords);
float dist = 0;
// left
if(textureCoords.x < awareArea.x && textureCoords.y < awareArea.y)
dist = distance(textureCoords, awareArea.xy);
else if(textureCoords.x < awareArea.x && textureCoords.y < awareArea.w)
dist = distance(textureCoords, vec2(awareArea.x, textureCoords.y));
else if(textureCoords.x < awareArea.x)
dist = distance(textureCoords, awareArea.xw);
// right
else if(textureCoords.x > awareArea.z && textureCoords.y < awareArea.y)
dist = distance(textureCoords, awareArea.zy);
else if(textureCoords.x > awareArea.z && textureCoords.y < awareArea.w)
dist = distance(textureCoords, vec2(awareArea.z, textureCoords.y));
else if(textureCoords.x > awareArea.z)
dist = distance(textureCoords, awareArea.zw);
// top
else if(textureCoords.y < awareArea.y)
dist = distance(textureCoords, vec2(textureCoords.x, awareArea.y));
// bottom
else if(textureCoords.y > awareArea.w)
dist = distance(textureCoords, vec2(textureCoords.x, awareArea.w));
if(dist > 0) {
float range = 0.01;
float factor = min(dist/range, 1.0);
color = grayScale(color, factor);
//color.rgb *= 1 - (factor * 0.5);
}
gl_FragColor = color;
}
*/
/*
sepia
void main()
{
vec4 color = texture2D(texture, textureCoords);
if(textureCoords.x < awareArea.x || textureCoords.y < awareArea.y || textureCoords.x > awareArea.z || textureCoords.y > awareArea.w) {
gl_FragColor.r = dot(color, vec4(.393, .769, .189, .0));
gl_FragColor.g = dot(color, vec4(.349, .686, .168, .0));
gl_FragColor.b = dot(color, vec4(.272, .534, .131, .0));
gl_FragColor.a = 1;
} else
gl_FragColor = color;
}
*/
/*
void main()
{
vec4 color = texture2D(texture, textureCoords);
vec2 awareRange = (awareArea.zw - awareArea.xy)/2.0;
float dist = distance(textureCoords, awareArea.xy + awareRange);
float start = min(awareRange.x, awareRange.y);
float range = awareRange*0.1;
float endFactor = 0.3;
if(dist >= start) {
color.rgb *= 1 - (min((dist - start)/range, 1.0) * (2.0 - endFactor));
}
gl_FragColor = color;
}
*/