Skip to content

Commit

Permalink
A patch for #4949.
Browse files Browse the repository at this point in the history
Added the following functions:
    gui-element guiCreateComboBox( float x, float y, float width, float height, string caption, bool relative [, gui-element parent ] );
    bool guiComboBoxAddItem( gui-element comboBox, string value );
    nil/string guiComboBoxGetSelected( gui-element comboBox );

Signed-off-by: Jyrno42 <jyrno42@gmail.com>
  • Loading branch information
Jyrno42 committed Apr 2, 2010
1 parent cb12f75 commit afaac54
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 13 deletions.
10 changes: 5 additions & 5 deletions MTA10/core/_Core 2008.vcproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Version="9,00"
Name="Client - Core"
ProjectGUID="{4C71249E-EA08-4A3D-9AEF-28707ACC6531}"
RootNamespace="Client - Core"
Expand Down Expand Up @@ -45,7 +45,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".;../../vendor;../sdk;../../Shared/sdk;../../vendor/sparsehash/current/src;../../vendor/sparsehash/current/src/windows"
AdditionalIncludeDirectories=".;../../vendor;../sdk;../../Shared/sdk;../../vendor/sparsehash/current/src;../../vendor/sparsehash/current/src/windows;&quot;C:\Program Files\Microsoft DirectX SDK (February 2010)\Include&quot;"
PreprocessorDefinitions="BUILD_NUMBER=$(BUILD_NUMBER);BUILD_CONFIG_$(BUILD_CONFIGURATION);_WIN32_WINNT=0x502;WIN32;MTA_DEBUG;COMPILE_FOR_SA;MTA_WINDOWED;_CRT_SECURE_NO_WARNINGS;INITGUID"
StringPooling="true"
BasicRuntimeChecks="3"
Expand Down Expand Up @@ -85,7 +85,7 @@
OutputFile="C:\Program Files\MTA San Andreas\mta\core_d.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../Shared/XML;../../vendor/libv2/lib;../../vendor/libpng/lib;../../vendor/zlib/lib;../../vendor/detours/lib"
AdditionalLibraryDirectories="../../Shared/XML;../../vendor/libv2/lib;../../vendor/libpng/lib;../../vendor/zlib/lib;../../vendor/detours/lib;&quot;C:\Program Files\Microsoft DirectX SDK (February 2010)\Lib\x86&quot;"

This comment has been minimized.

Copy link
@mabako

mabako Apr 3, 2010

Should be done in your Visual Studio settings, as changing it for everyone using it might lead to problems and has no guarantee to be accurate - for example, I'm not using the February 2010 SDK.

IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
ProgramDatabaseFile=".\Debug/core_.pdb"
Expand Down Expand Up @@ -153,7 +153,7 @@
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories=".;../../vendor;../sdk;../../Shared/sdk;../../vendor/sparsehash/current/src;../../vendor/sparsehash/current/src/windows"
AdditionalIncludeDirectories=".;../../vendor;../sdk;../../Shared/sdk;../../vendor/sparsehash/current/src;../../vendor/sparsehash/current/src/windows;&quot;C:\Program Files\Microsoft DirectX SDK (February 2010)\Include&quot;"
PreprocessorDefinitions="BUILD_NUMBER=$(BUILD_NUMBER);BUILD_CONFIG_$(BUILD_CONFIGURATION);_WIN32_WINNT=0x502;WIN32;MTA_RELEASE;COMPILE_FOR_SA;_CRT_SECURE_NO_WARNINGS;INITGUID"
StringPooling="true"
RuntimeLibrary="2"
Expand Down Expand Up @@ -187,7 +187,7 @@
OutputFile="C:\Program Files\MTA San Andreas\MTA\core.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../Shared/XML;../../vendor/libv2/lib;../../vendor/libpng/lib;../../vendor/zlib/lib;../../vendor/detours/lib"
AdditionalLibraryDirectories="../../Shared/XML;../../vendor/libv2/lib;../../vendor/libpng/lib;../../vendor/zlib/lib;../../vendor/detours/lib;&quot;C:\Program Files\Microsoft DirectX SDK (February 2010)\Lib\x86&quot;"
IgnoreDefaultLibraryNames="LIBCMT"
GenerateDebugInformation="true"
ProgramDatabaseFile="C:/Symbols/$(ConfigurationName)_$(SafeParentName).pdb"
Expand Down
3 changes: 3 additions & 0 deletions MTA10/gui/CGUIComboBox_Impl.cpp
Expand Up @@ -50,6 +50,9 @@ CGUIComboBox_Impl::CGUIComboBox_Impl ( CGUI_Impl* pGUI, CGUIElement* pParent, co
pGUI->AddChild ( this );
SetParent ( NULL );
}

