|
| 1 | + |
| 2 | +using SFS.Translations; |
| 3 | +using UnityEngine; |
| 4 | + |
| 5 | +namespace ModLoader.UI |
| 6 | +{ |
| 7 | + class ModsMenuGUI : MonoBehaviour |
| 8 | + { |
| 9 | + |
| 10 | + private Vector2 _scroll; |
| 11 | + |
| 12 | + private GUIStyle _windowStyle; |
| 13 | + private GUIStyle _modInformationStyle; |
| 14 | + private GUIStyle _titleStyle; |
| 15 | + private GUIStyle _modInformationTextStyle; |
| 16 | + |
| 17 | + private Rect _windowsPosition; |
| 18 | + private const float _margin = 0.2f; |
| 19 | + |
| 20 | + private void Awake() |
| 21 | + { |
| 22 | + this._scroll = Vector2.zero; |
| 23 | + |
| 24 | + this._windowStyle = new GUIStyle(); |
| 25 | + this._modInformationStyle = new GUIStyle(); |
| 26 | + this._titleStyle = new GUIStyle(); |
| 27 | + this._modInformationTextStyle = new GUIStyle(); |
| 28 | + |
| 29 | + } |
| 30 | + |
| 31 | + private void Start() |
| 32 | + { |
| 33 | + this._windowStyle.normal.background = this.makeTexture(new Color32(14, 17,27,230)); |
| 34 | + |
| 35 | + this._modInformationStyle.normal.background = this.makeTexture(new Color32(27, 32, 50, 240)); |
| 36 | + this._modInformationStyle.padding = new RectOffset(10,10,10,10); |
| 37 | + this._modInformationStyle.margin.top = 10; |
| 38 | + |
| 39 | + this._modInformationTextStyle.fontSize = 20; |
| 40 | + this._modInformationTextStyle.normal.textColor = Color.white; |
| 41 | + |
| 42 | + this._titleStyle.fontSize = 30; |
| 43 | + this._titleStyle.fontStyle = FontStyle.Bold; |
| 44 | + this._titleStyle.normal.textColor = Color.white; |
| 45 | + this._titleStyle.alignment = TextAnchor.MiddleCenter; |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | + /// <sumary> |
| 50 | + /// Create solid color texture |
| 51 | + ///</sumary> |
| 52 | + private Texture2D makeTexture(Color col) |
| 53 | + { |
| 54 | + Color[] pix = new Color[1]; |
| 55 | + for (int i = 0; i < pix.Length; ++i) |
| 56 | + { |
| 57 | + pix[i] = col; |
| 58 | + } |
| 59 | + Texture2D result = new Texture2D(1, 1); |
| 60 | + result.SetPixels(pix); |
| 61 | + result.Apply(); |
| 62 | + return result; |
| 63 | + } |
| 64 | + |
| 65 | + private void OnEnable() |
| 66 | + { |
| 67 | + |
| 68 | + float windowsHeigth = Screen.height * (1 - _margin - _margin); |
| 69 | + float windowsWidth = Screen.width * (1 - _margin - _margin); |
| 70 | + float windowsX = Screen.width * _margin; |
| 71 | + float windowsY = Screen.height * _margin; |
| 72 | + |
| 73 | + this._windowsPosition = new Rect(windowsX, windowsY, windowsWidth,windowsHeigth); |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + private void OnGUI() |
| 78 | + { |
| 79 | + GUI.BeginGroup(this._windowsPosition, this._windowStyle); |
| 80 | + GUILayout.Label("Installed Mods",this._titleStyle); |
| 81 | + this._scroll = GUILayout.BeginScrollView(this._scroll, GUILayout.Width(this._windowsPosition.width),GUILayout.Height(this._windowsPosition.height - 70)); |
| 82 | + |
| 83 | + foreach(SFSMod mod in Loader.main.getMods()) |
| 84 | + { |
| 85 | + this.modInformation(mod); |
| 86 | + } |
| 87 | + |
| 88 | + GUILayout.EndScrollView(); |
| 89 | + bool click = GUILayout.Button(Loc.main.Close); |
| 90 | + GUI.EndGroup(); |
| 91 | + if (click) |
| 92 | + { |
| 93 | + ModsMenu.Main.Close(); |
| 94 | + ModsMenu.Main.OnClose(); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + public void modInformation(SFSMod mod) |
| 99 | + { |
| 100 | + |
| 101 | + GUILayout.BeginVertical(this._modInformationStyle,GUILayout.Width(this._windowsPosition.width-20)); |
| 102 | + |
| 103 | + GUILayout.BeginHorizontal(); |
| 104 | + GUILayout.Label($"Mod: {mod.Name}",this._modInformationTextStyle); |
| 105 | + GUILayout.Label($"Version: {mod.Version}", this._modInformationTextStyle); |
| 106 | + GUILayout.Label($"Author: {mod.Author}", this._modInformationTextStyle); |
| 107 | + GUILayout.EndHorizontal(); |
| 108 | + GUILayout.Label($"Description:\n{mod.Description}", this._modInformationTextStyle); |
| 109 | + //bool click = GUILayout.Button("Config"); |
| 110 | + GUILayout.EndVertical(); |
| 111 | + } |
| 112 | + } |
| 113 | +} |
0 commit comments