Skip to content

Commit ff6ca9c

Browse files
committed
Merge remote-tracking branch 'tmpe/master' into u-more-osd2
2 parents c236a30 + 5eff305 commit ff6ca9c

File tree

9 files changed

+95
-70
lines changed

9 files changed

+95
-70
lines changed

TLM/TLM/State/ConfigData/Main.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class Main {
3232
public bool EnableTutorial = true;
3333

3434
/// <summary>Determines if the main menu shall be displayed in a tiny format.</summary>
35-
[Obsolete("Do not use. Main Menu now scales based on screen size")]
35+
[Obsolete("Do not use. TM:PE now has UI scale slider")]
3636
public bool TinyMainMenu = true;
3737

3838
/// <summary>User interface transparency, unit: percents, range: 0..100.</summary>

TLM/TLM/State/GlobalConfig.cs

-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ private static GlobalConfig WriteDefaultConfig(GlobalConfig oldConfig, bool rese
9898
conf.Main.GuiOpacity = oldConfig.Main.GuiOpacity;
9999
conf.Main.OverlayTransparency = oldConfig.Main.OverlayTransparency;
100100

101-
// conf.Main.TinyMainMenu = oldConfig.Main.TinyMainMenu;
102-
103101
conf.Main.EnableTutorial = oldConfig.Main.EnableTutorial;
104102
conf.Main.DisplayedTutorialMessages = oldConfig.Main.DisplayedTutorialMessages;
105103
}

TLM/TLM/State/OptionsTabs/OptionsGameplayTab.cs

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ private static void OnAltLaneSelectionRatioChanged(float newVal) {
167167
_altLaneSelectionRatioSlider.tooltip =
168168
Translation.Options.Get("Gameplay.Tooltip:DLS_percentage") + ": " +
169169
Options.altLaneSelectionRatio + " %";
170+
_altLaneSelectionRatioSlider.RefreshTooltip();
170171

171172
Log._Debug($"altLaneSelectionRatio changed to {Options.altLaneSelectionRatio}");
172173
}

TLM/TLM/State/OptionsTabs/OptionsGeneralTab.cs

+39-36
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public static class OptionsGeneralTab {
4545
internal static void MakeSettings_General(ExtUITabstrip tabStrip) {
4646
UIHelper panelHelper = tabStrip.AddTabPage(T("Tab:General"));
4747

48-
UIHelperBase generalGroup = panelHelper.AddGroup(
49-
T("Tab:General"));
48+
UIHelperBase generalGroup = panelHelper.AddGroup(T("Tab:General"));
5049
string[] languageLabels = new string[Translation.AvailableLanguageCodes.Count + 1];
5150
languageLabels[0] = T("General.Dropdown.Option:Game language");
5251

5352
for (int i = 0; i < Translation.AvailableLanguageCodes.Count; ++i) {
5453
languageLabels[i + 1] = Translation.Options.Get(
55-
Translation.AvailableLanguageCodes[i], "General.Dropdown.Option:Language Name");
54+
lang: Translation.AvailableLanguageCodes[i],
55+
key: "General.Dropdown.Option:Language Name");
5656
}
5757

5858
int languageIndex = 0;
@@ -68,18 +68,18 @@ internal static void MakeSettings_General(ExtUITabstrip tabStrip) {
6868
}
6969

7070
_languageDropdown = generalGroup.AddDropdown(
71-
T("General.Dropdown:Select language") + ":",
72-
languageLabels,
73-
languageIndex,
74-
OnLanguageChanged) as UIDropDown;
71+
text: T("General.Dropdown:Select language") + ":",
72+
options: languageLabels,
73+
defaultSelection: languageIndex,
74+
eventCallback: OnLanguageChanged) as UIDropDown;
7575
_lockButtonToggle = generalGroup.AddCheckbox(
76-
T("General.Checkbox:Lock main menu button position"),
77-
GlobalConfig.Instance.Main.MainMenuButtonPosLocked,
78-
OnLockButtonChanged) as UICheckBox;
76+
text: T("General.Checkbox:Lock main menu button position"),
77+
defaultValue: GlobalConfig.Instance.Main.MainMenuButtonPosLocked,
78+
eventCallback: OnLockButtonChanged) as UICheckBox;
7979
_lockMenuToggle = generalGroup.AddCheckbox(
80-
T("General.Checkbox:Lock main menu window position"),
81-
GlobalConfig.Instance.Main.MainMenuPosLocked,
82-
OnLockMenuChanged) as UICheckBox;
80+
text: T("General.Checkbox:Lock main menu window position"),
81+
defaultValue: GlobalConfig.Instance.Main.MainMenuPosLocked,
82+
eventCallback: OnLockMenuChanged) as UICheckBox;
8383