// Disable editing of the box...
SetReadOnly ( true );
}


Expand Down
4 changes: 2 additions & 2 deletions MTA10/gui/CGUI_Impl.h
Expand Up @@ -125,7 +125,7 @@ class CGUI_Impl : public CGUI, public CGUITabList
CGUIComboBox* CreateComboBox ( CGUIElement* pParent = NULL, const char* szCaption = "" );
CGUIComboBox* CreateComboBox ( CGUIComboBox* pParent = NULL, const char* szCaption = "" );

CGUIWindow* CreateWnd ( CGUIElement* pParent = NULL, const char* szCaption = "" );
CGUIWindow* CreateWnd ( CGUIElement* pParent = NULL, const char* szCaption = "" );
//

CGUITexture* CreateTexture ( void );
Expand Down Expand Up @@ -209,7 +209,7 @@ class CGUI_Impl : public CGUI, public CGUITabList
CGUIScrollPane* _CreateScrollPane ( CGUIElement_Impl* pParent = NULL );
CGUIScrollBar* _CreateScrollBar ( bool bHorizontal, CGUIElement_Impl* pParent = NULL );
CGUIComboBox* _CreateComboBox ( CGUIElement_Impl* pParent = NULL, const char* szCaption = "" );

IDirect3DDevice9* m_pDevice;

CEGUI::Renderer* m_pRenderer;
Expand Down
10 changes: 5 additions & 5 deletions MTA10/gui/gui 2008.vcproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Version="9,00"
Name="Client - GUI"
ProjectGUID="{485149E1-799C-4925-AA17-0FEA77C85418}"
Keyword="Win32Proj"
Expand Down Expand Up @@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../sdk;../../Shared/sdk;&quot;../../vendor/cegui-0.4.0-custom/include&quot;;../../vendor/sparsehash/current/src;../../vendor/sparsehash/current/src/windows"
AdditionalIncludeDirectories="../sdk;../../Shared/sdk;&quot;../../vendor/cegui-0.4.0-custom/include&quot;;../../vendor/sparsehash/current/src;../../vendor/sparsehash/current/src/windows;&quot;C:\Program Files\Microsoft DirectX SDK (February 2010)\Include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GUI_EXPORTS;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand Down Expand Up @@ -71,7 +71,7 @@
OutputFile="C:\Program Files\MTA San Andreas\mta\cgui_d.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../vendor/cegui-0.4.0-custom/lib"
AdditionalLibraryDirectories="&quot;../../vendor/cegui-0.4.0-custom/lib&quot;;&quot;C:\Program Files\Microsoft DirectX SDK (February 2010)\Lib\x86&quot;"
IgnoreAllDefaultLibraries="false"
IgnoreDefaultLibraryNames="LIBCMTD"
GenerateDebugInformation="true"
Expand Down Expand Up @@ -135,7 +135,7 @@
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="../sdk;../../Shared/sdk;&quot;../../vendor/cegui-0.4.0-custom/include&quot;;../../vendor/sparsehash/current/src;../../vendor/sparsehash/current/src/windows"
AdditionalIncludeDirectories="../sdk;../../Shared/sdk;&quot;../../vendor/cegui-0.4.0-custom/include&quot;;../../vendor/sparsehash/current/src;../../vendor/sparsehash/current/src/windows;&quot;C:\Program Files\Microsoft DirectX SDK (February 2010)\Include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GUI_EXPORTS;_CRT_SECURE_NO_WARNINGS"
StringPooling="true"
RuntimeLibrary="2"
Expand All @@ -161,7 +161,7 @@
OutputFile="C:\Program Files\MTA San Andreas\MTA\cgui.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../vendor/cegui-0.4.0-custom/lib"
AdditionalLibraryDirectories="&quot;../../vendor/cegui-0.4.0-custom/lib&quot;;&quot;C:\Program Files\Microsoft DirectX SDK (February 2010)\Lib\x86&quot;"
IgnoreDefaultLibraryNames="LIBCMT"
GenerateDebugInformation="true"
AssemblyDebug="0"
Expand Down
75 changes: 75 additions & 0 deletions MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -3853,6 +3853,81 @@ bool CStaticFunctionDefinitions::GUIDeleteTab ( CLuaMain& LuaMain, CClientGUIEle
return true;
}

