improve minimap

This commit is contained in:
Eduardo Bart 2012-06-22 02:26:22 -03:00
parent aed779a2c8
commit d39cf361ab
20 changed files with 144 additions and 77 deletions

View File

@ -25,7 +25,10 @@ local skin = {
'spinboxes.otui',
'messageboxes.otui',
'scrollbars.otui',
'splitters.otui'
'splitters.otui',
'miniwindow.otui',
'items.otui',
'creatures.otui'
}
}

View File

@ -85,7 +85,7 @@ function HealthBar.onMiniWindowClose()
end
function HealthBar.offline()
healthBarWindow:recursiveGetChildById('conditions_content'):destroyChildren()
healthBarWindow:recursiveGetChildById('conditionPanel'):destroyChildren()
end
-- hooked events
@ -121,7 +121,7 @@ function HealthBar.onStatesChange(localPlayer, now, old)
end
function HealthBar.toggleIcon(bitChanged)
local content = healthBarWindow:recursiveGetChildById('conditions_content')
local content = healthBarWindow:recursiveGetChildById('conditionPanel')
local icon = content:getChildById(Icons[bitChanged].id)
if icon then

View File

@ -53,7 +53,7 @@ MiniWindow
ManaBar
ManaLabel
Panel
id: conditions_content
id: conditionPanel
layout:
type: horizontalBox
fit-children: true

View File

@ -65,6 +65,15 @@ function GameInterface.init()
Keyboard.bindKeyDown('Ctrl+L', GameInterface.tryLogout, gameRootPanel)
Keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() TextMessage.clearMessages() end, gameRootPanel)
Keyboard.bindKeyDown('Ctrl+.', function()
if gameMapPanel:isKeepAspectRatioEnabled() then
gameMapPanel:setKeepAspectRatio(false)
else
gameMapPanel:setKeepAspectRatio(true)
gameMapPanel:setVisibleDimension({ width = 15, height = 11 })
end
end)
if g_game.isOnline() then
GameInterface.show()
end

View File

@ -5,9 +5,6 @@ Module
website: www.otclient.info
@onLoad: |
importStyle 'styles/items.otui'
importStyle 'styles/creatures.otui'
importStyle 'styles/miniwindow.otui'
importStyle 'styles/countwindow.otui'
dofile 'widgets/uigamemap'

View File

@ -3,7 +3,9 @@ Minimap = {}
-- private variables
local minimapWidget
local minimapButton
local minimapWindow
local DEFAULT_ZOOM = 45
minimapFirstLoad = true
-- private functions
function onMinimapMouseRelease(self, mousePosition, mouseButton)
@ -37,30 +39,58 @@ function Minimap.init()
minimapButton = TopMenu.addGameToggleButton('minimapButton', tr('Minimap') .. ' (Ctrl+M)', 'minimap.png', Minimap.toggle)
minimapButton:setOn(false)
minimapWidget = loadUI('minimap.otui', GameInterface.getMapPanel())
minimapWindow = loadUI('minimap.otui', GameInterface.getRightPanel())
minimapWindow:setOn(true)
minimapWidget = minimapWindow:recursiveGetChildById('minimap')
minimapWidget:setAutoViewMode(false)
minimapWidget:setViewMode(1) -- mid view
minimapWidget:setDrawMinimapColors(true)
minimapWidget:setMultifloor(false)
minimapWidget:setKeepAspectRatio(false)
minimapWidget.onMouseRelease = onMinimapMouseRelease
minimapWidget.onMouseWheel = onMinimapMouseWheel
minimapWidget:hide()
Minimap.reset()
-- load only the first time (avoid load/save between reloads)
if minimapFirstLoad then
minimapFirstLoad = false
if g_resources.fileExists('/minimap.otcm') then
if g_game.isOnline() then
perror('cannot load minimap while online')
else
g_map.loadOtcm('/minimap.otcm')
end
end
-- save only when closing the client
connect(g_app, { onTerminate = function()
g_map.saveOtcm('/minimap.otcm')
end})
end
end
function Minimap.terminate()
disconnect(g_game, { onGameStart = Minimap.reset })
Keyboard.unbindKeyDown('Ctrl+M')
minimapWidget:destroy()
minimapWindow:destroy()
minimapWindow = nil
minimapWidget = nil
minimapButton:destroy()
minimapButton = nil
Minimap = nil
end
function Minimap.toggle()
local visible = not minimapWidget:isExplicitlyVisible()
minimapWidget:setVisible(visible)
minimapButton:setOn(visible)
local visible = not minimapWindow:isExplicitlyVisible()
if visible then
minimapWindow:open()
minimapButton:setOn(true)
else
minimapWindow:close()
minimapButton:setOn(false)
end
end
function Minimap.reset()

View File

