Fixed #165, Fine tune fixes!

* Fixed an issue with the cooldown timing.
* Fixed issue with 'right click' using items under players.
* Some changes to the minimap control (ctrl + mouse wheel to
  change floors and tweaked the zoom/move speeds).
* Fixed some bugs in the trade module.
* Added new Spells table for spell related functions
  (Also added getSpellByName and getSpellByWords).
* Fixed an issue with follow/attack cancelling (wasn't calling
  onFollowChanged for updates in battle, etc).
This commit is contained in:
BeniS 2013-01-07 04:04:49 +13:00
parent 3fa5993177
commit fddbafebd3
8 changed files with 124 additions and 66 deletions

View File

@ -34,6 +34,7 @@ function init()
mouseWidget = g_ui.createWidget('UIButton')
mouseWidget:setVisible(false)
mouseWidget:setFocusable(false)
mouseWidget.cancelNextRelease = false
battleWindow:setContentMinimumHeight(80)
--battleWindow:setContentMaximumHeight(384)
@ -220,21 +221,27 @@ function addCreature(creature)
end
function onMouseRelease(self, mousePosition, mouseButton)
if mouseButton == MouseRightButton then
if mouseWidget.cancelNextRelease then
mouseWidget.cancelNextRelease = false
return false
end
if ((g_mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton)
or (g_mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
mouseWidget.cancelNextRelease = true
g_game.look(self.creature)
return true
elseif mouseButton == MouseRightButton and g_keyboard.isCtrlPressed() and not g_mouse.isPressed(MouseLeftButton) then
modules.game_interface.createThingMenu(mousePosition, nil, nil, self.creature)
return true
elseif mouseButton == MouseLeftButton then
if g_keyboard.isShiftPressed() then
g_game.look(self.creature)
else
elseif mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then
if self.isTarget then
g_game.cancelAttack()
else
g_game.attack(self.creature)
end
end
return true
end
return false
end
function removeAllCreatures()

View File

@ -65,7 +65,7 @@ function updateProgressRect(progressRect, interval, init)
if init then
progressRect:setPercent(0)
else
progressRect:setPercent(progressRect:getPercent() + 4)
progressRect:setPercent(progressRect:getPercent() + 5)
end
if progressRect:getPercent() < 100 then
@ -78,6 +78,7 @@ function onSpellCooldown(iconId, duration)
local spellName = SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].spellIcons[iconId]
if not spellName then return end
local duration = duration - (g_game.getPing()/2)
local otcIconId = tonumber(SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon)
if not otcIconId and SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon] then
otcIconId = SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon][1]
@ -102,6 +103,7 @@ end
function onSpellGroupCooldown(groupId, duration)
if not SpellGroups[groupId] then return end
local duration = duration - (g_game.getPing()/2)
local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId])
local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId])
if icon then

View File

@ -95,9 +95,12 @@ function bindKeys()
end
function terminate()
disconnect(g_game, { onGameStart = show,
disconnect(g_game, {
onGameStart = show,
onGameEnd = hide,
onLoginAdvice = onLoginAdvice })
onLoginAdvice = onLoginAdvice
})
disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
logoutButton:destroy()
@ -475,6 +478,8 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u
g_game.attack(creatureThing)
return true
end
-- classic control
else
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then
local player = g_game.getLocalPlayer()
@ -493,7 +498,7 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u
startUseWith(useThing)
return true
else
g_game.use(multiUseThing)
g_game.use(useThing)
end
return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then

View File

