コード例 #1
0
ファイル: UI.cs プロジェクト: ManicJamie/HollowKnight-Timer
        public void InitDisplay()
        {
            if (menu != null)
            {
                GameObject.DestroyImmediate(menu);
            }
            CanvasUtil.CreateFonts();
            menu           = CanvasUtil.CreateCanvas(UnityEngine.RenderMode.ScreenSpaceOverlay, 100);
            this.showTimer = new UIOption <ToggleOption>(
                CanvasUtil.CreateTextPanel(
                    menu, "Show Timer", 30, TextAnchor.MiddleLeft,
                    new CanvasUtil.RectData(new Vector2(300, 60), new Vector2(-150, 180), MIDDLE, MIDDLE)
                    ),
                CanvasUtil.CreateTextPanel(
                    menu, "", 30, TextAnchor.MiddleRight,
                    new CanvasUtil.RectData(new Vector2(300, 60), new Vector2(150, 180), MIDDLE, MIDDLE)
                    ),
                new Vector2(-330, 180),
                ToggleOption.values,
                (v) => this.timer.ShowDisplay(v.enabled),
                1
                );
            this.resetPb = new UIButton(
                CanvasUtil.CreateTextPanel(
                    menu, "Reset PB", 30, TextAnchor.MiddleCenter,
                    new CanvasUtil.RectData(new Vector2(360, 60), new Vector2(0, 120), MIDDLE, MIDDLE)
                    ),
                new Vector2(-210, 120),
                () => {
                if (this.tm != null)
                {
                    this.tm.ResetPB();
                }
            }
                );

            this.triggerType = new UIOption <TriggerTypeOption>(
                CanvasUtil.CreateTextPanel(
                    menu, "Trigger Type", 30, TextAnchor.MiddleLeft,
                    new CanvasUtil.RectData(new Vector2(300, 60), new Vector2(-150, 0), MIDDLE, MIDDLE)
                    ),
                CanvasUtil.CreateTextPanel(
                    menu, "", 30, TextAnchor.MiddleRight,
                    new CanvasUtil.RectData(new Vector2(300, 60), new Vector2(150, 0), MIDDLE, MIDDLE)
                    ),
                new Vector2(-330, 0),
                TriggerTypeOption.values,
                (e) => this.tm.triggerPlaceType = e.variant
                );
            this.saveTriggers = new UIButton(
                CanvasUtil.CreateTextPanel(
                    menu, "Save Triggers", 30, TextAnchor.MiddleCenter,
                    new CanvasUtil.RectData(new Vector2(360, 60), new Vector2(0, -60), MIDDLE, MIDDLE)
                    ),
                new Vector2(-210, -60),
                () => {
                if (this.tm != null)
                {
                    this.tm.SaveTriggers();
                }
            }
                );
            this.loadTriggers = new UIButton(
                CanvasUtil.CreateTextPanel(
                    menu, "Load Triggers", 30, TextAnchor.MiddleCenter,
                    new CanvasUtil.RectData(new Vector2(360, 60), new Vector2(0, -120), MIDDLE, MIDDLE)
                    ),
                new Vector2(-210, -120),
                () => {
                if (this.tm != null)
                {
                    this.tm.LoadTriggers();
                }
            }
                );

            this.reloadSettings = new UIButton(
                CanvasUtil.CreateTextPanel(
                    menu, "Reload Settings", 30, TextAnchor.MiddleCenter,
                    new CanvasUtil.RectData(new Vector2(360, 60), new Vector2(0, -240), MIDDLE, MIDDLE)
                    ),
                new Vector2(-210, -240),
                () => {
                if (this.hktimer != null)
                {
                    this.hktimer.ReloadSettings();
                }
            }
                );

            this.cursorDisplay = CanvasUtil.CreateTextPanel(
                menu, ">", 50, TextAnchor.MiddleCenter,
                new CanvasUtil.RectData(new Vector2(60, 60), new Vector2(0, 0), MIDDLE, MIDDLE)
                );

            this.elements = new UIElement[] {
                this.showTimer,
                this.resetPb,
                this.triggerType,
                this.saveTriggers,
                this.loadTriggers,
                this.reloadSettings
            };
            this.SetShown(false);
            this.uiOpen = false;
            GameObject.DontDestroyOnLoad(this.menu);
        }