Skip to content

Commit

Permalink
Add support for custom fonts to facilitate modded localizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachHembree committed Mar 1, 2023
1 parent dc0960b commit bd4b8ca
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 12 deletions.
6 changes: 5 additions & 1 deletion BuildVision2/Data/Scripts/BuildVision2/Config/ConfigTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public class UIConfig : Config<UIConfig>
[XmlElement(ElementName = "HudPosition")]
public Vector2 hudPos;

[XmlElement(ElementName = "FontName")]
public string fontName;

protected override UIConfig GetDefaults()
{
return new UIConfig
Expand All @@ -171,7 +174,8 @@ protected override UIConfig GetDefaults()
wheelMaxVisible = 16,
clampHudPos = true,
useCustomPos = false,
hudPos = new Vector2(-0.4823f, 0.4676f)
hudPos = new Vector2(-0.4823f, 0.4676f),
fontName = "SpaceEngineers"
};
}

Expand Down
26 changes: 26 additions & 0 deletions BuildVision2/Data/Scripts/BuildVision2/Input/SettingsMenu.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using RichHudFramework;
using RichHudFramework.Internal;
using RichHudFramework.UI;
using RichHudFramework.UI.Rendering;
using RichHudFramework.UI.Client;
using System;
using System.Collections.Generic;
using System.Text;
using VRage;
using VRageMath;
using RichHudFramework.UI.Rendering.Client;

namespace DarkHelmet.BuildVision2
{
Expand Down Expand Up @@ -389,6 +391,28 @@ private ControlCategory GetGuiSettings()
setPosition,
};

var fontSelection = new TerminalDropdown<string>()
{
Name = "Font",
ControlChangedHandler = (sender, args) =>
{
var dd = sender as TerminalDropdown<string>;
BvConfig.Current.genUI.fontName = dd.Value.AssocObject;
}
};

var loadFontsButton = new TerminalButton()
{
Name = "Load Fonts",
ControlChangedHandler = (sender, args) =>
{
fontSelection.List.Clear();

foreach (IFontMin font in FontManager.Fonts)
fontSelection.List.Add(font.Name, font.Name);
}
};

