Skip to content

Add gui combobox missing functions #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Sep 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Client/gui/CGUIComboBox_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ void CGUIComboBox_Impl::Clear(void)
m_pWindow->setText(storedCaption);
}

bool CGUIComboBox_Impl::IsOpen(void)
{
return reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->isDropDownListVisible();
}

void CGUIComboBox_Impl::SetReadOnly(bool bReadonly)
{
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->setReadOnly(bReadonly);
Expand Down
1 change: 1 addition & 0 deletions Client/gui/CGUIComboBox_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CGUIComboBox_Impl : public CGUIComboBox, public CGUIElement_Impl
bool SetItemText(int index, const char* szText);
bool SetSelectedItemByIndex(int index);
void Clear(void);
bool IsOpen(void);

void SetReadOnly(bool bReadonly);

Expand Down
64 changes: 63 additions & 1 deletion Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static CCoreInterface* m_pCore;
static CGame* m_pGame;
static CClientGame* m_pClientGame;
static CClientManager* m_pManager;
static CClientEntity* m_pRootEntity;
static CClientEntity* m_pRooGtEntity;
static CClientPlayerManager* m_pPlayerManager;
static CClientVehicleManager* m_pVehicleManager;
static CClientObjectManager* m_pObjectManager;
Expand Down Expand Up @@ -5417,6 +5417,68 @@ bool CStaticFunctionDefinitions::GUIComboBoxSetItemText(CClientEntity& Entity, i
return false;
}

int CStaticFunctionDefinitions::GUIComboBoxGetItemCount(CClientEntity& Entity)
{
// Are we a CGUI Element?
if (IS_GUI(&Entity))
{
CClientGUIElement& GUIElement = static_cast<CClientGUIElement&>(Entity);

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

return 0;
}

bool CStaticFunctionDefinitions::GUIComboBoxSetOpen(CClientEntity& Entity, bool state)
{
RUN_CHILDREN(GUIComboBoxSetOpen(**iter, state))

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

// Are we a combobox?
if (IS_CGUIELEMENT_COMBOBOX(&GUIElement))
{
if (state)
{
static_cast<CGUIComboBox*>(GUIElement.GetCGUIElement())->ShowDropList();
}
else if (!state)
{
static_cast<CGUIComboBox*>(GUIElement.GetCGUIElement())->HideDropList();
}
return true;
}
}

return false;
}

bool CStaticFunctionDefinitions::GUIComboBoxIsOpen(CClientEntity& Entity)
{
// 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 static_cast<CGUIComboBox*>(GUIElement.GetCGUIElement())->IsOpen();
}
}

return false;
}

CClientGUIElement* CStaticFunctionDefinitions::GUICreateBrowser(CLuaMain& LuaMain, const CVector2D& position, const CVector2D& size, bool bIsLocal,
bool bIsTransparent, bool bRelative, CClientGUIElement* pParent)
{
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ class CStaticFunctionDefinitions
static bool GUIComboBoxSetSelected(CClientEntity& Entity, int index);
static std::string GUIComboBoxGetItemText(CClientEntity& Entity, int index);
static bool GUIComboBoxSetItemText(CClientEntity& Entity, int index, const char* szText);
static int GUIComboBoxGetItemCount(CClientEntity& Entity);
static bool GUIComboBoxSetOpen(CClientEntity& Entity, bool state);
static bool GUIComboBoxIsOpen(CClientEntity& Entity);

// World functions
static bool GetTime(unsigned char& ucHour, unsigned char& ucMin);
Expand Down
71 changes: 71 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ void CLuaGUIDefs::LoadFunctions(void)
{"guiComboBoxSetSelected", GUIComboBoxSetSelected},
{"guiComboBoxGetItemText", GUIComboBoxGetItemText},
{"guiComboBoxSetItemText", GUIComboBoxSetItemText},
{"guiComboBoxGetItemCount", GUIComboBoxGetItemCount},
{"guiComboBoxSetOpen", GUIComboBoxSetOpen},
{"guiComboBoxIsOpen", GUIComboBoxIsOpen},
};

