diff --git a/modules/game_cooldown/cooldown.lua b/modules/game_cooldown/cooldown.lua new file mode 100644 index 00000000..2b313902 --- /dev/null +++ b/modules/game_cooldown/cooldown.lua @@ -0,0 +1,93 @@ +cooldownPanel = nil +spellCooldownPanel = nil + +function init() + connect(g_game, { onGameStart = show, + onGameEnd = hide, + onSpellGroupCooldown = onSpellGroupCooldown, + onSpellCooldown = onSpellCooldown }) + + cooldownPanel = g_ui.displayUI('cooldown.otui') + cooldownPanel:hide() + + spellCooldownPanel = cooldownPanel:getChildById('spellCooldownPanel') + + if g_game.isOnline() then + show() + end +end + +function terminate() + disconnect(g_game, { onGameStart = show, + onGameEnd = hide, + onSpellGroupCooldown = onSpellGroupCooldown, + onSpellCooldown = onSpellCooldown }) + + spellCooldownPanel:destroy() + cooldownPanel:destroy() +end + +function show() + if g_game.getFeature(GameSpellList) then + cooldownPanel:show() + end +end + +function hide() + cooldownPanel:hide() +end + +function updateProgressRect(progressRect, interval, init) + if init then + progressRect:setPercent(0) + else + progressRect:setPercent(progressRect:getPercent() + 4) + end + + if progressRect:getPercent() < 100 then + removeEvent(progressRect.event) + progressRect.event = scheduleEvent(function() updateProgressRect(progressRect, interval) end, interval) + end +end + +function onSpellCooldown(iconId, duration) + local spellName = SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].spellIcons[iconId] + if not spellName then return end + + 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] + end + + if not otcIconId then return end + + local icon = cooldownPanel:getChildById(spellName) + if not icon then + icon = g_ui.createWidget('SpellIcon', spellCooldownPanel) + icon:setId(spellName) + icon:setImageSource('/game_cooldown/icons/' .. SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].iconFile) + icon:setTooltip(spellformula) + icon:setImageClip(modules.game_spelllist.getIconImageClip(otcIconId)) + icon.event = scheduleEvent(function() icon:destroy() end, duration) + + local progressRect = g_ui.createWidget('ProgressRect', icon) + updateProgressRect(progressRect, duration/25, true) + end +end + +function onSpellGroupCooldown(groupId, duration) + if not SpellGroups[groupId] then return end + + local icon = cooldownPanel:getChildById('groupIcon' .. SpellGroups[groupId]) + local progressRect = cooldownPanel:getChildById('progressRect' .. SpellGroups[groupId]) + if icon then + icon:setOn(true) + removeEvent(icon.event) + icon.event = scheduleEvent(function() icon:setOn(false) end, duration) + end + + if progressRect then + removeEvent(progressRect.event) + updateProgressRect(progressRect, duration/25, true) + end +end diff --git a/modules/game_cooldown/cooldown.otmod b/modules/game_cooldown/cooldown.otmod new file mode 100644 index 00000000..7946ad35 --- /dev/null +++ b/modules/game_cooldown/cooldown.otmod @@ -0,0 +1,9 @@ +Module + name: game_cooldown + description: Spellcooldowns + author: OTClient team + website: www.otclient.info + sandboxed: true + scripts: [ cooldown.lua ] + @onLoad: init() + @onUnload: terminate() diff --git a/modules/game_cooldown/cooldown.otui b/modules/game_cooldown/cooldown.otui new file mode 100644 index 00000000..ebeddb07 --- /dev/null +++ b/modules/game_cooldown/cooldown.otui @@ -0,0 +1,104 @@ +SpellGroupIcon < UIWidget + size: 22 22 + image-size: 22 22 + image-source: /game_cooldown/icons/cooldownIcons.png + focusable: false + +SpellIcon < UIWidget + size: 22 22 + image-size: 22 22 + margin-left: 2 + anchors.top: prev.top + anchors.left: prev.right + focusable: false + + $first: + margin-top: 3 + anchors.top: parent.top + anchors.left: parent.left + +ProgressRect < UIProgressRect + background: #585858AA + percent: 100 + anchors.fill: parent + focusable: false + +Panel + id: spellPanel + layout: + type: anchor + height: 28 + width: 250 + anchors.top: parent.top + anchors.left: parent.left + margin-top: 70 + margin-left: 10 + border-width: 1 + border-color: #00000077 + background-color: #ffffff11 + focusable: false + + SpellGroupIcon + id: groupIconAttack + image-clip: 0 0 20 20 + anchors.top: parent.top + anchors.left: parent.left + margin-top: 3 + margin-left: 3 + $on: + image-clip: 0 20 20 20 + + ProgressRect + id: progressRectAttack + anchors.fill: groupIconAttack + !tooltip: tr('Attack') + + SpellGroupIcon + id: groupIconHealing + image-clip: 20 0 20 20 + anchors.top: parent.top + anchors.left: groupIconAttack.right + margin-top: 3 + margin-left: 3 + $on: + image-clip: 20 20 20 20 + + ProgressRect + id: progressRectHealing + anchors.fill: groupIconHealing + !tooltip: tr('Healing') + + SpellGroupIcon + id: groupIconSupport + image-clip: 40 0 20 20 + anchors.top: parent.top + anchors.left: groupIconHealing.right + margin-top: 3 + margin-left: 3 + $on: + image-clip: 40 20 20 20 + + ProgressRect + id: progressRectSupport + anchors.fill: groupIconSupport + !tooltip: tr('Support') + + SpellGroupIcon + id: groupIconSpecial + image-clip: 60 0 20 20 + anchors.top: parent.top + anchors.left: groupIconSupport.right + margin-top: 3 + margin-left: 3 + $on: + image-clip: 60 20 20 20 + + ProgressRect + id: progressRectSpecial + anchors.fill: groupIconSpecial + !tooltip: tr('Special') + + Panel + id: spellCooldownPanel + anchors.fill: parent + margin-left: 102 \ No newline at end of file diff --git a/modules/game_cooldown/icons/cooldownIcons.png b/modules/game_cooldown/icons/cooldownIcons.png new file mode 100644 index 00000000..a8c9d64f Binary files /dev/null and b/modules/game_cooldown/icons/cooldownIcons.png differ diff --git a/modules/game_cooldown/icons/icons.png b/modules/game_cooldown/icons/icons.png new file mode 100644 index 00000000..d1926f37 Binary files /dev/null and b/modules/game_cooldown/icons/icons.png differ diff --git a/modules/game_cooldown/icons/sample.png b/modules/game_cooldown/icons/sample.png new file mode 100644 index 00000000..14aa3b05 Binary files /dev/null and b/modules/game_cooldown/icons/sample.png differ diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index fa9de4d6..8dc9dd13 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -10,7 +10,6 @@ mouseGrabberWidget = nil countWindow = nil logoutWindow = nil exitWindow = nil -cooldownPanel = nil function init() g_ui.importStyle('styles/countwindow.otui') @@ -23,8 +22,6 @@ function init() gameRootPanel:hide() gameRootPanel:lower() - cooldownPanel = gameRootPanel:getChildById('spellPanel') - mouseGrabberWidget = gameRootPanel:getChildById('mouseGrabber') mouseGrabberWidget.onMouseRelease = onMouseGrabberRelease @@ -82,8 +79,6 @@ function terminate() onLoginAdvice = onLoginAdvice }) disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange }) - cooldownPanel:destroy() - logoutButton:destroy() gameRootPanel:destroy() end @@ -95,8 +90,6 @@ function show() gameRootPanel:show() gameRootPanel:focus() gameMapPanel:followCreature(g_game.getLocalPlayer()) - - cooldownPanel:setVisible((g_game.getClientVersion() >= 870)) end function hide() @@ -551,31 +544,4 @@ function onLeftPanelVisibilityChange(leftPanel, visible) children[i]:setParent(gameRightPanel) end end -end - -function setGroupCooldown(groupId, duration) - if not SpellGroups[groupId] then return end - - local icon = gameRootPanel:getChildById('groupIcon' .. SpellGroups[groupId]) - if icon then - icon:setOn(true) - removeEvent(icon.event) - icon.event = scheduleEvent(function() icon:setOn(false) end, duration) - end -end - -function setCooldown(iconFile, iconId, spellformula, duration) - local icon = cooldownPanel:getChildById(spellformula) - - if icon then - removeEvent(icon.event) - icon.event = scheduleEvent(function() icon:destroy() end, duration) - else - icon = g_ui.createWidget('SpellIcon', cooldownPanel) - icon:setId(spellformula) - icon:setImageSource('/game_spelllist/icons/' .. iconFile) - icon:setTooltip(spellformula) - icon:setImageClip(modules.game_spelllist.getIconImageClip(iconId)) - icon.event = scheduleEvent(function() icon:destroy() end, duration) - end -end +end \ No newline at end of file diff --git a/modules/game_interface/gameinterface.otui b/modules/game_interface/gameinterface.otui index 220955d9..8c899e48 100644 --- a/modules/game_interface/gameinterface.otui +++ b/modules/game_interface/gameinterface.otui @@ -1,19 +1,4 @@ -SpellGroupIcon < UIWidget - size: 22 22 - image-size: 22 22 - image-source: /game_spelllist/icons/cooldownIcons.png - focusable: false -SpellIcon < UIWidget - size: 22 22 - image-size: 22 22 - margin-right: 3 - margin-top: 6 - margin-left: 3 - focusable: false - $first: - margin-left: 100 - GameSidePanel < UIMiniWindowContainer image-source: /images/sidepanel.png image-border: 4 @@ -71,67 +56,6 @@ UIWidget focusable: false on: true - Panel - id: spellPanel - layout: - type: horizontalBox - height: 32 - width: 250 - anchors.left: gameLeftPanel.right - anchors.bottom: parent.bottom - relative-margin: bottom - margin-bottom: 187 - margin-left: 10 - border-width: 1 - border-color: #00000077 - background-color: #ffffff11 - focusable: false - - SpellGroupIcon - id: groupIconAttack - parent: spellPanel - image-clip: 0 32 32 32 - anchors.top: spellPanel.top - anchors.left: spellPanel.left - !tooltip: tr('Attack') - margin-top: 3 - margin-left: 3 - $on: - image-clip: 0 0 32 32 - - SpellGroupIcon - id: groupIconHealing - image-clip: 32 32 32 32 - anchors.top: spellPanel.top - anchors.left: groupIconAttack.right - !tooltip: tr('Healing') - margin-top: 3 - margin-left: 3 - $on: - image-clip: 32 0 32 32 - - SpellGroupIcon - id: groupIconSupport - image-clip: 64 32 32 32 - anchors.top: spellPanel.top - anchors.left: groupIconHealing.right - !tooltip: tr('Support') - margin-top: 3 - margin-left: 3 - $on: - image-clip: 64 0 32 32 - - SpellGroupIcon - id: groupIconSpecial - image-clip: 96 32 32 32 - anchors.top: spellPanel.top - anchors.left: groupIconSupport.right - !tooltip: tr('Special') - margin-top: 3 - margin-left: 3 - $on: - image-clip: 96 0 32 32 - Splitter id: bottomSplitter anchors.left: gameLeftPanel.right @@ -140,9 +64,9 @@ UIWidget relative-margin: bottom margin-bottom: 172 @canUpdateMargin: function(self, newMargin) return math.max(math.min(newMargin, self:getParent():getHeight() - 300), 100) end - @onGeometryChange: function(self) self:setMarginBottom(math.min(math.max(self:getParent():getHeight() - 300, 100), self:getMarginBottom())) self:getParent():getChildById('spellPanel'):setMarginBottom(15 + math.min(math.max(self:getParent():getHeight() - 300, 100), self:getMarginBottom())) end + @onGeometryChange: function(self) self:setMarginBottom(math.min(math.max(self:getParent():getHeight() - 300, 100), self:getMarginBottom())) end UIWidget id: mouseGrabber focusable: false - visible: false + visible: false \ No newline at end of file diff --git a/modules/game_spelllist/icons/cooldownIcons.png b/modules/game_spelllist/icons/cooldownIcons.png deleted file mode 100644 index 16ed3de6..00000000 Binary files a/modules/game_spelllist/icons/cooldownIcons.png and /dev/null differ diff --git a/modules/game_spelllist/spelllist.lua b/modules/game_spelllist/spelllist.lua index 875227d4..0a371f58 100644 --- a/modules/game_spelllist/spelllist.lua +++ b/modules/game_spelllist/spelllist.lua @@ -59,6 +59,10 @@ local filters = { groupId = FILTER_GROUP_ANY } +function getSpelllistProfile() + return SpelllistProfile +end + function setSpelllistProfile(name) if SpelllistProfile == name then return end @@ -83,24 +87,9 @@ function setOptions() end end -function onSpellCooldown(iconId, duration) - local spellName = SpelllistSettings[SpelllistProfile].spellIcons[iconId] - if not spellName then return end - - local otcIconId = tonumber(SpellInfo[SpelllistProfile][spellName].icon) - if not otcIconId and SpellIcons[SpellInfo[SpelllistProfile][spellName].icon] then - otcIconId = SpellIcons[SpellInfo[SpelllistProfile][spellName].icon][1] - end - - if not otcIconId then return end - modules.game_interface.setCooldown(SpelllistSettings[SpelllistProfile].iconFile, otcIconId, spellName, duration) -end - function init() connect(g_game, { onGameStart = setOptions, - onGameEnd = resetWindow, - onSpellGroupCooldown = modules.game_interface.setGroupCooldown, - onSpellCooldown = onSpellCooldown }) + onGameEnd = resetWindow }) spelllistWindow = g_ui.displayUI('spelllist.otui', modules.game_interface.getRightPanel()) spelllistWindow:hide()