Add introduction prompt on first run.
This commit is contained in:
147
OpenRA.Mods.Common/Widgets/Logic/IntroductionPromptLogic.cs
Normal file
147
OpenRA.Mods.Common/Widgets/Logic/IntroductionPromptLogic.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class IntroductionPromptLogic : ChromeLogic
|
||||
{
|
||||
// Increment the version number when adding new stats
|
||||
const int IntroductionVersion = 1;
|
||||
|
||||
public static bool ShouldShowPrompt()
|
||||
{
|
||||
return Game.Settings.Game.IntroductionPromptVersion < IntroductionVersion;
|
||||
}
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public IntroductionPromptLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, Action onComplete)
|
||||
{
|
||||
var ps = Game.Settings.Player;
|
||||
var ds = Game.Settings.Graphics;
|
||||
var gs = Game.Settings.Game;
|
||||
|
||||
var escPressed = false;
|
||||
var nameTextfield = widget.Get<TextFieldWidget>("PLAYERNAME");
|
||||
nameTextfield.IsDisabled = () => worldRenderer.World.Type != WorldType.Shellmap;
|
||||
nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name);
|
||||
nameTextfield.OnLoseFocus = () =>
|
||||
{
|
||||
if (escPressed)
|
||||
{
|
||||
escPressed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
nameTextfield.Text = nameTextfield.Text.Trim();
|
||||
if (nameTextfield.Text.Length == 0)
|
||||
nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name);
|
||||
else
|
||||
{
|
||||
nameTextfield.Text = Settings.SanitizedPlayerName(nameTextfield.Text);
|
||||
ps.Name = nameTextfield.Text;
|
||||
}
|
||||
};
|
||||
|
||||
nameTextfield.OnEnterKey = () => { nameTextfield.YieldKeyboardFocus(); return true; };
|
||||
nameTextfield.OnEscKey = () =>
|
||||
{
|
||||
nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name);
|
||||
escPressed = true;
|
||||
nameTextfield.YieldKeyboardFocus();
|
||||
return true;
|
||||
};
|
||||
|
||||
var colorPreview = widget.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
|
||||
colorPreview.Color = ps.Color;
|
||||
|
||||
var mouseControlDescClassic = widget.Get("MOUSE_CONTROL_DESC_CLASSIC");
|
||||
mouseControlDescClassic.IsVisible = () => gs.UseClassicMouseStyle;
|
||||
|
||||
var classicScrollRight = mouseControlDescClassic.Get("DESC_SCROLL_RIGHT");
|
||||
classicScrollRight.IsVisible = () => !gs.ClassicMouseMiddleScroll;
|
||||
|
||||
var classicScrollMiddle = mouseControlDescClassic.Get("DESC_SCROLL_MIDDLE");
|
||||
classicScrollMiddle.IsVisible = () => gs.ClassicMouseMiddleScroll;
|
||||
|
||||
var mouseControlDescModern = widget.Get("MOUSE_CONTROL_DESC_MODERN");
|
||||
mouseControlDescModern.IsVisible = () => !gs.UseClassicMouseStyle;
|
||||
|
||||
var mouseControlDropdown = widget.Get<DropDownButtonWidget>("MOUSE_CONTROL_DROPDOWN");
|
||||
mouseControlDropdown.OnMouseDown = _ => SettingsLogic.ShowMouseControlDropdown(mouseControlDropdown, gs);
|
||||
mouseControlDropdown.GetText = () => gs.UseClassicMouseStyle ? "Classic" : "Modern";
|
||||
|
||||
foreach (var container in new[] { mouseControlDescClassic, mouseControlDescModern })
|
||||
{
|
||||
var zoomDesc = container.Get("DESC_ZOOM");
|
||||
zoomDesc.IsVisible = () => gs.ZoomModifier == Modifiers.None;
|
||||
|
||||
var zoomDescModifier = container.Get<LabelWidget>("DESC_ZOOM_MODIFIER");
|
||||
zoomDescModifier.IsVisible = () => gs.ZoomModifier != Modifiers.None;
|
||||
|
||||
var zoomDescModifierTemplate = zoomDescModifier.Text;
|
||||
var zoomDescModifierLabel = new CachedTransform<Modifiers, string>(
|
||||
mod => zoomDescModifierTemplate.Replace("MODIFIER", mod.ToString()));
|
||||
zoomDescModifier.GetText = () => zoomDescModifierLabel.Update(gs.ZoomModifier);
|
||||
|
||||
var edgescrollDesc = container.Get<LabelWidget>("DESC_EDGESCROLL");
|
||||
edgescrollDesc.IsVisible = () => gs.ViewportEdgeScroll;
|
||||
}
|
||||
|
||||
SettingsLogic.BindCheckboxPref(widget, "EDGESCROLL_CHECKBOX", gs, "ViewportEdgeScroll");
|
||||
|
||||
var colorDropdown = widget.Get<DropDownButtonWidget>("PLAYERCOLOR");
|
||||
colorDropdown.IsDisabled = () => worldRenderer.World.Type != WorldType.Shellmap;
|
||||
colorDropdown.OnMouseDown = _ => ColorPickerLogic.ShowColorDropDown(colorDropdown, colorPreview, worldRenderer.World);
|
||||
colorDropdown.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => ps.Color;
|
||||
|
||||
var viewportSizes = modData.Manifest.Get<WorldViewportSizes>();
|
||||
var battlefieldCameraDropDown = widget.Get<DropDownButtonWidget>("BATTLEFIELD_CAMERA_DROPDOWN");
|
||||
var battlefieldCameraLabel = new CachedTransform<WorldViewport, string>(vs => SettingsLogic.ViewportSizeNames[vs]);
|
||||
battlefieldCameraDropDown.OnMouseDown = _ => SettingsLogic.ShowBattlefieldCameraDropdown(battlefieldCameraDropDown, viewportSizes, ds);
|
||||
battlefieldCameraDropDown.GetText = () => battlefieldCameraLabel.Update(ds.ViewportDistance);
|
||||
|
||||
var uiScaleDropdown = widget.Get<DropDownButtonWidget>("UI_SCALE_DROPDOWN");
|
||||
var uiScaleLabel = new CachedTransform<float, string>(s => "{0}%".F((int)(100 * s)));
|
||||
uiScaleDropdown.OnMouseDown = _ => SettingsLogic.ShowUIScaleDropdown(uiScaleDropdown, ds);
|
||||
uiScaleDropdown.GetText = () => uiScaleLabel.Update(ds.UIScale);
|
||||
|
||||
var minResolution = viewportSizes.MinEffectiveResolution;
|
||||
var resolution = Game.Renderer.Resolution;
|
||||
var disableUIScale = worldRenderer.World.Type != WorldType.Shellmap ||
|
||||
resolution.Width * ds.UIScale < 1.25f * minResolution.Width ||
|
||||
resolution.Height * ds.UIScale < 1.25f * minResolution.Height;
|
||||
|
||||
uiScaleDropdown.IsDisabled = () => disableUIScale;
|
||||
|
||||
SettingsLogic.BindCheckboxPref(widget, "CURSORDOUBLE_CHECKBOX", ds, "CursorDouble");
|
||||
|
||||
widget.Get<ButtonWidget>("CONTINUE_BUTTON").OnClick = () =>
|
||||
{
|
||||
Game.Settings.Game.IntroductionPromptVersion = IntroductionVersion;
|
||||
Game.Settings.Save();
|
||||
Ui.CloseWindow();
|
||||
onComplete();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,21 +226,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
|
||||
menuType = MenuType.StartupPrompts;
|
||||
Action onSysInfoComplete = () =>
|
||||
|
||||
Action onIntroductionComplete = () =>
|
||||
{
|
||||
LoadAndDisplayNews(webServices.GameNews, newsBG);
|
||||
SwitchMenu(MenuType.Main);
|
||||
Action onSysInfoComplete = () =>
|
||||
{
|
||||
LoadAndDisplayNews(webServices.GameNews, newsBG);
|
||||
SwitchMenu(MenuType.Main);
|
||||
};
|
||||
|
||||
if (SystemInfoPromptLogic.ShouldShowPrompt())
|
||||
{
|
||||
Ui.OpenWindow("MAINMENU_SYSTEM_INFO_PROMPT", new WidgetArgs
|
||||
{
|
||||
{ "onComplete", onSysInfoComplete }
|
||||
});
|
||||
}
|
||||
else
|
||||
onSysInfoComplete();
|
||||
};
|
||||
|
||||
if (SystemInfoPromptLogic.ShouldShowPrompt())
|
||||
if (IntroductionPromptLogic.ShouldShowPrompt())
|
||||
{
|
||||
Ui.OpenWindow("MAINMENU_SYSTEM_INFO_PROMPT", new WidgetArgs
|
||||
Game.OpenWindow("MAINMENU_INTRODUCTION_PROMPT", new WidgetArgs
|
||||
{
|
||||
{ "onComplete", onSysInfoComplete }
|
||||
{ "onComplete", onIntroductionComplete }
|
||||
});
|
||||
}
|
||||
else
|
||||
onSysInfoComplete();
|
||||
onIntroductionComplete();
|
||||
|
||||
Game.OnShellmapLoaded += OpenMenuBasedOnLastGame;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
};
|
||||
}
|
||||
|
||||
static void BindCheckboxPref(Widget parent, string id, object group, string pref)
|
||||
public static void BindCheckboxPref(Widget parent, string id, object group, string pref)
|
||||
{
|
||||
var field = group.GetType().GetField(pref);
|
||||
if (field == null)
|
||||
@@ -221,7 +221,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
resetPanelActions.Add(type, reset(panel));
|
||||
}
|
||||
|
||||
static readonly Dictionary<WorldViewport, string> ViewportSizeNames = new Dictionary<WorldViewport, string>()
|
||||
public static readonly Dictionary<WorldViewport, string> ViewportSizeNames = new Dictionary<WorldViewport, string>()
|
||||
{
|
||||
{ WorldViewport.Close, "Close" },
|
||||
{ WorldViewport.Medium, "Medium" },
|
||||
@@ -697,7 +697,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
};
|
||||
}
|
||||
|
||||
static void ShowMouseControlDropdown(DropDownButtonWidget dropdown, GameSettings s)
|
||||
public static void ShowMouseControlDropdown(DropDownButtonWidget dropdown, GameSettings s)
|
||||
{
|
||||
var options = new Dictionary<string, bool>()
|
||||
{
|
||||
@@ -880,7 +880,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem);
|
||||
}
|
||||
|
||||
static void ShowBattlefieldCameraDropdown(DropDownButtonWidget dropdown, WorldViewportSizes viewportSizes, GraphicSettings gs)
|
||||
public static void ShowBattlefieldCameraDropdown(DropDownButtonWidget dropdown, WorldViewportSizes viewportSizes, GraphicSettings gs)
|
||||
{
|
||||
Func<WorldViewport, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
|
||||
{
|
||||
@@ -949,7 +949,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
RecalculateWidgetLayout(c, insideScrollPanel || w is ScrollPanelWidget);
|
||||
}
|
||||
|
||||
static void ShowUIScaleDropdown(DropDownButtonWidget dropdown, GraphicSettings gs)
|
||||
public static void ShowUIScaleDropdown(DropDownButtonWidget dropdown, GraphicSettings gs)
|
||||
{
|
||||
Func<float, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user