Skip to content

Commit

Permalink
feat(nui-core): add options to switch between fixed size modes
Browse files Browse the repository at this point in the history
- for players with larger screens (4160x2160) 1920x1080 might be too big this adds an option to scale to 1920x1080 or 2560x1440
- see #2397 for more discussion
  • Loading branch information
AvarianKnight committed Feb 27, 2024
1 parent 88a0a6c commit 9531488
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
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>;

0 comments on commit 9531488

Please sign in to comment.