Skip to content

Commit

Permalink
Fix some implementation issues (WIP)
Browse files Browse the repository at this point in the history
Enough so that MTA launches at least (and then crashes when creating menus). WIP
  • Loading branch information
Lpsd committed Oct 5, 2024
1 parent 1d1d92e commit 2a42af5
Show file tree
Hide file tree
Showing 23 changed files with 369 additions and 403 deletions.
2 changes: 1 addition & 1 deletion Client/core/CGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ void CLocalGUI::DrawMouseCursor()
{
CGUI* pGUI = CCore::GetSingleton().GetGUI();

pGUI->DrawMouseCursor();
//pGUI->DrawMouseCursor();
}

CConsole* CLocalGUI::GetConsole()
Expand Down
35 changes: 18 additions & 17 deletions Client/gui_new/CGUIComboBox_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CGUIComboBox_Impl::CGUIComboBox_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, cons
storedCaption = CGUI_Impl::GetUTFString(szCaption);

m_pWindow->setText(storedCaption);

m_pWindow->setSize(pGUI->CreateAbsoluteSize(128.0f, 24.0f));
m_pWindow->setVisible(true);

Expand Down Expand Up @@ -66,7 +66,7 @@ CGUIListItem* CGUIComboBox_Impl::AddItem(const char* szText)
{
CGUIListItem_Impl* pNewItem = new CGUIListItem_Impl(m_pManager, szText, CGUIListItem_Impl::TextItem, NULL);
CEGUI::ListboxItem* pListboxItem = pNewItem->GetListItem();
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->addItem(pListboxItem);
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->addItem((CEGUI::StandardItem*)pListboxItem);
m_Items[pNewItem->GetListItem()] = pNewItem;
return pNewItem;
}
Expand All @@ -75,7 +75,7 @@ CGUIListItem* CGUIComboBox_Impl::AddItem(CGUIStaticImage* pImage)
{
CGUIListItem_Impl* pNewItem = new CGUIListItem_Impl(m_pManager, "", CGUIListItem_Impl::ImageItem, (CGUIStaticImage_Impl*)pImage);
CEGUI::ListboxItem* pListboxItem = pNewItem->GetListItem();
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->addItem(pListboxItem);
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->addItem((CEGUI::StandardItem*)pListboxItem);
m_Items[pNewItem->GetListItem()] = pNewItem;
return pNewItem;
}
Expand All @@ -84,12 +84,12 @@ bool CGUIComboBox_Impl::RemoveItem(int index)
{
try
{
CEGUI::ListboxItem* pItem = reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getListboxItemFromIndex(index);
CEGUI::ListboxItem* pItem = (CEGUI::ListboxItem*)reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getItemFromIndex(index);
if (pItem->isSelected()) // if this is currently selected, let's update the editbox.
{
m_pWindow->setText(storedCaption);
}
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->removeItem(pItem);
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->removeItem((CEGUI::StandardItem*)pItem);
return true;
}
catch (...)
Expand All @@ -101,20 +101,21 @@ bool CGUIComboBox_Impl::RemoveItem(int index)

CGUIListItem* CGUIComboBox_Impl::GetSelectedItem()
{
return GetListItem(reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getSelectedItem());
return GetListItem((CEGUI::ListboxItem*)reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getSelectedItem());
}

int CGUIComboBox_Impl::GetSelectedItemIndex()
{
CEGUI::ListboxItem* pItem = reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getSelectedItem();
CEGUI::ListboxItem* pItem = (CEGUI::ListboxItem*)reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getSelectedItem();

CFastHashMap<CEGUI::ListboxItem*, CGUIListItem_Impl*>::iterator it;
it = m_Items.find(pItem);
if (it == m_Items.end())
return -1;

try
{
return reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getItemIndex(it->first);
return reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getItemIndex((CEGUI::StandardItem*)it->first);
}
catch (...)
{
Expand All @@ -139,7 +140,7 @@ int CGUIComboBox_Impl::GetItemIndex(CGUIListItem* pItem)
{
try
{
return reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getItemIndex(it->first);
return reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getItemIndex((CEGUI::StandardItem*)it->first);
}
catch (...)
{
Expand All @@ -156,14 +157,14 @@ const char* CGUIComboBox_Impl::GetItemText(int index)
{
if (index == -1)
{
return m_pWindow->getText().c_str();
return (const char*)m_pWindow->getText().c_str();
}
else
{
CEGUI::ListboxItem* pItem = reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getListboxItemFromIndex(index);
CEGUI::ListboxItem* pItem = (CEGUI::ListboxItem*)reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getItemFromIndex(index);
if (pItem != NULL)
{
return pItem->getText().c_str();
return (const char*)pItem->getText().c_str();
}
}
}
Expand All @@ -178,7 +179,7 @@ bool CGUIComboBox_Impl::SetItemText(int index, const char* szText)
{
try
{
CEGUI::ListboxItem* pItem = reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getListboxItemFromIndex(index);
CEGUI::ListboxItem* pItem = (CEGUI::ListboxItem*)reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getItemFromIndex(index);
pItem->setText(CGUI_Impl::GetUTFString(szText));
if (pItem->isSelected()) // if this is currently selected, let's update the editbox.
{
Expand All @@ -195,7 +196,7 @@ bool CGUIComboBox_Impl::SetItemText(int index, const char* szText)

CGUIListItem* CGUIComboBox_Impl::GetItemByIndex(int index)
{
CEGUI::ListboxItem* pCEGUIItem = reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getListboxItemFromIndex(index);
CEGUI::ListboxItem* pCEGUIItem = (CEGUI::ListboxItem*)reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getItemFromIndex(index);
CGUIListItem* pItem = GetListItem(pCEGUIItem);
return pItem;
}
Expand All @@ -213,7 +214,7 @@ bool CGUIComboBox_Impl::SetSelectedItemByIndex(int index)
}
else
{
CEGUI::ListboxItem* pItem = reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getListboxItemFromIndex(index);
CEGUI::ListboxItem* pItem = (CEGUI::ListboxItem*)reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getItemFromIndex(index);
if (pItem != NULL)
{
pItem->setSelected(true);
Expand All @@ -231,7 +232,7 @@ bool CGUIComboBox_Impl::SetSelectedItemByIndex(int index)

void CGUIComboBox_Impl::Clear()
{
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getDropList()->resetList();
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->getDropList()->clearList();

CFastHashMap<CEGUI::ListboxItem*, CGUIListItem_Impl*>::iterator it;
for (it = m_Items.begin(); it != m_Items.end(); it++)
Expand Down Expand Up @@ -295,7 +296,7 @@ bool CGUIComboBox_Impl::Event_OnDropListRemoved(const CEGUI::EventArgs& e)
void CGUIComboBox_Impl::ShowDropList()
{
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->showDropList();
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->setSingleClickEnabled(true);
reinterpret_cast<CEGUI::Combobox*>(m_pWindow)->setSingleCursorActivationEnabled(true);
}

void CGUIComboBox_Impl::HideDropList()
Expand Down
13 changes: 7 additions & 6 deletions Client/gui_new/CGUIEdit_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ bool CGUIEdit_Impl::IsReadOnly()

void CGUIEdit_Impl::SetMasked(bool bMasked)
{
reinterpret_cast<CEGUI::Editbox*>(m_pWindow)->setTextMasked(bMasked);
reinterpret_cast<CEGUI::Editbox*>(m_pWindow)->setTextMaskingEnabled(bMasked);
}

bool CGUIEdit_Impl::IsMasked()
{
return reinterpret_cast<CEGUI::Editbox*>(m_pWindow)->isTextMasked();
return reinterpret_cast<CEGUI::Editbox*>(m_pWindow)->isTextMaskingEnabled();
}

void CGUIEdit_Impl::SetMaxLength(unsigned int uiMaxLength)
Expand All @@ -105,12 +105,12 @@ void CGUIEdit_Impl::SetSelection(unsigned int uiStart, unsigned int uiEnd)

unsigned int CGUIEdit_Impl::GetSelectionStart()
{
return static_cast<unsigned int>(reinterpret_cast<CEGUI::Editbox*>(m_pWindow)->getSelectionStartIndex());
return static_cast<unsigned int>(reinterpret_cast<CEGUI::Editbox*>(m_pWindow)->getSelectionStart());
}

unsigned int CGUIEdit_Impl::GetSelectionEnd()
{
return static_cast<unsigned int>(reinterpret_cast<CEGUI::Editbox*>(m_pWindow)->getSelectionEndIndex());
return static_cast<unsigned int>(reinterpret_cast<CEGUI::Editbox*>(m_pWindow)->getSelectionEnd());
}

unsigned int CGUIEdit_Impl::GetSelectionLength()
Expand Down Expand Up @@ -194,7 +194,8 @@ bool CGUIEdit_Impl::Event_OnRenderingStarted(const CEGUI::EventArgs& e)
bool CGUIEdit_Impl::Event_OnKeyDown(const CEGUI::EventArgs& e)
{
const CEGUI::KeyEventArgs& KeyboardArgs = reinterpret_cast<const CEGUI::KeyEventArgs&>(e);
if (KeyboardArgs.scancode == CGUIKeys::Tab)
auto scancode = (CGUIKeys::Scan)KeyboardArgs.d_key;
if (scancode == CGUIKeys::Scan::Tab)
{
// tab pressed, if we are in a window with tab enabled, just switch to the next element
if (GetParent() == NULL)
Expand All @@ -206,7 +207,7 @@ bool CGUIEdit_Impl::Event_OnKeyDown(const CEGUI::EventArgs& e)
pTabList->SelectNext(this);
}
}
else if (KeyboardArgs.scancode == CGUIKeys::Return || KeyboardArgs.scancode == CGUIKeys::NumpadEnter)
else if (scancode == CGUIKeys::Return || scancode == CGUIKeys::NumpadEnter)
{
// Enter/Return event is split from Tab now, since we use that for Console, Quick Connect, etc. as enter-only
if (m_OnTextAccepted)
Expand Down
49 changes: 24 additions & 25 deletions Client/gui_new/CGUIElement_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ void CGUIElement_Impl::SetPosition(const CVector2D& Position, bool bRelative)
CEGUI::UVector2 position;

if (bRelative)
position = CEGUI::Vector2(CEGUI::UDim(Position.fX, 0), CEGUI::UDim(Position.fY, 0));
position = CEGUI::UVector2(CEGUI::UDim(Position.fX, 0), CEGUI::UDim(Position.fY, 0));
else
position = CEGUI::Vector2(CEGUI::UDim(0, Position.fX), CEGUI::UDim(0, Position.fY));
position = CEGUI::UVector2(CEGUI::UDim(0, Position.fX), CEGUI::UDim(0, Position.fY));

m_pWindow->setPosition(position);
}
Expand Down Expand Up @@ -161,7 +161,10 @@ void CGUIElement_Impl::GetSize(CVector2D& vecSize, bool bRelative)

void CGUIElement_Impl::AutoSize(const char* Text, float fPaddingX, float fPaddingY)
{
const CEGUI::Font* pFont = m_pWindow->getFont();
CEGUI::Font* pFont = m_pWindow->getFont();

if (!pFont)
return;

// Add hack factor to height to allow for long characters such as 'g' or 'j'
m_pWindow->setSize(CEGUI::USize(CEGUI::UDim(0, pFont->getTextExtent(Text ? Text : GetText()) + fPaddingX), CEGUI::UDim(0, pFont->getFontHeight() + fPaddingY)));
Expand Down Expand Up @@ -208,7 +211,7 @@ void CGUIElement_Impl::SetText(const char* szText)

std::string CGUIElement_Impl::GetText()
{
return CGUI_Impl::GetUTFString(m_pWindow->getText().c_str()).c_str();
return (const char*)CGUI_Impl::GetUTFString((const char*)m_pWindow->getText().c_str()).c_str();
}

void CGUIElement_Impl::SetAlpha(float fAlpha)
Expand Down Expand Up @@ -310,9 +313,9 @@ CVector2D CGUIElement_Impl::RelativeToAbsolute(const CVector2D& Vector)
CEGUI::USize relativeSize = CEGUI::USize(CEGUI::UDim(Vector.fX, 0), CEGUI::UDim(Vector.fY, 0));
CEGUI::USize baseSize = m_pWindow->getSize();

CEGUI::Size size = CEGUI::Size(baseSize.d_width.d_offset, baseSize.d_height.d_offset);
CEGUI::Sizef size = CEGUI::Sizef(baseSize.d_width.d_offset, baseSize.d_height.d_offset);

CEGUI::Size absoluteSize = CEGUI::CoordConverter::asAbsolute(relativeSize, size, true);
CEGUI::Sizef absoluteSize = CEGUI::CoordConverter::asAbsolute(relativeSize, size, true);

return CVector2D(absoluteSize.d_width, absoluteSize.d_height);
}
Expand Down Expand Up @@ -351,8 +354,8 @@ void CGUIElement_Impl::CorrectEdges()
CEGUI::UVector2 currentPosition = m_pWindow->getPosition();
CEGUI::USize currentSize = m_pWindow->getSize();

std::string strType = m_pWindow->getType().c_str();
std::string strParentType = m_pWindow->getParent()->getType().c_str();
std::string strType = (const char*)m_pWindow->getType().c_str();
std::string strParentType = (const char*)m_pWindow->getParent()->getType().c_str();

// Label turns out to be buggy
if (strType == m_pManager->GetElementPrefix() + "/StaticText")
Expand Down Expand Up @@ -396,7 +399,7 @@ std::string CGUIElement_Impl::GetFont()
{
// Return the contname. std::string will copy it.
CEGUI::String strFontName = pFont->getName();
return strFontName.c_str();
return (const char*)strFontName.c_str();
}
}
catch (CEGUI::Exception e)
Expand All @@ -423,13 +426,13 @@ std::string CGUIElement_Impl::GetProperty(const char* szProperty)
try
{
// Return the string. std::string will copy it
strValue = CGUI_Impl::GetUTFString(m_pWindow->getProperty(CGUI_Impl::GetUTFString(szProperty)).c_str());
strValue = CGUI_Impl::GetUTFString((const char*)m_pWindow->getProperty(CGUI_Impl::GetUTFString(szProperty)).c_str());
}
catch (CEGUI::Exception e)
{
}

return strValue.c_str();
return (const char*)strValue.c_str();
}

void CGUIElement_Impl::FillProperties()
Expand All @@ -441,8 +444,8 @@ void CGUIElement_Impl::FillProperties()
CEGUI::String strValue = m_pWindow->getProperty(strKey);

CGUIProperty* pProperty = new CGUIProperty;
pProperty->strKey = strKey.c_str();
pProperty->strValue = strValue.c_str();
pProperty->strKey = (const char*)strKey.c_str();
pProperty->strValue = (const char*)strValue.c_str();

m_Properties.push_back(pProperty);
itPropertySet++;
Expand Down Expand Up @@ -591,7 +594,7 @@ bool CGUIElement_Impl::Event_OnSized(const CEGUI::EventArgs& e)

bool CGUIElement_Impl::Event_OnClick(const CEGUI::EventArgs& eBase)
{
const CEGUI::MouseEventArgs& e = reinterpret_cast<const CEGUI::MouseEventArgs&>(eBase);
const CEGUI::MouseButtonEventArgs& e = reinterpret_cast<const CEGUI::MouseButtonEventArgs&>(eBase);
CGUIElement* pElement = reinterpret_cast<CGUIElement*>(this);

if (m_OnClick)
Expand All @@ -602,11 +605,9 @@ bool CGUIElement_Impl::Event_OnClick(const CEGUI::EventArgs& eBase)
CGUIMouseEventArgs NewArgs;

// copy the variables
NewArgs.button = static_cast<CGUIMouse::MouseButton>(e.button);
NewArgs.moveDelta = CVector2D(e.moveDelta.d_x, e.moveDelta.d_y);
NewArgs.position = CGUIPosition(e.position.d_x, e.position.d_y);
NewArgs.sysKeys = e.sysKeys;
NewArgs.wheelChange = e.wheelChange;
NewArgs.button = static_cast<CGUIMouse::MouseButton>(e.d_button);
NewArgs.position = CGUIPosition(e.d_globalPos.x, e.d_globalPos.y);
NewArgs.modifiers = e.d_modifiers.getMask();
NewArgs.pWindow = pElement;

m_OnClickWithArgs(NewArgs);
Expand Down Expand Up @@ -672,9 +673,7 @@ bool CGUIElement_Impl::Event_OnKeyDown(const CEGUI::EventArgs& e)
CGUIKeyEventArgs NewArgs;

// copy the variables
NewArgs.codepoint = Args.codepoint;
NewArgs.scancode = (CGUIKeys::Scan)Args.scancode;
NewArgs.sysKeys = Args.sysKeys;
NewArgs.scancode = (CGUIKeys::Scan)Args.d_key;

// get the CGUIElement
CGUIElement* pElement = reinterpret_cast<CGUIElement*>((Args.window)->getUserData());
Expand All @@ -685,11 +684,11 @@ bool CGUIElement_Impl::Event_OnKeyDown(const CEGUI::EventArgs& e)

if (m_OnEnter)
{
switch (Args.scancode)
switch (Args.d_key)
{
// Return key
case CEGUI::Key::NumpadEnter:
case CEGUI::Key::Return:
case CEGUI::Key::Scan::NumpadEnter:
case CEGUI::Key::Scan::Return:
{
// Fire the event
m_OnEnter(pCGUIElement);
Expand Down
Loading

0 comments on commit 2a42af5

Please sign in to comment.