@ -1,21 +1,11 @@
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
MiniWindow
id: minimapWindow
!text: tr('Minimap')
height: 150
icon: minimap.png
CheckBox
anchors.top: parent.top
anchors.right: parent.right
margin-top: 2
margin-right: 2
size: 16 16
@onCheckChange: self:getParent():setDrawMinimapColors(self:isChecked())
MiniWindowContents
padding: 3
UIMap
id: minimap
anchors.fill: parent

View File

@ -8,9 +8,9 @@ void main()
int j;
int i;
for(i = -2 ;i <= 2; i++)
for(j = -2; j <= 2; j++)
color += texture2D(u_Tex0, v_TexCoord + vec2(i, j)*0.0025) * 0.025;
for(i = -4 ;i <= 4; i++)
for(j = -4; j <= 4; j++)
color += texture2D(u_Tex0, v_TexCoord + vec2(i, j)*0.003) * 0.008;
gl_FragColor = color;
}

View File

@ -60,7 +60,7 @@ void FrameBuffer::resize(const Size& size)
return;
m_texture = TexturePtr(new Texture(size));
m_texture->setSmooth(true);
m_texture->setSmooth(m_smooth);
m_texture->setUpsideDown(true);
if(m_fbo) {

View File

@ -44,10 +44,12 @@ public:
void draw(const Rect& dest, const Rect& src);
void setBackuping(bool enabled) { m_backuping = enabled; }
void setSmooth(bool enabled) { m_smooth = enabled; }
TexturePtr getTexture() { return m_texture; }
Size getSize();
bool isBackuping() { return m_backuping; }
bool isSmooth() { return m_smooth; }
private:
void internalCreate();
@ -60,6 +62,7 @@ private:
uint m_fbo;
uint m_prevBoundFbo;
Boolean<true> m_backuping;
Boolean<true> m_smooth;
static uint boundFbo;
};

View File

@ -556,6 +556,9 @@ void Map::setCentralPosition(const Position& centralPosition)
g_game.processCreatureTeleport(localPlayer);
}
});
for(const MapViewPtr& mapView : m_mapViews)
mapView->onMapCenterChange(centralPosition);
}
std::vector<CreaturePtr> Map::getSpectators(const Position& centerPos, bool multiFloor)

View File

