Skip to content

Commit

Permalink
Implement all CGUI element types & enable modern skin for entire menu
Browse files Browse the repository at this point in the history
Plus other small fixes.

Note: 'host game' window will still use the selected/non-modern skin, since it's created after CLocalGUI (which is wrapped by modern skin toggle)
  • Loading branch information
Lpsd committed Jan 16, 2025
1 parent bb6c882 commit 528244a
Show file tree
Hide file tree
Showing 22 changed files with 2,085 additions and 73 deletions.
3 changes: 3 additions & 0 deletions Client/core/CGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void CLocalGUI::ChangeLocale(const char* szName)
void CLocalGUI::CreateWindows(bool bGameIsAlreadyLoaded)
{
CGUI* pGUI = CCore::GetSingleton().GetGUI();
pGUI->SetModernSkinEnabled(true);

// Create chatbox
m_pChat = new CChat(pGUI, CVector2D(0.0125f, 0.015f));
Expand Down Expand Up @@ -171,6 +172,8 @@ void CLocalGUI::CreateWindows(bool bGameIsAlreadyLoaded)
// Create our news headlines if we're already ingame
if (bGameIsAlreadyLoaded)
m_pMainMenu->GetNewsBrowser()->CreateHeadlines();

pGUI->SetModernSkinEnabled(false);
}

void CLocalGUI::CreateObjects(IUnknown* pDevice)
Expand Down
4 changes: 0 additions & 4 deletions Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ void CSettings::CreateGUI()
CGUITab *pTabMultiplayer, *pTabVideo, *pTabAudio, *pTabBinds, *pTabControls, *pTabAdvanced;
CGUI* pManager = g_pCore->GetGUI();

pManager->SetModernSkinEnabled(true);

// Init
m_bIsModLoaded = false;
m_bCaptureKey = false;
Expand Down Expand Up @@ -1381,8 +1379,6 @@ void CSettings::CreateGUI()

// Load the load of skins
LoadSkins();

pManager->SetModernSkinEnabled(false);
}

void CSettings::DestroyGUI()
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIButton_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CGUIButton_Impl::CGUIButton_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const ch
pGUI->GetUniqueName(szUnique);

// Create the window and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUIBUTTON_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUIBUTTON_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);

m_pWindow->setText(CGUI_Impl::GetUTFString(szCaption));
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUICheckBox_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CGUICheckBox_Impl::CGUICheckBox_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, cons
pGUI->GetUniqueName(szUnique);

// Create the window and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUICHECKBOX_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUICHECKBOX_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);

m_pWindow->setText(CGUI_Impl::GetUTFString(szCaption));
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIComboBox_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CGUIComboBox_Impl::CGUIComboBox_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, cons
pGUI->GetUniqueName(szUnique);

// Create the window and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUICOMBOBOX_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUICOMBOBOX_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);

// This needs a better alternative, so changing comboBox will change this - Jyrno42
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIEdit_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CGUIEdit_Impl::CGUIEdit_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const char*
pGUI->GetUniqueName(szUnique);

// Create the edit and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUIEDIT_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUIEDIT_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);
m_pWindow->setRect(CEGUI::Absolute, CEGUI::Rect(0.00f, 0.00f, 0.128f, 0.24f));

Expand Down
4 changes: 2 additions & 2 deletions Client/gui/CGUIGridList_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ CGUIGridList_Impl::CGUIGridList_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, bool

// Create the window and set default settings
if (bFrame)
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUIGRIDLIST_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUIGRIDLIST_NAME), szUnique);
else
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUIGRIDLISTNOFRAME_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUIGRIDLISTNOFRAME_NAME), szUnique);

m_pWindow->setDestroyedByParent(false);
m_pWindow->setRect(CEGUI::Relative, CEGUI::Rect(0.00f, 0.00f, 0.40f, 0.40f));
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUILabel_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CGUILabel_Impl::CGUILabel_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const char
pGUI->GetUniqueName(szUnique);

// Create the window and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUILABEL_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUILABEL_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);

// Store the pointer to this CGUI element in the CEGUI element
Expand Down
4 changes: 3 additions & 1 deletion Client/gui/CGUIListItem_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "StdInc.h"

extern CGUI_Impl* g_pGUI;

