guiGameListOptionsCtrl.cpp
Engine/source/gui/controls/guiGameListOptionsCtrl.cpp
Public Functions
ConsoleDocClass(GuiGameListOptionsCtrl , "@brief A <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> showing pages of options that are gamepad <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">friendly.\n\n</a>" "Each row in this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> allows the selection of one <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> from <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> set of " "options using the keyboard, gamepad or mouse. The row is rendered as 2 " "columns:the first column contains the row label, the second column " "contains left and right arrows(<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> mouse picking) and the currently " "selected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">value.\n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiGameListOptionsProfile\n\n</a>" " @ingroup GuiGame" )
ConsoleDocClass(GuiGameListOptionsProfile , "@brief A <a href="/coding/class/classguicontrolprofile/">GuiControlProfile</a> with additional fields specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiGameListOptionsCtrl.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguigamelistoptionsprofile/">GuiGameListOptionsProfile</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " columnSplit = \"100\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " rightPad = \"4\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " //Properties not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> have been omitted from this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">example.\n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup GuiGame" )
DefineEngineMethod(GuiGameListOptionsCtrl , addRow , void , (const char *label, const char *options, bool wrapOptions, const char *callback, S32 icon, S32 yPad, bool enabled) , (-1, 0, true) , "Add <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> row <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the list <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@param label The text <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> display on the row as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">label.\n</a>" "@param options A tab separated list of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">options.\n</a>" "@param wrapOptions Specify true <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> allow options <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> wrap at each end or false <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> prevent <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">wrapping.\n</a>" "@param callback Name of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> script function <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> use as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> callback when this row is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">activated.\n</a>" "@param icon Index of the icon <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> use as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">marker.\n</a>" "@param yPad An extra amount of height padding before the row. Does nothing on the first <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">row.\n</a>" "@param enabled If this row is initially enabled." )
DefineEngineMethod(GuiGameListOptionsCtrl , clearOptions , void , () , "Sets the list of options on the given <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">row.\n\n</a>" "@param row Index of the row <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set options on." "@param optionsList A tab separated list of options <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the control." )
DefineEngineMethod(GuiGameListOptionsCtrl , getCurrentOption , const char * , (S32 row) , "Gets the text <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the currently selected option of the given <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">row.\n\n</a>" "@param row Index of the row <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> get the option <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">from.\n</a>" "@return A string representing the text currently displayed as the selected option on the given row. If there is no such displayed text then the empty string is returned." )
DefineEngineMethod(GuiGameListOptionsCtrl , selectOption , bool , (S32 row, const char *option) , "Set the row's current option <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the one <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">specified\n\n</a>" "@param row Index of the row <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set an option <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">on.\n</a>" "@param option The option <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be made <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">active.\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the row contained the option and was set, false otherwise." )
DefineEngineMethod(GuiGameListOptionsCtrl , setOptions , void , (S32 row, const char *optionsList) , "Sets the list of options on the given <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">row.\n\n</a>" "@param row Index of the row <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set options on." "@param optionsList A tab separated list of options <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the control." )
Detailed Description
Public Functions
ConsoleDocClass(GuiGameListOptionsCtrl , "@brief A <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> showing pages of options that are gamepad <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">friendly.\n\n</a>" "Each row in this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> allows the selection of one <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> from <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> set of " "options using the keyboard, gamepad or mouse. The row is rendered as 2 " "columns:the first column contains the row label, the second column " "contains left and right arrows(<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> mouse picking) and the currently " "selected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">value.\n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiGameListOptionsProfile\n\n</a>" " @ingroup GuiGame" )
ConsoleDocClass(GuiGameListOptionsProfile , "@brief A <a href="/coding/class/classguicontrolprofile/">GuiControlProfile</a> with additional fields specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiGameListOptionsCtrl.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguigamelistoptionsprofile/">GuiGameListOptionsProfile</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " columnSplit = \"100\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " rightPad = \"4\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " //Properties not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> have been omitted from this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">example.\n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup GuiGame" )
DefineEngineMethod(GuiGameListOptionsCtrl , addRow , void , (const char *label, const char *options, bool wrapOptions, const char *callback, S32 icon, S32 yPad, bool enabled) , (-1, 0, true) , "Add <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> row <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the list <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">control.\n\n</a>" "@param label The text <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> display on the row as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">label.\n</a>" "@param options A tab separated list of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">options.\n</a>" "@param wrapOptions Specify true <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> allow options <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> wrap at each end or false <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> prevent <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">wrapping.\n</a>" "@param callback Name of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> script function <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> use as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> callback when this row is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">activated.\n</a>" "@param icon Index of the icon <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> use as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">marker.\n</a>" "@param yPad An extra amount of height padding before the row. Does nothing on the first <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">row.\n</a>" "@param enabled If this row is initially enabled." )
DefineEngineMethod(GuiGameListOptionsCtrl , clearOptions , void , () , "Sets the list of options on the given <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">row.\n\n</a>" "@param row Index of the row <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set options on." "@param optionsList A tab separated list of options <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the control." )
DefineEngineMethod(GuiGameListOptionsCtrl , getCurrentOption , const char * , (S32 row) , "Gets the text <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the currently selected option of the given <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">row.\n\n</a>" "@param row Index of the row <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> get the option <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">from.\n</a>" "@return A string representing the text currently displayed as the selected option on the given row. If there is no such displayed text then the empty string is returned." )
DefineEngineMethod(GuiGameListOptionsCtrl , selectOption , bool , (S32 row, const char *option) , "Set the row's current option <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the one <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">specified\n\n</a>" "@param row Index of the row <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set an option <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">on.\n</a>" "@param option The option <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be made <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">active.\n</a>" "@return True <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the row contained the option and was set, false otherwise." )
DefineEngineMethod(GuiGameListOptionsCtrl , setOptions , void , (S32 row, const char *optionsList) , "Sets the list of options on the given <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">row.\n\n</a>" "@param row Index of the row <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set options on." "@param optionsList A tab separated list of options <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the control." )
IMPLEMENT_CONOBJECT(GuiGameListOptionsCtrl )
IMPLEMENT_CONOBJECT(GuiGameListOptionsProfile )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "guiGameListOptionsCtrl.h" 25#include "gfx/gfxDrawUtil.h" 26#include "console/consoleTypes.h" 27#include "console/engineAPI.h" 28#include "core/strings/stringUnit.h" 29 30//----------------------------------------------------------------------------- 31// GuiGameListOptionsCtrl 32//----------------------------------------------------------------------------- 33 34GuiGameListOptionsCtrl::GuiGameListOptionsCtrl() 35{ 36} 37 38GuiGameListOptionsCtrl::~GuiGameListOptionsCtrl() 39{ 40} 41 42bool GuiGameListOptionsCtrl::onAdd() 43{ 44 if( !Parent::onAdd() ) 45 return false; 46 47 if( !hasValidProfile() ) 48 { 49 GuiGameListOptionsProfile* profile; 50 if( !Sim::findObject( "DefaultOptionsMenuProfile", profile ) ) 51 { 52 Con::errorf( "GuiGameListOptionsCtrl: %s can't be created with a profile of type %s. Please create it with a profile of type GuiGameListOptionsProfile.", 53 getName(), mProfile->getClassName() ); 54 return false; 55 } 56 else 57 Con::warnf( "GuiGameListOptionsCtrl: substituted non-GuiGameListOptionsProfile in %s for DefaultOptionsMenuProfile", getName() ); 58 59 setControlProfile( profile ); 60 } 61 62 return true; 63} 64 65void GuiGameListOptionsCtrl::onRender(Point2I offset, const RectI &updateRect) 66{ 67 Parent::onRender(offset, updateRect); 68 GuiGameListOptionsProfile * profile = (GuiGameListOptionsProfile *) mProfile; 69 70 F32 xScale = (float) getWidth() / profile->getRowWidth(); 71 72 S32 rowHeight = profile->getRowHeight(); 73 74 bool profileHasArrows = profile->hasArrows(); 75 Point2I arrowExtent; 76 S32 arrowOffsetY(0); 77 if (profileHasArrows) 78 { 79 arrowExtent = profile->getArrowExtent(); 80 81 // icon is centered vertically 82 arrowOffsetY = (rowHeight - arrowExtent.y) >> 1; 83 } 84 85 GFXDrawUtil *drawer = GFX->getDrawUtil(); 86 87 Point2I currentOffset = offset; 88 Point2I arrowOffset; 89 S32 columnSplit = profile->mColumnSplit * xScale; 90 S32 iconIndex; 91 for (Vector<Parent::Row *>::iterator row = mRows.begin(); row < mRows.end(); ++row) 92 { 93 Row * myRow = (Row *) *row; 94 if (row != mRows.begin()) 95 { 96 // rows other than the first can have padding above them 97 currentOffset.y += myRow->mHeightPad; 98 currentOffset.y += rowHeight; 99 } 100 101 bool hasOptions = (myRow->mOptions.size() > 0) && myRow->mSelectedOption > -1; 102 if (hasOptions) 103 { 104 bool isRowSelected = (getSelected() != NO_ROW) && (row == &mRows[getSelected()]); 105 bool isRowHighlighted = (getHighlighted() != NO_ROW) ? ((row == &mRows[getHighlighted()]) && ((*row)->mEnabled)) : false; 106 if (profileHasArrows) 107 { 108 // render the left arrow 109 bool arrowOnL = (isRowSelected || isRowHighlighted) && (myRow->mWrapOptions || (myRow->mSelectedOption > 0)); 110 iconIndex = (arrowOnL) ? Profile::TEX_L_ARROW_ON : Profile::TEX_L_ARROW_OFF; 111 arrowOffset.x = currentOffset.x + columnSplit; 112 arrowOffset.y = currentOffset.y + arrowOffsetY; 113 114 drawer->clearBitmapModulation(); 115 drawer->drawBitmapStretchSR(profile->mTextureObject, RectI(arrowOffset, arrowExtent), profile->getBitmapArrayRect((U32)iconIndex)); 116 117 // render the right arrow 118 bool arrowOnR = (isRowSelected || isRowHighlighted) && (myRow->mWrapOptions || (myRow->mSelectedOption < myRow->mOptions.size() - 1)); 119 iconIndex = (arrowOnR) ? Profile::TEX_R_ARROW_ON : Profile::TEX_R_ARROW_OFF; 120 arrowOffset.x = currentOffset.x + (profile->mHitAreaLowerRight.x - profile->mRightPad) * xScale - arrowExtent.x; 121 arrowOffset.y = currentOffset.y + arrowOffsetY; 122 123 drawer->clearBitmapModulation(); 124 drawer->drawBitmapStretchSR(profile->mTextureObject, RectI(arrowOffset, arrowExtent), profile->getBitmapArrayRect((U32)iconIndex)); 125 } 126 127 // get the appropriate font color 128 ColorI fontColor; 129 if (! myRow->mEnabled) 130 { 131 fontColor = profile->mFontColorNA; 132 } 133 else if (isRowSelected) 134 { 135 fontColor = profile->mFontColorSEL; 136 } 137 else if (isRowHighlighted) 138 { 139 fontColor = profile->mFontColorHL; 140 } 141 else 142 { 143 fontColor = profile->mFontColor; 144 } 145 146 // calculate text to be at the center between the arrows 147 GFont * font = profile->mFont; 148 StringTableEntry text = myRow->mOptions[myRow->mSelectedOption]; 149 S32 textWidth = font->getStrWidth(text); 150 S32 columnWidth = profile->mHitAreaLowerRight.x * xScale - profile->mRightPad - columnSplit; 151 S32 columnCenter = columnSplit + (columnWidth >> 1); 152 S32 textStartX = columnCenter - (textWidth >> 1); 153 Point2I textOffset(textStartX, 0); 154 155 // render the option text itself 156 Point2I textExtent(columnWidth, rowHeight); 157 drawer->setBitmapModulation(fontColor); 158 renderJustifiedText(currentOffset + textOffset, textExtent, text); 159 } 160 } 161} 162 163void GuiGameListOptionsCtrl::onDebugRender(Point2I offset) 164{ 165 Parent::onDebugRender(offset); 166 GuiGameListOptionsProfile * profile = (GuiGameListOptionsProfile *) mProfile; 167 168 F32 xScale = (float) getWidth() / profile->getRowWidth(); 169 170 ColorI column1Color(255, 255, 0); // yellow 171 ColorI column2Color(0, 255, 0); // green 172 Point2I shrinker(-1, -1); 173 174 S32 rowHeight = profile->getRowHeight(); 175 Point2I currentOffset(offset); 176 Point2I rowExtent(getExtent().x, rowHeight); 177 Point2I hitAreaExtent(profile->getHitAreaExtent()); 178 hitAreaExtent.x *= xScale; 179 hitAreaExtent += shrinker; 180 Point2I column1Extent((profile->mColumnSplit - profile->mHitAreaUpperLeft.x) * xScale - 1, hitAreaExtent.y); 181 Point2I column2Extent(hitAreaExtent.x - column1Extent.x - 1, hitAreaExtent.y); 182 Point2I hitAreaOffset = profile->mHitAreaUpperLeft; 183 hitAreaOffset.x *= xScale; 184 185 RectI borderRect; 186 Point2I upperLeft; 187 for (Vector<Parent::Row *>::iterator row = mRows.begin(); row < mRows.end(); ++row) 188 { 189 // set the top of the current row 190 if (row != mRows.begin()) 191 { 192 // rows other than the first can have padding above them 193 currentOffset.y += (*row)->mHeightPad; 194 currentOffset.y += rowHeight; 195 } 196 197 // draw the box around column 1 198 upperLeft = currentOffset + hitAreaOffset; 199 borderRect.point = upperLeft; 200 borderRect.extent = column1Extent; 201 GFX->getDrawUtil()->drawRect(borderRect, column1Color); 202 203 // draw the box around column 2 204 upperLeft.x += column1Extent.x + 1; 205 borderRect.point = upperLeft; 206 borderRect.extent = column2Extent; 207 GFX->getDrawUtil()->drawRect(borderRect, column2Color); 208 } 209} 210 211void GuiGameListOptionsCtrl::addRow(const char* label, const char* optionsList, bool wrapOptions, const char* callback, S32 icon, S32 yPad, bool enabled) 212{ 213 static StringTableEntry DELIM = StringTable->insert("\t", true); 214 Row * row = new Row(); 215 Vector<StringTableEntry> options( __FILE__, __LINE__ ); 216 S32 count = StringUnit::getUnitCount(optionsList, DELIM); 217 for (S32 i = 0; i < count; ++i) 218 { 219 const char * option = StringUnit::getUnit(optionsList, i, DELIM); 220 options.push_back(StringTable->insert(option, true)); 221 } 222 row->mOptions = options; 223 bool hasOptions = row->mOptions.size() > 0; 224 row->mSelectedOption = (hasOptions) ? 0 : NO_OPTION; 225 row->mWrapOptions = wrapOptions; 226 Parent::addRow(row, label, callback, icon, yPad, true, (hasOptions) ? enabled : false); 227} 228 229void GuiGameListOptionsCtrl::setOptions(S32 rowIndex, const char * optionsList) 230{ 231 static StringTableEntry DELIM = StringTable->insert("\t", true); 232 233 if (! isValidRowIndex(rowIndex)) 234 { 235 return; 236 } 237 238 Row * row = (Row *)mRows[rowIndex]; 239 240 S32 count = StringUnit::getUnitCount(optionsList, DELIM); 241 row->mOptions.setSize(count); 242 for (S32 i = 0; i < count; ++i) 243 { 244 const char * option = StringUnit::getUnit(optionsList, i, DELIM); 245 row->mOptions[i] = StringTable->insert(option, true); 246 } 247 248 if (row->mSelectedOption >= row->mOptions.size()) 249 { 250 row->mSelectedOption = row->mOptions.size() - 1; 251 } 252} 253 254bool GuiGameListOptionsCtrl::hasValidProfile() const 255{ 256 GuiGameListOptionsProfile * profile = dynamic_cast<GuiGameListOptionsProfile *>(mProfile); 257 return profile; 258} 259 260void GuiGameListOptionsCtrl::enforceConstraints() 261{ 262 Parent::enforceConstraints(); 263} 264 265void GuiGameListOptionsCtrl::onMouseUp(const GuiEvent &event) 266{ 267 S32 hitRow = getRow(event.mousePoint); 268 if ((hitRow != NO_ROW) && isRowEnabled(hitRow) && (hitRow == getSelected())) 269 { 270 S32 xPos = globalToLocalCoord(event.mousePoint).x; 271 clickOption((Row *) mRows[getSelected()], xPos); 272 } 273} 274 275void GuiGameListOptionsCtrl::clickOption(Row * row, S32 xPos) 276{ 277 GuiGameListOptionsProfile * profile = (GuiGameListOptionsProfile *) mProfile; 278 if (! profile->hasArrows()) 279 { 280 return; 281 } 282 283 F32 xScale = (float) getWidth() / profile->getRowWidth(); 284 285 S32 bitmapArrowWidth = mProfile->getBitmapArrayRect(Profile::TEX_FIRST_ARROW).extent.x; 286 287 S32 leftArrowX1 = profile->mColumnSplit * xScale; 288 S32 leftArrowX2 = leftArrowX1 + bitmapArrowWidth; 289 290 S32 rightArrowX2 = (profile->mHitAreaLowerRight.x - profile->mRightPad) * xScale; 291 S32 rightArrowX1 = rightArrowX2 - bitmapArrowWidth; 292 293 if ((leftArrowX1 <= xPos) && (xPos <= leftArrowX2)) 294 { 295 changeOption(row, -1); 296 } 297 else if ((rightArrowX1 <= xPos) && (xPos <= rightArrowX2)) 298 { 299 changeOption(row, 1); 300 } 301} 302 303bool GuiGameListOptionsCtrl::onKeyDown(const GuiEvent &event) 304{ 305 switch (event.keyCode) 306 { 307 case KEY_LEFT: 308 changeOption(-1); 309 return true; 310 311 case KEY_RIGHT: 312 changeOption(1); 313 return true; 314 315 default: 316 break; 317 } 318 319 return Parent::onKeyDown(event); 320} 321 322bool GuiGameListOptionsCtrl::onGamepadAxisLeft( const GuiEvent &event ) 323{ 324 changeOption(-1); 325 return true; 326} 327 328bool GuiGameListOptionsCtrl::onGamepadAxisRight( const GuiEvent &event ) 329{ 330 changeOption(1); 331 return true; 332} 333 334void GuiGameListOptionsCtrl::changeOption(S32 delta) 335{ 336 if (getSelected() != NO_ROW) 337 { 338 Row * row = (Row *) mRows[getSelected()]; 339 changeOption(row, delta); 340 } 341} 342 343void GuiGameListOptionsCtrl::changeOption(Row * row, S32 delta) 344{ 345 S32 optionCount = row->mOptions.size(); 346 347 S32 newSelection = row->mSelectedOption + delta; 348 if (optionCount == 0) 349 { 350 newSelection = NO_OPTION; 351 } 352 else if (! row->mWrapOptions) 353 { 354 newSelection = mClamp(newSelection, 0, optionCount - 1); 355 } 356 else if (newSelection < 0) 357 { 358 newSelection = optionCount - 1; 359 } 360 else if (newSelection >= optionCount) 361 { 362 newSelection = 0; 363 } 364 row->mSelectedOption = newSelection; 365 366 static StringTableEntry LEFT = StringTable->insert("LEFT", true); 367 static StringTableEntry RIGHT = StringTable->insert("RIGHT", true); 368 369 if (row->mScriptCallback != NULL) 370 { 371 setThisControl(); 372 StringTableEntry direction = NULL; 373 if (delta < 0) 374 { 375 direction = LEFT; 376 } 377 else if (delta > 0) 378 { 379 direction = RIGHT; 380 } 381 if ((direction != NULL) && (Con::isFunction(row->mScriptCallback))) 382 { 383 Con::executef(row->mScriptCallback, direction); 384 } 385 } 386} 387 388StringTableEntry GuiGameListOptionsCtrl::getCurrentOption(S32 rowIndex) const 389{ 390 if (isValidRowIndex(rowIndex)) 391 { 392 Row * row = (Row *) mRows[rowIndex]; 393 if (row->mSelectedOption != NO_OPTION) 394 { 395 return row->mOptions[row->mSelectedOption]; 396 } 397 } 398 return StringTable->insert("", false); 399} 400 401bool GuiGameListOptionsCtrl::selectOption(S32 rowIndex, const char * theOption) 402{ 403 if (! isValidRowIndex(rowIndex)) 404 { 405 return false; 406 } 407 408 Row * row = (Row *) mRows[rowIndex]; 409 410 for (Vector<StringTableEntry>::iterator anOption = row->mOptions.begin(); anOption < row->mOptions.end(); ++anOption) 411 { 412 if (String::compare(*anOption, theOption) == 0) 413 { 414 S32 newIndex = anOption - row->mOptions.begin(); 415 row->mSelectedOption = newIndex; 416 return true; 417 } 418 } 419 420 return false; 421} 422 423void GuiGameListOptionsCtrl::clearRows() 424{ 425 mRows.clear(); 426} 427 428//----------------------------------------------------------------------------- 429// Console stuff (GuiGameListOptionsCtrl) 430//----------------------------------------------------------------------------- 431 432IMPLEMENT_CONOBJECT(GuiGameListOptionsCtrl); 433 434ConsoleDocClass( GuiGameListOptionsCtrl, 435 "@brief A control for showing pages of options that are gamepad friendly.\n\n" 436 437 "Each row in this control allows the selection of one value from a set of " 438 "options using the keyboard, gamepad or mouse. The row is rendered as 2 " 439 "columns: the first column contains the row label, the second column " 440 "contains left and right arrows (for mouse picking) and the currently " 441 "selected value.\n\n" 442 443 "@see GuiGameListOptionsProfile\n\n" 444 445 "@ingroup GuiGame" 446); 447 448void GuiGameListOptionsCtrl::initPersistFields() 449{ 450 Parent::initPersistFields(); 451} 452 453DefineEngineMethod( GuiGameListOptionsCtrl, addRow, void, 454 ( const char* label, const char* options, bool wrapOptions, const char* callback, S32 icon, S32 yPad, bool enabled ), 455 ( -1, 0, true ), 456 "Add a row to the list control.\n\n" 457 "@param label The text to display on the row as a label.\n" 458 "@param options A tab separated list of options.\n" 459 "@param wrapOptions Specify true to allow options to wrap at each end or false to prevent wrapping.\n" 460 "@param callback Name of a script function to use as a callback when this row is activated.\n" 461 "@param icon [optional] Index of the icon to use as a marker.\n" 462 "@param yPad [optional] An extra amount of height padding before the row. Does nothing on the first row.\n" 463 "@param enabled [optional] If this row is initially enabled." ) 464{ 465 object->addRow( label, options, wrapOptions, callback, icon, yPad, enabled ); 466} 467 468DefineEngineMethod( GuiGameListOptionsCtrl, getCurrentOption, const char *, ( S32 row ),, 469 "Gets the text for the currently selected option of the given row.\n\n" 470 "@param row Index of the row to get the option from.\n" 471 "@return A string representing the text currently displayed as the selected option on the given row. If there is no such displayed text then the empty string is returned." ) 472{ 473 return object->getCurrentOption( row ); 474} 475 476DefineEngineMethod( GuiGameListOptionsCtrl, selectOption, bool, ( S32 row, const char* option ),, 477 "Set the row's current option to the one specified\n\n" 478 "@param row Index of the row to set an option on.\n" 479 "@param option The option to be made active.\n" 480 "@return True if the row contained the option and was set, false otherwise." ) 481{ 482 return object->selectOption( row, option ); 483} 484 485DefineEngineMethod( GuiGameListOptionsCtrl, setOptions, void, ( S32 row, const char* optionsList ),, 486 "Sets the list of options on the given row.\n\n" 487 "@param row Index of the row to set options on." 488 "@param optionsList A tab separated list of options for the control." ) 489{ 490 object->setOptions( row, optionsList ); 491} 492 493DefineEngineMethod(GuiGameListOptionsCtrl, clearOptions, void, (), , 494 "Sets the list of options on the given row.\n\n" 495 "@param row Index of the row to set options on." 496 "@param optionsList A tab separated list of options for the control.") 497{ 498 object->clearRows(); 499} 500 501 502//----------------------------------------------------------------------------- 503// GuiGameListOptionsProfile 504//----------------------------------------------------------------------------- 505 506GuiGameListOptionsProfile::GuiGameListOptionsProfile() 507: mColumnSplit(0), 508 mRightPad(0) 509{ 510} 511 512void GuiGameListOptionsProfile::enforceConstraints() 513{ 514 Parent::enforceConstraints(); 515 516 if( mHitAreaUpperLeft.x > mColumnSplit || mColumnSplit > mHitAreaLowerRight.x ) 517 Con::errorf( "GuiGameListOptionsProfile: You can't create %s with a ColumnSplit outside the hit area. You set the split to %d. Please change the ColumnSplit to be in the range [%d, %d].", 518 getName(), mColumnSplit, mHitAreaUpperLeft.x, mHitAreaLowerRight.x); 519 520 mColumnSplit = mClamp(mColumnSplit, mHitAreaUpperLeft.x, mHitAreaLowerRight.x); 521} 522 523//----------------------------------------------------------------------------- 524// Console stuff (GuiGameListOptionsProfile) 525//----------------------------------------------------------------------------- 526 527IMPLEMENT_CONOBJECT(GuiGameListOptionsProfile); 528 529ConsoleDocClass( GuiGameListOptionsProfile, 530 "@brief A GuiControlProfile with additional fields specific to GuiGameListOptionsCtrl.\n\n" 531 532 "@tsexample\n" 533 "new GuiGameListOptionsProfile()\n" 534 "{\n" 535 " columnSplit = \"100\";\n" 536 " rightPad = \"4\";\n" 537 " //Properties not specific to this control have been omitted from this example.\n" 538 "};\n" 539 "@endtsexample\n\n" 540 541 "@ingroup GuiGame" 542); 543 544void GuiGameListOptionsProfile::initPersistFields() 545{ 546 addField( "columnSplit", TypeS32, Offset(mColumnSplit, GuiGameListOptionsProfile), 547 "Padding between the leftmost edge of the control, and the row's left arrow." ); 548 549 addField( "rightPad", TypeS32, Offset(mRightPad, GuiGameListOptionsProfile), 550 "Padding between the rightmost edge of the control and the row's right arrow." ); 551 552 Parent::initPersistFields(); 553} 554