parent
e51789378a
commit
ee1357a848
@ -0,0 +1,43 @@
|
|||||||
|
RadioGroup = newclass()
|
||||||
|
|
||||||
|
function RadioGroup.create()
|
||||||
|
local radiogroup = RadioGroup.internalCreate()
|
||||||
|
radiogroup.widgets = {}
|
||||||
|
return radiogroup
|
||||||
|
end
|
||||||
|
|
||||||
|
function RadioGroup:destroy()
|
||||||
|
while #self.widgets ~= 0 do
|
||||||
|
self:removeWidget(self.widgets[1])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function RadioGroup:addWidget(widget)
|
||||||
|
table.insert(self.widgets, widget)
|
||||||
|
widget.onMousePress = function(widget) self:selectWidget(widget) end
|
||||||
|
end
|
||||||
|
|
||||||
|
function RadioGroup:removeWidget(widget)
|
||||||
|
if self.selectedWidget == widget then
|
||||||
|
self:selectWidget(nil)
|
||||||
|
end
|
||||||
|
widget.onMousePress = nil
|
||||||
|
table.removevalue(self.widgets, widget)
|
||||||
|
end
|
||||||
|
|
||||||
|
function RadioGroup:selectWidget(selectedWidget)
|
||||||
|
if selectedWidget == self.selectedWidget then return end
|
||||||
|
|
||||||
|
local previousSelectedWidget = self.selectedWidget
|
||||||
|
self.selectedWidget = selectedWidget
|
||||||
|
|
||||||
|
if previousSelectedWidget then
|
||||||
|
previousSelectedWidget:setChecked(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
if selectedWidget then
|
||||||
|
selectedWidget:setChecked(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
signalcall(self.onSelectionChange, self, selectedWidget, previousSelectedWidget)
|
||||||
|
end
|
@ -1,13 +1,132 @@
|
|||||||
CombatControls = {}
|
CombatControls = {}
|
||||||
|
|
||||||
|
-- private variables
|
||||||
local combatControlsButton
|
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 Game.getFightMode ~= fightMode then
|
||||||
|
Game.setFightMode(fightMode)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onChaseModeChange(self, checked)
|
||||||
|
local chaseMode
|
||||||
|
if checked then
|
||||||
|
chaseMode = ChaseOpponent
|
||||||
|
else
|
||||||
|
chaseMode = DontChase
|
||||||
|
end
|
||||||
|
if Game.getChaseMode() ~= chaseMode then
|
||||||
|
Game.setChaseMode(chaseMode)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onSafeFightChange(self, checked)
|
||||||
|
local safeFight = not checked
|
||||||
|
if Game.isSafeFight() ~= safeFight then
|
||||||
|
Game.setSafeFight(not checked)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- public functions
|
||||||
function CombatControls.init()
|
function CombatControls.init()
|
||||||
combatControlsButton = TopMenu.addGameButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle)
|
combatControlsButton = TopMenu.addGameButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle)
|
||||||
end
|
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(Game, { onLogin = CombatControls.online })
|
||||||
|
connect(Game, { onLogout = CombatControls.offline })
|
||||||
|
|
||||||
|
if Game.isOnline() then
|
||||||
|
CombatControls.online()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function CombatControls.terminate()
|
function CombatControls.terminate()
|
||||||
|
if Game.isOnline() then
|
||||||
|
CombatControls.offline()
|
||||||
|
end
|
||||||
|
|
||||||
|
fightModeRadioGroup:destroy()
|
||||||
|
fightModeRadioGroup = nil
|
||||||
|
|
||||||
|
fightOffensiveBox = nil
|
||||||
|
fightBalancedBox = nil
|
||||||
|
fightDefensiveBox = nil
|
||||||
|
chaseModeButton = nil
|
||||||
|
safeFightButton = nil
|
||||||
|
|
||||||
combatControlsButton:destroy()
|
combatControlsButton:destroy()
|
||||||
combatControlsButton = nil
|
combatControlsButton = nil
|
||||||
|
|
||||||
|
combatControlsWindow:destroy()
|
||||||
|
combatControlsWindow = nil
|
||||||
|
|
||||||
|
disconnect(Game, { onLogin = CombatControls.online })
|
||||||
|
disconnect(Game, { onLogout = CombatControls.offline })
|
||||||
|
|
||||||
|
CombatControls = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CombatControls.online()
|
||||||
|
Game.gameRightPanel:addChild(combatControlsWindow)
|
||||||
|
combatControlsWindow:setVisible(combatControlsButton:isOn())
|
||||||
|
|
||||||
|
local fightMode = Game.getFightMode()
|
||||||
|
if fightMode == FightOffensive then
|
||||||
|
fightModeRadioGroup:selectWidget(fightOffensiveBox)
|
||||||
|
elseif fightMode == FightBalanced then
|
||||||
|
fightModeRadioGroup:selectWidget(fightBalancedBox)
|
||||||
|
else
|
||||||
|
fightModeRadioGroup:selectWidget(fightDefensiveBox)
|
||||||
|
end
|
||||||
|
|
||||||
|
local chaseMode = Game.getChaseMode()
|
||||||
|
chaseModeButton:setChecked(chaseMode == ChaseOpponent)
|
||||||
|
|
||||||
|
local safeFight = Game.isSafeFight()
|
||||||
|
safeFightButton:setChecked(not safeFight)
|
||||||
|
end
|
||||||
|
|
||||||
|
function CombatControls.offline()
|
||||||
|
Game.gameRightPanel:removeChild(combatControlsWindow)
|
||||||
|
end
|
||||||
|
|
||||||
|
function CombatControls.toggle()
|
||||||
|
local visible = not combatControlsWindow:isExplicitlyVisible()
|
||||||
|
combatControlsWindow:setVisible(visible)
|
||||||
|
combatControlsButton:setOn(visible)
|
||||||
|
end
|
||||||
|
|
||||||
|
@ -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
|
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 1.9 KiB |
Loading…
Reference in new issue