@ -35,7 +35,6 @@ function init()
minimapWindow:setContentMaximumHeight(256)
minimapWidget = minimapWindow:recursiveGetChildById('minimap')
--g_mouse.bindAutoPress(minimapWidget, compassClick, nil, MouseRightButton)
g_mouse.bindAutoPress(minimapWidget, compassClick, nil, MouseLeftButton)
minimapWidget:setAutoViewMode(false)
@ -293,15 +292,18 @@ function 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
function reset()
function reset(zoom)
if zoom == nil then zoom = true end
local player = g_game.getLocalPlayer()
if not player then return end
minimapWidget:followCreature(player)
if zoom then
minimapWidget:setZoom(DEFAULT_ZOOM)
end
end
function center()
reset()
reset(false)
updateMapFlags()
end
@ -319,10 +321,11 @@ function compassClick(self, mousePos, mouseButton, elapsed)
dx = dx/radius
dy = dy/radius
if dx > 0.5 then movex = 1 end
if dx < -0.5 then movex = -1 end
if dy > 0.5 then movey = -1 end
if dy < -0.5 then movey = 1 end
local speed = math.ceil(minimapWidget:getZoom()/22)
if dx > 0.5 then movex = speed end
if dx < -0.5 then movex = -speed end
if dy > 0.5 then movey = -speed end
if dy < -0.5 then movey = speed end
local cameraPos = minimapWidget:getCameraPosition()
local pos = {x = cameraPos.x + movex, y = cameraPos.y + movey, z = cameraPos.z}
@ -331,23 +334,39 @@ function compassClick(self, mousePos, mouseButton, elapsed)
updateMapFlags()
end
function onButtonClick(id)
if id == "zoomIn" then
minimapWidget:setZoom(math.max(minimapWidget:getMaxZoomIn(), minimapWidget:getZoom()-15))
elseif id == "zoomOut" then
minimapWidget:setZoom(math.min(minimapWidget:getMaxZoomOut(), minimapWidget:getZoom()+15))
elseif id == "floorUp" then
function miniMapZoomIn(zoom)
minimapWidget:setZoom(math.max(minimapWidget:getMaxZoomIn(), minimapWidget:getZoom()-zoom))
end
function miniMapZoomOut(zoom)
minimapWidget:setZoom(math.min(minimapWidget:getMaxZoomOut(), minimapWidget:getZoom()+zoom))
end
function minimapFloorUp(floors)
local pos = minimapWidget:getCameraPosition()
pos.z = pos.z - 1
pos.z = pos.z - floors
if pos.z > MAX_FLOOR_UP then
minimapWidget:setCameraPosition(pos)
end
elseif id == "floorDown" then
end
function minimapFloorDown(floors)
local pos = minimapWidget:getCameraPosition()
pos.z = pos.z + 1
pos.z = pos.z + floors
if pos.z < MAX_FLOOR_DOWN then
minimapWidget:setCameraPosition(pos)
end
end
function onButtonClick(id)
if id == "zoomIn" then
miniMapZoomIn(20)
elseif id == "zoomOut" then
miniMapZoomOut(20)
elseif id == "floorUp" then
minimapFloorUp(1)
elseif id == "floorDown" then
minimapFloorDown(1)
end
updateMapFlags()
@ -375,10 +394,16 @@ function onMinimapMouseRelease(self, mousePosition, mouseButton)
end
function onMinimapMouseWheel(self, mousePos, direction)
if direction == MouseWheelUp then
self:zoomIn()
else
self:zoomOut()
local keyboardModifiers = g_keyboard.getModifiers()
if direction == MouseWheelUp and keyboardModifiers == KeyboardNoModifier then
miniMapZoomIn(10)
elseif direction == MouseWheelDown and keyboardModifiers == KeyboardNoModifier then
miniMapZoomOut(10)
elseif direction == MouseWheelDown and keyboardModifiers == KeyboardCtrlModifier then
minimapFloorUp(1)
elseif direction == MouseWheelUp and keyboardModifiers == KeyboardCtrlModifier then
minimapFloorDown(1)
end
updateMapFlags()
end

View File