@ -101,7 +101,11 @@ void MapView::draw(const Rect& rect)
if(!m_drawMinimapColors)
tile->draw(transformPositionTo2D(tilePos, cameraPosition), scaleFactor, drawFlags);
else {
g_painter->setColor(tile->getMinimapColor());
uint8 c = tile->getMinimapColorByte();
if(c == 0)
continue;
g_painter->setColor(Color::from8bit(c));
g_painter->drawFilledRect(Rect(transformPositionTo2D(tilePos, cameraPosition), tileSize));
}
}
@ -399,9 +403,11 @@ void MapView::updateVisibleTilesCache(int start)
void MapView::updateGeometry(const Size& visibleDimension, const Size& optimizedSize)
{
int possiblesTileSizes[] = {1,2,4,8,16,32};
int tileSize = 0;
Size bufferSize;
if(!m_drawMinimapColors) {
int possiblesTileSizes[] = {1,2,4,8,16,32};
for(int candidateTileSize : possiblesTileSizes) {
bufferSize = (visibleDimension + Size(3,3)) * candidateTileSize;
if(bufferSize.width() > g_graphics.getMaxTextureSize() || bufferSize.height() > g_graphics.getMaxTextureSize())
@ -416,6 +422,10 @@ void MapView::updateGeometry(const Size& visibleDimension, const Size& optimized
g_logger.traceError("reached max zoom out");
return;
}
} else {
tileSize = 1;
bufferSize = visibleDimension + Size(3,3);
}
Size drawDimension = visibleDimension + Size(3,3);
Point virtualCenterOffset = (drawDimension/2 - Size(1,1)).toPoint();
@ -456,7 +466,12 @@ void MapView::updateGeometry(const Size& visibleDimension, const Size& optimized
void MapView::onTileUpdate(const Position& pos)
{
//if(m_viewMode <= FAR_VIEW)
if(!m_drawMinimapColors)
requestVisibleTilesCacheUpdate();
}
void MapView::onMapCenterChange(const Position& pos)
{
requestVisibleTilesCacheUpdate();
}
@ -656,3 +671,14 @@ TilePtr MapView::getTile(const Point& mousePos, const Rect& mapRect)
return tile;
}
void MapView::setDrawMinimapColors(bool enable)
{
if(m_drawMinimapColors == enable)
return;
m_drawMinimapColors = enable;
updateGeometry(m_visibleDimension, m_optimizedSize);
requestVisibleTilesCacheUpdate();
m_smooth = !enable;
m_framebuffer->setSmooth(m_smooth);
}

View File

@ -61,6 +61,7 @@ private:
protected:
void onTileUpdate(const Position& pos);
void onMapCenterChange(const Position& pos);
friend class Map;
@ -99,7 +100,7 @@ public:
void setDrawTexts(bool enable) { m_drawTexts = enable; }
bool isDrawingTexts() { return m_drawTexts; }
void setDrawMinimapColors(bool enable) { m_drawMinimapColors = enable; requestVisibleTilesCacheUpdate(); }
void setDrawMinimapColors(bool enable);
bool isDrawingMinimapColors() { return m_drawMinimapColors; }
void setAnimated(bool animated) { m_animated = animated; requestVisibleTilesCacheUpdate(); }
@ -138,6 +139,7 @@ private:
Boolean<true> m_animated;
Boolean<true> m_autoViewMode;
Boolean<true> m_drawTexts;
Boolean<true> m_smooth;
Boolean<false> m_drawMinimapColors;
std::vector<TilePtr> m_cachedVisibleTiles;
std::vector<CreaturePtr> m_cachedFloorVisibleCreatures;

View File

@ -34,6 +34,7 @@ Tile::Tile(const Position& position)
{
m_drawElevation = 0;
m_position = position;
m_minimapColorByte = 0;
}
void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
@ -192,6 +193,7 @@ ThingPtr Tile::addThing(const ThingPtr& thing, int stackPos)
if(m_things.size() > MAX_THINGS)
removeThing(m_things[MAX_THINGS]);
update();
return oldObject;
}
@ -217,10 +219,8 @@ bool Tile::removeThing(ThingPtr thing)
}
// reset values managed by this tile
if(removed) {
//thing->setDrawOffset(0);
//thing->setStackpos(0);
}
if(removed)
update();
return removed;
}
@ -281,19 +281,6 @@ int Tile::getGroundSpeed()
return groundSpeed;
}
Color Tile::getMinimapColor()
{
Color color = Color::black;
for(const ThingPtr& thing : m_things) {
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())
break;
int c = thing->getMinimapColor();
if(c != 0)
color = Color::from8bit(c);
}
return color;
}
ThingPtr Tile::getTopLookThing()
{
if(isEmpty())
@ -493,3 +480,14 @@ bool Tile::canErase()
return m_walkingCreatures.empty() && m_effects.empty() && m_things.empty();
}
void Tile::update()
{
m_minimapColorByte = 0;
for(const ThingPtr& thing : m_things) {
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())
break;
uint8 c = thing->getMinimapColor();
if(c != 0)
m_minimapColorByte = c;
}
}

View File

@ -82,7 +82,7 @@ public:
const std::vector<ThingPtr>& getThings() { return m_things; }
ItemPtr getGround();
int getGroundSpeed();
Color getMinimapColor();
uint8 getMinimapColorByte() { return m_minimapColorByte; }
int getThingCount() { return m_things.size() + m_effects.size(); }
bool isPathable();
bool isWalkable();
@ -101,12 +101,15 @@ public:
void setFlags(tileflags_t flags) { m_flags |= (uint32)flags; }
private:
void update();
std::vector<CreaturePtr> m_walkingCreatures;
std::vector<EffectPtr> m_effects; // leave this outside m_things because it has no stackpos.
std::vector<ThingPtr> m_things;
Position m_position;
uint8 m_drawElevation;
uint32 m_flags;
uint8 m_minimapColorByte;
};
#endif

View File

@ -101,8 +101,10 @@ void UIMap::setVisibleDimension(const Size& visibleDimension)
{
m_mapView->setVisibleDimension(visibleDimension);
if(m_aspectRatio != 0.0f)
if(m_aspectRatio != 0.0f) {
m_aspectRatio = visibleDimension.ratio();
updateMapSize();
}
}
void UIMap::setKeepAspectRatio(bool enable)
@ -111,6 +113,7 @@ void UIMap::setKeepAspectRatio(bool enable)
m_aspectRatio = getVisibleDimension().ratio();
else
m_aspectRatio = 0.0f;
updateMapSize();
}
TilePtr UIMap::getTile(const Point& mousePos)

View File

@ -61,7 +61,7 @@ public:
bool isDrawingTexts() { return m_mapView->isDrawingTexts(); }
bool isDrawingMinimapColors() { return m_mapView->isDrawingMinimapColors(); }
bool isAnimating() { return m_mapView->isAnimating(); }
float isKeepAspectRatioEnabled() { return m_aspectRatio != 0.0f; }
bool isKeepAspectRatioEnabled() { return m_aspectRatio != 0.0f; }
Size getVisibleDimension() { return m_mapView->getVisibleDimension(); }
MapView::ViewMode getViewMode() { return m_mapView->getViewMode(); }