Skip to content
Draft
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
Binary file added images/hud/spinner_saving_strip.tga
Binary file not shown.
1 change: 1 addition & 0 deletions layout/hud/hud.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<!-- HUD anchored to top-left corner of screen, laid out vertically top-to-bottom -->
<Panel id="HudTopLeft" hittest="false" hittestchildren="false">
<SaveIndicator />
</Panel>

<!-- Anchored to below the center of the screen, laid out from top to bottom -->
Expand Down
22 changes: 22 additions & 0 deletions layout/hud/save-indicator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<root>
<styles>
<include src="file://{resources}/styles/main.scss" />
<include src="file://{resources}/styles/hud/save-indicator.scss" />
</styles>
<scripts>
<include src="file://{scripts}/common/dev.ts" />
<include src="file://{scripts}/hud/save-indicator.ts" />
</scripts>

<Panel class="save-indicator">
<AnimatedImageStrip
id="Spinner"
animating="true"
defaultframe="0"
frametime="100ms"
src="file://{images}/hud/spinner_saving_strip.tga"
scaling="stretch-to-cover-preserve-aspect"
/>
<Label class="save-indicator__label" id="StatusLabel" text="#PORTAL2_Hud_GameSaved" />
</Panel>
Comment on lines +11 to +21

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to note, we have an internally registered Save Indicator panel already from Revolution. I actually didn't know this and found it on accident when pulling up the other save files in the codebase. It's called HudSaveIndicator.

So you can drop the custom panel registration, and then change where you reference SaveIndicator to HudSaveIndicator:

Suggested change
<Panel class="save-indicator">
<AnimatedImageStrip
id="Spinner"
animating="true"
defaultframe="0"
frametime="100ms"
src="file://{images}/hud/spinner_saving_strip.tga"
scaling="stretch-to-cover-preserve-aspect"
/>
<Label class="save-indicator__label" id="StatusLabel" text="#PORTAL2_Hud_GameSaved" />
</Panel>
<HudSaveIndicator class="save-indicator">
<AnimatedImageStrip
id="Spinner"
animating="true"
defaultframe="0"
frametime="100ms"
src="file://{images}/hud/spinner_saving_strip.tga"
scaling="stretch-to-cover-preserve-aspect"
/>
<Label class="save-indicator__label" id="StatusLabel" text="#PORTAL2_Hud_GameSaved" />
</HudSaveIndicator>

</root>
5 changes: 5 additions & 0 deletions layout/pages/settings/interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
hasdocspage="false"
viewgameduringedit="true"
/>

<SettingsEnum text="#Settings_Hud_Autosave" convar="save_hud_autosave" infomessage="#Settings_Hud_Autosave_Info" hasdocspage="false">
<RadioButton group="hudautosave" text="#Common_Off" value="0" />
<RadioButton group="hudautosave" text="#Common_On" value="1" />
</SettingsEnum>
</Panel>
</Panel>
</Panel>
Expand Down
15 changes: 12 additions & 3 deletions localization/panorama_english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@
"HL2_Grenade" "Fragmentation Grenade"
"HL2_RPG" "RPG\n(Rocket-Propelled Grenade)"
"HL2_Bugbait" "Pheropod\n(Bugbait)"

"HL2_SAVING" "Saving..."
"HL2_Saved" "Saved."

"HL2_SetupMicrophone" "Configure Advanced Microphone Settings"
"HL2_SetupMicrophoneSteam" "The Steam Overlay is currently disabled.\nPlease enable the Steam Overlay or configure your microphone settings through the Steam client."
Expand Down Expand Up @@ -271,6 +268,15 @@
"Instructor_SS_Control" "Press to Control Other Player"

"Paint_Instructor_teach_bounce_suppression" "Hold to prevent bouncing"

"PORTAL2_Hud_SavingGame" "Saving Game..."
"PORTAL2_Hud_GameSaved" "Game Saved."

"PORTAL2_Hud_AutoSavingGame" "Autosaving Game..."
"PORTAL2_Hud_GameAutoSaved" "Game Autosaved."

"PORTAL2_Hud_SavingProfile" "Saving Profile..."
"PORTAL2_Hud_ProfileSaved" "Profile Saved."

// Invites
"P2COOP_Invite_Title" "Portal 2: Commnuity Edition Invite"
Expand Down Expand Up @@ -795,6 +801,9 @@
"Settings_Menu_Movie" "Main Menu Video Background"
"Settings_Menu_Movie_Info" "Enables the animated main menu background. May be a minor performance loss when the menu is open."