CGUIListItem_Impl::CGUIListItem_Impl(const char* szText, unsigned int uiType, CGUIStaticImage_Impl* pImage)
{
ItemType = uiType;
Expand All @@ -33,7 +35,7 @@ CGUIListItem_Impl::CGUIListItem_Impl(const char* szText, unsigned int uiType, CG
{
// Set flags and properties
m_pListItem->setAutoDeleted(false);
m_pListItem->setSelectionBrushImage("CGUI-Images", "ListboxSelectionBrush");
m_pListItem->setSelectionBrushImage("CGUI-Images", g_pGUI->ResolveModernName("ListboxSelectionBrush"));
}

m_pData = NULL;
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIMemo_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CGUIMemo_Impl::CGUIMemo_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const char*
pGUI->GetUniqueName(szUnique);

// Create the window and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUIMEMO_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUIMEMO_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);

// Store the pointer to this CGUI element in the CEGUI element
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIProgressBar_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CGUIProgressBar_Impl::CGUIProgressBar_Impl(CGUI_Impl* pGUI, CGUIElement* pParent
pGUI->GetUniqueName(szUnique);

// Create the window and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUILABEL_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUILABEL_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);

// Store the pointer to this CGUI element in the CEGUI element
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIRadioButton_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CGUIRadioButton_Impl::CGUIRadioButton_Impl(CGUI_Impl* pGUI, CGUIElement* pParent
pGUI->GetUniqueName(szUnique);

// Create the window and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUIRADIOBUTTON_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUIRADIOBUTTON_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);

m_pWindow->setText(CGUI_Impl::GetUTFString(szCaption));
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIScrollBar_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CGUIScrollBar_Impl::CGUIScrollBar_Impl(CGUI_Impl* pGUI, bool bHorizontal, CGUIEl
pGUI->GetUniqueName(szUnique);

// Create the window and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(bHorizontal ? CGUISCROLLBAR_HORIZONTAL_NAME : CGUISCROLLBAR_VERTICAL_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(bHorizontal ? CGUISCROLLBAR_HORIZONTAL_NAME : CGUISCROLLBAR_VERTICAL_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);

// Store the pointer to this CGUI element in the CEGUI element
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIScrollPane_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CGUIScrollPane_Impl::CGUIScrollPane_Impl(CGUI_Impl* pGUI, CGUIElement* pParent)
pGUI->GetUniqueName(szUnique);

// Create the window and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUISCROLLPANE_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUISCROLLPANE_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);
m_pWindow->setRect(CEGUI::Relative, CEGUI::Rect(0.9f, 0.9f, 0.9f, 0.9f));

Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIStaticImage_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CGUIStaticImage_Impl::CGUIStaticImage_Impl(CGUI_Impl* pGUI, CGUIElement* pParent
pGUI->GetUniqueName(szUnique);

// Create the control and set default properties
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUISTATICIMAGE_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUISTATICIMAGE_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);
m_pWindow->setRect(CEGUI::Relative, CEGUI::Rect(0.0f, 0.0f, 1.0f, 1.0f));
reinterpret_cast<CEGUI::StaticImage*>(m_pWindow)->setBackgroundEnabled(false);
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUITabPanel_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CGUITabPanel_Impl::CGUITabPanel_Impl(CGUI_Impl* pGUI, CGUIElement* pParent)
pGUI->GetUniqueName(szUnique);

// Create the window and set default settings
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUITABPANEL_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUITABPANEL_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);
m_pWindow->setRect(CEGUI::Relative, CEGUI::Rect(0.9f, 0.9f, 0.9f, 0.9f));
reinterpret_cast<CEGUI::TabControl*>(m_pWindow)->setAbsoluteTabTextPadding(10.0f);
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIWebBrowser_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CGUIWebBrowser_Impl::CGUIWebBrowser_Impl(CGUI_Impl* pGUI, CGUIElement* pParent)
pGUI->GetUniqueName(szUnique);

// Create the control and set default properties
m_pWindow = pGUI->GetWindowManager()->createWindow(CGUIWEBBROWSER_NAME, szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUIWEBBROWSER_NAME), szUnique);
m_pWindow->setDestroyedByParent(false);
m_pWindow->setRect(CEGUI::Relative, CEGUI::Rect(0.0f, 0.0f, 1.0f, 1.0f));
reinterpret_cast<CEGUI::StaticImage*>(m_pWindow)->setBackgroundEnabled(false);
Expand Down
2 changes: 1 addition & 1 deletion Client/gui/CGUIWindow_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CGUIWindow_Impl::CGUIWindow_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, const ch
if (!m_pWindow)
{
// Create new here
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveSkin(CGUIWINDOW_NAME), szUnique);
m_pWindow = pGUI->GetWindowManager()->createWindow(pGUI->ResolveModernName(CGUIWINDOW_NAME), szUnique);
m_pWindow->setRect(CEGUI::Relative, CEGUI::Rect(0.10f, 0.10f, 0.60f, 0.90f));
m_pWindow->setAlpha(0.8f);

Expand Down
33 changes: 25 additions & 8 deletions Client/gui/CGUI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void CGUI_Impl::SetSkin(const char* szName)

PopGuiWorkingDirectory();

CEGUI::System::getSingleton().setDefaultMouseCursor("CGUI-Images", "MouseArrow");
CEGUI::System::getSingleton().setDefaultMouseCursor("CGUI-Images", "MouseArrowModern"); // Always use modern mouse arrow

// Destroy any windows we already have
CEGUI::WindowManager::getSingleton().destroyAllWindows();
Expand Down Expand Up @@ -430,9 +430,9 @@ bool CGUI_Impl::ConvertToModernSkin(const char* skinName)
}

// Load the requested skin's imageset, read-write
CXMLFile* skinImagesetFile = m_pXML->CreateXML(tempImagesetXmlPath);
CXMLFile* tempImagesetFile = m_pXML->CreateXML(tempImagesetXmlPath);

if (!skinImagesetFile || !skinImagesetFile->Parse())
if (!tempImagesetFile || !tempImagesetFile->Parse())
{
AddReportLog(1337, "ConvertToModernSkin: Failed to open/parse skin imageset");
return false;
Expand Down Expand Up @@ -472,11 +472,26 @@ bool CGUI_Impl::ConvertToModernSkin(const char* skinName)
}
}

// Set the Imageset root node NativeHorzRes and NativeVertRes to the modern imageset's resolution
CXMLAttributes& skinAttributes = tempImagesetFile->GetRootNode()->GetAttributes();
CXMLAttributes& modernAttributes = modernImagesetFile->GetRootNode()->GetAttributes();

auto skinHorzRes = skinAttributes.Find("NativeHorzRes");
auto skinVertRes = skinAttributes.Find("NativeVertRes");
auto modernHorzRes = modernAttributes.Find("NativeHorzRes");
auto modernVertRes = modernAttributes.Find("NativeVertRes");

if (skinHorzRes && skinVertRes && modernHorzRes && modernVertRes)
{
skinHorzRes->SetValue(modernHorzRes->GetValue().c_str());
skinVertRes->SetValue(modernVertRes->GetValue().c_str());
}

// Copy the modern imageset into the skin imageset
modernRootNode->CopyChildrenInto(skinImagesetFile->GetRootNode(), true, false);
modernRootNode->CopyChildrenInto(tempImagesetFile->GetRootNode(), true, false);

// Save the skin imageset
if (!skinImagesetFile->Write())
if (!tempImagesetFile->Write())
{
AddReportLog(1337, "ConvertToModernSkin: Failed to write skin imageset");
return false;
Expand Down Expand Up @@ -2045,8 +2060,10 @@ CEGUI::Window* CGUI_Impl::GetMasterWindow(CEGUI::Window* wnd)
return wnd;
}

const char* CGUI_Impl::ResolveSkin(const char* szSkin)
std::string CGUI_Impl::ResolveModernName(const char* name)
{
const std::string name = m_bUseModernSkin ? std::string(szSkin) + "Modern" : szSkin;
return name.c_str();
if (name == "DefaultWindow")
return "FrameWindowModern";

return m_bUseModernSkin ? std::string(name) + "Modern" : name;
}
9 changes: 4 additions & 5 deletions Client/gui/CGUI_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ class CGUI_Impl : public CGUI, public CGUITabList
CGUIWindow* LoadLayout(CGUIElement* pParent, const SString& strFilename);
bool LoadImageset(const SString& strFilename);

void SetModernSkinEnabled(bool bEnabled) { m_bUseModernSkin = bEnabled; }
const char* ResolveSkin(const char* szSkin);
void SetModernSkinEnabled(bool bEnabled) { m_bUseModernSkin = bEnabled; }
std::string ResolveModernName(const char* szSkin);

void SetXMLParser(CXML* pXML) { m_pXML = pXML; }
void SetGraphics(CGraphicsInterface* pGraphicsInterface) { m_pGraphics = pGraphicsInterface; }
Expand Down Expand Up @@ -361,8 +361,7 @@ class CGUI_Impl : public CGUI, public CGUITabList
SString m_CurrentSchemeName;
CElapsedTime m_RenderOkTimer;

bool m_bUseModernSkin = false;
bool m_bUseModernSkin = false;
CGraphicsInterface* m_pGraphics;
CXML* m_pXML;

CXML* m_pXML;
};
Loading

0 comments on commit 528244a

Please sign in to comment.