diff --git a/Client/core/CClientChatboxVariables.h b/Client/core/CClientChatboxVariables.h new file mode 100644 index 0000000000..ace5278b2f --- /dev/null +++ b/Client/core/CClientChatboxVariables.h @@ -0,0 +1,38 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * FILE: core/CClientChatboxVariables.h + * PURPOSE: Header file for client chatbox variables + * + * Multi Theft Auto is available from http://www.multitheftauto.com/ + * + *****************************************************************************/ + +#pragma once + +#include + +#define MAX_CHATBOX_LAYOUT_CVARS 21 + +static const SFixedArray& g_chatboxLayoutCVars = {{"chat_font", + "chat_lines", + "chat_color", + "chat_text_color", + "chat_input_color", + "chat_input_prefix_color", + "chat_input_text_color", + "chat_scale", + "chat_position_offset_x", + "chat_position_offset_y", + "chat_position_horizontal", + "chat_position_vertical", + "chat_text_alignment", + "chat_width", + "chat_css_style_text", + "chat_css_style_background", + "chat_line_life", + "chat_line_fade_out", + "chat_use_cegui", + "text_scale", + "chat_text_outline"}}; diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 847735a891..354cb3f694 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -3619,6 +3619,7 @@ void CSettings::SaveData() } // Chat + this->SetChatLayoutChanged(false); SaveChatColor(Chat::ColorType::BG, "chat_color"); SaveChatColor(Chat::ColorType::TEXT, "chat_text_color"); SaveChatColor(Chat::ColorType::INPUT_BG, "chat_input_color"); @@ -3627,38 +3628,46 @@ void CSettings::SaveData() { if (m_pRadioChatFont[iFont]->GetSelected()) { - CVARS_SET("chat_font", iFont); + SaveChatSetting("chat_font", iFont); break; } } - strVar = m_pChatScaleX->GetText() + " " + m_pChatScaleY->GetText(); - CVARS_SET("chat_scale", strVar); - CVARS_SET("chat_lines", m_pChatLines->GetText()); - CVARS_SET("chat_width", m_pChatWidth->GetText()); - CVARS_SET("chat_css_style_text", m_pChatCssText->GetSelected()); - CVARS_SET("chat_css_style_background", m_pChatCssBackground->GetSelected()); - CVARS_SET("chat_nickcompletion", m_pChatNickCompletion->GetSelected()); - CVARS_SET("chat_text_outline", m_pChatTextBlackOutline->GetSelected()); - CVARS_SET("chat_line_life", GetMilliseconds(m_pChatLineLife)); - CVARS_SET("chat_line_fade_out", GetMilliseconds(m_pChatLineFadeout)); - - CVARS_SET("chat_position_offset_x", m_pChatOffsetX->GetText()); - CVARS_SET("chat_position_offset_y", m_pChatOffsetY->GetText()); + std::stringstream ss; + ss << std::stof(m_pChatScaleX->GetText()) << " " << std::stof(m_pChatScaleY->GetText()); + + SaveChatSetting("chat_scale", ss.str()); + SaveChatSetting("chat_lines", m_pChatLines->GetText()); + SaveChatSetting("chat_width", m_pChatWidth->GetText()); + + SaveChatSetting("chat_css_style_text", m_pChatCssText->GetSelected()); + SaveChatSetting("chat_css_style_background", m_pChatCssBackground->GetSelected()); + SaveChatSetting("chat_nickcompletion", m_pChatNickCompletion->GetSelected()); + SaveChatSetting("chat_text_outline", m_pChatTextBlackOutline->GetSelected()); + SaveChatSetting("chat_line_life", GetMilliseconds(m_pChatLineLife)); + SaveChatSetting("chat_line_fade_out", GetMilliseconds(m_pChatLineFadeout)); + + SaveChatSetting("chat_position_offset_x", m_pChatOffsetX->GetText()); + SaveChatSetting("chat_position_offset_y", m_pChatOffsetY->GetText()); if (CGUIListItem* pSelected = m_pChatHorizontalCombo->GetSelectedItem()) { int iSelected = (int)pSelected->GetData(); - CVARS_SET("chat_position_horizontal", iSelected); + SaveChatSetting("chat_position_horizontal", iSelected); } if (CGUIListItem* pSelected = m_pChatVerticalCombo->GetSelectedItem()) { int iSelected = (int)pSelected->GetData(); - CVARS_SET("chat_position_vertical", iSelected); + SaveChatSetting("chat_position_vertical", iSelected); } if (CGUIListItem* pSelected = m_pChatTextAlignCombo->GetSelectedItem()) { int iSelected = (int)pSelected->GetData(); - CVARS_SET("chat_text_alignment", iSelected); + SaveChatSetting("chat_text_alignment", iSelected); + } + + if (this->GetChatLayoutChanged() && CModManager::GetSingleton().IsLoaded()) + { + CModManager::GetSingletonPtr()->GetCurrentMod()->OnChatboxLayoutChange(); } // Interface @@ -3904,7 +3913,47 @@ void CSettings::SaveChatColor(eChatColorType eType, const char* szCVar) CVARS_GET(szCVar, pOldColor); if (pColor.R != pOldColor.R || pColor.G != pOldColor.G || pColor.B != pOldColor.B || pColor.A != pOldColor.A) + { CVARS_SET(szCVar, pColor); + this->SetChatLayoutChanged(true); + } +} + + +void CSettings::SaveChatSetting(const char* szCVar, int iVal) +{ + // Save value to the CVar if it's different from previous + int iPreviousValue; + CVARS_GET(szCVar, iPreviousValue); + if (iPreviousValue != iVal) + { + CVARS_SET(szCVar, iVal); + this->SetChatLayoutChanged(true); + } +} + +void CSettings::SaveChatSetting(const char* szCVar, const std::string& strVal) +{ + // Save value to the CVar if it's different from previous + std::string strPreviousValue; + CVARS_GET(szCVar, strPreviousValue); + if (strPreviousValue != strVal) + { + CVARS_SET(szCVar, strVal); + this->SetChatLayoutChanged(true); + } +} + +void CSettings::SaveChatSetting(const char* szCVar, bool bVal) +{ + // Save value to the CVar if it's different from previous + bool bPreviousValue; + CVARS_GET(szCVar, bPreviousValue); + if (bPreviousValue != bVal) + { + CVARS_SET(szCVar, bVal); + this->SetChatLayoutChanged(true); + } } CColor CSettings::GetChatColorValues(eChatColorType eType) diff --git a/Client/core/CSettings.h b/Client/core/CSettings.h index bfeec87c44..cb92013683 100644 --- a/Client/core/CSettings.h +++ b/Client/core/CSettings.h @@ -420,11 +420,17 @@ class CSettings void LoadChatColorFromCVar(eChatColorType eType, const char* szCVar); void LoadChatColorFromString(eChatColorType eType, const std::string& strColor); void SaveChatColor(eChatColorType eType, const char* szCVar); + void SaveChatSetting(const char* szCVar, int iVal); + void SaveChatSetting(const char* szCVar, const std::string& strVal); + void SaveChatSetting(const char* szCVar, bool bVal); CColor GetChatColorValues(eChatColorType eType); void SetChatColorValues(eChatColorType eType, CColor pColor); int GetMilliseconds(CGUIEdit* pEdit); void SetMilliseconds(CGUIEdit* pEdit, int milliseconds); + void SetChatLayoutChanged(bool changed) { m_bChatLayoutChanged = changed; }; + bool GetChatLayoutChanged() const { return m_bChatLayoutChanged; }; + void ResetGTAVolume(); void SetRadioVolume(float fVolume); void SetSFXVolume(float fVolume); @@ -465,4 +471,6 @@ class CSettings int m_iMaxAnisotropic; std::list m_pKeyBindSections; + + bool m_bChatLayoutChanged = false; }; diff --git a/Client/mods/deathmatch/CClient.cpp b/Client/mods/deathmatch/CClient.cpp index ec17655996..649cd76c77 100644 --- a/Client/mods/deathmatch/CClient.cpp +++ b/Client/mods/deathmatch/CClient.cpp @@ -13,6 +13,7 @@ #define ALLOC_STATS_MODULE_NAME "client" #include "SharedUtil.hpp" #include +#include <../Client/core/CClientChatboxVariables.h> CCoreInterface* g_pCore = NULL; CLocalizationInterface* g_pLocalization = NULL; @@ -305,6 +306,75 @@ void CClient::OnWindowFocusChange(bool state) g_pClientGame->OnWindowFocusChange(state); } +void CClient::OnChatboxLayoutChange() +{ + if (g_pClientGame) + { + CCVarsInterface* pCVars = g_pCore->GetCVars(); + SString strCVarValue; + std::stringstream ss; + float fNumber, fX, fY; + int iR, iG, iB, iA; + CLuaArguments chatboxItemList; + + for (unsigned int i = 0; i < MAX_CHATBOX_LAYOUT_CVARS; i++) + { + chatboxItemList.PushString(g_chatboxLayoutCVars[i]); + if (g_chatboxLayoutCVars[i] == "chat_color" || g_chatboxLayoutCVars[i] == "chat_text_color" || g_chatboxLayoutCVars[i] == "chat_input_color" || + g_chatboxLayoutCVars[i] == "chat_input_prefix_color" || g_chatboxLayoutCVars[i] == "chat_input_text_color") + { + pCVars->Get(g_chatboxLayoutCVars[i], strCVarValue); + if (strCVarValue.empty()) + continue; + ss.clear(); + ss.str(strCVarValue); + ss >> iR >> iG >> iB >> iA; + + CLuaArguments chatboxColorItem; + chatboxColorItem.PushNumber(1); + chatboxColorItem.PushNumber(iR); + chatboxColorItem.PushNumber(2); + chatboxColorItem.PushNumber(iG); + chatboxColorItem.PushNumber(3); + chatboxColorItem.PushNumber(iB); + chatboxColorItem.PushNumber(4); + chatboxColorItem.PushNumber(iA); + + chatboxItemList.PushTable(&chatboxColorItem); + } + else if (g_chatboxLayoutCVars[i] == "chat_scale") + { + pCVars->Get(g_chatboxLayoutCVars[i], strCVarValue); + if (strCVarValue.empty()) + continue; + ss.clear(); + ss.str(strCVarValue); + ss >> fX >> fY; + + CLuaArguments numberTable; + numberTable.PushNumber(1); + numberTable.PushNumber(fX); + numberTable.PushNumber(2); + numberTable.PushNumber(fY); + + chatboxItemList.PushTable(&numberTable); + } + else + { + pCVars->Get(g_chatboxLayoutCVars[i], fNumber); + if (g_chatboxLayoutCVars[i] == "chat_use_cegui") + chatboxItemList.PushBoolean(fNumber ? true : false); + else + chatboxItemList.PushNumber(fNumber); + } + } + + CLuaArguments Arguments; + Arguments.PushTable(&chatboxItemList); + g_pClientGame->GetRootEntity()->CallEvent("onClientChatboxLayoutChange", Arguments, false); + } +} + CClient::InitializeArguments CClient::ExtractInitializeArguments(const char* arguments) { // Format: "nickname [password]" diff --git a/Client/mods/deathmatch/CClient.h b/Client/mods/deathmatch/CClient.h index 49c4a95c7d..0f4ec3fc51 100644 --- a/Client/mods/deathmatch/CClient.h +++ b/Client/mods/deathmatch/CClient.h @@ -34,6 +34,8 @@ class CClient : public CClientBase void OnWindowFocusChange(bool state) override; + void OnChatboxLayoutChange(); + private: struct InitializeArguments { diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index 7b57fe13e1..0759551a9b 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -2784,6 +2784,8 @@ void CClientGame::AddBuiltInEvents() m_Events.AddEvent("onClientWeaponFire", "ped, x, y, z", NULL, false); m_Events.AddEvent("onClientWorldSound", "group, index, x, y, z", nullptr, false); + + m_Events.AddEvent("onClientChatboxLayoutChange", "chatboxLayout", NULL, false); } void CClientGame::DrawFPS() diff --git a/Client/mods/deathmatch/logic/CClientGame.h b/Client/mods/deathmatch/logic/CClientGame.h index f2c290d94c..79aaa5f656 100644 --- a/Client/mods/deathmatch/logic/CClientGame.h +++ b/Client/mods/deathmatch/logic/CClientGame.h @@ -446,6 +446,8 @@ class CClientGame void OnWindowFocusChange(bool state); + void OnChatboxLayoutChange(); + private: // CGUI Callbacks bool OnKeyDown(CGUIKeyEventArgs Args); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp index a3b7e35545..c4955227f3 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp @@ -11,28 +11,7 @@ #include "StdInc.h" #include - -static const SFixedArray g_chatboxLayoutCVars = {{"chat_font", - "chat_lines", - "chat_color", - "chat_text_color", - "chat_input_color", - "chat_input_prefix_color", - "chat_input_text_color", - "chat_scale", - "chat_position_offset_x", - "chat_position_offset_y", - "chat_position_horizontal", - "chat_position_vertical", - "chat_text_alignment", - "chat_width", - "chat_css_style_text", - "chat_css_style_background", - "chat_line_life", - "chat_line_fade_out", - "chat_use_cegui", - "text_scale", - "chat_text_outline"}}; +#include <../Client/core/CClientChatboxVariables.h> void CLuaGUIDefs::LoadFunctions() { diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h index ac778abf95..c1b3857cf3 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h @@ -12,7 +12,6 @@ #pragma once #include "CLuaDefs.h" -#define MAX_CHATBOX_LAYOUT_CVARS 21 class CLuaGUIDefs : public CLuaDefs { diff --git a/Client/sdk/core/CClientBase.h b/Client/sdk/core/CClientBase.h index 17634dab81..ee6f55426d 100644 --- a/Client/sdk/core/CClientBase.h +++ b/Client/sdk/core/CClientBase.h @@ -34,4 +34,6 @@ class CClientBase virtual void GetPlayerNames(std::vector& vPlayerNames) = 0; virtual void OnWindowFocusChange(bool state) = 0; + + virtual void OnChatboxLayoutChange() = 0; };