guiGameListOptionsCtrl.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GuiGameListOptionsCtrl_H_
  23. #define _GuiGameListOptionsCtrl_H_
  24. #include "gui/controls/guiGameListMenuCtrl.h"
  25. /// \class GuiGameListOptionsCtrl
  26. /// A control for showing pages of options that are gamepad friendly.
  27. class GuiGameListOptionsCtrl : public GuiGameListMenuCtrl
  28. {
  29. typedef GuiGameListMenuCtrl Parent;
  30. protected:
  31. /// \struct Row
  32. /// An extension to the parent's row, adding the ability to keep a collection
  33. /// of options and track status related to them.
  34. struct Row : public Parent::Row
  35. {
  36. Vector<StringTableEntry> mOptions; ///< Collection of options available to display
  37. S32 mSelectedOption; ///< Index into mOptions pointing at the selected option
  38. bool mWrapOptions; ///< Determines if options should "wrap around" at the ends
  39. enum Mode
  40. {
  41. Default = 0,
  42. OptionsList,
  43. Keybind
  44. };
  45. Mode mMode;
  46. Row() : mSelectedOption(0), mWrapOptions(false), mMode(Mode::Default)
  47. {
  48. VECTOR_SET_ASSOCIATION( mOptions );
  49. }
  50. };
  51. public:
  52. /// Gets the text for the currently selected option of the given row.
  53. ///
  54. /// \param rowIndex Index of the row to get the option from.
  55. /// \return A string representing the text currently displayed as the selected
  56. /// option on the given row. If there is no such displayed text then the empty
  57. /// string is returned.
  58. StringTableEntry getCurrentOption(S32 rowIndex) const;
  59. /// Attempts to set the given row to the specified selected option. The option
  60. /// will only be set if the option exists in the control.
  61. ///
  62. /// \param rowIndex Index of the row to set an option on.
  63. /// \param option The option to be made active.
  64. /// \return True if the row contained the option and was set, false otherwise.
  65. bool selectOption(S32 rowIndex, StringTableEntry option);
  66. /// Sets the list of options on the given row.
  67. ///
  68. /// \param rowIndex Index of the row to set options on.
  69. /// \param optionsList A tab separated list of options for the control.
  70. void setOptions(S32 rowIndex, const char * optionsList);
  71. /// Adds a row to the control.
  72. ///
  73. /// \param label The text to display on the row as a label.
  74. /// \param optionsList A tab separated list of options for the control.
  75. /// \param wrapOptions Specify true to allow options to wrap at the ends or
  76. /// false to prevent wrapping.
  77. /// \param callback [optional] Name of a script function to use as a callback
  78. /// when this row is activated. Default NULL means no callback.
  79. /// \param icon [optional] Index of the icon to use as a marker. Default -1
  80. /// means no icon will be shown on this row.
  81. /// \param yPad [optional] An extra amount of height padding before the row.
  82. /// \param enabled [optional] If this row is initially enabled. Default true.
  83. void addRow(const char* label, const char* optionsList, bool wrapOptions, const char* callback, S32 icon = -1, S32 yPad = 0, bool enabled = true);
  84. void onRender(Point2I offset, const RectI &updateRect);
  85. /// Callback when the mouse button is released.
  86. ///
  87. /// \param event A reference to the event that triggered the callback.
  88. void onMouseUp(const GuiEvent &event);
  89. /// Callback when a key is pressed.
  90. ///
  91. /// \param event The event that triggered this callback.
  92. bool onKeyDown(const GuiEvent &event);
  93. /// Callback when a key is repeating.
  94. ///
  95. /// \param event The event that triggered this callback.
  96. bool onKeyRepeat(const GuiEvent &event){ return onKeyDown(event); }
  97. /// Callback when the gamepad axis is activated.
  98. ///
  99. /// \param event A reference to the event that triggered the callback.
  100. virtual bool onGamepadAxisLeft(const GuiEvent &event);
  101. /// Callback when the gamepad axis is activated.
  102. ///
  103. /// \param event A reference to the event that triggered the callback.
  104. virtual bool onGamepadAxisRight(const GuiEvent &event);
  105. virtual void clearRows();
  106. GuiGameListOptionsCtrl();
  107. ~GuiGameListOptionsCtrl();
  108. DECLARE_CONOBJECT(GuiGameListOptionsCtrl);
  109. DECLARE_DESCRIPTION( "A control for showing pages of options that are gamepad friendly." );
  110. virtual bool onAdd();
  111. /// Initializes fields accessible through the console.
  112. static void initPersistFields();
  113. static const S32 NO_OPTION = -1; ///< Indicates there is no option
  114. protected:
  115. /// Checks to make sure our control has a profile of the correct type.
  116. ///
  117. /// \return True if the profile is of type GuiGameListOptionsProfile or false
  118. /// if the profile is of any other type.
  119. bool hasValidProfile() const;
  120. /// Enforces the validity of the fields on this control and its profile (if the
  121. /// profile is valid, see: hasValidProfile).
  122. void enforceConstraints();
  123. /// Adds lines around the column divisions to the feedback already provided
  124. /// in the Parent.
  125. void onDebugRender(Point2I offset);
  126. private:
  127. /// Performs a click on the current option row. The x position is used to
  128. /// determine if the left or right arrow were clicked. If one was clicked, the
  129. /// option will be changed. If neither was clicked, the option is unaffected.
  130. /// This method should only be called when there is an actively selected row.
  131. ///
  132. /// \param row The row to perform the click on.
  133. /// \param xPos The x position of the the click, relative to the control.
  134. void clickOption(Row * row, S32 xPos);
  135. /// Changes the option on the currently selected row. If there is no row
  136. /// selected, this method does nothing.
  137. ///
  138. /// \param delta The amount to change the option selection by. Typically this
  139. /// will be 1 or -1.
  140. void changeOption(S32 delta);
  141. /// Changes the option on the given row.
  142. ///
  143. /// \param row The row to change the option on.
  144. /// \param delta The amount to change the option selection by. Typically this
  145. /// will be 1 or -1.
  146. void changeOption(Row * row, S32 delta);
  147. };
  148. /// \class GuiGameListOptionsProfile
  149. /// A gui profile with additional fields specific to GuiGameListOptionsCtrl.
  150. class GuiGameListOptionsProfile : public GuiGameListMenuProfile
  151. {
  152. typedef GuiGameListMenuProfile Parent;
  153. public:
  154. /// Enforces range constraints on all required fields.
  155. void enforceConstraints();
  156. GuiGameListOptionsProfile();
  157. S32 mColumnSplit; ///< Absolute position of the split between columns
  158. S32 mRightPad; ///< Extra padding between the right arrow and the hit area
  159. DECLARE_CONOBJECT(GuiGameListOptionsProfile);
  160. /// Initializes fields accessible through the console.
  161. static void initPersistFields();
  162. };
  163. #endif