|
| 1 | +using UnityEngine; |
| 2 | +using DaggerfallWorkshop.Game.Utility.ModSupport; |
| 3 | +using DaggerfallWorkshop.Game.Utility.ModSupport.ModSettings; |
| 4 | +using DaggerfallWorkshop.Game; |
| 5 | + |
| 6 | +namespace SystemClockMod |
| 7 | +{ |
| 8 | + public class SystemClockMod : MonoBehaviour |
| 9 | + { |
| 10 | + public static Mod Mod; |
| 11 | + private static GUIStyle style; |
| 12 | + private static Rect rect; |
| 13 | + private static Vector2 rectSize; |
| 14 | + private static Vector2 rectPosition; |
| 15 | + |
| 16 | + // Mod options |
| 17 | + static int horizontalPositionPercent; |
| 18 | + static int verticalPositionPercent; |
| 19 | + static string format; // https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings |
| 20 | + static Color fontColor; |
| 21 | + static int fontSize; |
| 22 | + static int guiDepth; |
| 23 | + |
| 24 | + [Invoke(StateManager.StateTypes.Start, 0)] |
| 25 | + public static void Init(InitParams initParams) |
| 26 | + { |
| 27 | + Mod = initParams.Mod; |
| 28 | + new GameObject(Mod.Title).AddComponent<SystemClockMod>(); |
| 29 | + Mod.LoadSettingsCallback = LoadSettings; |
| 30 | + Mod.IsReady = true; |
| 31 | + } |
| 32 | + |
| 33 | + void Start() |
| 34 | + { |
| 35 | + style = new GUIStyle(); |
| 36 | + style.alignment = TextAnchor.MiddleCenter; |
| 37 | + Mod.LoadSettings(); |
| 38 | + } |
| 39 | + |
| 40 | + void OnGUI() |
| 41 | + { |
| 42 | + GUI.depth = guiDepth; |
| 43 | + GUI.Label( |
| 44 | + rect, |
| 45 | + System.DateTime.Now.ToString(format), |
| 46 | + style |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + static void LoadSettings(ModSettings modSettings, ModSettingsChange change) |
| 51 | + { |
| 52 | + if (modSettings != null) |
| 53 | + { |
| 54 | + format = modSettings.GetString("Settings", "Format"); |
| 55 | + guiDepth = modSettings.GetValue<int>("Settings", "RenderOrder"); ; |
| 56 | + horizontalPositionPercent = modSettings.GetValue<int>("Settings", "HorizontalPositionPercent"); |
| 57 | + verticalPositionPercent = modSettings.GetValue<int>("Settings", "VerticalPositionPercent"); |
| 58 | + fontSize = modSettings.GetValue<int>("Settings", "Size"); |
| 59 | + fontColor = modSettings.GetColor("Settings", "Color"); |
| 60 | + |
| 61 | + style.normal.textColor = fontColor; |
| 62 | + style.fontSize = fontSize; |
| 63 | + rectSize = style.CalcSize(new GUIContent(System.DateTime.Now.ToString(format))); |
| 64 | + rectPosition.x = (Screen.width - rectSize.x) * (horizontalPositionPercent / 100f); |
| 65 | + rectPosition.y = (Screen.height - rectSize.y) * (verticalPositionPercent / 100f); |
| 66 | + rect = new Rect(rectPosition.x, rectPosition.y, rectSize.x, rectSize.y); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + } |
| 71 | +} |
0 commit comments