v 0. Pasted by Anonymous as text at 2010-04-03 06:08:40 MSK and set expiration to never.

Paste will expire never.

  1. From afaac54d586c7a81e6116a262a4e6217665c7801 Mon Sep 17 00:00:00 2001
  2. From: Jyrno42 <jyrno42@gmail.com>
  3. Date: Sat, 3 Apr 2010 01:58:49 +0300
  4. Subject: [PATCH] A patch for #4949.
  5.  Added the following functions:
  6.      gui-element guiCreateComboBox( float x, float y, float width, float height, string caption, bool relative [, gui-element parent ] );
  7.      bool guiComboBoxAddItem( gui-element comboBox, string value );
  8.      nil/string guiComboBoxGetSelected( gui-element comboBox );
  9.  
  10. Signed-off-by: Jyrno42 <jyrno42@gmail.com>
  11. ---
  12.  MTA10/gui/CGUIComboBox_Impl.cpp                    |    3 +
  13.  MTA10/gui/CGUI_Impl.h                              |    4 +-
  14.  .../logic/CStaticFunctionDefinitions.cpp           |   75 +++++++++++++++
  15.  .../deathmatch/logic/CStaticFunctionDefinitions.h  |    6 +
  16.  MTA10/mods/shared_logic/CClientGUIElement.h        |    1 +
  17.  .../mods/shared_logic/lua/CLuaFunctionDefs.GUI.cpp |  101 ++++++++++++++++++++
  18.  MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h     |    5 +-
  19.  MTA10/mods/shared_logic/lua/CLuaManager.cpp        |    5 +
  20.  MTA10/sdk/gui/CGUI.h                               |    1 +
  21.  9 files changed, 208 insertions(+), 13 deletions(-)
  22.  
  23. diff --git a/MTA10/gui/CGUIComboBox_Impl.cpp b/MTA10/gui/CGUIComboBox_Impl.cpp
  24. index 1f46f6c..5fe83fc 100644
  25. --- a/MTA10/gui/CGUIComboBox_Impl.cpp
  26. +++ b/MTA10/gui/CGUIComboBox_Impl.cpp
  27. @@ -50,6 +50,9 @@ CGUIComboBox_Impl::CGUIComboBox_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent, co
  28.          pGUI->AddChild ( this );
  29.          SetParent ( NULL );
  30.      }
  31. +
  32. +   // Disable editing of the box...
  33. +   SetReadOnly ( true );
  34.  }
  35.  
  36.  
  37. diff --git a/MTA10/gui/CGUI_Impl.h b/MTA10/gui/CGUI_Impl.h
  38. index 28b135f..d00454c 100644
  39. --- a/MTA10/gui/CGUI_Impl.h
  40. +++ b/MTA10/gui/CGUI_Impl.h
  41. @@ -125,7 +125,7 @@ public:
  42.      CGUIComboBox*                   CreateComboBox              ( CGUIElement* pParent = NULL, const char* szCaption = "" );
  43.      CGUIComboBox*                   CreateComboBox              ( CGUIComboBox* pParent = NULL, const char* szCaption = "" );
  44.  
  45. -    CGUIWindow*                     CreateWnd                   ( CGUIElement* pParent = NULL, const char* szCaption = "" );
  46. +   CGUIWindow*                     CreateWnd                   ( CGUIElement* pParent = NULL, const char* szCaption = "" );
  47.      //
  48.  
  49.      CGUITexture*                    CreateTexture               ( void );
  50. @@ -209,7 +209,7 @@ private:
  51.      CGUIScrollPane*                 _CreateScrollPane           ( CGUIElement_Impl* pParent = NULL );
  52.      CGUIScrollBar*                  _CreateScrollBar            ( bool bHorizontal, CGUIElement_Impl* pParent = NULL );
  53.      CGUIComboBox*                   _CreateComboBox             ( CGUIElement_Impl* pParent = NULL, const char* szCaption = "" );
  54. -
  55. +   
  56.      IDirect3DDevice9*               m_pDevice;
  57.  
  58.      CEGUI::Renderer*                m_pRenderer;
  59.  
  60. diff --git a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
  61. index 7d0538c..aff0b29 100644
  62. --- a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
  63. +++ b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
  64. @@ -3853,6 +3853,81 @@ bool CStaticFunctionDefinitions::GUIDeleteTab ( CLuaMain& LuaMain, CClientGUIEle
  65.      return true;
  66.  }
  67.  
  68. +CClientGUIElement* CStaticFunctionDefinitions::GUICreateComboBox ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent )
  69. +{
  70. +    CGUIElement *pElement = m_pGUI->CreateComboBox ( pParent ? pParent->GetCGUIElement () : NULL, szCaption );
  71. +    pElement->SetPosition ( CVector2D ( fX, fY ), bRelative );
  72. +    pElement->SetSize ( CVector2D ( fWidth, fHeight ), bRelative );
  73. +
  74. +    // register to the gui manager
  75. +    CClientGUIElement *pGUIElement = new CClientGUIElement ( m_pManager, &LuaMain, pElement );
  76. +    pGUIElement->SetParent ( pParent ? pParent : LuaMain.GetResource()->GetResourceGUIEntity()  );
  77. +
  78. +    return pGUIElement;
  79. +}
  80. +
  81. +bool CStaticFunctionDefinitions::GUIComboBoxAddItem ( CClientEntity& Entity, const char* szText  )
  82. +{
  83. +   RUN_CHILDREN GUIComboBoxAddItem ( **iter, szText );
  84. +
  85. +   // Are we a CGUI element?
  86. +   if ( IS_GUI ( &Entity ) )
  87. +   {
  88. +       CClientGUIElement& GUIElement = static_cast < CClientGUIElement& > ( Entity );
  89. +
  90. +       // Are we a combobox?
  91. +       if ( IS_CGUIELEMENT_COMBOBOX ( &GUIElement ) )
  92. +       {
  93. +           // Add a new item.
  94. +           CGUIListItem* item = static_cast < CGUIComboBox* > ( GUIElement.GetCGUIElement () ) ->AddItem ( szText );
  95. +           return true;
  96. +       }
  97. +   }   
  98. +
  99. +    return false;
  100. +}
  101. +
  102. +bool CStaticFunctionDefinitions::GUIComboBoxClear ( CClientEntity& Entity  )
  103. +{
  104. +   RUN_CHILDREN GUIComboBoxClear ( **iter );
  105. +
  106. +   // Are we a CGUI element?
  107. +   if ( IS_GUI ( &Entity ) )
  108. +   {
  109. +       CClientGUIElement& GUIElement = static_cast < CClientGUIElement& > ( Entity );
  110. +
  111. +       // Are we a combobox?
  112. +       if ( IS_CGUIELEMENT_COMBOBOX ( &GUIElement ) )
  113. +       {
  114. +           // Clear the combobox
  115. +           static_cast < CGUIComboBox* > ( GUIElement.GetCGUIElement () ) ->Clear ( );
  116. +           return true;
  117. +       }
  118. +   }   
  119. +
  120. +    return false;
  121. +}
  122. +
  123. +std::string CStaticFunctionDefinitions::GUIComboBoxGetSelected ( CClientEntity& Entity )
  124. +{
  125. +   RUN_CHILDREN GUIComboBoxGetSelected ( **iter );
  126. +
  127. +   // Are we a CGUI element?
  128. +   if ( IS_GUI ( &Entity ) )
  129. +   {
  130. +       CClientGUIElement& GUIElement = static_cast < CClientGUIElement& > ( Entity );
  131. +
  132. +       // Are we a combobox?
  133. +       if ( IS_CGUIELEMENT_COMBOBOX ( &GUIElement ) )
  134. +       {
  135. +           // return the selected...
  136. +           CGUIListItem * item = static_cast < CGUIComboBox* > ( GUIElement.GetCGUIElement () ) ->GetSelectedItem ( );
  137. +           if( item ) return item->GetText( );
  138. +       }
  139. +   }   
  140. +
  141. +    return "";
  142. +}
  143.  
  144.  void CStaticFunctionDefinitions::GUISetText ( CClientEntity& Entity, const char* szText )
  145.  {
  146. diff --git a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h
  147. index 0fe0777..6f5cd6a 100644
  148. --- a/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h
  149. +++ b/MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h
  150. @@ -302,6 +302,8 @@ public:
  151.      static CClientGUIElement*           GUICreateCheckBox                   ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bChecked, bool bRelative, CClientGUIElement* pParent );
  152.      static CClientGUIElement*           GUICreateRadioButton                ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent );
  153.      static CClientGUIElement*           GUICreateStaticImage                ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strFile, bool bRelative, CClientGUIElement* pParent );
  154. +   static CClientGUIElement*           GUICreateComboBox                   ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent );
  155. +   
  156.      
  157.      static bool                         GUIStaticImageLoadImage             ( CClientEntity& Element, const SString& strDir );
  158.  
  159. @@ -368,6 +370,10 @@ public:
  160.      static void                         GUILabelSetVerticalAlign            ( CClientEntity& Element, CGUIVerticalAlign eAlign );
  161.      static void                         GUILabelSetHorizontalAlign          ( CClientEntity& Element, CGUIHorizontalAlign eAlign );
  162.  
  163. +   static bool                         GUIComboBoxAddItem                  ( CClientEntity& Entity, const char* szText );
  164. +   static bool                         GUIComboBoxClear                    ( CClientEntity& Entity );
  165. +   static std::string                  GUIComboBoxGetSelected              ( CClientEntity& Entity );
  166. +
  167.      // World functions
  168.      static bool                         GetTime                             ( unsigned char &ucHour, unsigned char &ucMin );
  169.      static bool                         ProcessLineOfSight                  ( CVector& vecStart, CVector& vecEnd, bool& bCollision, CColPoint** pColPoint, CClientEntity** pColEntity, bool bCheckBuildings = true, bool bCheckVehicles = true, bool bCheckPeds = true, bool bCheckObjects = true, bool bCheckDummies = true, bool bSeeThroughStuff = false, bool bIgnoreSomeObjectsForCamera = false, bool bShootThroughStuff = false, CEntity* pIgnoredEntity = NULL );
  170. diff --git a/MTA10/mods/shared_logic/CClientGUIElement.h b/MTA10/mods/shared_logic/CClientGUIElement.h
  171. index e6585d2..4f06a1d 100644
  172. --- a/MTA10/mods/shared_logic/CClientGUIElement.h
  173. +++ b/MTA10/mods/shared_logic/CClientGUIElement.h
  174. @@ -42,6 +42,7 @@ class CClientGUIElement;
  175.  #define IS_CGUIELEMENT_STATICIMAGE(entity)      ((entity)->GetCGUIType()==CGUI_STATICIMAGE)
  176.  #define IS_CGUIELEMENT_TAB(entity)              ((entity)->GetCGUIType()==CGUI_TAB)
  177.  #define IS_CGUIELEMENT_TABPANEL(entity)         ((entity)->GetCGUIType()==CGUI_TABPANEL)
  178. +#define IS_CGUIELEMENT_COMBOBOX(entity)         ((entity)->GetCGUIType()==CGUI_COMBOBOX)
  179.  #define IS_CGUIELEMENT_WINDOW(entity)           ((entity)->GetCGUIType()==CGUI_WINDOW)
  180.  
  181.  #define IS_CGUIELEMENT_VALID_PARENT(entity)     (IS_CGUIELEMENT_SCROLLPANE(entity) || IS_CGUIELEMENT_WINDOW(entity) || IS_CGUIELEMENT_TAB(entity) )
  182. diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.GUI.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.GUI.cpp
  183. index 08dcd0f..af2acf8 100644
  184. --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.GUI.cpp
  185. +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.GUI.cpp
  186. @@ -2510,3 +2510,104 @@ int CLuaFunctionDefs::GUIGetChatboxLayout ( lua_State* luaVM )
  187.      lua_pushboolean ( luaVM, false );
  188.      return 1;
  189.  }
  190. +
  191. +int CLuaFunctionDefs::GUICreateComboBox ( lua_State* luaVM )
  192. +{
  193. +    CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
  194. +    if ( pLuaMain )
  195. +    {
  196. +        if ( lua_istype ( luaVM, 1, LUA_TNUMBER ) && lua_istype ( luaVM, 2, LUA_TNUMBER ) &&
  197. +            lua_istype ( luaVM, 3, LUA_TNUMBER ) && lua_istype ( luaVM, 4, LUA_TNUMBER ) &&
  198. +           lua_istype ( luaVM, 5, LUA_TSTRING ) && lua_istype ( luaVM, 6, LUA_TBOOLEAN ) )
  199. +        {
  200. +            CClientGUIElement* pParent = lua_toguielement ( luaVM, 7 );
  201. +
  202. +            CClientGUIElement* pGUIElement = CStaticFunctionDefinitions::GUICreateComboBox (
  203. +                *pLuaMain,
  204. +                static_cast < float > ( lua_tonumber ( luaVM, 1 ) ),
  205. +                static_cast < float > ( lua_tonumber ( luaVM, 2 ) ),
  206. +                static_cast < float > ( lua_tonumber ( luaVM, 3 ) ),
  207. +                static_cast < float > ( lua_tonumber ( luaVM, 4 ) ),
  208. +                lua_tostring ( luaVM, 5 ),
  209. +                lua_toboolean ( luaVM, 6 ) ? true : false,
  210. +                pParent
  211. +                );
  212. +
  213. +            if ( pGUIElement ) {
  214. +                lua_pushelement ( luaVM, pGUIElement );
  215. +                return 1;
  216. +            }
  217. +        }
  218. +    }
  219. +
  220. +    // error: bad arguments
  221. +    lua_pushboolean ( luaVM, false );
  222. +    return 1;
  223. +}
  224. +
  225. +int CLuaFunctionDefs::GUIComboBoxAddItem ( lua_State* luaVM )
  226. +{
  227. +    CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
  228. +   bool returnVal = false;
  229. +
  230. +    if ( lua_istype ( luaVM, 1, LUA_TLIGHTUSERDATA ) && lua_istype ( luaVM, 2, LUA_TSTRING )
  231. +       )
  232. +    {
  233. +       CClientEntity* pEntity = lua_toelement ( luaVM, 1 );
  234. +       if ( pEntity )
  235. +       {
  236. +           returnVal = CStaticFunctionDefinitions::GUIComboBoxAddItem (
  237. +               *pEntity,
  238. +               lua_tostring ( luaVM, 2 )
  239. +               );
  240. +       }
  241. +       else m_pScriptDebugging->LogBadPointer ( luaVM, "guiComboBoxAddItem", "gui-element", 1 );
  242. +    }
  243. +
  244. +    // error: bad arguments
  245. +    lua_pushboolean ( luaVM, returnVal );
  246. +    return 1;
  247. +}
  248. +
  249. +int CLuaFunctionDefs::GUIComboBoxClear ( lua_State* luaVM )
  250. +{
  251. +   bool returnVal = false;
  252. +    if ( lua_istype ( luaVM, 1, LUA_TLIGHTUSERDATA ) )
  253. +    {
  254. +       CClientEntity* pEntity = lua_toelement ( luaVM, 1 );
  255. +       if ( pEntity )
  256. +       {
  257. +           returnVal = CStaticFunctionDefinitions::GUIComboBoxClear (
  258. +               *pEntity
  259. +               );
  260. +       }
  261. +       else m_pScriptDebugging->LogBadPointer ( luaVM, "guiComboBoxClear", "gui-element", 1 );
  262. +    }
  263. +    lua_pushboolean ( luaVM, returnVal );
  264. +    return 1;
  265. +}
  266. +
  267. +int CLuaFunctionDefs::GUIComboBoxGetSelected ( lua_State* luaVM )
  268. +{
  269. +    if ( lua_istype ( luaVM, 1, LUA_TLIGHTUSERDATA ) )
  270. +    {
  271. +       CClientEntity* pEntity = lua_toelement ( luaVM, 1 );
  272. +       if ( pEntity )
  273. +       {
  274. +           std::string strText = CStaticFunctionDefinitions::GUIComboBoxGetSelected( *pEntity );
  275. +           if ( strText.size() > 0 )
  276. +            {
  277. +               lua_pushstring ( luaVM, strText.c_str( ) );
  278. +                return 1;
  279. +            }
  280. +            else
  281. +            {
  282. +                lua_pushnil ( luaVM );
  283. +                return 1;
  284. +            }
  285. +       }
  286. +       else m_pScriptDebugging->LogBadPointer ( luaVM, "guiComboBoxGetSelected", "gui-element", 1 );
  287. +    }
  288. +   lua_pushnil ( luaVM );
  289. +    return 1;
  290. +}
  291. \ No newline at end of file
  292. diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h
  293. index fa1ac48..4fa5ddf 100644
  294. --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h
  295. +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h
  296. @@ -573,7 +573,10 @@ public:
  297.      LUA_DECLARE ( GUILabelGetTextExtent );
  298.      LUA_DECLARE ( GUILabelGetFontHeight );
  299.      LUA_DECLARE ( GUIGetChatboxLayout );
  300. -
  301. +    LUA_DECLARE ( GUICreateComboBox );
  302. +    LUA_DECLARE ( GUIComboBoxAddItem );
  303. +    LUA_DECLARE ( GUIComboBoxClear );
  304. +    LUA_DECLARE ( GUIComboBoxGetSelected );
  305.  
  306.      // World functions
  307.      LUA_DECLARE ( GetTime_ );
  308. diff --git a/MTA10/mods/shared_logic/lua/CLuaManager.cpp b/MTA10/mods/shared_logic/lua/CLuaManager.cpp
  309. index 804e371..ddd3eb0 100644
  310. --- a/MTA10/mods/shared_logic/lua/CLuaManager.cpp
  311. +++ b/MTA10/mods/shared_logic/lua/CLuaManager.cpp
  312. @@ -659,6 +659,7 @@ void CLuaManager::LoadCFunctions ( void )
  313.      CLuaCFunctions::AddFunction ( "guiCreateCheckBox", CLuaFunctionDefs::GUICreateCheckBox );
  314.      CLuaCFunctions::AddFunction ( "guiCreateRadioButton", CLuaFunctionDefs::GUICreateRadioButton );
  315.      CLuaCFunctions::AddFunction ( "guiCreateStaticImage", CLuaFunctionDefs::GUICreateStaticImage );
  316. +    CLuaCFunctions::AddFunction ( "guiCreateComboBox", CLuaFunctionDefs::GUICreateComboBox );
  317.  
  318.      CLuaCFunctions::AddFunction ( "guiStaticImageLoadImage", CLuaFunctionDefs::GUIStaticImageLoadImage );
  319.      CLuaCFunctions::AddFunction ( "guiGetSelectedTab", CLuaFunctionDefs::GUIGetSelectedTab );
  320. @@ -754,6 +755,10 @@ void CLuaManager::LoadCFunctions ( void )
  321.  
  322.      CLuaCFunctions::AddFunction ( "getChatboxLayout", CLuaFunctionDefs::GUIGetChatboxLayout );
  323.  
  324. +   CLuaCFunctions::AddFunction ( "guiComboBoxAddItem", CLuaFunctionDefs::GUIComboBoxAddItem );
  325. +   CLuaCFunctions::AddFunction ( "guiComboBoxClear", CLuaFunctionDefs::GUIComboBoxClear );
  326. +   CLuaCFunctions::AddFunction ( "guiComboBoxGetSelected", CLuaFunctionDefs::GUIComboBoxGetSelected );
  327. +
  328.      // Util functions
  329.      CLuaCFunctions::AddFunction ( "gettok", CLuaFunctionDefs::GetTok );
  330.      CLuaCFunctions::AddFunction ( "split", CLuaFunctionDefs::Split );
  331. diff --git a/MTA10/sdk/gui/CGUI.h b/MTA10/sdk/gui/CGUI.h
  332. index 7651f50..1b0d88f 100644
  333. --- a/MTA10/sdk/gui/CGUI.h
  334. +++ b/MTA10/sdk/gui/CGUI.h
  335. @@ -128,6 +128,7 @@ public:
  336.  
  337.      virtual CGUIComboBox*       CreateComboBox          ( CGUIElement* pParent = NULL, const char* szCaption = "" ) = 0;
  338.      virtual CGUIComboBox*       CreateComboBox          ( CGUIComboBox* pParent = NULL, const char* szCaption = "" ) = 0;
  339. +
  340.      //
  341.  
  342.      virtual CGUIWindow*         CreateWnd               ( CGUIElement* pParent = NULL, const char* szCaption = "" ) = 0;
  343. --
  344. 1.7.0.2.msysgit.0