Skip to content

Commit

Permalink
Added effective resolution display in wizard and Display Settings view
Browse files Browse the repository at this point in the history
fixes #1348
  • Loading branch information
vchelaru committed Feb 6, 2024
1 parent 8969ef8 commit 7cf4333
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@

<StackPanel Orientation="Horizontal">
<Label Content="{x:Static localization:Texts.Scale}" />
<Button Width="20" Margin="5" Click="ScaleMinusClicked">-</Button>
<Button Width="20" Margin="5" Click="ScaleMinusClicked" IsEnabled="{Binding IsScaleUiEnabled}">-</Button>
<TextBox Width="40" Height="18" Text="{Binding Scale}" IsEnabled="{Binding IsScaleUiEnabled}" VerticalContentAlignment="Center" KeyUp="TextBox_KeyUp"></TextBox>
<Button Width="20" Margin="5,5,0,5" Click="ScalePlusClicked">+</Button>
<Button Width="20" Margin="5,5,0,5" Click="ScalePlusClicked" IsEnabled="{Binding IsScaleUiEnabled}">+</Button>
<Label>%</Label>
</StackPanel>
<Label FontSize="10" Margin="8, -10, 0,0" Visibility="{Binding GameResolutionLabelVisibility}" Content="{Binding GameDisplayResolutionText}"></Label>

<GroupBox Margin="20,0,0,0" Background="LightYellow" Visibility="{Binding FullScreenScaleMessageVisibility}">
<StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ public int Scale
set => Set(value);
}

[DependsOn(nameof(IsScaleUiEnabled))]
public Visibility GameResolutionLabelVisibility => IsScaleUiEnabled.ToVisibility();

[DependsOn(nameof(Scale))]
[DependsOn(nameof(ResolutionWidth))]
[DependsOn(nameof(ResolutionHeight))]
public string GameDisplayResolutionText => $"Game Display Resolution: {ResolutionWidth*Scale/100}x{ResolutionHeight*Scale/100}";

[DependsOn(nameof(RunInFullScreen))]
public bool IsScaleUiEnabled => RunInFullScreen == false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public void CreatePages()
options.Add("1920x1080 (16:9)", CameraResolution._1920x1080);

formsData.AddIntValue("Game Scale%", nameof(ViewModel.ScalePercent));
formsData.AddBoundText(nameof(ViewModel.EffectiveCameraResolutionText));

formsData.AddText("The Camera Controller Entity can simplify code for following a player and staying within the bounds of a map.");

Expand Down
28 changes: 24 additions & 4 deletions FRBDK/Glue/OfficialPlugins/Wizard/Models/WizardPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ class DataItem
public StackOrFill StackOrFill { get; set; }

public int? LabelFontSize { get; set; }
/// <summary>
/// The string value to display. This is only applied if LabelBinding is not set.
/// </summary>
public string LabelText { get; set; }

/// <summary>
/// The property to bind to on the view model, allowing for labels to have dynamic text
/// </summary>
public string LabelBinding { get; set; }
public object Value { get; set; }

public string ViewModelProperty { get; set; }
Expand Down Expand Up @@ -136,6 +144,14 @@ public void AddText(string text, string visibilityBinding = null)
Add(dataItem);
}

public void AddBoundText(string dataBinding)
{
var dataItem = new DataItem { LabelText = dataBinding };
dataItem.ViewType = ViewType.TextBlock;
dataItem.LabelBinding = dataBinding;
Add(dataItem);
}

public void AddAction(string text, Action clickAction)
{
var dataItem = new DataItem { LabelText = text };
Expand Down Expand Up @@ -333,12 +349,16 @@ void TryBindVisibility(FrameworkElement element)
innerStack.Children.Add(radioButton);
}
break;
//case ViewType.RadioButton:

// break;
case ViewType.TextBlock:
var textBlock = new TextBlock();
textBlock.Text = dataItem.LabelText;
if (!string.IsNullOrEmpty(dataItem.LabelBinding))
{
textBlock.SetBinding(TextBlock.TextProperty, dataItem.LabelBinding);
}
else
{
textBlock.Text = dataItem.LabelText;
}
textBlock.TextWrapping = TextWrapping.Wrap;
if (dataItem.LabelFontSize != null)
{
Expand Down
38 changes: 38 additions & 0 deletions FRBDK/Glue/OfficialPlugins/Wizard/ViewModels/WizardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OfficialPluginsCore.Wizard.ViewModels;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows;
using System.Xml.Serialization;
Expand Down Expand Up @@ -43,6 +44,39 @@ public enum CameraResolution
_1920x1080
}

public static class CameraResolutionExtensions
{
public static int ResolutionWidth(this CameraResolution cameraResolution)
{
switch (cameraResolution)
{
case CameraResolution._256x224: return 256;
case CameraResolution._360x240: return 360;
case CameraResolution._480x360: return 480;
case CameraResolution._640x480: return 640;
case CameraResolution._800x600: return 800;
case CameraResolution._1024x768: return 1024;
case CameraResolution._1920x1080: return 1920;
}
return 0;
}

public static int ResolutionHeight(this CameraResolution cameraResolution)
{
switch (cameraResolution)
{
case CameraResolution._256x224: return 224;
case CameraResolution._360x240: return 240;
case CameraResolution._480x360: return 360;
case CameraResolution._640x480: return 480;
case CameraResolution._800x600: return 600;
case CameraResolution._1024x768: return 768;
case CameraResolution._1920x1080: return 1080;
}
return 0;
}
}

#endregion

public class WizardViewModel : ViewModel
Expand Down Expand Up @@ -327,6 +361,10 @@ public int ScalePercent
set => Set(value);
}

[DependsOn(nameof(SelectedCameraResolution))]
[DependsOn(nameof(ScalePercent))]
public string EffectiveCameraResolutionText => $"Game Display Size: {SelectedCameraResolution.ResolutionWidth() * ScalePercent/100}x{SelectedCameraResolution.ResolutionHeight() * ScalePercent/100}";

#endregion

#region Additional Entities
Expand Down

0 comments on commit 7cf4333

Please sign in to comment.