Example #1
0
        public RemoveActorAction(EditorActorLayer editorActorLayer, EditorActorPreview actor)
        {
            this.editorActorLayer = editorActorLayer;
            this.actor            = actor;

            Text = "Removed {0} ({1})".F(actor.Info.Name, actor.ID);
        }
Example #2
0
        public RemoveActorAction(EditorActorLayer editorActorLayer, EditorActorPreview actor)
        {
            this.editorActorLayer = editorActorLayer;
            this.actor            = actor;

            Text = $"Removed {actor.Info.Name} ({actor.ID})";
        }
Example #3
0
        public AddActorAction(EditorActorLayer editorLayer, ActorReference actor)
        {
            this.editorLayer = editorLayer;

            // Take an immutable copy of the reference
            this.actor = actor.Clone();
        }
Example #4
0
        public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo actor, PlayerReference owner, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;
            world             = wr.World;
            editorLayer       = world.WorldActor.Trait <EditorActorLayer>();

            Actor      = actor;
            this.owner = owner;

            preview           = editorWidget.Get <ActorPreviewWidget>("DRAG_ACTOR_PREVIEW");
            preview.GetScale  = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            var buildingInfo = actor.Traits.GetOrDefault <BuildingInfo>();

            if (buildingInfo != null)
            {
                locationOffset = -FootprintUtils.AdjustForBuildingSize(buildingInfo);
                previewOffset  = FootprintUtils.CenterOffset(world, buildingInfo);
            }

            var td = new TypeDictionary();

            td.Add(new FacingInit(facing));
            td.Add(new TurretFacingInit(facing));
            td.Add(new OwnerInit(owner.Name));
            td.Add(new RaceInit(owner.Race));
            preview.SetPreview(actor, td);

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }
Example #5
0
 public EditActorEditorAction(EditorActorLayer editorActorLayer, EditorActorPreview actor, IEnumerable <IEditActorHandle> handles)
 {
     this.editorActorLayer = editorActorLayer;
     actorId      = actor.ID;
     this.actor   = actor;
     this.handles = handles;
     Text         = "Edited {0} ({1})".F(actor.Info.Name, actor.ID);
 }
Example #6
0
        public EditorCopyPasteBrush(EditorViewportControllerWidget editorWidget, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;

            selectionLayer = wr.World.WorldActor.Trait <EditorSelectionLayer>();
            editorLayer    = wr.World.WorldActor.Trait <EditorActorLayer>();
        }
Example #7
0
 public AddActorAction(EditorActorLayer editorLayer, ActorInfo actor, CPos cell, PlayerReference owner, int facing)
 {
     this.editorLayer = editorLayer;
     this.actor       = actor;
     this.cell        = cell;
     this.owner       = owner;
     this.facing      = facing;
 }
Example #8
0
        public EditorCopyPasteBrush(EditorViewportControllerWidget editorWidget, WorldRenderer wr, Func <MapCopyFilters> getCopyFilters)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;

            selectionLayer      = wr.World.WorldActor.Trait <EditorSelectionLayer>();
            editorLayer         = wr.World.WorldActor.Trait <EditorActorLayer>();
            this.getCopyFilters = getCopyFilters;
        }