CClientGUIElement* CStaticFunctionDefinitions::GUICreateComboBox ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent )
{
CGUIElement *pElement = m_pGUI->CreateComboBox ( pParent ? pParent->GetCGUIElement () : NULL, szCaption );
pElement->SetPosition ( CVector2D ( fX, fY ), bRelative );
pElement->SetSize ( CVector2D ( fWidth, fHeight ), bRelative );

// register to the gui manager
CClientGUIElement *pGUIElement = new CClientGUIElement ( m_pManager, &LuaMain, pElement );
pGUIElement->SetParent ( pParent ? pParent : LuaMain.GetResource()->GetResourceGUIEntity() );

return pGUIElement;
}

bool CStaticFunctionDefinitions::GUIComboBoxAddItem ( CClientEntity& Entity, const char* szText )
{
RUN_CHILDREN GUIComboBoxAddItem ( **iter, szText );

// Are we a CGUI element?
if ( IS_GUI ( &Entity ) )
{
CClientGUIElement& GUIElement = static_cast < CClientGUIElement& > ( Entity );

// Are we a combobox?
if ( IS_CGUIELEMENT_COMBOBOX ( &GUIElement ) )
{
// Add a new item.
CGUIListItem* item = static_cast < CGUIComboBox* > ( GUIElement.GetCGUIElement () ) ->AddItem ( szText );
return true;
}
}

return false;
}

bool CStaticFunctionDefinitions::GUIComboBoxClear ( CClientEntity& Entity )
{
RUN_CHILDREN GUIComboBoxClear ( **iter );

// Are we a CGUI element?
if ( IS_GUI ( &Entity ) )
{
CClientGUIElement& GUIElement = static_cast < CClientGUIElement& > ( Entity );

// Are we a combobox?
if ( IS_CGUIELEMENT_COMBOBOX ( &GUIElement ) )
{
// Clear the combobox
static_cast < CGUIComboBox* > ( GUIElement.GetCGUIElement () ) ->Clear ( );
return true;
}
}

return false;
}

std::string CStaticFunctionDefinitions::GUIComboBoxGetSelected ( CClientEntity& Entity )
{
RUN_CHILDREN GUIComboBoxGetSelected ( **iter );

// Are we a CGUI element?
if ( IS_GUI ( &Entity ) )
{
CClientGUIElement& GUIElement = static_cast < CClientGUIElement& > ( Entity );

// Are we a combobox?
if ( IS_CGUIELEMENT_COMBOBOX ( &GUIElement ) )
{
// return the selected...
CGUIListItem * item = static_cast < CGUIComboBox* > ( GUIElement.GetCGUIElement () ) ->GetSelectedItem ( );
if( item ) return item->GetText( );
}
}

return "";
}

void CStaticFunctionDefinitions::GUISetText ( CClientEntity& Entity, const char* szText )
{
Expand Down
6 changes: 6 additions & 0 deletions MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Expand Up @@ -302,6 +302,8 @@ class CStaticFunctionDefinitions
static CClientGUIElement* GUICreateCheckBox ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bChecked, bool bRelative, CClientGUIElement* pParent );
static CClientGUIElement* GUICreateRadioButton ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent );
static CClientGUIElement* GUICreateStaticImage ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const SString& strFile, bool bRelative, CClientGUIElement* pParent );
static CClientGUIElement* GUICreateComboBox ( CLuaMain& LuaMain, float fX, float fY, float fWidth, float fHeight, const char* szCaption, bool bRelative, CClientGUIElement* pParent );


static bool GUIStaticImageLoadImage ( CClientEntity& Element, const SString& strDir );

Expand Down Expand Up @@ -368,6 +370,10 @@ class CStaticFunctionDefinitions
static void GUILabelSetVerticalAlign ( CClientEntity& Element, CGUIVerticalAlign eAlign );
static void GUILabelSetHorizontalAlign ( CClientEntity& Element, CGUIHorizontalAlign eAlign );

static bool GUIComboBoxAddItem ( CClientEntity& Entity, const char* szText );
static bool GUIComboBoxClear ( CClientEntity& Entity );
static std::string GUIComboBoxGetSelected ( CClientEntity& Entity );

