Exemple #1
0
        public void CreateImageWizard()
        {
            string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

            if (!Directory.Exists(home))
            {
                return;
            }

            FileSelection.OnFileSelected = file =>
            {
                Vector2 pos = Screen.Selected.Cam.ScreenToWorld(PlayerInput.MousePosition);
                pos.Y = -pos.Y;
                Images.Add(new EditorImage(file, pos)
                {
                    DrawTarget = EditorImage.DrawTargetType.World
                });
                UpdateImageCategories();
                GameMain.Config.SaveNewPlayerConfig();
            };

            FileSelection.ClearFileTypeFilters();
            FileSelection.AddFileTypeFilter("PNG", "*.png");
            FileSelection.AddFileTypeFilter("JPEG", "*.jpg, *.jpeg");
            FileSelection.AddFileTypeFilter("All files", "*.*");
            FileSelection.SelectFileTypeFilter("*.png");
            FileSelection.CurrentDirectory = home;
            FileSelection.Open             = true;
        }
        private void CreateGUI()
        {
            GuiFrame = new GUIFrame(new RectTransform(new Vector2(0.2f, 0.4f), GUICanvas.Instance)
            {
                MinSize = new Point(300, 400)
            });
            GUILayoutGroup layoutGroup = new GUILayoutGroup(RectTransform(0.9f, 0.9f, GuiFrame, Anchor.Center))
            {
                Stretch = true
            };

            // === BUTTONS === //
            GUILayoutGroup buttonLayout = new GUILayoutGroup(RectTransform(1.0f, 0.50f, layoutGroup))
            {
                RelativeSpacing = 0.04f
            };
            GUIButton newProjectButton    = new GUIButton(RectTransform(1.0f, 0.33f, buttonLayout), TextManager.Get("EventEditor.NewProject"));
            GUIButton saveProjectButton   = new GUIButton(RectTransform(1.0f, 0.33f, buttonLayout), TextManager.Get("EventEditor.SaveProject"));
            GUIButton loadProjectButton   = new GUIButton(RectTransform(1.0f, 0.33f, buttonLayout), TextManager.Get("EventEditor.LoadProject"));
            GUIButton exportProjectButton = new GUIButton(RectTransform(1.0f, 0.33f, buttonLayout), TextManager.Get("EventEditor.Export"));


            // === LOAD PREFAB === //

            GUILayoutGroup loadEventLayout = new GUILayoutGroup(RectTransform(1.0f, 0.125f, layoutGroup));

            new GUITextBlock(RectTransform(1.0f, 0.5f, loadEventLayout), TextManager.Get("EventEditor.LoadEvent"), font: GUI.SubHeadingFont);

            GUILayoutGroup loadDropdownLayout = new GUILayoutGroup(RectTransform(1.0f, 0.5f, loadEventLayout), isHorizontal: true, childAnchor: Anchor.CenterLeft);
            GUIDropDown    loadDropdown       = new GUIDropDown(RectTransform(0.8f, 1.0f, loadDropdownLayout), elementCount: 10);
            GUIButton      loadButton         = new GUIButton(RectTransform(0.2f, 1.0f, loadDropdownLayout), TextManager.Get("Load"));

            // === ADD ACTION === //

            GUILayoutGroup addActionLayout = new GUILayoutGroup(RectTransform(1.0f, 0.125f, layoutGroup));

            new GUITextBlock(RectTransform(1.0f, 0.5f, addActionLayout), TextManager.Get("EventEditor.AddAction"), font: GUI.SubHeadingFont);

            GUILayoutGroup addActionDropdownLayout = new GUILayoutGroup(RectTransform(1.0f, 0.5f, addActionLayout), isHorizontal: true, childAnchor: Anchor.CenterLeft);
            GUIDropDown    addActionDropdown       = new GUIDropDown(RectTransform(0.8f, 1.0f, addActionDropdownLayout), elementCount: 10);
            GUIButton      addActionButton         = new GUIButton(RectTransform(0.2f, 1.0f, addActionDropdownLayout), TextManager.Get("EventEditor.Add"));

            // === ADD VALUE === //
            GUILayoutGroup addValueLayout = new GUILayoutGroup(RectTransform(1.0f, 0.125f, layoutGroup));

            new GUITextBlock(RectTransform(1.0f, 0.5f, addValueLayout), TextManager.Get("EventEditor.AddValue"), font: GUI.SubHeadingFont);

            GUILayoutGroup addValueDropdownLayout = new GUILayoutGroup(RectTransform(1.0f, 0.5f, addValueLayout), isHorizontal: true, childAnchor: Anchor.CenterLeft);
            GUIDropDown    addValueDropdown       = new GUIDropDown(RectTransform(0.8f, 1.0f, addValueDropdownLayout), elementCount: 7);
            GUIButton      addValueButton         = new GUIButton(RectTransform(0.2f, 1.0f, addValueDropdownLayout), TextManager.Get("EventEditor.Add"));

            // === ADD SPECIAL === //
            GUILayoutGroup addSpecialLayout = new GUILayoutGroup(RectTransform(1.0f, 0.125f, layoutGroup));

            new GUITextBlock(RectTransform(1.0f, 0.5f, addSpecialLayout), TextManager.Get("EventEditor.AddSpecial"), font: GUI.SubHeadingFont);
            GUILayoutGroup addSpecialDropdownLayout = new GUILayoutGroup(RectTransform(1.0f, 0.5f, addSpecialLayout), isHorizontal: true, childAnchor: Anchor.CenterLeft);
            GUIDropDown    addSpecialDropdown       = new GUIDropDown(RectTransform(0.8f, 1.0f, addSpecialDropdownLayout), elementCount: 1);
            GUIButton      addSpecialButton         = new GUIButton(RectTransform(0.2f, 1.0f, addSpecialDropdownLayout), TextManager.Get("EventEditor.Add"));

            // Add event prefabs with identifiers to the list
            foreach (EventPrefab eventPrefab in EventSet.GetAllEventPrefabs().Where(prefab => !string.IsNullOrWhiteSpace(prefab.Identifier)).Distinct())
            {
                loadDropdown.AddItem(eventPrefab.Identifier, eventPrefab);
            }

            // Add all types that inherit the EventAction class
            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes().Where(type => type.IsSubclassOf(typeof(EventAction))))
            {
                addActionDropdown.AddItem(type.Name, type);
            }

            addSpecialDropdown.AddItem("Custom", typeof(CustomNode));

            addValueDropdown.AddItem(nameof(Single), typeof(float));
            addValueDropdown.AddItem(nameof(Boolean), typeof(bool));
            addValueDropdown.AddItem(nameof(String), typeof(string));
            addValueDropdown.AddItem(nameof(SpawnType), typeof(SpawnType));
            addValueDropdown.AddItem(nameof(LimbType), typeof(LimbType));
            addValueDropdown.AddItem(nameof(ReputationAction.ReputationType), typeof(ReputationAction.ReputationType));
            addValueDropdown.AddItem(nameof(SpawnAction.SpawnLocationType), typeof(SpawnAction.SpawnLocationType));

            loadButton.OnClicked          += (button, o) => Load(loadDropdown.SelectedData as EventPrefab);
            addActionButton.OnClicked     += (button, o) => AddAction(addActionDropdown.SelectedData as Type);
            addValueButton.OnClicked      += (button, o) => AddValue(addValueDropdown.SelectedData as Type);
            addSpecialButton.OnClicked    += (button, o) => AddSpecial(addSpecialDropdown.SelectedData as Type);
            exportProjectButton.OnClicked += ExportEventToFile;
            saveProjectButton.OnClicked   += SaveProjectToFile;
            newProjectButton.OnClicked    += TryCreateNewProject;
            loadProjectButton.OnClicked   += (button, o) =>
            {
                FileSelection.OnFileSelected = (file) =>
                {
                    XDocument?document = XMLExtensions.TryLoadXml(file);
                    if (document?.Root != null)
                    {
                        Load(document.Root);
                    }
                };

                string directory = Path.GetFullPath("EventProjects");
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                FileSelection.ClearFileTypeFilters();
                FileSelection.AddFileTypeFilter("Scripted Event", "*.sevproj");
                FileSelection.SelectFileTypeFilter("*.sevproj");
                FileSelection.CurrentDirectory = directory;
                FileSelection.Open             = true;
                return(true);
            };
            screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
        }