PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/ManiaLivePlugins/MLEPP/ForceMods/Gui/Windows/SettingsWindow.php

http://mlepp.googlecode.com/
PHP | 177 lines | 76 code | 31 blank | 70 comment | 4 complexity | 87b54bacae93c2524cf55bc5f2545fbb MD5 | raw file
  1. <?php
  2. /**
  3. * MLEPP - ManiaLive Extending Plugin Pack
  4. *
  5. * -- MLEPP Plugin --
  6. * @name ForceMods
  7. * @date $Date: 2011-07-09 19:18:31 +0200 (za, 09 jul 2011) $
  8. * @version $Revision: 858 $
  9. * @website mlepp.trackmania.nl
  10. * @package MLEPP
  11. *
  12. * @author Klaus "schmidi" Schmidhuber <schmidi.tm@gmail.com>
  13. * @copyright 2010 - 2011
  14. *
  15. * ---------------------------------------------------------------------
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. * ---------------------------------------------------------------------
  29. * You are allowed to change things of use this in other projects, as
  30. * long as you leave the information at the top (name, date, version,
  31. * website, package, author, copyright) and publish the code under
  32. * the GNU General Public License version 3.
  33. * ---------------------------------------------------------------------
  34. */
  35. namespace ManiaLivePlugins\MLEPP\ForceMods\Gui\Windows;
  36. use ManiaLivePlugins\MLEPP\ForceMods\ForceMods;
  37. use ManiaLivePlugins\MLEPP\ForceMods\Gui\Elements\Button;
  38. use ManiaLib\Gui\Elements\Label;
  39. class SettingsWindow extends \ManiaLive\Gui\Windowing\ManagedWindow {
  40. protected $callback = NULL;
  41. protected $disableButton;
  42. protected $incrementButton;
  43. protected $randomButton;
  44. protected $overrideOnButton;
  45. protected $overrideOffButton;
  46. /**
  47. * @fn initializeComponents()
  48. * @brief Function called on initialisation.
  49. *
  50. * @return void
  51. */
  52. function initializeComponents() {
  53. $this->setTitle('ForceMods Settings');
  54. $this->setSize(72, 72);
  55. // mode label
  56. $label = new Label(40, 20);
  57. $label->setPosition(18, 20);
  58. $label->setAlign('center', 'center');
  59. $label->setText('$880$o Mode ');
  60. $this->addComponent($label);
  61. // mode 0 button
  62. $this->disableButton = new Button(10, 8, 'disable', array($this, 'onClick'), 'off', true);
  63. $this->disableButton->setPosition(7.5, 23);
  64. $this->addComponent($this->disableButton);
  65. // mode 1 button
  66. $this->incrementButton = new Button(10, 8, 'sequential', array($this, 'onClick'), 'inc', true);
  67. $this->incrementButton->setPosition(18.5, 23);
  68. $this->addComponent($this->incrementButton);
  69. // mode 2 button
  70. $this->randomButton = new Button(10, 8, 'random', array($this, 'onClick'), 'rand', true);
  71. $this->randomButton->setPosition(29.5, 23);
  72. $this->addComponent($this->randomButton);
  73. // override label
  74. $label = new Label(40, 20);
  75. $label->setPosition(18, 35);
  76. $label->setAlign('center', 'center');
  77. $label->setText('$880$o Override');
  78. $this->addComponent($label);
  79. // override on button
  80. $this->overrideOnButton = new Button(10, 8, 'enable', array($this, 'onClick'), 'overrOn', true);
  81. $this->overrideOnButton->setPosition(7.5, 38);
  82. $this->addComponent($this->overrideOnButton);
  83. // override off button
  84. $this->overrideOffButton = new Button(10, 8, 'disable', array($this, 'onClick'), 'overrOff', true);
  85. $this->overrideOffButton->setPosition(18.5, 38);
  86. $this->addComponent($this->overrideOffButton);
  87. // environments label
  88. $label = new Label(40, 20);
  89. $label->setPosition(18, 48);
  90. $label->setAlign('center', 'center');
  91. $label->setText('$880$o Environments');
  92. $this->addComponent($label);
  93. // adjust size
  94. $envis = ForceMods::getEnvironments();
  95. $this->setSizeY($this->getSizeY() + (ceil(count($envis) / 3) * 5));
  96. // environment buttons
  97. $i = 0;
  98. foreach($envis as &$name) {
  99. $button = new Button(10, 4, ' '.$name.' ', array($this, 'onClick'), $name, true);
  100. $button->setPosition(7.5, 53);
  101. $this->addComponent($button);
  102. $i++;
  103. }
  104. }
  105. /**
  106. * @fn onDraw()
  107. * @brief Function called on draw.
  108. *
  109. * @return void
  110. */
  111. function onDraw() {
  112. $this->disableButton->setActive(ForceMods::$mode != 0);
  113. $this->incrementButton->setActive(ForceMods::$mode != 1);
  114. $this->randomButton->setActive(ForceMods::$mode != 2);
  115. $this->overrideOnButton->setActive(ForceMods::$override === false);
  116. $this->overrideOffButton->setActive(ForceMods::$override === true);
  117. }
  118. /**
  119. * @fn setCallback()
  120. * @brief Function to set callback handle.
  121. *
  122. * @param mixed $callback
  123. * @return void
  124. */
  125. function setCallback($callback) {
  126. $this->callback = $callback;
  127. }
  128. /**
  129. * @fn onClick()
  130. * @brief Function called on click.
  131. *
  132. * @param mixed $login
  133. * @param mixed $action
  134. * @return void
  135. */
  136. function onClick($login, $action) {
  137. if(is_callable($this->callback)) {
  138. call_user_func($this->callback, $login, $action);
  139. }
  140. }
  141. function destroy()
  142. {
  143. parent::destroy();
  144. }
  145. }
  146. ?>