No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

combatcontrols.lua 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. CombatControls = {}
  2. -- private variables
  3. local combatControlsButton
  4. local combatControlsWindow
  5. local fightOffensiveBox
  6. local fightBalancedBox
  7. local fightDefensiveBox
  8. local chaseModeButton
  9. local safeFightButton
  10. local fightModeRadioGroup
  11. -- private functions
  12. local function onFightModeChange(self, selectedFightButton)
  13. if selectedFightButton == nil then return end
  14. local buttonId = selectedFightButton:getId()
  15. local fightMode
  16. if buttonId == 'fightOffensiveBox' then
  17. fightMode = FightOffensive
  18. elseif buttonId == 'fightBalancedBox' then
  19. fightMode = FightBalanced
  20. else
  21. fightMode = FightDefensive
  22. end
  23. if Game.getFightMode ~= fightMode then
  24. Game.setFightMode(fightMode)
  25. end
  26. end
  27. local function onChaseModeChange(self, checked)
  28. local chaseMode
  29. if checked then
  30. chaseMode = ChaseOpponent
  31. else
  32. chaseMode = DontChase
  33. end
  34. if Game.getChaseMode() ~= chaseMode then
  35. Game.setChaseMode(chaseMode)
  36. end
  37. end
  38. local function onSafeFightChange(self, checked)
  39. local safeFight = not checked
  40. if Game.isSafeFight() ~= safeFight then
  41. Game.setSafeFight(not checked)
  42. end
  43. end
  44. -- public functions
  45. function CombatControls.init()
  46. combatControlsButton = TopMenu.addGameButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle)
  47. combatControlsButton:setOn(true)
  48. combatControlsWindow = loadUI('combatcontrols.otui')
  49. fightOffensiveBox = combatControlsWindow:getChildById('fightOffensiveBox')
  50. fightBalancedBox = combatControlsWindow:getChildById('fightBalancedBox')
  51. fightDefensiveBox = combatControlsWindow:getChildById('fightDefensiveBox')
  52. chaseModeButton = combatControlsWindow:getChildById('chaseModeBox')
  53. safeFightButton = combatControlsWindow:getChildById('safeFightBox')
  54. fightModeRadioGroup = RadioGroup.create()
  55. fightModeRadioGroup:addWidget(fightOffensiveBox)
  56. fightModeRadioGroup:addWidget(fightBalancedBox)
  57. fightModeRadioGroup:addWidget(fightDefensiveBox)
  58. connect(fightModeRadioGroup, { onSelectionChange = onFightModeChange })
  59. connect(chaseModeButton, { onCheckChange = onChaseModeChange })
  60. connect(safeFightButton, { onCheckChange = onSafeFightChange })
  61. connect(Game, { onGameStart = CombatControls.online })
  62. connect(Game, { onGameEnd = CombatControls.offline })
  63. if Game.isOnline() then
  64. CombatControls.online()
  65. end
  66. end
  67. function CombatControls.terminate()
  68. if Game.isOnline() then
  69. CombatControls.offline()
  70. end
  71. fightModeRadioGroup:destroy()
  72. fightModeRadioGroup = nil
  73. fightOffensiveBox = nil
  74. fightBalancedBox = nil
  75. fightDefensiveBox = nil
  76. chaseModeButton = nil
  77. safeFightButton = nil
  78. combatControlsButton:destroy()
  79. combatControlsButton = nil
  80. combatControlsWindow:destroy()
  81. combatControlsWindow = nil
  82. disconnect(Game, { onGameStart = CombatControls.online })
  83. disconnect(Game, { onGameEnd = CombatControls.offline })
  84. CombatControls = nil
  85. end
  86. function CombatControls.online()
  87. Game.gameRightPanel:addChild(combatControlsWindow)
  88. combatControlsWindow:setVisible(combatControlsButton:isOn())
  89. local fightMode = Game.getFightMode()
  90. if fightMode == FightOffensive then
  91. fightModeRadioGroup:selectWidget(fightOffensiveBox)
  92. elseif fightMode == FightBalanced then
  93. fightModeRadioGroup:selectWidget(fightBalancedBox)
  94. else
  95. fightModeRadioGroup:selectWidget(fightDefensiveBox)
  96. end
  97. local chaseMode = Game.getChaseMode()
  98. chaseModeButton:setChecked(chaseMode == ChaseOpponent)
  99. local safeFight = Game.isSafeFight()
  100. safeFightButton:setChecked(not safeFight)
  101. end
  102. function CombatControls.offline()
  103. Game.gameRightPanel:removeChild(combatControlsWindow)
  104. end
  105. function CombatControls.toggle()
  106. local visible = not combatControlsWindow:isExplicitlyVisible()
  107. combatControlsWindow:setVisible(visible)
  108. combatControlsButton:setOn(visible)
  109. end