Skip to content

Commit

Permalink
fixup! feat: add horizontal FOV converter
Browse files Browse the repository at this point in the history
  • Loading branch information
wertiop121 committed Jul 25, 2024
1 parent d135cd1 commit 5d54f08
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
15 changes: 11 additions & 4 deletions layout/pages/settings/video.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@
<Label class="settings-group__title" text="#Settings_Video" />
</Panel>

<Panel class="settings-group__combo" onload="Fov.loadSettings()">
<SettingsSlider id="FOV" text="#Settings_Video_FOV" min="50" max="130" convar="fov_desired" hasdocspage="false" onvaluechanged="Fov.updateFOV()" />
<SettingsSlider id="FOV" text="#Settings_Video_FOV" min="50" max="130" convar="fov_desired" hasdocspage="false" onvaluechanged="Fov.updateFOV()" />

<Panel class="settings-enum__values pr-2 pl-4 mb-1">
<Panel class="settings-group__combo" onload="Fov.loadSettings()" infotitle="#Settings_Video_Horizontal_FOV" infomessage="#Settings_Video_Horizontal_FOV_Info">
<Panel class="settings-enum">
<Label text="#Settings_Video_Horizontal_FOV" class="settings-enum__title" />
<TextEntry id="FOV_Horizontal" class="textentry settings-slider__textentry HasInput ml-4" multiline="false" textmode="numeric" oninputsubmit="Fov.updateHorizontalFov()" />
<Panel class="settings-enum__values">
<TextEntry id="FOV_Horizontal" class="textentry settings-slider__textentry HasInput ml-4" multiline="false" textmode="numeric" oninputsubmit="Fov.updateHorizontalFov()" />
<DropDown id="FOV_Horizontal_AspectRatioEnum" class="dropdown ml-4" menuclass="dropdown-menu" onuserinputsubmit="Fov.updateFOV()">
<Label text="#Settings_Video_AspectRatio_Normal" value="0" id="aspectratio0" />
<Label text="#Settings_Video_AspectRatio_16x9" value="1" id="aspectratio1" />
<Label text="#Settings_Video_AspectRatio_16x10" value="2" id="aspectratio2" />
</DropDown>
</Panel>
</Panel>
</Panel>

Expand Down
21 changes: 12 additions & 9 deletions scripts/pages/settings/fov.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ class Fov {
/** @type {SettingsSlider} @static */
fov: $('#FOV'),
/** @type {TextEntry} @static */
horizontalFov: $('#FOV_Horizontal')
horizontalFov: $('#FOV_Horizontal'),
aspectRatio: $('#FOV_Horizontal_AspectRatioEnum')
};

static loadSettings() {
this.panels.aspectRatio.SetSelected('aspectratio1');
this.updateFOV();
}

static aspectRatio() {
// find the display panel
// there doesn't seem to be an api for this yet
let panel = this.panels.fov;
let parent = panel;
while ((parent = panel.GetParent())) {
panel = parent;
const id = this.panels.aspectRatio.GetSelected().id;
switch(id) {
case 'aspectratio0':
return 4/3;
case 'aspectratio1':
return 16/9;
case 'aspectratio2':
return 16/10;
}

return panel.actuallayoutwidth / panel.actuallayoutheight;
return Number.NaN;
}

static fovToHorizontal(fov) {
Expand Down
17 changes: 9 additions & 8 deletions scripts/pages/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ class MainMenuSettings {

static initPanelsRecursive(panel) {
// Initialise info panel event handlers
if (this.isSettingsPanel(panel) || this.isSpeedometerPanel(panel)) {
this.setPanelInfoEvents(panel);
}
this.setPanelInfoEvents(panel);

// Initialise all the settings using persistent storage
// Only Enum and EnumDropDown are currently supported, others can be added when/if needed
Expand Down Expand Up @@ -312,13 +310,20 @@ class MainMenuSettings {

static setPanelInfoEvents(panel) {
const message = panel.GetAttributeString('infomessage', '');
const title = panel.GetAttributeString('infotitle', '');

// Don't set events if there's no info to show
if(!this.isSettingsPanel(panel) && message === '' && title === '' && !panel.convar && !panel.bind) return;

// Default to true if not set
const hasDocs = !(panel.GetAttributeString('hasdocspage', '') === 'false');


panel.SetPanelEvent('onmouseover', () => {
// Set onmouseover events for all settings panels
this.showInfo(
// If a panel has a specific title use that, if not use the panel's name. Child ID names vary between panel types, blame Valve
panel.GetAttributeString('infotitle', '') ||
title ||
panel.FindChildTraverse('Title')?.text ||
panel.FindChildTraverse('title')?.text,
message,
Expand Down Expand Up @@ -438,8 +443,4 @@ class MainMenuSettings {
'ConVarColorDisplay'
].includes(panel.paneltype);
}

static isSpeedometerPanel(panel) {
return ['SpeedometersContainer', 'RangeColorProfilesContainer'].includes(panel.id);
}
}

0 comments on commit 5d54f08

Please sign in to comment.