8484
_guiScaleSlider = generalGroup.AddSlider(
8585
text: T("General.Slider:GUI scale") + ":",
@@ -122,9 +122,9 @@ internal static void MakeSettings_General(ExtUITabstrip tabStrip) {
122122
GlobalConfig.Instance.Main.ScanForKnownIncompatibleModsAtStartup,
123123
OnScanForKnownIncompatibleModsChanged) as UICheckBox;
124124
_ignoreDisabledModsToggle = generalGroup.AddCheckbox(
125-
Translation.ModConflicts.Get("Checkbox:Ignore disabled mods"),
126-
GlobalConfig.Instance.Main.IgnoreDisabledMods,
127-
OnIgnoreDisabledModsChanged) as UICheckBox;
125+
text: Translation.ModConflicts.Get("Checkbox:Ignore disabled mods"),
126+
defaultValue: GlobalConfig.Instance.Main.IgnoreDisabledMods,
127+
eventCallback: OnIgnoreDisabledModsChanged) as UICheckBox;
128128
Options.Indent(_ignoreDisabledModsToggle);
129129

130130
// General: Speed Limits
@@ -133,28 +133,28 @@ internal static void MakeSettings_General(ExtUITabstrip tabStrip) {
133133
// General: Simulation
134134
UIHelperBase simGroup = panelHelper.AddGroup(T("General.Group:Simulation"));
135135
_simulationAccuracyDropdown = simGroup.AddDropdown(
136-
T("General.Dropdown:Simulation accuracy") + ":",
137-
new[] {
138-
T("General.Dropdown.Option:Very low"),
139-
T("General.Dropdown.Option:Low"),
140-
T("General.Dropdown.Option:Medium"),
141-
T("General.Dropdown.Option:High"),
142-
T("General.Dropdown.Option:Very high")
143-
},
144-
(int)Options.simulationAccuracy,
145-
OnSimulationAccuracyChanged) as UIDropDown;
136+
text: T("General.Dropdown:Simulation accuracy") + ":",
137+
options: new[] {
138+
T("General.Dropdown.Option:Very low"),
139+
T("General.Dropdown.Option:Low"),
140+
T("General.Dropdown.Option:Medium"),
141+
T("General.Dropdown.Option:High"),
142+
T("General.Dropdown.Option:Very high"),
143+
},
144+
defaultSelection: (int)Options.simulationAccuracy,
145+
eventCallback: OnSimulationAccuracyChanged) as UIDropDown;
146146

147147
_instantEffectsToggle = simGroup.AddCheckbox(
148-
T("General.Checkbox:Apply AI changes right away"),
149-
Options.instantEffects,
150-
OnInstantEffectsChanged) as UICheckBox;
148+
text: T("General.Checkbox:Apply AI changes right away"),
149+
defaultValue: Options.instantEffects,
150+
eventCallback: OnInstantEffectsChanged) as UICheckBox;
151151
}
152152

