diff --git a/.gitignore b/.gitignore index 4b2deb73..657dde36 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ CMakeLists.txt.user* /modules/myotclientrc.lua !.gitignore otclient.map +otclient.layout diff --git a/modules/game_battle/battle.lua b/modules/game_battle/battle.lua index dcf882e8..899b6c89 100644 --- a/modules/game_battle/battle.lua +++ b/modules/game_battle/battle.lua @@ -130,13 +130,13 @@ function Battle.doCreatureFitFilters(creature) local hideSkulls = hideSkullsButton:isChecked() local hideParty = hidePartyButton:isChecked() - if hidePlayers and not creature:asMonster() and not creature:asNpc() then + if hidePlayers and creature:asPlayer() then return false elseif hideNPCs and creature:asNpc() then return false elseif hideMonsters and creature:asMonster() then return false - elseif hideSkulls and creature:getSkull() == SkullNone then + elseif hideSkulls and creature:asPlayer() and creature:getSkull() == SkullNone then return false elseif hideParty and creature:getShield() > ShieldWhiteBlue then return false @@ -359,6 +359,7 @@ function Battle.checkBattleButton(battleButton) end if battleButton.isTarget or battleButton.isFollowed then + -- set new last battle button switched if lastBattleButtonSwitched and lastBattleButtonSwitched ~= battleButton then lastBattleButtonSwitched.isTarget = false lastBattleButtonSwitched.isFollowed = false diff --git a/modules/game_minimap/compass.png b/modules/game_minimap/compass.png index 8754c3a0..3de73991 100644 Binary files a/modules/game_minimap/compass.png and b/modules/game_minimap/compass.png differ diff --git a/modules/game_minimap/floor_down.png b/modules/game_minimap/floor_down.png new file mode 100644 index 00000000..b508610e Binary files /dev/null and b/modules/game_minimap/floor_down.png differ diff --git a/modules/game_minimap/floor_up.png b/modules/game_minimap/floor_up.png new file mode 100644 index 00000000..804aa9ea Binary files /dev/null and b/modules/game_minimap/floor_up.png differ diff --git a/modules/game_minimap/minimap.lua b/modules/game_minimap/minimap.lua index fb7542d5..ea04fa29 100644 --- a/modules/game_minimap/minimap.lua +++ b/modules/game_minimap/minimap.lua @@ -30,9 +30,16 @@ function onMinimapMouseWheel(self, mousePos, direction) end end +--[[ + Known Issue (TODO): + If you move the minimap compass directions and + you change floor it will not update the minimap. +]] -- public functions function Minimap.init() - connect(g_game, { onGameStart = Minimap.reset }) + connect(g_game, { onGameStart = Minimap.reset, + onForceWalk = Minimap.center } ) + g_keyboard.bindKeyDown('Ctrl+M', Minimap.toggle) minimapButton = TopMenu.addGameToggleButton('minimapButton', tr('Minimap') .. ' (Ctrl+M)', 'minimap.png', Minimap.toggle) @@ -70,7 +77,9 @@ function Minimap.init() end function Minimap.terminate() - disconnect(g_game, { onGameStart = Minimap.reset }) + disconnect(g_game, { onGameStart = Minimap.reset, + onForceWalk = Minimap.center } ) + g_keyboard.unbindKeyDown('Ctrl+M') minimapButton:destroy() @@ -102,6 +111,12 @@ function Minimap.reset() minimapWidget:setZoom(DEFAULT_ZOOM) end +function Minimap.center() + local player = g_game.getLocalPlayer() + if not player then return end + minimapWidget:followCreature(player) +end + function Minimap.isClickInRange(position, fromPosition, toPosition) return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.x <= toPosition.x and position.y <= toPosition.y) end @@ -111,32 +126,23 @@ compassZones.west = {x = 0, y = 30, posx = -1, posy = 0} compassZones.north = {x = 30, y = 0, posx = 0, posy = -1} compassZones.south = {x = 30, y = 57, posx = 0, posy = 1} compassZones.east = {x = 57, y = 30, posx = 1, posy = 0} -compassZones.center = {x = 30, y = 30, posx = 0, posy = 0, center = true} function Minimap.compassClick(self, mousePos) local compassPos = self:getRect() local pos = {x = mousePos.x-compassPos.x, y = mousePos.y-compassPos.y} local move = {x = 0, y = 0} - local center = false for i,v in pairs(compassZones) do local lowPos = {x = v.x-15, y = v.y-15} local highPos = {x = v.x+15, y = v.y+15} if Minimap.isClickInRange(pos, lowPos, highPos) then move.x = move.x + v.posx * minimapWidget:getZoom()/10 move.y = move.y + v.posy * minimapWidget:getZoom()/10 - if v.center then center = true end break end end - if center then - local player = g_game.getLocalPlayer() - if not player then return end - minimapWidget:followCreature(player) - else - local cameraPos = minimapWidget:getCameraPosition() - local pos = {x = cameraPos.x + move.x, y = cameraPos.y + move.y, z = cameraPos.z} - minimapWidget:setCameraPosition(pos) - end + local cameraPos = minimapWidget:getCameraPosition() + local pos = {x = cameraPos.x + move.x, y = cameraPos.y + move.y, z = cameraPos.z} + minimapWidget:setCameraPosition(pos) end function Minimap.onButtonClick(id) diff --git a/modules/game_minimap/minimap.otui b/modules/game_minimap/minimap.otui index fea6e717..a1308aef 100644 --- a/modules/game_minimap/minimap.otui +++ b/modules/game_minimap/minimap.otui @@ -1,3 +1,30 @@ +MapControl < Button + size: 16 16 + + $pressed: + image-clip: 0 0 16 16 + + $hover !pressed: + image-clip: 0 16 16 16 + + $!pressed !hover: + image-clip: 0 32 16 16 + + $disabled: + image-color: #ffffff88 + +FloorUpControl < MapControl + image-source: /game_minimap/floor_up.png + +FloorDownControl < MapControl + image-source: /game_minimap/floor_down.png + +//ZoomOutControl < MapControl + //image-source: /game_minimap/zoom_out.png + +//ZoomInControl < MapControl + //image-source: /game_minimap/zoom_in.png + MiniWindow id: minimapWindow !text: tr('Minimap') @@ -17,46 +44,74 @@ MiniWindow UIButton id: compass image-source: /game_minimap/compass.png + color: #ffffff anchors.left: minimap.right anchors.top: minimap.top size: 60 60 + margin-top: 3 margin-left: 5 @onClick: function(...) Minimap.compassClick(...) end + UIButton + id: compassReset + text: Reset + font: verdana-11px-rounded + anchors.left: compass.left + anchors.top: compass.top + margin-top: 25 + margin-left: 14 + @onClick: function(...) Minimap.center(...) end + $pressed: + color: #eb9f4f88 + margin-top: 26 + margin-left: 15 + + $hover !pressed: + color: #eb9f4f + + $!pressed !hover: + color: #ffffff + margin-top: 25 + margin-left: 14 + + $disabled: + image-color: #ffffff88 + Button id: zoomOut text: - - size: 20 20 + font: terminus-14px-bold + size: 16 16 anchors.left: minimap.right anchors.top: compass.bottom - margin-top: 5 - margin-left: 15 + margin-top: 10 + margin-left: 10 + enabled: true @onClick: Minimap.onButtonClick(self:getId()) Button id: zoomIn text: + - size: 20 20 + size: 16 16 anchors.left: zoomOut.left anchors.top: zoomOut.bottom - margin-top: 2 + margin-top: 4 + enabled: true @onClick: Minimap.onButtonClick(self:getId()) - Button + FloorUpControl id: levelUp - text: /\ - size: 20 20 anchors.left: zoomOut.right anchors.top: zoomOut.top - margin-left: 2 + margin-left: 15 + enabled: true @onClick: Minimap.onButtonClick(self:getId()) - Button + FloorDownControl id: levelDown - text: \/ - size: 20 20 anchors.left: zoomIn.right anchors.top: zoomIn.top - margin-left: 2 + margin-left: 15 + enabled: true @onClick: Minimap.onButtonClick(self:getId()) diff --git a/modules/game_minimap/zoom_in.png b/modules/game_minimap/zoom_in.png new file mode 100644 index 00000000..5bec5146 Binary files /dev/null and b/modules/game_minimap/zoom_in.png differ diff --git a/modules/game_minimap/zoom_out.png b/modules/game_minimap/zoom_out.png new file mode 100644 index 00000000..9da7a4f1 Binary files /dev/null and b/modules/game_minimap/zoom_out.png differ diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 3b4978c0..c5ca88c8 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -241,6 +241,8 @@ void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldP { // animate walk creature->walk(oldPos, newPos); + + g_lua.callGlobalField("g_game", "onCreatureMove", creature, oldPos, newPos); } void Game::processCreatureTeleport(const CreaturePtr& creature) @@ -251,6 +253,8 @@ void Game::processCreatureTeleport(const CreaturePtr& creature) // locks the walk for a while when teleporting if(creature == m_localPlayer) m_localPlayer->lockWalk(); + + g_lua.callGlobalField("g_game", "onCreatureTeleport", creature); } void Game::processChannelList(const std::vector>& channelList) @@ -528,6 +532,8 @@ void Game::forceWalk(Otc::Direction direction) default: break; } + + g_lua.callGlobalField("g_game", "onForceWalk", direction); } void Game::turn(Otc::Direction direction) @@ -736,8 +742,11 @@ void Game::cancelAttackAndFollow() m_localPlayer->lockWalk(); - setAttackingCreature(nullptr); - setFollowingCreature(nullptr); + if(isAttacking()) + setAttackingCreature(nullptr); + if(isFollowing()) + setFollowingCreature(nullptr); + m_protocolGame->sendCancelAttackAndFollow(); } diff --git a/src/otclient/core/mapview.cpp b/src/otclient/core/mapview.cpp index c15dbdc6..47cfc313 100644 --- a/src/otclient/core/mapview.cpp +++ b/src/otclient/core/mapview.cpp @@ -127,7 +127,7 @@ void MapView::draw(const Rect& rect) Point drawOffset = ((m_drawDimension - m_visibleDimension - Size(1,1)).toPoint()/2) * m_tileSize; - if(m_followingCreature) + if(isFollowingCreature()) drawOffset += m_followingCreature->getWalkOffset() * scaleFactor; Size srcSize = rect.size(); @@ -210,11 +210,32 @@ void MapView::draw(const Rect& rect) } } else if(m_viewMode > NEAR_VIEW) { // draw a cross in the center instead of our creature + /* + Known Issue: Changing Z axis causes the cross to go off a little bit. + */ Rect vRect(0, 0, 2, 10); Rect hRect(0, 0, 10, 2); - vRect.moveCenter(rect.center()); - hRect.moveCenter(rect.center()); g_painter->setColor(Color::white); + + if(!m_follow && m_followingCreature) + { + Position pos = m_followingCreature->getPosition(); + Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset; + p.x = p.x * horizontalStretchFactor; + p.y = p.y * verticalStretchFactor; + p += rect.topLeft(); + + vRect.setX(p.x); vRect.setY(p.y - 4); + hRect.setX(p.x - 4); hRect.setY(p.y); + + hRect.setWidth(10); hRect.setHeight(2); + vRect.setWidth(2); vRect.setHeight(10); + } + else { + vRect.moveCenter(rect.center()); + hRect.moveCenter(rect.center()); + } + g_painter->drawFilledRect(vRect); g_painter->drawFilledRect(hRect); } @@ -525,14 +546,15 @@ void MapView::optimizeForSize(const Size& visibleSize) void MapView::followCreature(const CreaturePtr& creature) { + m_follow = true; m_followingCreature = creature; requestVisibleTilesCacheUpdate(); } void MapView::setCameraPosition(const Position& pos) { + m_follow = false; m_customCameraPosition = pos; - m_followingCreature = nullptr; requestVisibleTilesCacheUpdate(); } @@ -623,8 +645,9 @@ int MapView::calcLastVisibleFloor() Position MapView::getCameraPosition() { - if(m_followingCreature) + if(isFollowingCreature()) return m_followingCreature->getPosition(); + return m_customCameraPosition; } @@ -641,13 +664,12 @@ TilePtr MapView::getTile(const Point& mousePos, const Rect& mapRect) float scaleFactor = m_tileSize / (float)Otc::TILE_PIXELS; - float horizontalStretchFactor = visibleSize.width() / (float)mapRect.width(); float verticalStretchFactor = visibleSize.height() / (float)mapRect.height(); Point tilePos2D = Point(relativeMousePos.x * horizontalStretchFactor, relativeMousePos.y * verticalStretchFactor); - if(m_followingCreature) + if(isFollowingCreature()) tilePos2D += m_followingCreature->getWalkOffset() * scaleFactor; tilePos2D /= m_tileSize; diff --git a/src/otclient/core/mapview.h b/src/otclient/core/mapview.h index 817a7630..a71dbbce 100644 --- a/src/otclient/core/mapview.h +++ b/src/otclient/core/mapview.h @@ -89,6 +89,7 @@ public: // camera related void followCreature(const CreaturePtr& creature); CreaturePtr getFollowingCreature() { return m_followingCreature; } + bool isFollowingCreature() { return m_followingCreature && m_follow; } void setCameraPosition(const Position& pos); Position getCameraPosition(); @@ -141,6 +142,7 @@ private: Boolean m_drawTexts; Boolean m_smooth; Boolean m_drawMinimapColors; + Boolean m_follow; std::vector m_cachedVisibleTiles; std::vector m_cachedFloorVisibleCreatures; EventPtr m_updateTilesCacheEvent; diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index c455d6e8..6d5fd20a 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -511,6 +511,7 @@ void ProtocolGame::parseCreatureMove(const InputMessagePtr& msg) // update map tiles if(!g_map.removeThing(thing)) g_logger.traceError("could not remove thing"); + g_map.addThing(thing, newPos); }