@ -41,7 +41,6 @@ function init()
searchText = npcWindow:recursiveGetChildById('searchText')
setupPanel = npcWindow:recursiveGetChildById('setupPanel')
quantityLabel = setupPanel:getChildById('quantity')
quantityScroll = setupPanel:getChildById('quantityScroll')
nameLabel = setupPanel:getChildById('name')
priceLabel = setupPanel:getChildById('price')
@ -117,8 +116,7 @@ function onItemBoxChecked(widget)
end
function onQuantityValueChange(quantity)
if quantityLabel and selectedItem then
quantityLabel:setText(quantity)
if selectedItem then
weightLabel:setText(string.format('%.2f', selectedItem.weight*quantity) .. ' ' .. WEIGHT_UNIT)
priceLabel:setText(getItemPrice(selectedItem) .. ' ' .. CURRENCY)
end
@ -191,7 +189,6 @@ function clearSelectedItem()
nameLabel:clearText()
weightLabel:clearText()
priceLabel:clearText()
quantityLabel:clearText()
tradeButton:disable()
quantityScroll:setMaximum(1)
if selectedItem then
@ -208,17 +205,22 @@ function getCurrentTradeType()
end
end
function getItemPrice(item)
function getItemPrice(item, single)
local amount = 1
local single = single or false
if not single then
amount = quantityScroll:getValue()
end
if getCurrentTradeType() == BUY then
if buyWithBackpack:isChecked() then
if item.ptr:isStackable() then
return item.price*quantityScroll:getValue() + 20;
return item.price*amount + 20
else
return item.price*quantityScroll:getValue() + math.ceil(quantityScroll:getValue()/20)*20
return item.price*amount + math.ceil(amount/20)*20
end
end
end
return item.price*quantityScroll:getValue()
return item.price*amount
end
function getSellQuantity(item)
@ -241,7 +243,7 @@ end
function canTradeItem(item)
if getCurrentTradeType() == BUY then
return (ignoreCapacity:isChecked() or (not ignoreCapacity:isChecked() and playerFreeCapacity >= item.weight)) and playerMoney >= getItemPrice(item)
return (ignoreCapacity:isChecked() or (not ignoreCapacity:isChecked() and playerFreeCapacity >= item.weight)) and playerMoney >= getItemPrice(item, true)
else
return getSellQuantity(item) > 0
end
@ -252,16 +254,18 @@ function refreshItem(item)
weightLabel:setText(string.format('%.2f', item.weight) .. ' ' .. WEIGHT_UNIT)
priceLabel:setText(getItemPrice(item) .. ' ' .. CURRENCY)
quantityLabel:setText(1)
quantityScroll:setValue(1)
if getCurrentTradeType() == BUY then
local capacityMaxCount = math.floor(playerFreeCapacity / item.weight)
if ignoreCapacity:isChecked() then
capacityMaxCount = 100
end
local priceMaxCount = math.floor(playerMoney / getItemPrice(item))
quantityScroll:setMaximum(math.max(0, math.min(100, math.min(priceMaxCount, capacityMaxCount))))
local priceMaxCount = math.floor(playerMoney / getItemPrice(item, true))
local finalCount = math.max(0, math.min(100, math.min(priceMaxCount, capacityMaxCount)))
quantityScroll:setMaximum(finalCount)
if quantityScroll:getValue() > finalCount then
quantityScroll:setValue(finalCount)
end
else
local removeAmount = 0
if ignoreEquipped:isChecked() then
@ -413,7 +417,7 @@ function onFreeCapacityChange(localPlayer, freeCapacity, oldFreeCapacity)
end
end
function onInventoryChange(inventory, item, oldeItem)
function onInventoryChange(inventory, item, oldItem)
if selectedItem then
refreshItem(selectedItem)
end

View File

@ -69,7 +69,7 @@ MainWindow
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
step: 16
step: 24
pixels-scroll: true
ScrollablePanel
@ -154,17 +154,6 @@ MainWindow
NPCOfferLabel
id: capacity
Label
!text: tr('Quantity:')
anchors.left: parent.left
anchors.top: prev.bottom
margin-top: 5
margin-left: 5
width: 85
NPCOfferLabel
id: quantity
HorizontalScrollBar
id: quantityScroll
anchors.left: parent.left
@ -173,6 +162,7 @@ MainWindow
margin-top: 5
margin-left: 5
margin-right: 5
show-value: true
minimum: 1
maximum: 100
step: 1

View File

@ -314,3 +314,21 @@ SpellGroups = {
[3] = 'Support',
[4] = 'Special'
}
Spells = {}
function Spells.getSpellByName(name)
return SpellInfo[name:lower():trim()]
end
function Spells.getSpellByWords(words)
local words = words:lower():trim()
for i,category in pairs(SpellInfo) do
for k,spell in pairs(category) do
if spell.words == words then
return spell
end
end
end
return nil
end

View File

@ -862,7 +862,14 @@ void Game::cancelAttackAndFollow()
if(!canPerformGameAction())
return;
if(isFollowing())
setFollowingCreature(nullptr);
if(isAttacking())
setAttackingCreature(nullptr);
m_protocolGame->sendCancelAttackAndFollow();
g_lua.callGlobalField("g_game", "onCancelAttackAndFollow");
}
void Game::talk(const std::string& message)