// Add functions
Expand Down Expand Up @@ -393,11 +396,16 @@ void CLuaGUIDefs::AddGuiComboBoxClass(lua_State* luaVM)

lua_classfunction(luaVM, "getSelected", "guiComboBoxGetSelected");
lua_classfunction(luaVM, "getItemText", "guiComboBoxGetItemText");
lua_classfunction(luaVM, "isOpen", "guiComboBoxIsOpen");
lua_classfunction(luaVM, "getItemCount", "guiComboBoxGetItemCount");

lua_classfunction(luaVM, "setItemText", "guiComboBoxSetItemText");
lua_classfunction(luaVM, "setSelected", "guiComboBoxSetSelected");
lua_classfunction(luaVM, "setOpen", "guiComboBoxSetOpen");

lua_classvariable(luaVM, "selected", "guiComboBoxSetSelected", "guiComboBoxGetSelected");
lua_classvariable(luaVM, "itemCount", nullptr, "guiComboBoxGetItemCount");
lua_classvariable(luaVM, "open", "guiComboBoxSetOpen", "guiComboBoxIsOpen");

lua_registerclass(luaVM, "GuiComboBox", "GuiElement");
}
Expand Down Expand Up @@ -3844,6 +3852,69 @@ int CLuaGUIDefs::GUIComboBoxSetItemText(lua_State* luaVM)
return 1;
}

int CLuaGUIDefs::GUIComboBoxGetItemCount(lua_State* luaVM)
{
// int guiComboBoxGetItemCount( element comboBox )
CClientGUIElement* comboBox;
CScriptArgReader argStream(luaVM);
argStream.ReadUserData<CGUIComboBox>(comboBox);

if (!argStream.HasErrors())
{
int items = CStaticFunctionDefinitions::GUIComboBoxGetItemCount(*comboBox);
lua_pushnumber(luaVM, items);
return 1;
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

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

int CLuaGUIDefs::GUIComboBoxSetOpen(lua_State* luaVM)
{
// bool guiComboBoxSetOpen( element comboBox, bool state)
CClientGUIElement* comboBox;
bool state;
CScriptArgReader argStream(luaVM);
argStream.ReadUserData<CGUIComboBox>(comboBox);
argStream.ReadBool(state);

if (!argStream.HasErrors())
{
lua_pushboolean(luaVM, CStaticFunctionDefinitions::GUIComboBoxSetOpen(*comboBox, state));
return 1;
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

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

int CLuaGUIDefs::GUIComboBoxIsOpen(lua_State* luaVM)
{
// bool guiComboBoxIsOpen( element comboBox )
CClientGUIElement* comboBox;
CScriptArgReader argStream(luaVM);
argStream.ReadUserData<CGUIComboBox>(comboBox);

if (!argStream.HasErrors())
{
lua_pushboolean(luaVM, CStaticFunctionDefinitions::GUIComboBoxIsOpen(*comboBox));
return 1;
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

// error: bad arguments
lua_pushnil(luaVM);
return 1;
}

int CLuaGUIDefs::GUICreateFont(lua_State* luaVM)
{
// element guiCreateFont( string filepath [, int size=9 ] )
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ class CLuaGUIDefs : public CLuaDefs
LUA_DECLARE(GUIComboBoxSetSelected);
LUA_DECLARE(GUIComboBoxGetItemText);
LUA_DECLARE(GUIComboBoxSetItemText);
LUA_DECLARE(GUIComboBoxGetItemCount);
LUA_DECLARE(GUIComboBoxSetOpen);
LUA_DECLARE(GUIComboBoxIsOpen);
LUA_DECLARE(GUIGetCursorType);

private:
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/gui/CGUIComboBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ class CGUIComboBox : public CGUIElement
virtual void SetDropListRemoveHandler(GUI_CALLBACK Callback) = 0;
virtual void ShowDropList(void) = 0;
virtual void HideDropList(void) = 0;
virtual bool IsOpen(void) = 0;
};