mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
introduce startup options
* startup options with -help and -version * many startup options for graphics
This commit is contained in:
132
modules/game_combatcontrols/combatcontrols.lua
Normal file
132
modules/game_combatcontrols/combatcontrols.lua
Normal file
@@ -0,0 +1,132 @@
|
||||
CombatControls = {}
|
||||
|
||||
-- private variables
|
||||
local combatControlsButton
|
||||
local combatControlsWindow
|
||||
local fightOffensiveBox
|
||||
local fightBalancedBox
|
||||
local fightDefensiveBox
|
||||
local chaseModeButton
|
||||
local safeFightButton
|
||||
local fightModeRadioGroup
|
||||
|
||||
-- private functions
|
||||
local function onFightModeChange(self, selectedFightButton)
|
||||
if selectedFightButton == nil then return end
|
||||
local buttonId = selectedFightButton:getId()
|
||||
local fightMode
|
||||
if buttonId == 'fightOffensiveBox' then
|
||||
fightMode = FightOffensive
|
||||
elseif buttonId == 'fightBalancedBox' then
|
||||
fightMode = FightBalanced
|
||||
else
|
||||
fightMode = FightDefensive
|
||||
end
|
||||
if g_game.getFightMode ~= fightMode then
|
||||
g_game.setFightMode(fightMode)
|
||||
end
|
||||
end
|
||||
|
||||
local function onChaseModeChange(self, checked)
|
||||
local chaseMode
|
||||
if checked then
|
||||
chaseMode = ChaseOpponent
|
||||
else
|
||||
chaseMode = DontChase
|
||||
end
|
||||
if g_game.getChaseMode() ~= chaseMode then
|
||||
g_game.setChaseMode(chaseMode)
|
||||
end
|
||||
end
|
||||
|
||||
local function onSafeFightChange(self, checked)
|
||||
local safeFight = not checked
|
||||
if g_game.isSafeFight() ~= safeFight then
|
||||
g_game.setSafeFight(not checked)
|
||||
end
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function CombatControls.init()
|
||||
combatControlsButton = TopMenu.addGameButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle)
|
||||
combatControlsButton:setOn(true)
|
||||
combatControlsWindow = loadUI('combatcontrols.otui')
|
||||
|
||||
fightOffensiveBox = combatControlsWindow:getChildById('fightOffensiveBox')
|
||||
fightBalancedBox = combatControlsWindow:getChildById('fightBalancedBox')
|
||||
fightDefensiveBox = combatControlsWindow:getChildById('fightDefensiveBox')
|
||||
chaseModeButton = combatControlsWindow:getChildById('chaseModeBox')
|
||||
safeFightButton = combatControlsWindow:getChildById('safeFightBox')
|
||||
|
||||
fightModeRadioGroup = RadioGroup.create()
|
||||
fightModeRadioGroup:addWidget(fightOffensiveBox)
|
||||
fightModeRadioGroup:addWidget(fightBalancedBox)
|
||||
fightModeRadioGroup:addWidget(fightDefensiveBox)
|
||||
|
||||
connect(fightModeRadioGroup, { onSelectionChange = onFightModeChange })
|
||||
connect(chaseModeButton, { onCheckChange = onChaseModeChange })
|
||||
connect(safeFightButton, { onCheckChange = onSafeFightChange })
|
||||
connect(g_game, { onGameStart = CombatControls.online })
|
||||
connect(g_game, { onGameEnd = CombatControls.offline })
|
||||
|
||||
if g_game.isOnline() then
|
||||
CombatControls.online()
|
||||
end
|
||||
end
|
||||
|
||||
function CombatControls.terminate()
|
||||
if g_game.isOnline() then
|
||||
CombatControls.offline()
|
||||
end
|
||||
|
||||
fightModeRadioGroup:destroy()
|
||||
fightModeRadioGroup = nil
|
||||
|
||||
fightOffensiveBox = nil
|
||||
fightBalancedBox = nil
|
||||
fightDefensiveBox = nil
|
||||
chaseModeButton = nil
|
||||
safeFightButton = nil
|
||||
|
||||
combatControlsButton:destroy()
|
||||
combatControlsButton = nil
|
||||
|
||||
combatControlsWindow:destroy()
|
||||
combatControlsWindow = nil
|
||||
|
||||
disconnect(g_game, { onGameStart = CombatControls.online })
|
||||
disconnect(g_game, { onGameEnd = CombatControls.offline })
|
||||
|
||||
CombatControls = nil
|
||||
end
|
||||
|
||||
function CombatControls.online()
|
||||
g_game.gameRightPanel:addChild(combatControlsWindow)
|
||||
combatControlsWindow:setVisible(combatControlsButton:isOn())
|
||||
|
||||
local fightMode = g_game.getFightMode()
|
||||
if fightMode == FightOffensive then
|
||||
fightModeRadioGroup:selectWidget(fightOffensiveBox)
|
||||
elseif fightMode == FightBalanced then
|
||||
fightModeRadioGroup:selectWidget(fightBalancedBox)
|
||||
else
|
||||
fightModeRadioGroup:selectWidget(fightDefensiveBox)
|
||||
end
|
||||
|
||||
local chaseMode = g_game.getChaseMode()
|
||||
chaseModeButton:setChecked(chaseMode == ChaseOpponent)
|
||||
|
||||
local safeFight = g_game.isSafeFight()
|
||||
safeFightButton:setChecked(not safeFight)
|
||||
end
|
||||
|
||||
function CombatControls.offline()
|
||||
g_game.gameRightPanel:removeChild(combatControlsWindow)
|
||||
end
|
||||
|
||||
function CombatControls.toggle()
|
||||
local visible = not combatControlsWindow:isExplicitlyVisible()
|
||||
combatControlsWindow:setVisible(visible)
|
||||
combatControlsButton:setOn(visible)
|
||||
end
|
||||
|
12
modules/game_combatcontrols/combatcontrols.otmod
Normal file
12
modules/game_combatcontrols/combatcontrols.otmod
Normal file
@@ -0,0 +1,12 @@
|
||||
Module
|
||||
name: game_combatcontrols
|
||||
description: Combat controls window
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
|
||||
onLoad: |
|
||||
dofile 'combatcontrols'
|
||||
CombatControls.init()
|
||||
|
||||
onUnload: |
|
||||
CombatControls.terminate()
|
43
modules/game_combatcontrols/combatcontrols.otui
Normal file
43
modules/game_combatcontrols/combatcontrols.otui
Normal file
@@ -0,0 +1,43 @@
|
||||
CombatBox < UICheckBox
|
||||
size: 20 20
|
||||
image-clip: 0 0 20 20
|
||||
anchors.top: parent.top
|
||||
margin-left: 5
|
||||
margin-right: 5
|
||||
|
||||
$checked:
|
||||
image-clip: 0 20 20 20
|
||||
|
||||
FightOffensiveBox < CombatBox
|
||||
image-source: /game_combatcontrols/icons/fightoffensive.png
|
||||
FightBalancedBox < CombatBox
|
||||
image-source: /game_combatcontrols/icons/fightbalanced.png
|
||||
FightDefensiveBox < CombatBox
|
||||
image-source: /game_combatcontrols/icons/fightdefensive.png
|
||||
ChaseModeBox < CombatBox
|
||||
image-source: /game_combatcontrols/icons/chasemode.png
|
||||
SafeFightBox < CombatBox
|
||||
image-source: /game_combatcontrols/icons/safefight.png
|
||||
|
||||
UIWindow
|
||||
width: 130
|
||||
height: 30
|
||||
margin-top: 10
|
||||
margin-left: 6
|
||||
margin-right: 6
|
||||
|
||||
FightOffensiveBox
|
||||
id: fightOffensiveBox
|
||||
anchors.right: next.left
|
||||
FightBalancedBox
|
||||
id: fightBalancedBox
|
||||
anchors.right: next.left
|
||||
FightDefensiveBox
|
||||
id: fightDefensiveBox
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
ChaseModeBox
|
||||
id: chaseModeBox
|
||||
anchors.left: prev.right
|
||||
SafeFightBox
|
||||
id: safeFightBox
|
||||
anchors.left: prev.right
|
BIN
modules/game_combatcontrols/combatcontrols.png
Normal file
BIN
modules/game_combatcontrols/combatcontrols.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 381 B |
BIN
modules/game_combatcontrols/icons/chasemode.png
Normal file
BIN
modules/game_combatcontrols/icons/chasemode.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
modules/game_combatcontrols/icons/fightbalanced.png
Normal file
BIN
modules/game_combatcontrols/icons/fightbalanced.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
BIN
modules/game_combatcontrols/icons/fightdefensive.png
Normal file
BIN
modules/game_combatcontrols/icons/fightdefensive.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
modules/game_combatcontrols/icons/fightoffensive.png
Normal file
BIN
modules/game_combatcontrols/icons/fightoffensive.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
BIN
modules/game_combatcontrols/icons/safefight.png
Normal file
BIN
modules/game_combatcontrols/icons/safefight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Reference in New Issue
Block a user