mirror of
https://github.com/OTCv8/otclientv8.git
synced 2025-10-20 14:43:27 +02:00
Updated to OTCv8 3.1 rev 132
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
actionPanel1 = nil
|
||||
actionPanel2 = nil
|
||||
---@diagnostic disable: undefined-global
|
||||
bottomActionPanel1 = nil
|
||||
bottomActionPanel2 = nil
|
||||
bottomActionPanel3 = nil
|
||||
leftActionPanel1 = nil
|
||||
leftActionPanel2 = nil
|
||||
leftActionPanel3 = nil
|
||||
|
||||
local actionConfig
|
||||
local settings = {}
|
||||
local hotkeyAssignWindow
|
||||
local actionButtonsInPanel = 50
|
||||
|
||||
@@ -24,13 +29,33 @@ ActionColors = {
|
||||
}
|
||||
|
||||
function init()
|
||||
local bottomPanel = modules.game_interface.getActionPanel()
|
||||
actionPanel1 = g_ui.loadUI('actionbar', bottomPanel)
|
||||
bottomPanel:moveChildToIndex(actionPanel1, 1)
|
||||
actionPanel2 = g_ui.loadUI('actionbar', bottomPanel)
|
||||
bottomPanel:moveChildToIndex(actionPanel2, 1)
|
||||
local bottomPanel = modules.game_interface.getBottomActionPanel()
|
||||
local leftPanel = modules.game_interface.getLeftActionPanel()
|
||||
local rightPanel = modules.game_interface.getRightActionPanel()
|
||||
|
||||
actionConfig = g_configs.create("/actionbar.otml")
|
||||
-- bottom
|
||||
bottomActionPanel1 = g_ui.loadUI('actionbar', bottomPanel)
|
||||
bottomPanel:moveChildToIndex(bottomActionPanel1, 1)
|
||||
bottomActionPanel2 = g_ui.loadUI('actionbar', bottomPanel)
|
||||
bottomPanel:moveChildToIndex(bottomActionPanel2, 1)
|
||||
bottomActionPanel3 = g_ui.loadUI('actionbar', bottomPanel)
|
||||
bottomPanel:moveChildToIndex(bottomActionPanel3, 1)
|
||||
|
||||
-- left
|
||||
leftActionPanel1 = g_ui.loadUI('sideactionbar', leftPanel)
|
||||
leftPanel:moveChildToIndex(leftActionPanel1, 1)
|
||||
leftActionPanel2 = g_ui.loadUI('sideactionbar', leftPanel)
|
||||
leftPanel:moveChildToIndex(leftActionPanel2, 1)
|
||||
leftActionPanel3 = g_ui.loadUI('sideactionbar', leftPanel)
|
||||
leftPanel:moveChildToIndex(leftActionPanel3, 1)
|
||||
|
||||
-- right
|
||||
rightActionPanel1 = g_ui.loadUI('sideactionbar', rightPanel)
|
||||
rightPanel:moveChildToIndex(rightActionPanel1, 1)
|
||||
rightActionPanel2 = g_ui.loadUI('sideactionbar', rightPanel)
|
||||
rightPanel:moveChildToIndex(rightActionPanel2, 1)
|
||||
rightActionPanel3 = g_ui.loadUI('sideactionbar', rightPanel)
|
||||
rightPanel:moveChildToIndex(rightActionPanel3, 1)
|
||||
|
||||
connect(g_game, {
|
||||
onGameStart = online,
|
||||
@@ -53,42 +78,105 @@ function terminate()
|
||||
})
|
||||
|
||||
-- remove hotkeys, also saves config
|
||||
if actionPanel1.tabBar:getChildCount() > 0 and actionPanel2.tabBar:getChildCount() > 0 then
|
||||
offline()
|
||||
local panels = {
|
||||
bottomActionPanel1,
|
||||
bottomActionPanel2,
|
||||
bottomActionPanel3,
|
||||
leftActionPanel1,
|
||||
leftActionPanel2,
|
||||
leftActionPanel3,
|
||||
rightActionPanel1,
|
||||
rightActionPanel2,
|
||||
rightActionPanel3,
|
||||
}
|
||||
|
||||
for i, panel in ipairs(panels) do
|
||||
if panel.tabBar:getChildCount() > 0 then
|
||||
offline()
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
actionPanel1:destroy()
|
||||
actionPanel2:destroy()
|
||||
bottomActionPanel1:destroy()
|
||||
bottomActionPanel2:destroy()
|
||||
bottomActionPanel3:destroy()
|
||||
leftActionPanel1:destroy()
|
||||
leftActionPanel2:destroy()
|
||||
leftActionPanel3:destroy()
|
||||
rightActionPanel1:destroy()
|
||||
rightActionPanel2:destroy()
|
||||
rightActionPanel3:destroy()
|
||||
end
|
||||
|
||||
function show()
|
||||
if not g_game.isOnline() then return end
|
||||
actionPanel1:setOn(g_settings.getBoolean("actionBar1", false))
|
||||
actionPanel2:setOn(g_settings.getBoolean("actionBar2", false))
|
||||
bottomActionPanel1:setOn(g_settings.getBoolean("actionbarBottom1", false))
|
||||
bottomActionPanel2:setOn(g_settings.getBoolean("actionbarBottom2", false))
|
||||
bottomActionPanel3:setOn(g_settings.getBoolean("actionbarBottom3", false))
|
||||
leftActionPanel1:setOn(g_settings.getBoolean("actionbarLeft1", false))
|
||||
leftActionPanel2:setOn(g_settings.getBoolean("actionbarLeft2", false))
|
||||
leftActionPanel3:setOn(g_settings.getBoolean("actionbarLeft3", false))
|
||||
rightActionPanel1:setOn(g_settings.getBoolean("actionbarRight1", false))
|
||||
rightActionPanel2:setOn(g_settings.getBoolean("actionbarRight2", false))
|
||||
rightActionPanel3:setOn(g_settings.getBoolean("actionbarRight3", false))
|
||||
end
|
||||
|
||||
function hide()
|
||||
actionPanel1:setOn(false)
|
||||
actionPanel2:setOn(false)
|
||||
bottomActionPanel1:setOn(false)
|
||||
bottomActionPanel2:setOn(false)
|
||||
bottomActionPanel3:setOn(false)
|
||||
leftActionPanel1:setOn(false)
|
||||
leftActionPanel2:setOn(false)
|
||||
leftActionPanel3:setOn(false)
|
||||
rightActionPanel1:setOn(false)
|
||||
rightActionPanel2:setOn(false)
|
||||
rightActionPanel3:setOn(false)
|
||||
end
|
||||
|
||||
function switchMode(newMode)
|
||||
if newMode then
|
||||
actionPanel1:setImageColor('#ffffff88')
|
||||
actionPanel2:setImageColor('#ffffff88')
|
||||
bottomActionPanel1:setImageColor('#ffffff88')
|
||||
bottomActionPanel2:setImageColor('#ffffff88')
|
||||
bottomActionPanel3:setImageColor('#ffffff88')
|
||||
leftActionPanel1:setImageColor('#ffffff88')
|
||||
leftActionPanel2:setImageColor('#ffffff88')
|
||||
leftActionPanel3:setImageColor('#ffffff88')
|
||||
rightActionPanel1:setImageColor('#ffffff88')
|
||||
rightActionPanel2:setImageColor('#ffffff88')
|
||||
rightActionPanel3:setImageColor('#ffffff88')
|
||||
else
|
||||
actionPanel1:setImageColor('white')
|
||||
actionPanel2:setImageColor('white')
|
||||
bottomActionPanel1:setImageColor('white')
|
||||
bottomActionPanel2:setImageColor('white')
|
||||
bottomActionPanel3:setImageColor('white')
|
||||
leftActionPanel1:setImageColor('white')
|
||||
leftActionPanel2:setImageColor('white')
|
||||
leftActionPanel3:setImageColor('white')
|
||||
rightActionPanel1:setImageColor('white')
|
||||
rightActionPanel2:setImageColor('white')
|
||||
rightActionPanel3:setImageColor('white')
|
||||
end
|
||||
end
|
||||
|
||||
function online()
|
||||
setupActionPanel(1, actionPanel1)
|
||||
setupActionPanel(2, actionPanel2)
|
||||
load()
|
||||
setupActionPanel(1, bottomActionPanel1, true)
|
||||
setupActionPanel(2, bottomActionPanel2, true)
|
||||
setupActionPanel(3, bottomActionPanel3, true)
|
||||
setupActionPanel(4, leftActionPanel1, false)
|
||||
setupActionPanel(5, leftActionPanel2, false)
|
||||
setupActionPanel(6, leftActionPanel3, false)
|
||||
setupActionPanel(7, rightActionPanel1, false)
|
||||
setupActionPanel(8, rightActionPanel2, false)
|
||||
setupActionPanel(9, rightActionPanel3, false)
|
||||
show()
|
||||
end
|
||||
|
||||
function offline()
|
||||
function refresh(reloaded)
|
||||
offline(reloaded)
|
||||
online()
|
||||
end
|
||||
|
||||
function offline(reloaded)
|
||||
hide()
|
||||
if hotkeyAssignWindow then
|
||||
hotkeyAssignWindow:destroy()
|
||||
@@ -96,37 +184,35 @@ function offline()
|
||||
end
|
||||
|
||||
local gameRootPanel = modules.game_interface.getRootPanel()
|
||||
for index, panel in ipairs({actionPanel1, actionPanel2}) do
|
||||
local config = {}
|
||||
for index, panel in ipairs({bottomActionPanel1, bottomActionPanel2, bottomActionPanel3,
|
||||
leftActionPanel1, leftActionPanel2, leftActionPanel3,
|
||||
rightActionPanel1, rightActionPanel2, rightActionPanel3}) do
|
||||
settings[tostring(index)] = {}
|
||||
for i, child in ipairs(panel.tabBar:getChildren()) do
|
||||
if child.config then
|
||||
table.insert(config, child.config)
|
||||
if child.config and child.config.item then
|
||||
settings[tostring(index)][tostring(i)] = child.config
|
||||
if type(child.config.hotkey) == 'string' and child.config.hotkey:len() > 0 then
|
||||
g_keyboard.unbindKeyPress(child.config.hotkey, child.callback, gameRootPanel)
|
||||
end
|
||||
else
|
||||
table.insert(config, {})
|
||||
end
|
||||
if child.cooldownEvent then
|
||||
removeEvent(child.cooldownEvent)
|
||||
end
|
||||
end
|
||||
actionConfig:setNode('actions_' .. index, config)
|
||||
panel.tabBar:destroyChildren()
|
||||
end
|
||||
actionConfig:save()
|
||||
if not reloaded then
|
||||
save()
|
||||
end
|
||||
end
|
||||
|
||||
function setupActionPanel(index, panel)
|
||||
local rawConfig = actionConfig:getNode('actions_' .. index) or {}
|
||||
local config = {}
|
||||
for i, buttonConfig in pairs(rawConfig) do -- sorting, because key in rawConfig is string
|
||||
config[tonumber(i)] = buttonConfig
|
||||
end
|
||||
function setupActionPanel(index, panel, bottom)
|
||||
local config = settings[tostring(index)] or {}
|
||||
|
||||
for i=1,actionButtonsInPanel do
|
||||
local action = g_ui.createWidget('ActionButton', panel.tabBar)
|
||||
action.config = config[i] or {}
|
||||
local type = bottom and 'ActionButton' or 'SideActionButton'
|
||||
local action = g_ui.createWidget(type, panel.tabBar)
|
||||
action.config = config[tostring(i)] or {}
|
||||
setupAction(action)
|
||||
end
|
||||
|
||||
@@ -143,7 +229,18 @@ function setupAction(action)
|
||||
action.item:setShowCount(false)
|
||||
action.onMouseRelease = actionOnMouseRelease
|
||||
action.onTouchRelease = actionOnMouseRelease
|
||||
action.callback = function(k, c, ticks) executeAction(action, ticks) end
|
||||
|
||||
action.callback = function(k, c, ticks)
|
||||
local lockKeyboard = g_settings.getBoolean('actionbarLock', false)
|
||||
local chatMode = not modules.game_walking.wsadWalking
|
||||
|
||||
if not lockKeyboard or not chatMode then
|
||||
print('lock', lockKeyboard)
|
||||
print('chatMode', chatMode)
|
||||
executeAction(action, ticks)
|
||||
end
|
||||
end
|
||||
|
||||
action.item.onItemChange = nil -- disable callbacks for setup
|
||||
|
||||
if config then
|
||||
@@ -327,7 +424,9 @@ function actionOnItemChange(widget)
|
||||
end
|
||||
|
||||
function onSpellCooldown(iconId, duration)
|
||||
for index, panel in ipairs({actionPanel1, actionPanel2}) do
|
||||
for index, panel in ipairs({bottomActionPanel1, bottomActionPanel2, bottomActionPanel3,
|
||||
leftActionPanel1, leftActionPanel2, leftActionPanel3,
|
||||
rightActionPanel1, rightActionPanel2, rightActionPanel3}) do
|
||||
for i, child in ipairs(panel.tabBar:getChildren()) do
|
||||
if child.spell and child.spell.id == iconId then
|
||||
startCooldown(child, duration)
|
||||
@@ -337,7 +436,9 @@ function onSpellCooldown(iconId, duration)
|
||||
end
|
||||
|
||||
function onSpellGroupCooldown(groupId, duration)
|
||||
for index, panel in ipairs({actionPanel1, actionPanel2}) do
|
||||
for index, panel in ipairs({bottomActionPanel1, bottomActionPanel2, bottomActionPanel3,
|
||||
leftActionPanel1, leftActionPanel2, leftActionPanel3,
|
||||
rightActionPanel1, rightActionPanel2, rightActionPanel3}) do
|
||||
for i, child in ipairs(panel.tabBar:getChildren()) do
|
||||
if child.spell and child.spell.group then
|
||||
for group, dur in pairs(child.spell.group) do
|
||||
@@ -483,4 +584,40 @@ function executeAction(action, ticks)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function save()
|
||||
local settingsFile = modules.client_profiles.getSettingsFilePath("actionbar.json")
|
||||
|
||||
local status, result = pcall(function() return json.encode(settings, 2) end)
|
||||
if not status then
|
||||
return onError(
|
||||
"Error while saving top bar settings. Data won't be saved. Details: " ..
|
||||
result)
|
||||
end
|
||||
|
||||
if result:len() > 100 * 1024 * 1024 then
|
||||
return onError(
|
||||
"Something went wrong, file is above 100MB, won't be saved")
|
||||
end
|
||||
|
||||
g_resources.writeFileContents(settingsFile, result)
|
||||
end
|
||||
|
||||
function load()
|
||||
local settingsFile = modules.client_profiles.getSettingsFilePath("actionbar.json")
|
||||
|
||||
if g_resources.fileExists(settingsFile) then
|
||||
local status, result = pcall(function()
|
||||
return json.decode(g_resources.readFileContents(settingsFile))
|
||||
end)
|
||||
if not status then
|
||||
return onError(
|
||||
"Error while reading top bar settings file. To fix this problem you can delete storage.json. Details: " ..
|
||||
result)
|
||||
end
|
||||
settings = result
|
||||
else
|
||||
settings = {}
|
||||
end
|
||||
end
|
||||
|
@@ -5,6 +5,7 @@ ActionButton < Panel
|
||||
width: 40
|
||||
padding: 1 1 1 1
|
||||
margin-left: 1
|
||||
draggable: true
|
||||
|
||||
$first:
|
||||
anchors.left: parent.left
|
||||
@@ -101,7 +102,6 @@ Panel
|
||||
margin-top: 1
|
||||
margin-bottom: 2
|
||||
|
||||
|
||||
ActionAssignWindow < MainWindow
|
||||
id: assignWindow
|
||||
!text: tr('Button Assign')
|
||||
|
149
modules/game_actionbar/sideactionbar.otui
Normal file
149
modules/game_actionbar/sideactionbar.otui
Normal file
@@ -0,0 +1,149 @@
|
||||
SideActionButton < Panel
|
||||
font: cipsoftFont
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
height: 40
|
||||
padding: 1 1 1 1
|
||||
margin-top: 1
|
||||
draggable: true
|
||||
|
||||
$first:
|
||||
anchors.top: parent.top
|
||||
margin-top: -3
|
||||
|
||||
$!first:
|
||||
anchors.top: prev.bottom
|
||||
|
||||
Item
|
||||
id: item
|
||||
anchors.fill: parent
|
||||
&selectable: true
|
||||
&editable: false
|
||||
virtual: true
|
||||
border-width: 1
|
||||
|
||||
border-color: #00000000
|
||||
|
||||
$!on:
|
||||
image-source: /images/game/actionbarslot
|
||||
|
||||
Label
|
||||
id: text
|
||||
anchors.fill: parent
|
||||
text-auto-resize: true
|
||||
text-wrap: true
|
||||
phantom: true
|
||||
text-align: center
|
||||
font: verdana-9px
|
||||
|
||||
Label
|
||||
id: hotkeyLabel
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
margin: 2 3 3 3
|
||||
text-auto-resize: true
|
||||
text-wrap: false
|
||||
phantom: true
|
||||
font: cipsoftFont
|
||||
color: white
|
||||
background: #292A2A
|
||||
|
||||
UIProgressRect
|
||||
id: cooldown
|
||||
background: #585858AA
|
||||
percent: 100
|
||||
focusable: false
|
||||
phantom: true
|
||||
anchors.fill: parent
|
||||
margin: 1 1 1 1
|
||||
font: verdana-11px-rounded
|
||||
color: white
|
||||
|
||||
Panel
|
||||
id: actionBar
|
||||
focusable: false
|
||||
image-source: /images/ui/panel_side
|
||||
image-border: 4
|
||||
margin-top: -2
|
||||
|
||||
$on:
|
||||
width: 40
|
||||
visible: true
|
||||
|
||||
$!on:
|
||||
width: 0
|
||||
visible: false
|
||||
|
||||
TabButton
|
||||
id: prevButton
|
||||
icon: /images/game/console/uparrow
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
margin-top: -1
|
||||
margin-left: 1
|
||||
margin-right: 1
|
||||
|
||||
Panel
|
||||
id: tabBar
|
||||
anchors.top: prev.bottom
|
||||
anchors.right: parent.right
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: next.top
|
||||
margin-top: 3
|
||||
clipping: true
|
||||
|
||||
TabButton
|
||||
id: nextButton
|
||||
icon: /images/game/console/downarrow
|
||||
anchors.right: parent.right
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin-right: 1
|
||||
margin-left: 1
|
||||
margin-bottom: 2
|
||||
|
||||
ActionAssignWindow < MainWindow
|
||||
id: assignWindow
|
||||
!text: tr('Button Assign')
|
||||
size: 360 150
|
||||
@onEscape: self:destroy()
|
||||
|
||||
Label
|
||||
!text: tr('Please, press the key you wish to use for action')
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
text-auto-resize: true
|
||||
text-align: left
|
||||
|
||||
Label
|
||||
id: comboPreview
|
||||
!text: tr('Current action hotkey: %s', 'none')
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 10
|
||||
text-auto-resize: true
|
||||
|
||||
HorizontalSeparator
|
||||
id: separator
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: next.top
|
||||
margin-bottom: 10
|
||||
|
||||
Button
|
||||
id: addButton
|
||||
!text: tr('Add')
|
||||
width: 64
|
||||
anchors.right: next.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin-right: 10
|
||||
|
||||
Button
|
||||
id: cancelButton
|
||||
!text: tr('Cancel')
|
||||
width: 64
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
@onClick: self:getParent():destroy()
|
Reference in New Issue
Block a user