Skip to content
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

feat(nui-core): add options to switch between fixed size modes #2403

Closed
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
2 changes: 2 additions & 0 deletions code/components/nui-core/include/NUIWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,6 @@ class
void HandlePopupShow(bool show);

bool IsFixedSizeWindow() const;

int GetFixedSizeMode() const;
};
20 changes: 18 additions & 2 deletions code/components/nui-core/src/NUIWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern nui::GameInterface* g_nuiGi;
extern std::wstring GetNUIStoragePath();

static bool nuiFixedSizeEnabled;
static int nuiFixedSizeMode;

namespace nui
{
Expand Down Expand Up @@ -562,8 +563,17 @@ void NUIWindow::UpdateFrame()

if (IsFixedSizeWindow())
{
resX = 1920;
resY = 1080;
const int fixedSizeMode = GetFixedSizeMode();
if (fixedSizeMode == 0)
{
resX = 1920;
resY = 1080;
}
else if (fixedSizeMode == 1)
{
resX = 2560;
resY = 1440;
}
}

if (m_width != resX || m_height != resY)
Expand Down Expand Up @@ -959,7 +969,13 @@ bool NUIWindow::IsFixedSizeWindow() const
return nuiFixedSizeEnabled && m_name == "root";
}

int NUIWindow::GetFixedSizeMode() const
{
return nuiFixedSizeMode;
}

static InitFunction initFunction([]
{
static ConVar<bool> nuiFixedSize("nui_useFixedSize", ConVar_Archive | ConVar_UserPref, false, &nuiFixedSizeEnabled);
static ConVar<int> nuiFixedSizeMode("nui_fixedSizeMode", ConVar_Archive | ConVar_UserPref, 0, &nuiFixedSizeMode);
});
4 changes: 3 additions & 1 deletion ext/cfx-ui/src/assets/languages/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@
"#Settings_InProcessGpu": "NUI in-process GPU",
"#Settings_InProcessGpuDesc": "Fix 'UI lag' at high GPU usage, but may cause reliability issues with GPU crashes (requires restart)",
"#Settings_FixedSizeNUI": "Fixed-size NUI",
"#Settings_FixedSizeNUIDesc": "Force in-server UI to 1920x1080 resolution, scaled/letterboxed to fit (for servers with UI assuming 1920x1080)",
"#Settings_FixedSizeNUIDesc": "Force in-server UI to one one of the specified resolutions resolutions, scaled/letterboxed to fit (for servers with UI assuming clients will have 1920x1080 or 2560x1440)",
"#Settings_FixedSizeNUIMode": "Fixed-size NUI mode",
"#Settings_FixedSizeNUIModeDesc": "",
"#Settings_NoiseSuppression": "Voice chat noise suppression",
"#Settings_NoiseSuppressionDesc": "Enable background noise suppression (using RNNoise) for the built-in voice chat",
"#Settings_ConnectedProfiles": "Linked identities",
Expand Down
16 changes: 15 additions & 1 deletion ext/cfx-ui/src/cfx/apps/mpMenu/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import emojiList from 'emoji.json/emoji-compact.json';
import { BrandIcon, Icons } from "cfx/ui/Icons";
import { BsDisplay } from "react-icons/bs";
import { ISetting, ISettings } from "cfx/common/services/settings/types";
import { FixedUiScaling, ISetting, ISettings } from "cfx/common/services/settings/types";
import { useService } from "cfx/base/servicesContainer";
import { CurrentGameName } from "cfx/base/gameRuntime";
import { CustomBackdropControl } from "./parts/SettingsFlyout/CustomBackdropControl/CustomBackdropControl";
Expand Down Expand Up @@ -221,6 +221,20 @@ const GAME_GAME_SETTINGS = new Map<string, ISetting.AnySetting>([

...convarAccessorsBoolean('nui_useFixedSize'),
}],
['fixedSizeNuiMode', {
type: 'switch',

label: $L('#Settings_FixedSizeNUIMode'),

options: {
[FixedUiScaling.ScaleBy_1920x1080]: '1920x1080',
[FixedUiScaling.ScaleBy_2560x1440]: '2560x1440',
},

...convarAccessorsString("nui_fixedSizeMode"),

visible: () => useService(IConvarService).getBoolean('nui_useFixedSize'),
}],
['noiseSuppression', {
type: 'checkbox',

Expand Down
5 changes: 5 additions & 0 deletions ext/cfx-ui/src/cfx/common/services/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ export type ICategory = {
settings: Map<string, ISetting.AnySetting>,
};

export enum FixedUiScaling {
ScaleBy_1920x1080,
ScaleBy_2560x1440
}

export type ISettings = Map<string, ICategory>;
Loading