Example #9
0
        public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo actor, PlayerReference owner, WorldRenderer wr)
        {
            this.editorWidget   = editorWidget;
            worldRenderer       = wr;
            world               = wr.World;
            editorLayer         = world.WorldActor.Trait <EditorActorLayer>();
            editorActionManager = world.WorldActor.Trait <EditorActionManager>();

            Actor      = actor;
            this.owner = owner;
            var ownerName = owner.Name;

            preview           = editorWidget.Get <ActorPreviewWidget>("DRAG_ACTOR_PREVIEW");
            preview.GetScale  = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            var buildingInfo = actor.TraitInfoOrDefault <BuildingInfo>();

            if (buildingInfo != null)
            {
                centerOffset = buildingInfo.CenterOffset(world);
            }

            // Enforce first entry of ValidOwnerNames as owner if the actor has RequiresSpecificOwners
            var specificOwnerInfo = actor.TraitInfoOrDefault <RequiresSpecificOwnersInfo>();

            if (specificOwnerInfo != null && !specificOwnerInfo.ValidOwnerNames.Contains(ownerName))
            {
                ownerName = specificOwnerInfo.ValidOwnerNames.First();
            }

            var td = new TypeDictionary();

            td.Add(new FacingInit(facing));
            td.Add(new TurretFacingInit(facing));
            td.Add(new OwnerInit(ownerName));
            td.Add(new FactionInit(owner.Faction));
            preview.SetPreview(actor, td);

            var ios = actor.TraitInfoOrDefault <IOccupySpaceInfo>();

            if (ios != null)
            {
                footprint = ios.OccupiedCells(actor, CPos.Zero)
                            .Select(c => c.Key - CPos.Zero)
                            .ToArray();
            }
            else
            {
                footprint = new CVec[0];
            }

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }
Example #10
0
        public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo actor, PlayerReference owner, WorldRenderer wr)
        {
            this.editorWidget   = editorWidget;
            world               = wr.World;
            editorLayer         = world.WorldActor.Trait <EditorActorLayer>();
            editorCursor        = world.WorldActor.Trait <EditorCursorLayer>();
            editorActionManager = world.WorldActor.Trait <EditorActionManager>();

            cursorToken = editorCursor.SetActor(wr, actor, owner);
        }
Example #11
0
        public EditorDefaultBrush(EditorViewportControllerWidget editorWidget, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;
            world             = wr.World;

            editorLayer = world.WorldActor.Trait <EditorActorLayer>();
            resources   = world.WorldActor.TraitsImplementing <ResourceType>()
                          .ToDictionary(r => r.Info.ResourceType, r => r);
        }
Example #12
0
        public EditorDefaultBrush(EditorViewportControllerWidget editorWidget, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer     = wr;
            world             = wr.World;

            editorLayer         = world.WorldActor.Trait <EditorActorLayer>();
            editorActionManager = world.WorldActor.Trait <EditorActionManager>();
            resourceLayer       = world.WorldActor.Trait <IResourceLayer>();
        }
Example #13
0
        public CopyPasteEditorAction(MapCopyFilters copyFilters, Map map,
                                     Dictionary <CPos, Tuple <TerrainTile, ResourceTile, byte> > tiles, Dictionary <string, ActorReference> previews,
                                     EditorActorLayer editorLayer, CellRegion dest)
        {
            this.copyFilters = copyFilters;
            this.tiles       = tiles;
            this.previews    = previews;
            this.editorLayer = editorLayer;
            this.dest        = dest;

            mapTiles     = map.Tiles;
            mapHeight    = map.Height;
            mapResources = map.Resources;

            Text = "Copied {0} tiles".F(tiles.Count);
        }