var resetGuiButton = new TerminalButton()
{
Name = "Reset GUI settings",
Expand All @@ -397,6 +421,8 @@ private ControlCategory GetGuiSettings()

var tile5 = new ControlTile()
{
fontSelection,
loadFontsButton,
resetGuiButton,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using RichHudFramework.UI.Rendering;
using RichHudFramework.UI.Client;
using RichHudFramework.Internal;
using RichHudFramework.UI.Rendering.Client;

namespace DarkHelmet.BuildVision2
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using RichHudFramework.UI.Rendering;
using RichHudFramework.UI.Client;
using RichHudFramework.Internal;
using RichHudFramework.UI.Rendering.Client;

namespace DarkHelmet.BuildVision2
{
Expand Down Expand Up @@ -91,47 +92,47 @@ public PropertyWheelMenu(QuickActionMenu parent) : base(null)
{
new PropertyWheelShortcutEntry()
{
Text = "Back",
Text = MyTexts.TrySubstitute("Back"),
ShortcutAction = quickActionMenu.StopPropertyDuplication,
},
new PropertyWheelShortcutEntry()
{
Text = "Open List",
Text = MyTexts.TrySubstitute("Open List"),
ShortcutAction = quickActionMenu.OpenDupeList,
},
new PropertyWheelShortcutEntry()
{
Text = "Open List and Select All",
Text = MyTexts.TrySubstitute("Open List and Select All"),
ShortcutAction = quickActionMenu.OpenDupeListAndSelectAll,
},
new PropertyWheelShortcutEntry()
{
Text = "Clear Selection",
Text = MyTexts.TrySubstitute("Clear Selection"),
ShortcutAction = quickActionMenu.ClearSelection,
},
new PropertyWheelShortcutEntry()
{
Text = "Copy Selected",
Text = MyTexts.TrySubstitute("Copy Selected"),
ShortcutAction = quickActionMenu.CopySelectedProperties,
},
new PropertyWheelShortcutEntry()
{
Text = "Copy All but Name",
Text = MyTexts.TrySubstitute("Copy All but Name"),
ShortcutAction = () => quickActionMenu.CopyAllProperties(false),
},
new PropertyWheelShortcutEntry()
{
Text = "Copy All",
Text = MyTexts.TrySubstitute("Copy All"),
ShortcutAction = () => quickActionMenu.CopyAllProperties(true),
},
new PropertyWheelShortcutEntry()
{
Text = "Paste",
Text = MyTexts.TrySubstitute("Paste"),
ShortcutAction = quickActionMenu.PasteCopiedProperties,
},
new PropertyWheelShortcutEntry()
{
Text = "Undo",
Text = MyTexts.TrySubstitute("Undo"),
ShortcutAction = quickActionMenu.UndoPropertyPaste,
},
}
Expand All @@ -143,7 +144,7 @@ public PropertyWheelMenu(QuickActionMenu parent) : base(null)
{
new PropertyWheelShortcutEntry()
{
Text = "Copy Settings",
Text = MyTexts.TrySubstitute("Copy Settings"),
ShortcutAction = () =>
{
MenuState = QuickActionMenuState.WheelMenuControl;
Expand Down Expand Up @@ -192,6 +193,22 @@ public void OpenMenu()
propertyWheel.Add(entry);
}

// Update shortcut font
IFontMin cfgFont = FontManager.GetFont(BvConfig.Current.genUI.fontName);

if (cfgFont != null)
{
foreach (PropertyWheelShortcutEntry entry in shortcutEntries)
{
entry.TextBoard.SetFormatting(entry.TextBoard.Format.WithFont(cfgFont));
}

foreach (PropertyWheelShortcutEntry entry in dupeWheel)
{
entry.TextBoard.SetFormatting(entry.TextBoard.Format.WithFont(cfgFont));
}
}

// Append registered shortcuts to end
propertyWheel.AddRange(shortcutEntries);
propertyWheel.SetHighlightAt(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using RichHudFramework.UI;
using RichHudFramework.UI.Rendering;
using RichHudFramework.UI.Rendering.Client;
using System;
using VRageMath;

Expand Down Expand Up @@ -36,6 +38,8 @@ public ColorWidget(HudParentBase parent = null) : base(parent)

public override void SetData(object member, Action CloseWidgetCallback)
{
SetFont(FontManager.GetFont(BvConfig.Current.genUI.fontName));

colorMember = member as IBlockValue<Color>;
this.CloseWidgetCallback = CloseWidgetCallback;

Expand All @@ -57,6 +61,17 @@ public override void Reset()
CloseWidgetCallback = null;
}

protected override void SetFont(IFontMin newFont)
{
base.SetFont(newFont);

if (newFont != null)
{
colorPicker.NameBuilder.SetFormatting(colorPicker.NameBuilder.Format.WithFont(newFont));
colorPicker.ValueFormat = colorPicker.ValueFormat.WithFont(newFont);
}
}

protected override void Confirm()
{
if (channelSelected || IsMousedOver)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using RichHudFramework.UI;
using RichHudFramework.UI.Rendering;
using RichHudFramework.UI.Rendering.Client;
using System;
using VRageMath;

Expand Down Expand Up @@ -36,6 +38,8 @@ public ColorWidgetHSV(HudParentBase parent = null) : base(parent)

public override void SetData(object member, Action CloseWidgetCallback)
{
SetFont(FontManager.GetFont(BvConfig.Current.genUI.fontName));

colorMember = member as IBlockValue<Vector3>;
this.CloseWidgetCallback = CloseWidgetCallback;

Expand All @@ -57,6 +61,17 @@ public override void Reset()
CloseWidgetCallback = null;
}

protected override void SetFont(IFontMin newFont)
{
base.SetFont(newFont);

if (newFont != null)
{
colorPicker.NameBuilder.SetFormatting(colorPicker.NameBuilder.Format.WithFont(newFont));
colorPicker.ValueFormat = colorPicker.ValueFormat.WithFont(newFont);
}
}

protected override void Confirm()
{
if (channelSelected || IsMousedOver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Text;
using System.Collections.Generic;
using VRageMath;
using RichHudFramework.UI.Rendering.Client;
using RichHudFramework.UI.Rendering;

namespace DarkHelmet.BuildVision2
{
Expand Down Expand Up @@ -38,6 +40,8 @@ public ComboWidget(HudParentBase parent = null) : base(parent)

public override void SetData(object member, Action CloseWidgetCallback)
{
SetFont(FontManager.GetFont(BvConfig.Current.genUI.fontName));

blockComboMember = member as IBlockComboBox;
this.CloseWidgetCallback = CloseWidgetCallback;

Expand All @@ -58,6 +62,16 @@ public override void Reset()
comboBox.ClearEntries();
}

protected override void SetFont(IFontMin newFont)
{
base.SetFont(newFont);

if (newFont != null)
{
comboBox.Format = comboBox.Format.WithFont(newFont);
}
}

protected override void Confirm()
{
if (comboBox.SelectionIndex != -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Sandbox.ModAPI;
using VRage.Utils;
using VRageMath;
using RichHudFramework.UI.Rendering.Client;

namespace DarkHelmet.BuildVision2
{
Expand Down Expand Up @@ -43,6 +44,8 @@ public FloatWidget(HudParentBase parent = null) : base(parent)

public override void SetData(object member, Action CloseWidgetCallback)
{
SetFont(FontManager.GetFont(BvConfig.Current.genUI.fontName));

floatMember = member as IBlockNumericValue<float>;
textMember = member as IBlockTextMember;
this.CloseWidgetCallback = CloseWidgetCallback;
Expand All @@ -63,6 +66,18 @@ public override void SetData(object member, Action CloseWidgetCallback)
}
}

protected override void SetFont(IFontMin newFont)
{
base.SetFont(newFont);

if (newFont != null)
{
sliderBox.NameBuilder.SetFormatting(sliderBox.NameBuilder.Format.WithFont(newFont));
sliderBox.ValueBuilder.SetFormatting(sliderBox.ValueBuilder.Format.WithFont(newFont));
sliderBox.FieldText.SetFormatting(sliderBox.FieldText.Format.WithFont(newFont));
}
}

public override void Reset()
{
floatMember = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using RichHudFramework.UI;
using RichHudFramework.UI.Client;
using RichHudFramework.UI.Rendering.Client;
using RichHudFramework.UI.Rendering;
using System;
using System.Reflection.Emit;
using VRageMath;
using VRage;
using VRage.Utils;

namespace DarkHelmet.BuildVision2
{
Expand Down Expand Up @@ -90,6 +95,18 @@ protected override void HandleInput(Vector2 cursorPos)
protected abstract void Confirm();

protected abstract void Cancel();

protected virtual void SetFont(IFontMin newFont)
{
if (newFont != null)
{
confirmButton.Format = confirmButton.Format.WithFont(newFont);
cancelButton.Format = cancelButton.Format.WithFont(newFont);

confirmButton.Text = MyTexts.TrySubstitute("Confirm");
confirmButton.Text = MyTexts.TrySubstitute("Cancel");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Sandbox.ModAPI;
using VRage.Utils;
using VRageMath;
using RichHudFramework.UI.Rendering.Client;
using RichHudFramework.UI.Rendering;

namespace DarkHelmet.BuildVision2
{
Expand Down Expand Up @@ -43,6 +45,8 @@ public TextWidget(HudParentBase parent = null) : base(parent)

public override void SetData(object member, Action CloseWidgetCallback)
{
SetFont(FontManager.GetFont(BvConfig.Current.genUI.fontName));

textValueMember = member as IBlockValue<StringBuilder>;
textMember = member as IBlockTextMember;
this.CloseWidgetCallback = CloseWidgetCallback;
Expand All @@ -61,6 +65,17 @@ public override void SetData(object member, Action CloseWidgetCallback)
textField.MouseInput.GetInputFocus();
}

protected override void SetFont(IFontMin newFont)
{
base.SetFont(newFont);

if (newFont != null)
{
label.TextBoard.SetFormatting(label.TextBoard.Format.WithFont(newFont));
textField.TextBoard.SetFormatting(textField.TextBoard.Format.WithFont(newFont));
}
}

public override void Reset()
{
CloseWidgetCallback = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public QuickActionMenu(HudParentBase parent = null) : base(parent)
if ((MenuState & QuickActionMenuState.Peek) == 0)
{
CloseMenu();
SetFont(BvConfig.Current.genUI.fontName);

if (initialState != default(QuickActionMenuState))
{
Expand Down
Loading

0 comments on commit bd4b8ca

Please sign in to comment.