// World functions
static bool GetTime ( unsigned char &ucHour, unsigned char &ucMin );
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 );
Expand Down
1 change: 1 addition & 0 deletions MTA10/mods/shared_logic/CClientGUIElement.h
Expand Up @@ -42,6 +42,7 @@ class CClientGUIElement;
#define IS_CGUIELEMENT_STATICIMAGE(entity) ((entity)->GetCGUIType()==CGUI_STATICIMAGE)
#define IS_CGUIELEMENT_TAB(entity) ((entity)->GetCGUIType()==CGUI_TAB)
#define IS_CGUIELEMENT_TABPANEL(entity) ((entity)->GetCGUIType()==CGUI_TABPANEL)
#define IS_CGUIELEMENT_COMBOBOX(entity) ((entity)->GetCGUIType()==CGUI_COMBOBOX)
#define IS_CGUIELEMENT_WINDOW(entity) ((entity)->GetCGUIType()==CGUI_WINDOW)

#define IS_CGUIELEMENT_VALID_PARENT(entity) (IS_CGUIELEMENT_SCROLLPANE(entity) || IS_CGUIELEMENT_WINDOW(entity) || IS_CGUIELEMENT_TAB(entity) )
Expand Down
101 changes: 101 additions & 0 deletions MTA10/mods/shared_logic/lua/CLuaFunctionDefs.GUI.cpp
Expand Up @@ -2510,3 +2510,104 @@ int CLuaFunctionDefs::GUIGetChatboxLayout ( lua_State* luaVM )
lua_pushboolean ( luaVM, false );
return 1;
}

int CLuaFunctionDefs::GUICreateComboBox ( lua_State* luaVM )
{
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
if ( pLuaMain )
{
if ( lua_istype ( luaVM, 1, LUA_TNUMBER ) && lua_istype ( luaVM, 2, LUA_TNUMBER ) &&
lua_istype ( luaVM, 3, LUA_TNUMBER ) && lua_istype ( luaVM, 4, LUA_TNUMBER ) &&
lua_istype ( luaVM, 5, LUA_TSTRING ) && lua_istype ( luaVM, 6, LUA_TBOOLEAN ) )
{
CClientGUIElement* pParent = lua_toguielement ( luaVM, 7 );

CClientGUIElement* pGUIElement = CStaticFunctionDefinitions::GUICreateComboBox (
*pLuaMain,
static_cast < float > ( lua_tonumber ( luaVM, 1 ) ),
static_cast < float > ( lua_tonumber ( luaVM, 2 ) ),
static_cast < float > ( lua_tonumber ( luaVM, 3 ) ),
static_cast < float > ( lua_tonumber ( luaVM, 4 ) ),
lua_tostring ( luaVM, 5 ),
lua_toboolean ( luaVM, 6 ) ? true : false,
pParent
);

if ( pGUIElement ) {
lua_pushelement ( luaVM, pGUIElement );
return 1;
}
}
}

// error: bad arguments
lua_pushboolean ( luaVM, false );
return 1;
}

int CLuaFunctionDefs::GUIComboBoxAddItem ( lua_State* luaVM )
{
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
bool returnVal = false;

if ( lua_istype ( luaVM, 1, LUA_TLIGHTUSERDATA ) && lua_istype ( luaVM, 2, LUA_TSTRING )
)
{
CClientEntity* pEntity = lua_toelement ( luaVM, 1 );
if ( pEntity )
{
returnVal = CStaticFunctionDefinitions::GUIComboBoxAddItem (
*pEntity,
lua_tostring ( luaVM, 2 )
);
}
else m_pScriptDebugging->LogBadPointer ( luaVM, "guiComboBoxAddItem", "gui-element", 1 );
}

// error: bad arguments
lua_pushboolean ( luaVM, returnVal );
return 1;
}

int CLuaFunctionDefs::GUIComboBoxClear ( lua_State* luaVM )
{
bool returnVal = false;
if ( lua_istype ( luaVM, 1, LUA_TLIGHTUSERDATA ) )
{
CClientEntity* pEntity = lua_toelement ( luaVM, 1 );
if ( pEntity )
{
returnVal = CStaticFunctionDefinitions::GUIComboBoxClear (
*pEntity
);
}
else m_pScriptDebugging->LogBadPointer ( luaVM, "guiComboBoxClear", "gui-element", 1 );
}
lua_pushboolean ( luaVM, returnVal );
return 1;
}