"Settings_Hud_Autosave" "Autosave Indicator"
"Settings_Hud_Autosave_Info" "Show an on-screen indicator when the game is automatically saved."

// Settings - Personalization
"Settings_Customization" "Customization"

Expand Down
62 changes: 62 additions & 0 deletions scripts/hud/save-indicator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

class SaveIndicator {
static fadeTimer: uuid | undefined = undefined;
static isAutoSave: boolean = false;

static {
$.RegisterForUnhandledEvent('GameSaved', this.onSaveStarted.bind(this));
$.RegisterForUnhandledEvent('LayoutReloaded', this.hide.bind(this));
$.RegisterForUnhandledEvent('LevelInitPostEntity', this.hide.bind(this));

// Workaround for animation sometimes getting stuck when pausing/unpausing
$.RegisterForUnhandledEvent('GameUIStateChanged', (old: GameUIState, now: GameUIState) => {
if (now === GameUIState.INGAME) {
$<AnimatedImageStrip>('#Spinner')!.SetReadyForDisplay(false);
}
});
}

static onSaveStarted(save_name: string, save_type: SaveType) {
if (!GameInterfaceAPI.GetSettingBool("save_hud")) return;

if (save_type == SaveType.Autosave) {
if (!GameInterfaceAPI.GetSettingBool("save_hud_autosave")) return;
this.isAutoSave = true;
} else {
this.isAutoSave = false;
}

const label = $<Label>('#StatusLabel');
label?.SetLocalizationString(this.isAutoSave ? "#PORTAL2_Hud_AutoSavingGame" : "#PORTAL2_Hud_SavingGame");

this.show();
this.fadeOutTimer();

}

static show() {
$.GetContextPanel().style.animation = 'FadeIn 0.01s ease-out 0s 1 normal forwards';
}

static hide() {
$.GetContextPanel().style.animation = 'FadeOut 0.01s ease-out 0s 1 normal forwards';
const kfs = $.GetContextPanel().CreateCopyOfCSSKeyframes('FadeOut');
$.GetContextPanel().UpdateCurrentAnimationKeyframes(kfs);
}

static fadeOutTimer() {
if (this.fadeTimer !== undefined) $.CancelScheduled(this.fadeTimer);
// TODO: Remove hardcoded delay, fadeout should start after the save finishes
this.fadeTimer = $.Schedule(1, () => {
// Update the text label to say "saved"
const label = $<Label>('#StatusLabel');
label?.SetLocalizationString(this.isAutoSave ? "#PORTAL2_Hud_GameAutoSaved" : "#PORTAL2_Hud_GameSaved");

$.GetContextPanel().style.animation = 'FadeOut 1s ease-out 0s 1 normal forwards';
const kfs = $.GetContextPanel().CreateCopyOfCSSKeyframes('FadeOut');
$.GetContextPanel().UpdateCurrentAnimationKeyframes(kfs);
this.fadeTimer = undefined;
});
}
}
1 change: 1 addition & 0 deletions scripts/util/panel-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
UiToolkitAPI.RegisterPanel2d('LineGraph', 'file://{resources}/layout/components/graphs/line-graph.xml');
UiToolkitAPI.RegisterPanel2d('VersionInfo', 'file://{resources}/layout/components/version-info.xml');
UiToolkitAPI.RegisterHUDPanel2d('WeaponSwitcher', 'file://{resources}/layout/hud/weapon-switcher.xml');
UiToolkitAPI.RegisterHUDPanel2d('SaveIndicator', 'file://{resources}/layout/hud/save-indicator.xml');
UiToolkitAPI.RegisterPanel2d('SourceIndicator', 'file://{resources}/layout/components/item-source.xml');
29 changes: 29 additions & 0 deletions styles/hud/save-indicator.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@use '../config' as *;

.save-indicator {
margin: 22px;
flow-children: right;
height: 90px;
width: fit-children;

&__label {
color: $bright-color;
font-size: 30px;

// Alternate style that matches Portal 2
// color: #dddddd;
// font-family: 'Univers LT Std 57 Cn';
// font-size: 34px;

vertical-align: center;
margin-left: 12px;
}

& > AnimatedImageStrip {
width:height-percentage(100%);
height: 100%;
}

// Temporary to prevent overlapping with VGUI version!!! Remove this!!!
margin-top: 120px;
}
Loading