guiGameListOptionsCtrl.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. Row() : mSelectedOption(0), mWrapOptions(false)
  40. {
  41. VECTOR_SET_ASSOCIATION( mOptions );
  42. }
  43. };
  44. public:
  45. /// Gets the text for the currently selected option of the given row.
  46. ///
  47. /// \param rowIndex Index of the row to get the option from.
  48. /// \return A string representing the text currently displayed as the selected
  49. /// option on the given row. If there is no such displayed text then the empty
  50. /// string is returned.
  51. StringTableEntry getCurrentOption(S32 rowIndex) const;
  52. /// Attempts to set the given row to the specified selected option. The option
  53. /// will only be set if the option exists in the control.
  54. ///
  55. /// \param rowIndex Index of the row to set an option on.
  56. /// \param option The option to be made active.
  57. /// \return True if the row contained the option and was set, false otherwise.
  58. bool selectOption(S32 rowIndex, StringTableEntry option);
  59. /// Sets the list of options on the given row.
  60. ///
  61. /// \param rowIndex Index of the row to set options on.
  62. /// \param optionsList A tab separated list of options for the control.
  63. void setOptions(S32 rowIndex, const char * optionsList);
  64. /// Adds a row to the control.
  65. ///
  66. /// \param label The text to display on the row as a label.
  67. /// \param optionsList A tab separated list of options for the control.
  68. /// \param wrapOptions Specify true to allow options to wrap at the ends or
  69. /// false to prevent wrapping.
  70. /// \param callback [optional] Name of a script function to use as a callback
  71. /// when this row is activated. Default NULL means no callback.
  72. /// \param icon [optional] Index of the icon to use as a marker. Default -1
  73. /// means no icon will be shown on this row.
  74. /// \param yPad [optional] An extra amount of height padding before the row.
  75. /// \param enabled [optional] If this row is initially enabled. Default true.
  76. void addRow(const char* label, const char* optionsList, bool wrapOptions, const char* callback, S32 icon = -1, S32 yPad = 0, bool enabled = true);
  77. void onRender(Point2I offset, const RectI &updateRect);
  78. /// Callback when the mouse button is released.
  79. ///
  80. /// \param event A reference to the event that triggered the callback.
  81. void onMouseUp(const GuiEvent &event);
  82. /// Callback when a key is pressed.
  83. ///
  84. /// \param event The event that triggered this callback.
  85. bool onKeyDown(const GuiEvent &event);
  86. /// Callback when a key is repeating.
  87. ///
  88. /// \param event The event that triggered this callback.
  89. bool onKeyRepeat(const GuiEvent &event){ return onKeyDown(event); }
  90. /// Callback when the gamepad axis is activated.
  91. ///
  92. /// \param event A reference to the event that triggered the callback.
  93. virtual bool onGamepadAxisLeft(const GuiEvent &event);
  94. /// Callback when the gamepad axis is activated.
  95. ///
  96. /// \param event A reference to the event that triggered the callback.
  97. virtual bool onGamepadAxisRight(const GuiEvent &event);
  98. GuiGameListOptionsCtrl();
  99. ~GuiGameListOptionsCtrl();
  100. DECLARE_CONOBJECT(GuiGameListOptionsCtrl);
  101. DECLARE_DESCRIPTION( "A control for showing pages of options that are gamepad friendly." );
  102. virtual bool onAdd();
  103. /// Initializes fields accessible through the console.
  104. static void initPersistFields();
  105. static const S32 NO_OPTION = -1; ///< Indicates there is no option
  106. protected:
  107. /// Checks to make sure our control has a profile of the correct type.
  108. ///
  109. /// \return True if the profile is of type GuiGameListOptionsProfile or false
  110. /// if the profile is of any other type.
  111. bool hasValidProfile() const;
  112. /// Enforces the validity of the fields on this control and its profile (if the
  113. /// profile is valid, see: hasValidProfile).
  114. void enforceConstraints();
  115. /// Adds lines around the column divisions to the feedback already provided
  116. /// in the Parent.
  117. void onDebugRender(Point2I offset);
  118. private:
  119. /// Performs a click on the current option row. The x position is used to
  120. /// determine if the left or right arrow were clicked. If one was clicked, the
  121. /// option will be changed. If neither was clicked, the option is unaffected.
  122. /// This method should only be called when there is an actively selected row.
  123. ///
  124. /// \param row The row to perform the click on.
  125. /// \param xPos The x position of the the click, relative to the control.
  126. void clickOption(Row * row, S32 xPos);
  127. /// Changes the option on the currently selected row. If there is no row
  128. /// selected, this method does nothing.
  129. ///
  130. /// \param delta The amount to change the option selection by. Typically this
  131. /// will be 1 or -1.
  132. void changeOption(S32 delta);
  133. /// Changes the option on the given row.
  134. ///
  135. /// \param row The row to change the option on.
  136. /// \param delta The amount to change the option selection by. Typically this
  137. /// will be 1 or -1.
  138. void changeOption(Row * row, S32 delta);
  139. };
  140. /// \class GuiGameListOptionsProfile
  141. /// A gui profile with additional fields specific to GuiGameListOptionsCtrl.
  142. class GuiGameListOptionsProfile : public GuiGameListMenuProfile
  143. {
  144. typedef GuiGameListMenuProfile Parent;
  145. public:
  146. /// Enforces range constraints on all required fields.
  147. void enforceConstraints();
  148. GuiGameListOptionsProfile();
  149. S32 mColumnSplit; ///< Absolute position of the split between columns
  150. S32 mRightPad; ///< Extra padding between the right arrow and the hit area
  151. DECLARE_CONOBJECT(GuiGameListOptionsProfile);
  152. /// Initializes fields accessible through the console.
  153. static void initPersistFields();
  154. };
  155. #endif