From 32c5f4285b5b0e07ed913eca790eb4b07aa80149 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Fri, 25 Jan 2013 17:26:51 -0200 Subject: [PATCH] Closes #210 * And minor adjustments --- data/locales/pt.lua | 2 +- modules/client_options/audio.otui | 4 -- modules/client_options/options.lua | 1 - modules/corelib/ui/uiminiwindowcontainer.lua | 2 +- modules/game_console/console.otui | 4 +- modules/game_interface/gameinterface.lua | 10 ++-- modules/game_interface/gameinterface.otui | 8 ++- modules/game_minimap/minimap.lua | 2 +- modules/game_skills/skills.lua | 63 +++++++++++++++++--- src/client/mapview.cpp | 56 +++++++++++++---- src/client/mapview.h | 3 + src/client/uimap.cpp | 24 +------- src/framework/ui/uitextedit.cpp | 2 +- 13 files changed, 121 insertions(+), 60 deletions(-) diff --git a/data/locales/pt.lua b/data/locales/pt.lua index a044828c..8f99cbf0 100644 --- a/data/locales/pt.lua +++ b/data/locales/pt.lua @@ -26,7 +26,7 @@ locale = { ["4c) False Report to Gamemaster"] = "4c) Relatório falso para Gamemaster", ["Accept"] = "Aceitar", ["Account name"] = "Nome da conta", - ["Account Status:"] = "Estado da Conta:", + ["Account Status"] = "Estado da Conta", ["Action"] = "Ação", ["Add"] = "Adicionar", ["Add new VIP"] = "Adicionar nova VIP", diff --git a/modules/client_options/audio.otui b/modules/client_options/audio.otui index 9fc60bdc..c688352b 100644 --- a/modules/client_options/audio.otui +++ b/modules/client_options/audio.otui @@ -15,10 +15,6 @@ Panel id: enableMusicSound !text: tr('Enable music sound') - OptionCheckBox - id: enableEffectsSound - !text: tr('Enable effects sound') - Label id: musicSoundVolumeLabel !text: tr('Music volume: %d', 100) diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index 3550dd48..4aacba88 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -25,7 +25,6 @@ local defaultOptions = { enableLights = true, enableShaders = true, ambientLight = 25, - enableEffectsSound = 0 } local optionsWindow diff --git a/modules/corelib/ui/uiminiwindowcontainer.lua b/modules/corelib/ui/uiminiwindowcontainer.lua index 8e9fffdb..7c00d67c 100644 --- a/modules/corelib/ui/uiminiwindowcontainer.lua +++ b/modules/corelib/ui/uiminiwindowcontainer.lua @@ -38,7 +38,7 @@ function UIMiniWindowContainer:fitAll(noRemoveChild) end end - local selfHeight = self:getHeight() - (self:getMarginTop() + self:getMarginBottom() + self:getPaddingTop() + self:getPaddingBottom()) + local selfHeight = self:getHeight() - (self:getPaddingTop() + self:getPaddingBottom()) if sumHeight <= selfHeight then return end diff --git a/modules/game_console/console.otui b/modules/game_console/console.otui index 5b8ccd5a..3e722603 100644 --- a/modules/game_console/console.otui +++ b/modules/game_console/console.otui @@ -33,7 +33,7 @@ ConsoleTabBarPanel < MoveableTabBarPanel align-bottom: true border-width: 1 border-color: #202327 - background: #00000044 + background: #00000066 inverted-scroll: true padding: 1 @@ -45,8 +45,6 @@ ConsoleTabBarPanel < MoveableTabBarPanel layout: type: verticalBox align-bottom: true - border-width: 1 - border-color: #202327 inverted-scroll: true padding: 1 @onScrollbarChange: | diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index e56a6638..ba12d163 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -660,8 +660,7 @@ function setupViewMode(mode) gameMapPanel:addAnchor(AnchorRight, 'gameRightPanel', AnchorLeft) gameMapPanel:addAnchor(AnchorBottom, 'gameBottomPanel', AnchorTop) gameRootPanel:addAnchor(AnchorTop, 'topMenu', AnchorBottom) - gameLeftPanel:setOn(false) - gameLeftPanel:setVisible(false) + gameLeftPanel:setOn(modules.client_options.getOption('showLeftPanel')) gameLeftPanel:setImageColor('white') gameRightPanel:setImageColor('white') gameLeftPanel:setMarginTop(0) @@ -689,12 +688,13 @@ function setupViewMode(mode) gameRootPanel:fill('parent') gameLeftPanel:setImageColor('alpha') gameRightPanel:setImageColor('alpha') - gameLeftPanel:setMarginTop(36) - gameRightPanel:setMarginTop(36) + gameLeftPanel:setMarginTop(modules.client_topmenu.getTopMenu():getHeight() - gameLeftPanel:getPaddingTop()) + gameRightPanel:setMarginTop(modules.client_topmenu.getTopMenu():getHeight() - gameRightPanel:getPaddingTop()) gameLeftPanel:setOn(true) gameLeftPanel:setVisible(true) gameRightPanel:setOn(true) - gameBottomPanel:setImageColor('#00000099') + gameMapPanel:setOn(true) + gameBottomPanel:setImageColor('#ffffff88') modules.client_topmenu.getTopMenu():setImageColor('#ffffff66') if not limitZoom then g_game.changeMapAwareRange(24, 20) diff --git a/modules/game_interface/gameinterface.otui b/modules/game_interface/gameinterface.otui index c4ed27bf..9196a223 100644 --- a/modules/game_interface/gameinterface.otui +++ b/modules/game_interface/gameinterface.otui @@ -4,6 +4,9 @@ GameSidePanel < UIMiniWindowContainer image-border: 4 padding: 4 width: 198 + layout: + type: verticalBox + //spacing: 1 GameBottomPanel < Panel image-source: /images/ui/panel_bottom @@ -14,6 +17,9 @@ GameMapPanel < UIGameMap image-source: /images/ui/panel_map image-border: 4 + $on: + padding: 0 + UIWidget id: gameRootPanel anchors.fill: parent @@ -36,7 +42,6 @@ UIWidget GameSidePanel id: gameLeftPanel - layout: verticalBox anchors.left: parent.left anchors.top: parent.top anchors.bottom: parent.bottom @@ -49,7 +54,6 @@ UIWidget GameSidePanel id: gameRightPanel - layout: verticalBox anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom diff --git a/modules/game_minimap/minimap.lua b/modules/game_minimap/minimap.lua index 005717da..1659b077 100644 --- a/modules/game_minimap/minimap.lua +++ b/modules/game_minimap/minimap.lua @@ -189,7 +189,7 @@ function addMapFlag(pos, icon, message, flagId, version) flagWidget.icon = icon flagWidget.description = message if message and message:len() > 0 then - flagWidget:setTooltip(tr(message)) + flagWidget:setTooltip(message) end flagWidget.id = flagId flagWidget.version = version diff --git a/modules/game_skills/skills.lua b/modules/game_skills/skills.lua index 496c94f1..21a4e018 100644 --- a/modules/game_skills/skills.lua +++ b/modules/game_skills/skills.lua @@ -21,7 +21,8 @@ function init() onBaseSkillChange = onBaseSkillChange }) connect(g_game, { - onGameStart = refresh + onGameStart = refresh, + onGameEnd = offline }) skillsButton = modules.client_topmenu.addRightGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', '/images/topbuttons/skills', toggle) @@ -55,7 +56,7 @@ function terminate() }) disconnect(g_game, { onGameStart = refresh, - onGameEnd = refresh + onGameEnd = offline }) g_keyboard.unbindKeyDown('Ctrl+S') @@ -63,6 +64,14 @@ function terminate() skillsWindow:destroy() end +function expForLevel(level) + return math.floor((50*level*level*level)/3 - 100*level*level + (850*level)/3 - 200) +end + +function expToAdvance(currentLevel, currentExp) + return expForLevel(currentLevel+1) - currentExp +end + function resetSkillColor(id) local skill = skillsWindow:recursiveGetChildById(id) local widget = skill:getChildById('value') @@ -180,6 +189,9 @@ function refresh() local player = g_game.getLocalPlayer() if not player then return end + if expSpeedEvent then expSpeedEvent:cancel() end + expSpeedEvent = cycleEvent(checkExpSpeed, 30*1000) + onExperienceChange(player, player:getExperience()) onLevelChange(player, player:getLevel(), player:getLevelPercent()) onHealthChange(player, player:getHealth(), player:getMaxHealth()) @@ -204,6 +216,10 @@ function refresh() skillsWindow:setContentMaximumHeight(contentsPanel:getChildrenRect().height) end +function offline() + expSpeedEvent:cancel() +end + function toggle() if skillsButton:isOn() then skillsWindow:close() @@ -214,6 +230,22 @@ function toggle() end end +function checkExpSpeed() + local player = g_game.getLocalPlayer() + local currentExp = player:getExperience() + local currentTime = g_clock.seconds() + if player.lastExps ~= nil then + player.expSpeed = (currentExp - player.lastExps[1][1])/(currentTime - player.lastExps[1][2]) + onLevelChange(player, player:getLevel(), player:getLevelPercent()) + else + player.lastExps = {} + end + table.insert(player.lastExps, {currentExp, currentTime}) + if #player.lastExps > 10 then + table.remove(player.lastExps, 1) + end +end + function onMiniWindowClose() skillsButton:setOn(false) end @@ -231,21 +263,36 @@ function onSkillButtonClick(button) end function onExperienceChange(localPlayer, value) - setSkillValue('experience', tr(value)) + setSkillValue('experience', value) end function onLevelChange(localPlayer, value, percent) - setSkillValue('level', tr(value)) - setSkillPercent('level', percent, tr('You have %s percent to go', 100 - percent)) + setSkillValue('level', value) + local text = tr('You have %s percent to go', 100 - percent) .. '\n' .. + tr('%s of experience left', expToAdvance(localPlayer:getLevel(), localPlayer:getExperience())) + + if localPlayer.expSpeed ~= nil then + local expPerHour = math.floor(localPlayer.expSpeed * 3600) + if expPerHour > 0 then + local nextLevelExp = expForLevel(localPlayer:getLevel()+1) + local hoursLeft = (nextLevelExp - localPlayer:getExperience()) / expPerHour + local minutesLeft = math.floor((hoursLeft - math.floor(hoursLeft))*60) + hoursLeft = math.floor(hoursLeft) + text = text .. '\n' .. tr('%d of experience per hour', expPerHour) + text = text .. '\n' .. tr('Next level in %d hours and %d minutes', hoursLeft, minutesLeft) + end + end + + setSkillPercent('level', percent, text) end function onHealthChange(localPlayer, health, maxHealth) - setSkillValue('health', tr(health)) + setSkillValue('health', health) checkAlert('health', health, maxHealth, 30) end function onManaChange(localPlayer, mana, maxMana) - setSkillValue('mana', tr(mana)) + setSkillValue('mana', mana) checkAlert('mana', mana, maxMana, 30) end @@ -333,4 +380,4 @@ end function onBaseSkillChange(localPlayer, id, baseLevel) setSkillBase('skillId'..id, localPlayer:getSkillLevel(id), baseLevel) -end \ No newline at end of file +end diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index e59c1e20..e044e716 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -37,6 +37,7 @@ #include #include #include +#include enum { @@ -163,16 +164,8 @@ void MapView::draw(const Rect& rect) if(m_shaderSwitchDone && m_shader && m_fadeInTime > 0) fadeOpacity = std::min(m_fadeTimer.timeElapsed() / m_fadeInTime, 1.0f); - Point drawOffset = ((m_drawDimension - m_visibleDimension - Size(1,1)).toPoint()/2) * m_tileSize; - if(isFollowingCreature()) - drawOffset += m_followingCreature->getWalkOffset() * scaleFactor; - - Size srcSize = rect.size(); - Size srcVisible = m_visibleDimension * m_tileSize; - srcSize.scale(srcVisible, Fw::KeepAspectRatio); - drawOffset.x += (srcVisible.width() - srcSize.width()) / 2; - drawOffset.y += (srcVisible.height() - srcSize.height()) / 2; - Rect srcRect = Rect(drawOffset, srcSize); + Rect srcRect = calcFramebufferSource(rect.size()); + Point drawOffset = srcRect.topLeft(); if(m_shader && g_painter->hasShaders() && g_graphics.shouldUseShaders() && m_viewMode == NEAR_VIEW) { Rect framebufferRect = Rect(0,0, m_drawDimension * m_tileSize); @@ -544,6 +537,49 @@ void MapView::setCameraPosition(const Position& pos) requestVisibleTilesCacheUpdate(); } +Position MapView::getPosition(const Point& point, const Size& mapSize) +{ + Position cameraPosition = getCameraPosition(); + + // if we have no camera, its impossible to get the tile + if(!cameraPosition.isValid()) + return Position(); + + Rect srcRect = calcFramebufferSource(mapSize); + float sh = srcRect.width() / (float)mapSize.width(); + float sv = srcRect.height() / (float)mapSize.height(); + + Point framebufferPos = Point(point.x * sh, point.y * sv); + Point centerOffset = (framebufferPos + srcRect.topLeft()) / m_tileSize; + + Point tilePos2D = getVisibleCenterOffset() - m_drawDimension.toPoint() + centerOffset + Point(2,2); + if(tilePos2D.x + cameraPosition.x < 0 && tilePos2D.y + cameraPosition.y < 0) + return Position(); + + Position position = Position(tilePos2D.x, tilePos2D.y, 0) + cameraPosition; + + if(!position.isValid()) + return Position(); + + return position; +} + +Rect MapView::calcFramebufferSource(const Size& destSize) +{ + float scaleFactor = m_tileSize/(float)Otc::TILE_PIXELS; + Point drawOffset = ((m_drawDimension - m_visibleDimension - Size(1,1)).toPoint()/2) * m_tileSize; + if(isFollowingCreature()) + drawOffset += m_followingCreature->getWalkOffset() * scaleFactor; + + Size srcSize = destSize; + Size srcVisible = m_visibleDimension * m_tileSize; + srcSize.scale(srcVisible, Fw::KeepAspectRatio); + drawOffset.x += (srcVisible.width() - srcSize.width()) / 2; + drawOffset.y += (srcVisible.height() - srcSize.height()) / 2; + + return Rect(drawOffset, srcSize); +} + int MapView::calcFirstVisibleFloor() { int z = 7; diff --git a/src/client/mapview.h b/src/client/mapview.h index 95b06049..6b9d56b6 100644 --- a/src/client/mapview.h +++ b/src/client/mapview.h @@ -107,9 +107,12 @@ public: void setShader(const PainterShaderProgramPtr& shader, float fadein, float fadeout); PainterShaderProgramPtr getShader() { return m_shader; } + Position getPosition(const Point& point, const Size& mapSize); + MapViewPtr asMapView() { return static_self_cast(); } private: + Rect calcFramebufferSource(const Size& destSize); int calcFirstVisibleFloor(); int calcLastVisibleFloor(); Point transformPositionTo2D(const Position& position, const Position& relativePosition) { diff --git a/src/client/uimap.cpp b/src/client/uimap.cpp index 8a7be5af..3a53444e 100644 --- a/src/client/uimap.cpp +++ b/src/client/uimap.cpp @@ -128,29 +128,7 @@ Position UIMap::getPosition(const Point& mousePos) return Position(); Point relativeMousePos = mousePos - m_mapRect.topLeft(); - Size visibleSize = getVisibleDimension() * m_mapView->getTileSize(); - Position cameraPosition = getCameraPosition(); - - // if we have no camera, its impossible to get the tile - if(!cameraPosition.isValid()) - return Position(); - - float scaleFactor = m_mapView->getTileSize() / (float)Otc::TILE_PIXELS; - float horizontalStretchFactor = visibleSize.width() / (float)m_mapRect.width(); - float verticalStretchFactor = visibleSize.height() / (float)m_mapRect.height(); - - Point tilePos2D = Point(relativeMousePos.x * horizontalStretchFactor, relativeMousePos.y * verticalStretchFactor); - - if(m_mapView->isFollowingCreature()) - tilePos2D += getFollowingCreature()->getWalkOffset() * scaleFactor; - tilePos2D /= m_mapView->getTileSize(); - - Point visibleCenterOffset = m_mapView->getVisibleCenterOffset(); - Position position = Position(1 + (int)tilePos2D.x - visibleCenterOffset.x, 1 + (int)tilePos2D.y - visibleCenterOffset.y, 0) + cameraPosition; - if(!position.isValid()) - return Position(); - - return position; + return m_mapView->getPosition(relativeMousePos, m_mapRect.size()); } TilePtr UIMap::getTile(const Point& mousePos) diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index 0dd96462..124db766 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -589,7 +589,7 @@ void UITextEdit::updateText() void UITextEdit::onHoverChange(bool hovered) { if(m_changeCursorImage) { - if(hovered) + if(hovered && !g_mouse.isCursorChanged()) g_mouse.pushCursor("text"); else g_mouse.popCursor("text");