Example #14
0
        public ActorEditLogic(Widget widget, World world, WorldRenderer worldRenderer, Dictionary <string, MiniYaml> logicArgs)
        {
            this.worldRenderer  = worldRenderer;
            editorActorLayer    = world.WorldActor.Trait <EditorActorLayer>();
            editorActionManager = world.WorldActor.Trait <EditorActionManager>();

            editor         = widget.Parent.Get <EditorViewportControllerWidget>("MAP_EDITOR");
            actorEditPanel = editor.Get <BackgroundWidget>("ACTOR_EDIT_PANEL");

            typeLabel    = actorEditPanel.Get <LabelWidget>("ACTOR_TYPE_LABEL");
            actorIDField = actorEditPanel.Get <TextFieldWidget>("ACTOR_ID");

            initContainer   = actorEditPanel.Get("ACTOR_INIT_CONTAINER");
            buttonContainer = actorEditPanel.Get("BUTTON_CONTAINER");

            checkboxOptionTemplate = initContainer.Get("CHECKBOX_OPTION_TEMPLATE");
            sliderOptionTemplate   = initContainer.Get("SLIDER_OPTION_TEMPLATE");
            dropdownOptionTemplate = initContainer.Get("DROPDOWN_OPTION_TEMPLATE");
            initContainer.RemoveChildren();

            var deleteButton = actorEditPanel.Get <ButtonWidget>("DELETE_BUTTON");
            var cancelButton = actorEditPanel.Get <ButtonWidget>("CANCEL_BUTTON");
            var okButton     = actorEditPanel.Get <ButtonWidget>("OK_BUTTON");

            actorIDErrorLabel           = actorEditPanel.Get <LabelWidget>("ACTOR_ID_ERROR_LABEL");
            actorIDErrorLabel.IsVisible = () => actorIDStatus != ActorIDStatus.Normal;
            actorIDErrorLabel.GetText   = () => actorIDStatus == ActorIDStatus.Duplicate ?
                                          "Duplicate Actor ID" : "Enter an Actor ID";

            MiniYaml yaml;

            if (logicArgs.TryGetValue("EditPanelPadding", out yaml))
            {
                editPanelPadding = FieldLoader.GetValue <int>("EditPanelPadding", yaml.Value);
            }

            okButton.IsDisabled      = () => !IsValid() || !editActorPreview.IsDirty;
            okButton.OnClick         = Save;
            cancelButton.OnClick     = Cancel;
            deleteButton.OnClick     = Delete;
            actorEditPanel.IsVisible = () => CurrentActor != null &&
                                       editor.CurrentBrush == editor.DefaultBrush &&
                                       Game.RunTime > lastScrollTime + scrollVisibleTimeout;

            actorIDField.OnEscKey = () =>
            {
                actorIDField.YieldKeyboardFocus();
                return(true);
            };

            actorIDField.OnTextEdited = () =>
            {
                var actorId = actorIDField.Text.Trim();
                if (string.IsNullOrWhiteSpace(actorId))
                {
                    nextActorIDStatus = ActorIDStatus.Empty;
                    return;
                }

                // Check for duplicate actor ID
                if (CurrentActor.ID.Equals(actorId, StringComparison.OrdinalIgnoreCase))
                {
                    if (editorActorLayer[actorId] != null)
                    {
                        nextActorIDStatus = ActorIDStatus.Duplicate;
                        return;
                    }
                }

                SetActorID(actorId);
                nextActorIDStatus = ActorIDStatus.Normal;
            };

            actorIDField.OnLoseFocus = () =>
            {
                // Reset invalid IDs back to their starting value
                if (actorIDStatus != ActorIDStatus.Normal)
                {
                    SetActorID(initialActorID);
                }
            };
        }
