diff --git a/Client/core/CClientVariables.cpp b/Client/core/CClientVariables.cpp index 858bc1af2f9..16b4dac647c 100644 --- a/Client/core/CClientVariables.cpp +++ b/Client/core/CClientVariables.cpp @@ -331,6 +331,7 @@ void CClientVariables::LoadDefaults() DEFAULT("high_detail_peds", 0); // Disable rendering high detail peds all the time DEFAULT("fast_clothes_loading", 1); // 0-off 1-auto 2-on DEFAULT("allow_screen_upload", 1); // 0-off 1-on + DEFAULT("allow_server_control_transferbox", 1); // 0-off 1-on DEFAULT("allow_external_sounds", 1); // 0-off 1-on DEFAULT("max_clientscript_log_kb", 5000); // Max size in KB (0-No limit) DEFAULT("display_fullscreen_style", 0); // 0-standard 1-borderless 2-borderless keep res 3-borderless stretch diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 95e47ab6539..e27376e703d 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -376,6 +376,12 @@ void CSettings::CreateGUI() m_pCheckBoxAllowScreenUpload->GetPosition(vecTemp, false); m_pCheckBoxAllowScreenUpload->AutoSize(NULL, 20.0f); + m_pCheckBoxAllowTransferBoxControl = + reinterpret_cast(pManager->CreateCheckBox(pTabMultiplayer, _("Allow server to control transfer box"), true)); + m_pCheckBoxAllowTransferBoxControl->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f)); + m_pCheckBoxAllowTransferBoxControl->GetPosition(vecTemp, false); + m_pCheckBoxAllowTransferBoxControl->AutoSize(NULL, 20.0f); + m_pCheckBoxAllowExternalSounds = reinterpret_cast(pManager->CreateCheckBox(pTabMultiplayer, _("Allow external sounds"), true)); m_pCheckBoxAllowExternalSounds->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f)); m_pCheckBoxAllowExternalSounds->GetPosition(vecTemp, false); @@ -1218,6 +1224,7 @@ void CSettings::CreateGUI() m_pComboFxQuality->SetSelectionHandler(GUI_CALLBACK(&CSettings::OnFxQualityChanged, this)); m_pCheckBoxVolumetricShadows->SetClickHandler(GUI_CALLBACK(&CSettings::OnVolumetricShadowsClick, this)); m_pCheckBoxAllowScreenUpload->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowScreenUploadClick, this)); + m_pCheckBoxAllowTransferBoxControl->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowTransferBoxControl, this)); m_pCheckBoxAllowExternalSounds->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowExternalSoundsClick, this)); m_pCheckBoxCustomizedSAFiles->SetClickHandler(GUI_CALLBACK(&CSettings::OnCustomizedSAFilesClick, this)); m_pCheckBoxWindowed->SetClickHandler(GUI_CALLBACK(&CSettings::OnWindowedClick, this)); @@ -1512,6 +1519,11 @@ void CSettings::UpdateVideoTab() CVARS_GET("allow_screen_upload", bAllowScreenUploadEnabled); m_pCheckBoxAllowScreenUpload->SetSelected(bAllowScreenUploadEnabled); + // Allow transfer box control + bool bAllowServerTransferBoxControl; + CVARS_GET("allow_server_control_transferbox", bAllowServerTransferBoxControl); + m_pCheckBoxAllowTransferBoxControl->SetSelected(bAllowServerTransferBoxControl); + // Allow external sounds bool bAllowExternalSoundsEnabled; CVARS_GET("allow_external_sounds", bAllowExternalSoundsEnabled); @@ -3344,6 +3356,10 @@ void CSettings::SaveData() bool bAllowScreenUploadEnabled = m_pCheckBoxAllowScreenUpload->GetSelected(); CVARS_SET("allow_screen_upload", bAllowScreenUploadEnabled); + // Allow transfer box control + bool bAllowServerTransferBoxControl = m_pCheckBoxAllowTransferBoxControl->GetSelected(); + CVARS_SET("allow_server_control_transferbox", bAllowServerTransferBoxControl); + // Allow external sounds bool bAllowExternalSoundsEnabled = m_pCheckBoxAllowExternalSounds->GetSelected(); CVARS_SET("allow_external_sounds", bAllowExternalSoundsEnabled); @@ -4351,6 +4367,18 @@ bool CSettings::OnAllowScreenUploadClick(CGUIElement* pElement) return true; } +bool CSettings::OnAllowTransferBoxControl(CGUIElement* pElement) +{ + bool bAllowTransferBoxControl = m_pCheckBoxAllowTransferBoxControl->GetSelected(); + CVARS_SET("allow_server_control_transferbox", bAllowTransferBoxControl); + + // Enable default transfer box now if script control is disabled + if (!bAllowTransferBoxControl) + g_pCore->GetGUI()->SetTransferBoxEnabled(true); + + return true; +} + // // AllowExternalSounds // diff --git a/Client/core/CSettings.h b/Client/core/CSettings.h index af12dac5838..3b608c9a1f4 100644 --- a/Client/core/CSettings.h +++ b/Client/core/CSettings.h @@ -152,6 +152,7 @@ class CSettings CGUICheckBox* m_pCheckBoxDeviceSelectionDialog; CGUICheckBox* m_pCheckBoxShowUnsafeResolutions; CGUICheckBox* m_pCheckBoxAllowScreenUpload; + CGUICheckBox* m_pCheckBoxAllowTransferBoxControl; CGUICheckBox* m_pCheckBoxAllowExternalSounds; CGUICheckBox* m_pCheckBoxCustomizedSAFiles; CGUICheckBox* m_pCheckBoxGrass; @@ -378,6 +379,7 @@ class CSettings bool OnFxQualityChanged(CGUIElement* pElement); bool OnVolumetricShadowsClick(CGUIElement* pElement); bool OnAllowScreenUploadClick(CGUIElement* pElement); + bool OnAllowTransferBoxControl(CGUIElement* pElement); bool OnAllowExternalSoundsClick(CGUIElement* pElement); bool OnCustomizedSAFilesClick(CGUIElement* pElement); bool ShowUnsafeResolutionsClick(CGUIElement* pElement); diff --git a/Client/gui/CGUI_Impl.h b/Client/gui/CGUI_Impl.h index 72fff13fe93..5757969fed9 100644 --- a/Client/gui/CGUI_Impl.h +++ b/Client/gui/CGUI_Impl.h @@ -1,6 +1,6 @@ /***************************************************************************** * - * PROJECT: Multi Theft Auto v1.0 + * PROJECT: Multi Theft Auto * LICENSE: See LICENSE in the top level directory * FILE: gui/CGUI_Impl.h * PURPOSE: Graphical User Interface module class @@ -255,9 +255,12 @@ class CGUI_Impl : public CGUI, public CGUITabList void ClearInputHandlers(eInputChannel channel); void ClearSystemKeys(); - bool IsTransferBoxVisible() { return m_bTransferBoxVisible; }; + bool IsTransferBoxVisible() const { return m_bTransferBoxVisible; }; void SetTransferBoxVisible(bool bVisible) { m_bTransferBoxVisible = bVisible; }; + bool IsTransferBoxEnabled() const { return m_bTransferBoxEnabled; }; + void SetTransferBoxEnabled(bool bEnabled) { m_bTransferBoxEnabled = bEnabled; }; + bool Event_CharacterKey(const CEGUI::EventArgs& e); bool Event_KeyDown(const CEGUI::EventArgs& e); bool Event_MouseClick(const CEGUI::EventArgs& e); @@ -350,6 +353,7 @@ class CGUI_Impl : public CGUI, public CGUITabList std::list m_GuiWorkingDirectoryStack; bool m_bTransferBoxVisible; + bool m_bTransferBoxEnabled = true; bool m_HasSchemeLoaded; SString m_CurrentSchemeName; diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index 0743a0dec43..15f1923fb1e 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -2917,6 +2917,8 @@ void CClientGame::AddBuiltInEvents() // Misc events m_Events.AddEvent("onClientFileDownloadComplete", "fileName, success", NULL, false); + m_Events.AddEvent("onClientTransferBoxProgressChange", "downloaded, total", NULL, false); + m_Events.AddEvent("onClientWeaponFire", "ped, x, y, z", NULL, false); m_Events.AddEvent("onClientWorldSound", "group, index, x, y, z", nullptr, false); diff --git a/Client/mods/deathmatch/logic/CResourceFileDownloadManager.cpp b/Client/mods/deathmatch/logic/CResourceFileDownloadManager.cpp index de8f50dba29..313fd3f86f5 100644 --- a/Client/mods/deathmatch/logic/CResourceFileDownloadManager.cpp +++ b/Client/mods/deathmatch/logic/CResourceFileDownloadManager.cpp @@ -136,10 +136,26 @@ void CResourceFileDownloadManager::DoPulse() return; } + bool bAllowTransferBoxControl = g_pCore->GetCVars()->GetValue("allow_server_control_transferbox", false); + if (!bAllowTransferBoxControl && !GetTransferBox()->IsEnabled()) + GetTransferBox()->SetEnabled(true); + + if (GetTransferBox()->IsEnabled() && !GetTransferBox()->IsVisible()) + GetTransferBox()->Show(); + // Update progress box GetTransferBox()->SetInfo(uiDownloadSizeTotal); GetTransferBox()->DoPulse(); + // Call onClientTransferBoxProgressChange if client allows control over it + if (bAllowTransferBoxControl) + { + CLuaArguments Arguments; + Arguments.PushNumber(uiDownloadSizeTotal); + Arguments.PushNumber(GetTransferBox()->GetTotalSize()); + g_pClientGame->GetLocalPlayer()->CallEvent("onClientTransferBoxProgressChange", Arguments, false); + } + // Check if completed downloading current group if (m_ActiveFileDownloadList.empty()) { @@ -228,7 +244,7 @@ bool CResourceFileDownloadManager::BeginResourceFileDownload(CDownloadableResour options.bIsLocal = g_pClientGame->IsLocalGame(); SString* pstrContext = MakeDownloadContextString(pResourceFile); SString strFilename = pResourceFile->GetName(); - bool bUniqueDownload = pHTTP->QueueFile(strHTTPDownloadURLFull, strFilename, pstrContext, StaticDownloadFinished, options); + bool bUniqueDownload = pHTTP->QueueFile(strHTTPDownloadURLFull, strFilename, pstrContext, StaticDownloadFinished, options); if (!bUniqueDownload) { // TODO - If piggybacking on another matching download, then adjust progress bar diff --git a/Client/mods/deathmatch/logic/CResourceFileDownloadManager.h b/Client/mods/deathmatch/logic/CResourceFileDownloadManager.h index 72a0e1cc0a2..d317a845a3a 100644 --- a/Client/mods/deathmatch/logic/CResourceFileDownloadManager.h +++ b/Client/mods/deathmatch/logic/CResourceFileDownloadManager.h @@ -38,6 +38,7 @@ class CResourceFileDownloadManager void DownloadFinished(const SHttpDownloadResult& result); SString* MakeDownloadContextString(CDownloadableResource* pDownloadableResource); CDownloadableResource* ResolveDownloadContextString(SString* pString); + double GetTotalSize() const { return g_pClientGame->GetTransferBox()->GetTotalSize(); }; std::vector m_PendingFileDownloadList; std::vector m_ActiveFileDownloadList; diff --git a/Client/mods/deathmatch/logic/CTransferBox.cpp b/Client/mods/deathmatch/logic/CTransferBox.cpp index e78d7449ce4..8ae0ae73858 100644 --- a/Client/mods/deathmatch/logic/CTransferBox.cpp +++ b/Client/mods/deathmatch/logic/CTransferBox.cpp @@ -1,6 +1,6 @@ /***************************************************************************** * - * PROJECT: Multi Theft Auto v1.0 + * PROJECT: Multi Theft Auto * LICENSE: See LICENSE in the top level directory * FILE: mods/deathmatch/logic/CTransferBox.cpp * PURPOSE: Transfer box GUI @@ -11,11 +11,11 @@ #include -#define TRANSFERBOX_HEIGHT 58 -#define TRANSFERBOX_ICONSIZE 20 -#define TRANSFERBOX_PROGRESSHEIGHT 28 -#define TRANSFERBOX_YSTART 20 -#define TRANSFERBOX_SPACER 11 +#define TRANSFERBOX_HEIGHT 58 +#define TRANSFERBOX_ICONSIZE 20 +#define TRANSFERBOX_PROGRESSHEIGHT 28 +#define TRANSFERBOX_YSTART 20 +#define TRANSFERBOX_SPACER 11 CTransferBox::CTransferBox() { @@ -83,20 +83,23 @@ CTransferBox::CTransferBox() CTransferBox::~CTransferBox() { for (unsigned int i = 0; i < TRANSFERBOX_FRAMES; i++) - { delete m_pIcon[i]; - } - if (m_pWindow != NULL) + if (m_pWindow != nullptr) delete m_pWindow; - if (m_pInfo != NULL) + + if (m_pInfo != nullptr) delete m_pInfo; - if (m_pProgress != NULL) + + if (m_pProgress != nullptr) delete m_pProgress; } void CTransferBox::Show() { + if (!IsEnabled()) + return; + m_pWindow->SetVisible(true); g_pCore->GetGUI()->SetTransferBoxVisible(true); } @@ -109,6 +112,16 @@ void CTransferBox::Hide() m_dTotalSize = 0; } +bool CTransferBox::IsEnabled() const +{ + return g_pCore->GetGUI()->IsTransferBoxEnabled(); +} + +void CTransferBox::SetEnabled(bool bEnabled) const +{ + g_pCore->GetGUI()->SetTransferBoxEnabled(bEnabled); +} + void CTransferBox::SetInfo(double dDownloadSizeNow, CTransferBox::Type eTransferType) { // Convert to reasonable units diff --git a/Client/mods/deathmatch/logic/CTransferBox.h b/Client/mods/deathmatch/logic/CTransferBox.h index d418dfca9e9..e356f94424e 100644 --- a/Client/mods/deathmatch/logic/CTransferBox.h +++ b/Client/mods/deathmatch/logic/CTransferBox.h @@ -1,6 +1,6 @@ /***************************************************************************** * - * PROJECT: Multi Theft Auto v1.0 + * PROJECT: Multi Theft Auto * LICENSE: See LICENSE in the top level directory * FILE: mods/deathmatch/logic/CTransferBox.h * PURPOSE: Header for transfer box class @@ -11,11 +11,8 @@ #pragma once -#define TRANSFERBOX_FRAMES 10 -#define TRANSFERBOX_DELAY 50 - -#include "CClientCommon.h" -#include +#define TRANSFERBOX_FRAMES 10 +#define TRANSFERBOX_DELAY 50 class CTransferBox { @@ -34,14 +31,14 @@ class CTransferBox void Hide(); void SetInfo(double dDownloadSizeNow, CTransferBox::Type eTransferType = CTransferBox::NORMAL); - void DoPulse(); + bool IsVisible() const { return m_pWindow->IsVisible(); }; - bool OnCancelClick(CGUIElement* pElement); - - bool IsVisible() { return m_pWindow->IsVisible(); }; + bool IsEnabled() const; + void SetEnabled(bool bEnabled) const; - void AddToTotalSize(double dSize) { m_dTotalSize += dSize; }; + void AddToTotalSize(double dSize) { m_dTotalSize += dSize; }; + double GetTotalSize() const { return m_dTotalSize; }; private: CGUIWindow* m_pWindow; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp index bd37eae9fa6..068974667c6 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp @@ -10,6 +10,7 @@ *****************************************************************************/ #include "StdInc.h" +#include "lua/CLuaFunctionParser.h" static const SFixedArray g_chatboxLayoutCVars = {{ "chat_font", @@ -49,6 +50,8 @@ void CLuaGUIDefs::LoadFunctions() {"isMainMenuActive", GUIIsMainMenuActive}, {"isMTAWindowActive", GUIIsMTAWindowActive}, {"isTransferBoxActive", GUIIsTransferBoxActive}, + {"isTransferBoxEnabled", ArgumentParser}, + {"setTransferBoxEnabled", ArgumentParser}, {"guiCreateWindow", GUICreateWindow}, {"guiCreateLabel", GUICreateLabel}, @@ -4061,3 +4064,21 @@ int CLuaGUIDefs::GUIGetCursorType(lua_State* luaVM) lua_pushstring(luaVM, EnumToString(eType)); return 1; } + +bool CLuaGUIDefs::GUISetTransferBoxEnabled(bool bEnabled) +{ + bool bAllowed = false; + g_pCore->GetCVars()->Get("allow_server_control_transferbox", bAllowed); + if (bAllowed && bEnabled != g_pClientGame->GetTransferBox()->IsEnabled()) + { + g_pClientGame->GetTransferBox()->SetEnabled(bEnabled); + return true; + } + + return false; +} + +bool CLuaGUIDefs::GUIIsTransferBoxEnabled() +{ + return g_pClientGame->GetTransferBox()->IsEnabled(); +} diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h index cf5cefd4a08..05b9a5abcb3 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h @@ -159,6 +159,9 @@ class CLuaGUIDefs : public CLuaDefs LUA_DECLARE(GUIComboBoxIsOpen); LUA_DECLARE(GUIGetCursorType); + static bool GUIIsTransferBoxEnabled(); + static bool GUISetTransferBoxEnabled(bool bEnabled); + private: static void AddGuiElementClass(lua_State* luaVM); static void AddGuiFontClass(lua_State* luaVM); diff --git a/Client/sdk/gui/CGUI.h b/Client/sdk/gui/CGUI.h index 6a74aa67133..fa337b1a210 100644 --- a/Client/sdk/gui/CGUI.h +++ b/Client/sdk/gui/CGUI.h @@ -1,6 +1,6 @@ /***************************************************************************** * - * PROJECT: Multi Theft Auto v1.0 + * PROJECT: Multi Theft Auto * LICENSE: See LICENSE in the top level directory * FILE: sdk/gui/CGUI.h * PURPOSE: Graphical User Interface module interface @@ -38,14 +38,14 @@ class CGUI; #include "CGUITypes.h" // Path defines for CGUI -#define CGUI_ICON_MESSAGEBOX_INFO "cgui\\images\\info.png" -#define CGUI_ICON_MESSAGEBOX_QUESTION "cgui\\images\\question.png" -#define CGUI_ICON_MESSAGEBOX_WARNING "cgui\\images\\warning.png" -#define CGUI_ICON_MESSAGEBOX_ERROR "cgui\\images\\error.png" -#define CGUI_ICON_SERVER_PASSWORD "cgui\\images\\locked.png" +#define CGUI_ICON_MESSAGEBOX_INFO "cgui\\images\\info.png" +#define CGUI_ICON_MESSAGEBOX_QUESTION "cgui\\images\\question.png" +#define CGUI_ICON_MESSAGEBOX_WARNING "cgui\\images\\warning.png" +#define CGUI_ICON_MESSAGEBOX_ERROR "cgui\\images\\error.png" +#define CGUI_ICON_SERVER_PASSWORD "cgui\\images\\locked.png" #define CGUI_GetMaxTextExtent(...) GetMaxTextExtent(__VA_ARGS__, SString()) -#define CHECK_CHANNEL(channel) assert ( (channel) >= 0 && (channel) < INPUT_CHANNEL_COUNT ) +#define CHECK_CHANNEL(channel) assert((channel) >= 0 && (channel) < INPUT_CHANNEL_COUNT) class CGUI { @@ -164,9 +164,12 @@ class CGUI virtual void ClearInputHandlers(eInputChannel channel) = 0; virtual void ClearSystemKeys() = 0; - virtual bool IsTransferBoxVisible() = 0; + virtual bool IsTransferBoxVisible() const = 0; virtual void SetTransferBoxVisible(bool bVisible) = 0; + virtual bool IsTransferBoxEnabled() const = 0; + virtual void SetTransferBoxEnabled(bool bEnabled) = 0; + virtual void CleanDeadPool() = 0; virtual CGUIWindow* LoadLayout(CGUIElement* pParent, const SString& strFilename) = 0;