153153
private static void SetupSpeedLimitsPanel(UIHelperBase generalGroup) {
154154
_displayMphToggle = generalGroup.AddCheckbox(
155-
Translation.SpeedLimits.Get("Checkbox:Display speed limits mph"),
156-
GlobalConfig.Instance.Main.DisplaySpeedLimitsMph,
157-
OnDisplayMphChanged) as UICheckBox;
155+
text: Translation.SpeedLimits.Get("Checkbox:Display speed limits mph"),
156+
defaultValue: GlobalConfig.Instance.Main.DisplaySpeedLimitsMph,
157+
eventCallback: OnDisplayMphChanged) as UICheckBox;
158158
string[] mphThemeOptions = {
159159
Translation.SpeedLimits.Get("General.Theme.Option:Square US"),
160160
Translation.SpeedLimits.Get("General.Theme.Option:Round UK"),
@@ -163,10 +163,10 @@ private static void SetupSpeedLimitsPanel(UIHelperBase generalGroup) {
163163
_roadSignMphStyleInt = (int)GlobalConfig.Instance.Main.MphRoadSignStyle;
164164
_roadSignsMphThemeDropdown
165165
= generalGroup.AddDropdown(
166-
Translation.SpeedLimits.Get("General.Dropdown:Road signs theme mph") + ":",
167-
mphThemeOptions,
168-
_roadSignMphStyleInt,
169-
OnRoadSignsMphThemeChanged) as UIDropDown;
166+
text: Translation.SpeedLimits.Get("General.Dropdown:Road signs theme mph") + ":",
167+
options: mphThemeOptions,
168+
defaultSelection: _roadSignMphStyleInt,
169+
eventCallback: OnRoadSignsMphThemeChanged) as UIDropDown;
170170
_roadSignsMphThemeDropdown.width = 400;
171171
}
172172

@@ -243,6 +243,7 @@ private static void OnGuiOpacityChanged(float newVal) {
243243
= string.Format(
244244
T("General.Tooltip.Format:Window transparency: {0}%"),
245245
GlobalConfig.Instance.Main.GuiOpacity);
246+
_guiOpacitySlider.RefreshTooltip();
246247

247248
GlobalConfig.WriteConfig();
248249
Log._Debug($"GuiTransparency changed to {GlobalConfig.Instance.Main.GuiOpacity}");
@@ -254,6 +255,7 @@ private static void OnGuiScaleChanged(float newVal) {
254255
= string.Format(
255256
T("General.Tooltip.Format:GUI scale: {0}%"),
256257
GlobalConfig.Instance.Main.GuiScale);
258+
_guiScaleSlider.RefreshTooltip();
257259

258260
GlobalConfig.WriteConfig();
259261
Log._Debug($"GuiScale changed to {GlobalConfig.Instance.Main.GuiScale}");
@@ -269,6 +271,7 @@ private static void OnOverlayTransparencyChanged(float newVal) {
269271
T("General.Tooltip.Format:Overlay transparency: {0}%"),
270272
GlobalConfig.Instance.Main.OverlayTransparency);
271273
GlobalConfig.WriteConfig();
274+
_overlayTransparencySlider.RefreshTooltip();
272275
Log._Debug($"Overlay transparency changed to {GlobalConfig.Instance.Main.OverlayTransparency}");
273276
}
274277

TLM/TLM/U/UIUtil.cs

+40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
namespace TrafficManager.U {
22
using System.Collections.Generic;
33
using System.Linq;
4+
using ColossalFramework.UI;
5+
using CSUtil.Commons;
46
using UnityEngine;
57

68
/// <summary>
@@ -27,5 +29,43 @@ IEnumerable<GameObject> objects
2729

2830
toMakeUnique.name = name;
2931
}
32+
33+
/// <summary>
34+
/// Checks <paramref name="alwaysVisible"/> and if it is anywhere outside the screen, brings
35+
/// it back into the screen, the <paramref name="window"/> is moved by that delta instead.
36+
/// This is to be called after the resize, and also after the move.
37+
/// </summary>
38+
/// <param name="window">Parent to be moved.</param>
39+
/// <param name="alwaysVisible">Object to be clamped to screen.</param>
40+
/// <returns>True if the position changed.</returns>
41+
public static bool ClampToScreen(UIComponent window, UIComponent alwaysVisible) {
42+
Rect origRect = new Rect(
43+
position: alwaysVisible.absolutePosition,
44+
size: alwaysVisible.size);
45+
46+
Rect clampedRect = new Rect(origRect);
47+
48+
VectorUtil.ClampRectToScreen(
49+
rect: ref clampedRect,
50+
resolution: new Vector2(UIScaler.GUI_WIDTH, UIScaler.GUI_HEIGHT));
51+
52+
float xMotion = clampedRect.x - origRect.x;
53+
float yMotion = clampedRect.y - origRect.y;
54+
55+
// Nothing to do, return here
56+
if (Mathf.Approximately(xMotion, 0f) && Mathf.Approximately(yMotion, 0f)) {
57+
return false;
58+
}
59+
60+
// Move the parent window by the difference
61+
Vector3 pos = window.absolutePosition;
62+
pos += new Vector3(xMotion, yMotion, 0f);
63+
window.absolutePosition = pos;
64+
65+
Log._Debug(
66+
$"Clamping origRect={origRect} to new={clampedRect} "
67+
+ $"moving by {xMotion};{yMotion} newpos={pos}");
68+
return true;
69+
}
3070
}
3171
}