Example #15
0
        public SaveMapLogic(Widget widget, Action onExit, Map map, EditorActorLayer editorActorLayer)
        {
            var title = widget.Get <TextFieldWidget>("TITLE");

            title.Text = map.Title;

            var author = widget.Get <TextFieldWidget>("AUTHOR");

            author.Text = map.Author;

            // TODO: This should use a multi-line textfield once they exist
            var description = widget.Get <TextFieldWidget>("DESCRIPTION");

            description.Text = map.Description;

            // TODO: This should use a multi-selection dropdown once they exist
            var visibilityDropdown = widget.Get <DropDownButtonWidget>("VISIBILITY_DROPDOWN");
            {
                var mapVisibility = new List <string>(Enum.GetNames(typeof(MapVisibility)));
                Func <string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
                {
                    var item = ScrollItemWidget.Setup(template,
                                                      () => visibilityDropdown.Text == option,
                                                      () => { visibilityDropdown.Text = option; });
                    item.Get <LabelWidget>("LABEL").GetText = () => option;
                    return(item);
                };

                visibilityDropdown.Text    = Enum.GetName(typeof(MapVisibility), map.Visibility);
                visibilityDropdown.OnClick = () =>
                                             visibilityDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapVisibility, setupItem);
            }

            var directoryDropdown = widget.Get <DropDownButtonWidget>("DIRECTORY_DROPDOWN");
            {
                var mapDirectories = Game.ModData.Manifest.MapFolders.Keys.Select(ff =>
                {
                    var f = Platform.UnresolvePath(ff);
                    if (f.StartsWith("~"))
                    {
                        f = f.Substring(1);
                    }

                    return(f);
                }).ToList();

                Func <string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
                {
                    var item = ScrollItemWidget.Setup(template,
                                                      () => directoryDropdown.Text == option,
                                                      () => directoryDropdown.Text = option);
                    item.Get <LabelWidget>("LABEL").GetText = () => option;
                    return(item);
                };

                var mapDirectory     = Platform.UnresolvePath(Path.GetDirectoryName(map.Path));
                var initialDirectory = mapDirectories.FirstOrDefault(f => f == mapDirectory);

                if (initialDirectory == null)
                {
                    initialDirectory = mapDirectories.First();
                }

                directoryDropdown.Text    = initialDirectory;
                directoryDropdown.OnClick = () =>
                                            directoryDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapDirectories, setupItem);
            }

            var filename = widget.Get <TextFieldWidget>("FILENAME");

            filename.Text = Path.GetFileNameWithoutExtension(map.Path);

            var fileTypes = new Dictionary <string, string>()
            {
                { ".oramap", ".oramap" },
                { "(unpacked)", "" }
            };

            var typeDropdown = widget.Get <DropDownButtonWidget>("TYPE_DROPDOWN");
            {
                Func <string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
                {
                    var item = ScrollItemWidget.Setup(template,
                                                      () => typeDropdown.Text == option,
                                                      () => typeDropdown.Text = option);
                    item.Get <LabelWidget>("LABEL").GetText = () => option;
                    return(item);
                };

                typeDropdown.Text = Path.GetExtension(map.Path);
                if (string.IsNullOrEmpty(typeDropdown.Text))
                {
                    typeDropdown.Text = fileTypes.First(t => t.Value == "").Key;
                }

                typeDropdown.OnClick = () =>
                                       typeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, fileTypes.Keys, setupItem);
            }

            var close = widget.Get <ButtonWidget>("BACK_BUTTON");

            close.OnClick = () => { Ui.CloseWindow(); onExit(); };

            var save = widget.Get <ButtonWidget>("SAVE_BUTTON");

            save.OnClick = () =>
            {
                if (string.IsNullOrEmpty(filename.Text))
                {
                    return;
                }

                map.Title             = title.Text;
                map.Description       = description.Text;
                map.Author            = author.Text;
                map.Visibility        = (MapVisibility)Enum.Parse(typeof(MapVisibility), visibilityDropdown.Text);
                map.ActorDefinitions  = editorActorLayer.Save();
                map.PlayerDefinitions = editorActorLayer.Players.ToMiniYaml();
                map.RequiresMod       = Game.ModData.Manifest.Mod.Id;

                var combinedPath = Platform.ResolvePath(Path.Combine(directoryDropdown.Text, filename.Text + fileTypes[typeDropdown.Text]));
                map.Save(combinedPath);

                // Update the map cache so it can be loaded without restarting the game
                Game.ModData.MapCache[map.Uid].UpdateFromMap(map, MapClassification.User);

                Console.WriteLine("Saved current map at {0}", combinedPath);
                Ui.CloseWindow();
                onExit();
            };
        }
Example #16
0
 public TSEditorResourceLayer(Actor self, TSEditorResourceLayerInfo info)
     : base(self, info)
 {
     this.info  = info;
     actorLayer = self.Trait <EditorActorLayer>();
 }