예제 #1
0
        /// <summary>
        /// Use this to create the UIFastList.
        /// Do NOT use AddUIComponent.
        /// I had to do that way because MonoBehaviors classes cannot be generic
        /// </summary>
        /// <typeparam name="T">The type of the row UI component</typeparam>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static UIFastList Create <T>(UIComponent parent)
            where T : UIPanel, IUIFastListRow
        {
            UIFastList list = parent.AddUIComponent <UIFastList>();

            list.m_rowType = typeof(T);
            return(list);
        }
예제 #2
0
        public override void Start()
        {
            name             = "CCX_SaveLoadWindow";
            atlas            = UIUtils.GetAtlas("Ingame");
            backgroundSprite = "SubcategoriesPanel";
            size             = new Vector2(465, 180);

            UIDragHandle dragHandle = AddUIComponent <UIDragHandle>();

            dragHandle.target           = parent;
            dragHandle.relativePosition = Vector3.zero;

            close                  = AddUIComponent <UIButton>();
            close.size             = new Vector2(30f, 30f);
            close.text             = "X";
            close.textScale        = 0.9f;
            close.textColor        = new Color32(118, 123, 123, 255);
            close.focusedTextColor = new Color32(118, 123, 123, 255);
            close.hoveredTextColor = new Color32(140, 142, 142, 255);
            close.pressedTextColor = new Color32(99, 102, 102, 102);
            close.textPadding      = new RectOffset(8, 8, 8, 8);
            close.canFocus         = false;
            close.playAudioEvents  = true;
            close.relativePosition = new Vector3(width - close.width, 0);

            close.eventClicked += (c, p) =>
            {
                isVisible = false;
                Destroy(gameObject);
            };

            UILabel label = AddUIComponent <UILabel>();

            label.textScale        = 0.9f;
            label.text             = "Save/Load Path";
            label.relativePosition = new Vector2(8, 8);
            label.SendToBack();

            // Save Panel
            UIPanel savePanel = AddUIComponent <UIPanel>();

            savePanel.atlas            = atlas;
            savePanel.backgroundSprite = "GenericPanel";
            savePanel.color            = new Color32(206, 206, 206, 255);
            savePanel.size             = new Vector2(width - 16, 46);
            savePanel.relativePosition = new Vector2(8, 28);

            // Input
            fileNameInput                     = UIUtils.CreateTextField(savePanel);
            fileNameInput.padding.top         = 7;
            fileNameInput.horizontalAlignment = UIHorizontalAlignment.Left;
            fileNameInput.relativePosition    = new Vector3(8, 8);

            // Save
            saveButton                  = UIUtils.CreateButton(savePanel);
            saveButton.name             = "CCX_SaveButton";
            saveButton.text             = "Save";
            saveButton.size             = new Vector2(100f, 30f);
            saveButton.relativePosition = new Vector3(savePanel.width - saveButton.width - 8, 8);

            fileNameInput.size = new Vector2(saveButton.relativePosition.x - 16f, 30f);

            // FastList
            fastList = UIFastList.Create <UISaveLoadFileRow>(this);
            fastList.backgroundSprite = "UnlockingPanel";
            fastList.width            = width - 16;
            fastList.height           = 46 * 5;
            fastList.canSelect        = true;
            fastList.relativePosition = new Vector3(8, savePanel.relativePosition.y + savePanel.height + 8);

            fastList.rowHeight = 46f;

            saveButton.eventClicked += (c, p) =>
            {
                string filename = fileNameInput.text.Trim();
                filename = String.Concat(filename.Split(Path.GetInvalidFileNameChars()));

                if (!fileNameInput.text.IsNullOrWhiteSpace())
                {
                    CameraDirector.cameraPath.Serialize(filename);
                    fileNameInput.text = "";
                    RefreshFileList();
                }
            };

            height           = fastList.relativePosition.y + fastList.height + 8;
            dragHandle.size  = size;
            absolutePosition = new Vector3(savedWindowX.value, savedWindowY.value);
            MakePixelPerfect();

            RefreshFileList();

            fileNameInput.Focus();
        }
        public override void Start()
        {
            name             = "CCX_MainWindow";
            atlas            = UIUtils.GetAtlas("Ingame");
            backgroundSprite = "SubcategoriesPanel";
            size             = new Vector2(465, 180);
            isVisible        = false;

            UIDragHandle dragHandle = AddUIComponent <UIDragHandle>();

            dragHandle.target           = parent;
            dragHandle.relativePosition = Vector3.zero;

            UIButton close = AddUIComponent <UIButton>();

            close.size             = new Vector2(30f, 30f);
            close.text             = "X";
            close.textScale        = 0.9f;
            close.textColor        = new Color32(118, 123, 123, 255);
            close.focusedTextColor = new Color32(118, 123, 123, 255);
            close.hoveredTextColor = new Color32(140, 142, 142, 255);
            close.pressedTextColor = new Color32(99, 102, 102, 102);
            close.textPadding      = new RectOffset(8, 8, 8, 8);
            close.canFocus         = false;
            close.playAudioEvents  = true;
            close.relativePosition = new Vector3(width - close.width, 0);

            close.eventClicked += (c, p) =>
            {
                if (isVisible)
                {
                    CameraDirector.ToggleUI();
                }
            };

            // Control panel
            UILabel label = AddUIComponent <UILabel>();

            label.textScale        = 0.9f;
            label.text             = "Cinematic Camera Extended";
            label.relativePosition = new Vector2(8, 8);
            label.SendToBack();

            UIPanel controlPanel = AddUIComponent <UIPanel>();

            controlPanel.atlas            = atlas;
            controlPanel.backgroundSprite = "GenericPanel";
            controlPanel.color            = new Color32(206, 206, 206, 255);
            controlPanel.size             = new Vector2(width - 16, 46);
            controlPanel.relativePosition = new Vector2(8, 28);

            addKnotButton                  = UIUtils.CreateButton(controlPanel);
            addKnotButton.name             = "CCX_AddKnot";
            addKnotButton.textScale        = 1.5f;
            addKnotButton.text             = "+";
            addKnotButton.size             = new Vector2(40f, 30f);
            addKnotButton.relativePosition = new Vector3(8, 8);
            addKnotButton.tooltip          = "Add a new point to the path";

            playButton                  = UIUtils.CreateButton(controlPanel);
            playButton.name             = "CCX_Play";
            playButton.textScale        = 1.5f;
            playButton.text             = ">";
            playButton.size             = new Vector2(40f, 30f);
            playButton.playAudioEvents  = false;
            playButton.relativePosition = new Vector3(controlPanel.width - playButton.width - 8, 8);
            playButton.tooltip          = "Play the current path";

            playSpeedDropDown       = UIUtils.CreateDropDown(controlPanel);
            playSpeedDropDown.width = 75;
            playSpeedDropDown.items = new string[]
            {
                "x 1/16",
                "x 1/8",
                "x 1/4",
                "x 1/2",
                "x 1",
                "x 2",
                "x 4",
                "x 8",
                "x 16"
            };
            playSpeedDropDown.selectedValue    = "x 1";
            playSpeedDropDown.relativePosition = new Vector3(playButton.relativePosition.x - playSpeedDropDown.width - 8, 8);
            playSpeedDropDown.tooltip          = "Playback speed";

            timelineSlider                  = controlPanel.AddUIComponent <UISlider>();
            timelineSlider.name             = "CCX_TimelineSlider";
            timelineSlider.size             = new Vector2(playSpeedDropDown.relativePosition.x - addKnotButton.relativePosition.x - addKnotButton.width - 20, 18);
            timelineSlider.relativePosition = new Vector2(addKnotButton.relativePosition.x + addKnotButton.width + 10, 14);

            UISlicedSprite bgSlider = timelineSlider.AddUIComponent <UISlicedSprite>();

            bgSlider.atlas            = atlas;
            bgSlider.spriteName       = "BudgetSlider";
            bgSlider.size             = new Vector2(timelineSlider.width, 9);
            bgSlider.relativePosition = new Vector2(0, 4);
            bgSlider.tooltip          = "Drag the slider to preview the animation";

            UISlicedSprite thumb = timelineSlider.AddUIComponent <UISlicedSprite>();

            thumb.atlas                = atlas;
            thumb.spriteName           = "SliderBudget";
            timelineSlider.thumbObject = thumb;

            timelineSlider.minValue = 0f;
            timelineSlider.maxValue = 1f;
            timelineSlider.stepSize = 0;
            timelineSlider.value    = 0;

            // FOV panel
            UIPanel fovPanel = AddUIComponent <UIPanel>();

            fovPanel.atlas            = atlas;
            fovPanel.backgroundSprite = "GenericPanel";
            fovPanel.color            = new Color32(206, 206, 206, 255);
            fovPanel.size             = new Vector2(width - 120 - 8 * 3, 46);
            fovPanel.relativePosition = new Vector2(8, controlPanel.relativePosition.y + controlPanel.height + 8);

            label                   = fovPanel.AddUIComponent <UILabel>();
            label.textScale         = 0.9f;
            label.text              = "Fov:";
            label.autoSize          = false;
            label.height            = 30;
            label.verticalAlignment = UIVerticalAlignment.Middle;
            label.relativePosition  = new Vector2(8, 8);

            fovInput                  = UIUtils.CreateTextField(fovPanel);
            fovInput.name             = "CCX_MainFovInput";
            fovInput.size             = new Vector2(45f, 26);
            fovInput.text             = (2f * CameraDirector.camera.fieldOfView).ToString();
            fovInput.numericalOnly    = true;
            fovInput.allowFloats      = true;
            fovInput.padding.top      = 6;
            fovInput.relativePosition = new Vector3(fovPanel.width - fovInput.width - 8, 10);
            fovInput.tooltip          = "Field of view in degrees";

            fovSlider                  = fovPanel.AddUIComponent <UISlider>();
            fovSlider.name             = "CCX_TimelineSlider";
            fovSlider.size             = new Vector2(fovInput.relativePosition.x - label.relativePosition.x - label.width - 20, 18);
            fovSlider.relativePosition = new Vector2(label.relativePosition.x + label.width + 10, 14);

            bgSlider                  = fovSlider.AddUIComponent <UISlicedSprite>();
            bgSlider.atlas            = atlas;
            bgSlider.spriteName       = "BudgetSlider";
            bgSlider.size             = new Vector2(fovSlider.width, 9);
            bgSlider.relativePosition = new Vector2(0, 4);
            bgSlider.tooltip          = "Drag the slider to change the field of view";

            thumb                 = fovSlider.AddUIComponent <UISlicedSprite>();
            thumb.atlas           = atlas;
            thumb.spriteName      = "SliderBudget";
            fovSlider.thumbObject = thumb;

            fovSlider.minValue = 20f;
            fovSlider.maxValue = 179f;
            fovSlider.stepSize = 1f;
            fovSlider.value    = CameraDirector.camera.fieldOfView * 2f;

            // FPS panel
            UIPanel fpsPanel = AddUIComponent <UIPanel>();

            fpsPanel.atlas            = atlas;
            fpsPanel.backgroundSprite = "GenericPanel";
            fpsPanel.color            = new Color32(206, 206, 206, 255);
            fpsPanel.size             = new Vector2(120, 46);
            fpsPanel.relativePosition = new Vector2(fovPanel.relativePosition.x + fovPanel.width + 8, fovPanel.relativePosition.y);

            fpsInput                  = UIUtils.CreateTextField(fpsPanel);
            fpsInput.name             = "CCX_FpsInput";
            fpsInput.size             = new Vector2(45f, 26);
            fpsInput.text             = CameraDirector.fps.ToString();
            fpsInput.numericalOnly    = true;
            fpsInput.allowFloats      = true;
            fpsInput.padding.top      = 6;
            fpsInput.relativePosition = new Vector3(fpsPanel.width - fpsInput.width - 8, 10);
            fpsInput.tooltip          = "Fps";
            fpsInput.tooltip          = "Sync the camera and the simulation at a set frame rate";

            fpsCheckBox                  = UIUtils.CreateCheckBox(fpsPanel);
            fpsCheckBox.text             = "Fps:";
            fpsCheckBox.isChecked        = false;
            fpsCheckBox.width            = fpsPanel.width - fpsInput.width - 24;
            fpsCheckBox.relativePosition = new Vector2(8, 16);
            fpsCheckBox.tooltip          = "Sync the camera and the simulation at a set frame rate";

            // Hide UI checkbox
            hideUICheckBox                  = UIUtils.CreateCheckBox(this);
            hideUICheckBox.name             = "CCX_HideUICheckBox";
            hideUICheckBox.text             = "Hide UI during playback";
            hideUICheckBox.isChecked        = true;
            hideUICheckBox.width            = width - 16;
            hideUICheckBox.relativePosition = new Vector2(8, fovPanel.relativePosition.y + fovPanel.height + 8);

            // Start simulation checkbox
            startSimCheckBox                  = UIUtils.CreateCheckBox(this);
            startSimCheckBox.name             = "CCX_StartSimCheckBox";
            startSimCheckBox.text             = "Unpause simulation";
            startSimCheckBox.isChecked        = false;
            startSimCheckBox.width            = (width - 16) / 2;
            startSimCheckBox.relativePosition = new Vector2(8, hideUICheckBox.relativePosition.y + hideUICheckBox.height + 8);

            // FastList
            fastList = UIFastList.Create <UIKnotsListRow>(this);
            fastList.backgroundSprite = "UnlockingPanel";
            fastList.width            = width - 16;
            fastList.height           = 46 * 5;
            fastList.canSelect        = true;
            fastList.relativePosition = new Vector3(8, startSimCheckBox.relativePosition.y + startSimCheckBox.height + 8);

            fastList.rowHeight = 46f;
            fastList.rowsData  = CameraDirector.cameraPath.knots;

            // Load/Save
            saveLoadButton                  = UIUtils.CreateButton(this);
            saveLoadButton.name             = "CCX_SaveLoadButton";
            saveLoadButton.text             = "Save/Load";
            saveLoadButton.size             = new Vector2(100f, 30f);
            saveLoadButton.relativePosition = new Vector3(width - saveLoadButton.width - 8, fastList.relativePosition.y + fastList.height + 8);
            saveLoadButton.tooltip          = "Work in progress";

            height           = saveLoadButton.relativePosition.y + saveLoadButton.height + 8;
            dragHandle.size  = size;
            absolutePosition = new Vector3(savedWindowX.value, savedWindowY.value);
            MakePixelPerfect();

            addKnotButton.eventClicked += (c, p) =>
            {
                int i = CameraDirector.cameraPath.AddKnot();
                fastList.DisplayAt(i);

                timelineSlider.minValue = 0f;
                float duration = CameraDirector.cameraPath.CalculateTotalDuraction();
                if (duration <= 0f)
                {
                    duration = 1f;
                }
                timelineSlider.maxValue = duration;
            };

            playButton.eventClicked += (c, p) =>
            {
                CameraDirector.cameraPath.Play();
            };

            timelineSlider.eventMouseDown += (c, p) =>
            {
                CameraPath.currentTransfrom = new Knot();
            };

            timelineSlider.eventValueChanged += (c, p) =>
            {
                CameraDirector.cameraPath.SetToTime(p);
            };

            hideUICheckBox.eventCheckChanged += (c, p) =>
            {
                CameraDirector.freeCamera = p;
            };

            startSimCheckBox.eventCheckChanged += (c, p) =>
            {
                CameraDirector.startSimulation = p;
            };

            fovSlider.eventValueChanged += (c, p) =>
            {
                CameraDirector.camera.fieldOfView = p / 2f;
                fovInput.text = p.ToString();
            };

            fovInput.eventTextSubmitted += (c, p) =>
            {
                float value;
                if (float.TryParse(p, out value))
                {
                    CameraDirector.camera.fieldOfView = Mathf.Clamp(value, 20f, 179f) / 2f;

                    if (fovSlider.value != value)
                    {
                        fovSlider.value = value;
                    }
                }

                fovInput.text = (2f * CameraDirector.camera.fieldOfView).ToString();
            };

            fovInput.eventMouseWheel += (c, p) =>
            {
                if (!p.used)
                {
                    fovSlider.value += p.wheelDelta;
                    p.Use();
                }
            };

            fpsCheckBox.eventCheckChanged += (c, p) =>
            {
                CameraDirector.useFps = p;
            };

            fpsInput.eventTextSubmitted += (c, p) =>
            {
                float value;
                if (float.TryParse(p, out value))
                {
                    CameraDirector.fps = Mathf.Max(0, value);
                }

                fpsInput.text = CameraDirector.fps.ToString();
            };

            fpsInput.eventMouseWheel += (c, p) =>
            {
                if (!p.used)
                {
                    CameraDirector.fps = Mathf.Max(0, CameraDirector.fps + p.wheelDelta);
                    fpsInput.text      = CameraDirector.fps.ToString();
                    p.Use();
                }
            };

            saveLoadButton.eventClicked += (c, p) =>
            {
                if (saveLoadWindow == null)
                {
                    saveLoadWindow = (UISaveLoadWindow)GetUIView().AddUIComponent(typeof(UISaveLoadWindow));
                }
                else
                {
                    Destroy(saveLoadWindow);
                }
            };

            DebugUtils.Log("UIMainWindow created");
        }