TLM/TLM/UI/MainMenu/MainMenuWindow.cs

+14-22
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class MainMenuWindow
2222
{
2323
public const int DEFAULT_MENU_X = 85;
2424
public const int DEFAULT_MENU_Y = 60;
25+
public const string WINDOW_CONTROL_NAME = "TMPE_MainMenu_Window";
2526

2627
/// <summary>
2728
/// Panel floating below the main menu and shows keybinds and mouse shortcuts.
@@ -130,7 +131,9 @@ private static readonly MenuButtonDef[] EXTRA_BUTTON_DEFS
130131
public override void Start() {
131132
base.Start();
132133

133-
U.UIUtil.MakeUniqueAndSetName(this.gameObject, "TMPE_MainMenuWindow");
134+
U.UIUtil.MakeUniqueAndSetName(
135+
toMakeUnique: this.gameObject,
136+
name: WINDOW_CONTROL_NAME);
134137

135138
GlobalConfig conf = GlobalConfig.Instance;
136139

@@ -166,7 +169,7 @@ internal static MainMenuWindow CreateMainMenuWindow() {
166169

167170
/// <summary>Called from constructor to setup own properties and events.</summary>
168171
private void SetupWindow() {
169-
this.name = "TMPE_MainMenu_Window";
172+
this.name = WINDOW_CONTROL_NAME;
170173
this.isVisible = false;
171174
this.backgroundSprite = "GenericPanel";
172175
this.color = new Color32(64, 64, 64, 240);
@@ -344,9 +347,6 @@ private void OnToggleOsdButtonClicked(U.Button.UButton button) {
344347

345348
// Refer to the TrafficManager tool asking it to request help from the current tool
346349
ModUI.GetTrafficManagerTool().RequestOnscreenDisplayUpdate();
347-
348-
// The task is delayed till next GUI update frame.
349-
// ModUI.GetTrafficManagerTool().InvalidateOnscreenDisplayFlag = true;
350350
}
351351

352352
private void SetupControls_DebugLabels(UiBuilder<MainMenuWindow> builder,
@@ -459,11 +459,11 @@ public override void OnBeforeResizerUpdate() {
459459
/// <summary>Called by UResizer for every control to be 'resized'.</summary>
460460
public override void OnAfterResizerUpdate() {
461461
if (this.DragHandle != null) {
462-
// Resize to the window width but remember there's padding on the left
463-
// this.DragHandle.size = new Vector2(x: this.width - (UConst.UIPADDING * 2f),
464-
// y: this.VersionLabel.height);
465-
466462
this.DragHandle.size = this.VersionLabel.size;
463+
464+
// Push the window back into screen if the label/draghandle are partially offscreen
465+
U.UIUtil.ClampToScreen(window: this,
466+
alwaysVisible: this.VersionLabel);
467467
}
468468
}
469469

@@ -577,24 +577,16 @@ public void OnUpdate(GlobalConfig config) {
577577
UpdatePosition(new Vector2(config.Main.MainMenuX, config.Main.MainMenuY));
578578
lastUpdatePositionFrame_ = nowFrame;
579579
}
580-
581-
// if (isStarted_) {
582-
// this.Invalidate();
583-
// }
584580
}
585581

586582
/// <summary>Always invalidates the main menu, do not call too often!</summary>
587583
/// <param name="pos">Config main menu position.</param>
588584
public void UpdatePosition(Vector2 pos) {
589-
Rect rect = new Rect(
590-
pos.x,
591-
pos.y,
592-
ModUI.Instance.MainMenu.width,
593-
this.height);
594-
Vector2 resolution = UIView.GetAView().GetScreenResolution();
595-
VectorUtil.ClampRectToScreen(ref rect, resolution);
596-
Log.Info($"Setting main menu position to [{pos.x},{pos.y}]");
597-
absolutePosition = rect.position;
585+
this.absolutePosition = new Vector2(pos.x, pos.y);
586+
if (U.UIUtil.ClampToScreen(window: this, alwaysVisible: this.VersionLabel)) {
587+
Log.Info($"Moving main menu pos={this.absolutePosition}");
588+
}
589+
598590
Invalidate();
599591
}
600592

TLM/TLM/UI/MainMenu/StatsLabel.cs

-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ public class StatsLabel : U.Label.ULabel {
77

88
public override void Start() {
99
base.Start();
10-
// size = new Vector2(
11-
// ModUI.Instance.MainMenu.width / 2f,
12-
// MainMenuWindow.ScaledSize.GetTitlebarHeight());
1310
this.text = "0";
1411
this.suffix = " pathfinds";
1512
this.textColor = Color.green;
16-
// relativePosition = new Vector3(5f, -20f);
17-
// textAlignment = UIHorizontalAlignment.Left;
18-
// anchor = UIAnchorStyle.Top | UIAnchorStyle.Left;
1913
}
2014

2115
#if QUEUEDSTATS

TLM/TLM/UI/SubTools/LaneArrows/LaneArrowTool.cs

-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ private void CreateLaneArrowsWindow(int numLanes) {
192192
ToolWindow.SetupControls(builder, numLanes);
193193

194194
// Resize everything correctly
195-
// builder.Control.SetTransparency(GlobalConfig.Instance.Main.GuiTransparency);
196195
builder.Done();
197196
RepositionWindowToNode(); // reposition again 2nd time now that size is known
198197
}
@@ -322,7 +321,6 @@ public override void OnToolLeftClick() {
322321
case State.EditLaneArrows:
323322
if (HoveredSegmentId != 0) {
324323
// Allow selecting other segments while doing lane editing
325-
// fsm_.SendTrigger(Trigger.ReenterSameState);
326324
OnToolLeftClick_Select();
327325
}
328326
break;

TLM/TLM/UI/SubTools/LaneArrows/LaneArrowToolWindow.cs

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public void SetupControls(UiBuilder<LaneArrowToolWindow> builder, int numLanes)
9090

9191
using (var buttonRowBuilder = builder.ChildPanel<U.Panel.UPanel>(
9292
setupFn: p => { p.name = "TMPE_ButtonRow"; })) {
93-
// buttonRowBuilder.SetPadding(Constants.U_UI_PADDING);
9493
buttonRowBuilder.ResizeFunction(
9594
r => {
9695
r.Stack(mode: UStackMode.Below,

0 commit comments

Comments
 (0)