int CLuaFunctionDefs::GUIComboBoxGetSelected ( lua_State* luaVM )
{
if ( lua_istype ( luaVM, 1, LUA_TLIGHTUSERDATA ) )
{
CClientEntity* pEntity = lua_toelement ( luaVM, 1 );
if ( pEntity )
{
std::string strText = CStaticFunctionDefinitions::GUIComboBoxGetSelected( *pEntity );
if ( strText.size() > 0 )
{
lua_pushstring ( luaVM, strText.c_str( ) );
return 1;
}
else
{
lua_pushnil ( luaVM );
return 1;
}
}
else m_pScriptDebugging->LogBadPointer ( luaVM, "guiComboBoxGetSelected", "gui-element", 1 );
}
lua_pushnil ( luaVM );
return 1;
}
5 changes: 4 additions & 1 deletion MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h
Expand Up @@ -573,7 +573,10 @@ class CLuaFunctionDefs
LUA_DECLARE ( GUILabelGetTextExtent );
LUA_DECLARE ( GUILabelGetFontHeight );
LUA_DECLARE ( GUIGetChatboxLayout );

LUA_DECLARE ( GUICreateComboBox );
LUA_DECLARE ( GUIComboBoxAddItem );
LUA_DECLARE ( GUIComboBoxClear );
LUA_DECLARE ( GUIComboBoxGetSelected );

// World functions
LUA_DECLARE ( GetTime_ );
Expand Down
5 changes: 5 additions & 0 deletions MTA10/mods/shared_logic/lua/CLuaManager.cpp
Expand Up @@ -659,6 +659,7 @@ void CLuaManager::LoadCFunctions ( void )
CLuaCFunctions::AddFunction ( "guiCreateCheckBox", CLuaFunctionDefs::GUICreateCheckBox );
CLuaCFunctions::AddFunction ( "guiCreateRadioButton", CLuaFunctionDefs::GUICreateRadioButton );
CLuaCFunctions::AddFunction ( "guiCreateStaticImage", CLuaFunctionDefs::GUICreateStaticImage );
CLuaCFunctions::AddFunction ( "guiCreateComboBox", CLuaFunctionDefs::GUICreateComboBox );

CLuaCFunctions::AddFunction ( "guiStaticImageLoadImage", CLuaFunctionDefs::GUIStaticImageLoadImage );
CLuaCFunctions::AddFunction ( "guiGetSelectedTab", CLuaFunctionDefs::GUIGetSelectedTab );
Expand Down Expand Up @@ -754,6 +755,10 @@ void CLuaManager::LoadCFunctions ( void )

CLuaCFunctions::AddFunction ( "getChatboxLayout", CLuaFunctionDefs::GUIGetChatboxLayout );

CLuaCFunctions::AddFunction ( "guiComboBoxAddItem", CLuaFunctionDefs::GUIComboBoxAddItem );
CLuaCFunctions::AddFunction ( "guiComboBoxClear", CLuaFunctionDefs::GUIComboBoxClear );
CLuaCFunctions::AddFunction ( "guiComboBoxGetSelected", CLuaFunctionDefs::GUIComboBoxGetSelected );

// Util functions
CLuaCFunctions::AddFunction ( "gettok", CLuaFunctionDefs::GetTok );
CLuaCFunctions::AddFunction ( "split", CLuaFunctionDefs::Split );
Expand Down
1 change: 1 addition & 0 deletions MTA10/sdk/gui/CGUI.h
Expand Up @@ -128,6 +128,7 @@ class CGUI

virtual CGUIComboBox* CreateComboBox ( CGUIElement* pParent = NULL, const char* szCaption = "" ) = 0;
virtual CGUIComboBox* CreateComboBox ( CGUIComboBox* pParent = NULL, const char* szCaption = "" ) = 0;

//

virtual CGUIWindow* CreateWnd ( CGUIElement* pParent = NULL, const char* szCaption = "" ) = 0;
Expand Down

2 comments on commit afaac54

@Flobu
Copy link

@Flobu Flobu commented on afaac54 Apr 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use 4 spaces instead of 1 tab

@Jyrno42
Copy link
Owner Author

@Jyrno42 Jyrno42 commented on afaac54 Apr 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will fix them in next commit.

Please sign in to comment.