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 bool HandleMouseInput(MouseInput mi)
        {
            // Exclusively uses mouse wheel and both mouse buttons, but nothing else
            // Mouse move events are important for tooltips, so we always allow these through
            if ((mi.Button != MouseButton.Left && mi.Button != MouseButton.Right &&
                 mi.Event != MouseInputEvent.Move && mi.Event != MouseInputEvent.Scroll) ||
                mi.Event == MouseInputEvent.Down)
            {
                return(false);
            }

            worldPixel = worldRenderer.Viewport.ViewToWorldPx(mi.Location);
            var cell = worldRenderer.Viewport.ViewToWorld(mi.Location);

            var underCursor         = editorLayer.PreviewsAt(worldPixel).MinByOrDefault(CalculateActorSelectionPriority);
            var resourceUnderCursor = resourceLayer.GetResource(cell).Type;

            if (underCursor != null)
            {
                editorWidget.SetTooltip(underCursor.Tooltip);
            }
            else if (resourceUnderCursor != null)
            {
                editorWidget.SetTooltip(resourceUnderCursor);
            }
            else
            {
                editorWidget.SetTooltip(null);
            }

            // Finished with mouse move events, so let them bubble up the widget tree
            if (mi.Event == MouseInputEvent.Move)
            {
                return(false);
            }

            if (mi.Button == MouseButton.Left)
            {
                editorWidget.SetTooltip(null);
                SelectedActor = underCursor;
            }

            if (mi.Button == MouseButton.Right)
            {
                editorWidget.SetTooltip(null);

                if (underCursor != null && underCursor != SelectedActor)
                {
                    editorActionManager.Add(new RemoveActorAction(editorLayer, underCursor));
                }

                if (resourceUnderCursor != null)
                {
                    editorActionManager.Add(new RemoveResourceAction(resourceLayer, cell, resourceUnderCursor));
                }
            }

            return(true);
        }
Example #4
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 #5
0
 public void Do()
 {
     actor = editorActorLayer[actorId.ToLowerInvariant()];
     foreach (var editorActionHandle in handles)
     {
         editorActionHandle.Do(actor);
     }
 }
Example #6
0
        long CalculateActorSelectionPriority(EditorActorPreview actor)
        {
            var centerPixel   = new int2(actor.Bounds.X, actor.Bounds.Y);
            var pixelDistance = (centerPixel - worldPixel).Length;

            // If 2+ actors have the same pixel position, then the highest appears on top.
            var worldZPosition = actor.CenterPosition.Z;

            // Sort by pixel distance then in world z position.
            return(((long)pixelDistance << 32) + worldZPosition);
        }
Example #7
0
        public void Do()
        {
            var ownerName         = owner.Name;
            var specificOwnerInfo = actor.TraitInfoOrDefault <RequiresSpecificOwnersInfo>();

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

            var newActorReference = new ActorReference(actor.Name);

            newActorReference.Add(new OwnerInit(ownerName));

            newActorReference.Add(new LocationInit(cell));

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

            if (ios != null && ios.SharesCell)
            {
                var subcell = editorLayer.FreeSubCellAt(cell);
                if (subcell != SubCell.Invalid)
                {
                    newActorReference.Add(new SubCellInit(subcell));
                }
            }

            var initDict = newActorReference.InitDict;

            if (actor.HasTraitInfo <IFacingInfo>())
            {
                initDict.Add(new FacingInit(facing));
            }

            if (actor.HasTraitInfo <TurretedInfo>())
            {
                initDict.Add(new TurretFacingInit(facing));
            }

            editorActorPreview = editorLayer.Add(newActorReference);

            Text = "Added {0} ({1})".F(editorActorPreview.Info.Name, editorActorPreview.ID);
        }
Example #8
0
        public bool HandleMouseInput(MouseInput mi)
        {
            // Exclusively uses mouse wheel and both mouse buttons, but nothing else
            // Mouse move events are important for tooltips, so we always allow these through
            if ((mi.Button != MouseButton.Left && mi.Button != MouseButton.Right &&
                 mi.Event != MouseInputEvent.Move && mi.Event != MouseInputEvent.Scroll) ||
                mi.Event == MouseInputEvent.Down)
            {
                return(false);
            }

            worldPixel = worldRenderer.Viewport.ViewToWorldPx(mi.Location);
            var cell = worldRenderer.Viewport.ViewToWorld(mi.Location);

            var underCursor = editorLayer.PreviewsAt(worldPixel).MinByOrDefault(CalculateActorSelectionPriority);

            var          mapResources = world.Map.Resources;
            ResourceType type;

            if (underCursor != null)
            {
                editorWidget.SetTooltip(underCursor.Tooltip);
            }
            else if (mapResources.Contains(cell) && resources.TryGetValue(mapResources[cell].Type, out type))
            {
                editorWidget.SetTooltip(type.Info.Type);
            }
            else
            {
                editorWidget.SetTooltip(null);
            }

            // Finished with mouse move events, so let them bubble up the widget tree
            if (mi.Event == MouseInputEvent.Move)
            {
                return(false);
            }

            if (mi.Button == MouseButton.Left)
            {
                editorWidget.SetTooltip(null);
                SelectedActor = underCursor;
            }

            if (mi.Button == MouseButton.Right)
            {
                editorWidget.SetTooltip(null);

                if (underCursor != null && underCursor != SelectedActor)
                {
                    editorLayer.Remove(underCursor);
                }

                if (mapResources.Contains(cell) && mapResources[cell].Type != 0)
                {
                    mapResources[cell] = default(ResourceTile);
                }
            }

            return(true);
        }
Example #9
0
 public void Undo(EditorActorPreview actor)
 {
     change(actor, initialValue);
 }
Example #10
0
 public void Do()
 {
     editorActorPreview = editorLayer.Add(actor);
     Text = $"Added {editorActorPreview.Info.Name} ({editorActorPreview.ID})";
 }
Example #11
0
 public void Do()
 {
     editorActorPreview = editorLayer.Add(actor);
     Text = "Added {0} ({1})".F(editorActorPreview.Info.Name, editorActorPreview.ID);
 }
Example #12
0
 public void Do(EditorActorPreview actor)
 {
     actor.ID = newID;
 }
Example #13
0
 public void Undo(EditorActorPreview actor)
 {
     actor.ID = initial;
 }
Example #14
0
        public void Remove(EditorActorPreview preview)
        {
            previews.Remove(preview);
            screenMap.Remove(preview);

            foreach (var kv in preview.Footprint)
            {
                List<EditorActorPreview> list;
                if (!cellMap.TryGetValue(kv.Key, out list))
                    continue;

                list.Remove(preview);

                if (!list.Any())
                    cellMap.Remove(kv.Key);
            }

            UpdateNeighbours(preview.Footprint);

            if (preview.Info.Name == "mpspawn")
                SyncMultiplayerCount();
        }
Example #15
0
 public EditActorPreview(EditorActorPreview actor)
 {
     this.actor       = actor;
     setActorIdAction = new SetActorIdAction(actor.ID);
     handles.Add(setActorIdAction);
 }
Example #16
0
        EditorActorPreview Add(string id, ActorReference reference, bool initialSetup = false)
        {
            var owner = Players.Players[reference.InitDict.Get<OwnerInit>().PlayerName];

            var preview = new EditorActorPreview(worldRenderer, id, reference, owner);
            previews.Add(preview);
            screenMap.Add(preview, preview.Bounds);

            foreach (var kv in preview.Footprint)
            {
                List<EditorActorPreview> list;
                if (!cellMap.TryGetValue(kv.Key, out list))
                {
                    list = new List<EditorActorPreview>();
                    cellMap.Add(kv.Key, list);
                }

                list.Add(preview);
            }

            if (!initialSetup)
            {
                UpdateNeighbours(preview.Footprint);

                if (reference.Type == "mpspawn")
                    SyncMultiplayerCount();
            }

            return preview;
        }
Example #17
0
        long CalculateActorSelectionPriority(EditorActorPreview actor)
        {
            var centerPixel = new int2(actor.Bounds.X, actor.Bounds.Y);
            var pixelDistance = (centerPixel - worldPixel).Length;

            // If 2+ actors have the same pixel position, then the highest appears on top.
            var worldZPosition = actor.CenterPosition.Z;

            // Sort by pixel distance then in world z position.
            return ((long)pixelDistance << 32) + worldZPosition;
        }
Example #18
0
 public void Do(EditorActorPreview actor)
 {
     change(actor, value);
 }
Example #19
0
 void Close()
 {
     actorIDField.YieldKeyboardFocus();
     editor.DefaultBrush.SelectedActor = null;
     CurrentActor = null;
 }
Example #20
0
        public override void Tick()
        {
            if (actorIDStatus != nextActorIDStatus)
            {
                if ((actorIDStatus & nextActorIDStatus) == 0)
                {
                    var offset = actorIDErrorLabel.Bounds.Height;
                    if (nextActorIDStatus == ActorIDStatus.Normal)
                    {
                        offset *= -1;
                    }

                    actorEditPanel.Bounds.Height += offset;
                    initContainer.Bounds.Y       += offset;
                    buttonContainer.Bounds.Y     += offset;
                }

                actorIDStatus = nextActorIDStatus;
            }

            var actor = editor.DefaultBrush.SelectedActor;

            if (actor != null)
            {
                var origin = worldRenderer.Viewport.WorldToViewPx(new int2(actor.Bounds.Right, actor.Bounds.Top));

                // If we scrolled, hide the edit box for a moment
                if (lastScrollPosition.X != origin.X || lastScrollPosition.Y != origin.Y)
                {
                    lastScrollTime     = Game.RunTime;
                    lastScrollPosition = origin;
                }

                // If we changed actor, move widgets
                if (CurrentActor != actor)
                {
                    lastScrollTime = 0;                     // Ensure visible
                    CurrentActor   = actor;

                    editActorPreview = new EditActorPreview(CurrentActor);

                    initialActorID = actorIDField.Text = actor.ID;

                    var font          = Game.Renderer.Fonts[typeLabel.Font];
                    var truncatedType = WidgetUtils.TruncateText(actor.DescriptiveName, typeLabel.Bounds.Width, font);
                    typeLabel.Text = truncatedType;

                    actorIDField.CursorPosition = actor.ID.Length;
                    nextActorIDStatus           = ActorIDStatus.Normal;

                    // Remove old widgets
                    var oldInitHeight = initContainer.Bounds.Height;
                    initContainer.Bounds.Height = 0;
                    initContainer.RemoveChildren();

                    // Add owner dropdown
                    var ownerContainer = dropdownOptionTemplate.Clone();
                    ownerContainer.Get <LabelWidget>("LABEL").GetText = () => "Owner";
                    var ownerDropdown = ownerContainer.Get <DropDownButtonWidget>("OPTION");
                    var selectedOwner = actor.Owner;

                    Action <EditorActorPreview, PlayerReference> updateOwner = (preview, reference) =>
                    {
                        preview.Owner = reference;
                        preview.ReplaceInit(new OwnerInit(reference.Name));
                    };

                    var ownerHandler = new EditorActorOptionActionHandle <PlayerReference>(updateOwner, actor.Owner);
                    editActorPreview.Add(ownerHandler);

                    Func <PlayerReference, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
                    {
                        var item = ScrollItemWidget.Setup(template, () => selectedOwner == option, () =>
                        {
                            selectedOwner = option;
                            updateOwner(CurrentActor, selectedOwner);
                            ownerHandler.OnChange(option);
                        });

                        item.Get <LabelWidget>("LABEL").GetText = () => option.Name;
                        item.GetColor = () => option.Color;
                        return(item);
                    };

                    ownerDropdown.GetText  = () => selectedOwner.Name;
                    ownerDropdown.GetColor = () => selectedOwner.Color;
                    ownerDropdown.OnClick  = () =>
                    {
                        var owners = editorActorLayer.Players.Players.Values.OrderBy(p => p.Name);
                        ownerDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, setupItem);
                    };

                    initContainer.Bounds.Height += ownerContainer.Bounds.Height;
                    initContainer.AddChild(ownerContainer);

                    // Add new children for inits
                    var options = actor.Info.TraitInfos <IEditorActorOptions>()
                                  .SelectMany(t => t.ActorOptions(actor.Info, worldRenderer.World))
                                  .OrderBy(o => o.DisplayOrder);

                    foreach (var o in options)
                    {
                        if (o is EditorActorCheckbox)
                        {
                            var co = (EditorActorCheckbox)o;
                            var checkboxContainer = checkboxOptionTemplate.Clone();
                            checkboxContainer.Bounds.Y   = initContainer.Bounds.Height;
                            initContainer.Bounds.Height += checkboxContainer.Bounds.Height;

                            var checkbox = checkboxContainer.Get <CheckboxWidget>("OPTION");
                            checkbox.GetText = () => co.Name;

                            var editorActionHandle = new EditorActorOptionActionHandle <bool>(co.OnChange, co.GetValue(actor));
                            editActorPreview.Add(editorActionHandle);

                            checkbox.IsChecked = () => co.GetValue(actor);
                            checkbox.OnClick   = () =>
                            {
                                var newValue = co.GetValue(actor) ^ true;
                                co.OnChange(actor, newValue);
                                editorActionHandle.OnChange(newValue);
                            };

                            initContainer.AddChild(checkboxContainer);
                        }
                        else if (o is EditorActorSlider)
                        {
                            var so = (EditorActorSlider)o;
                            var sliderContainer = sliderOptionTemplate.Clone();
                            sliderContainer.Bounds.Y     = initContainer.Bounds.Height;
                            initContainer.Bounds.Height += sliderContainer.Bounds.Height;
                            sliderContainer.Get <LabelWidget>("LABEL").GetText = () => so.Name;

                            var slider = sliderContainer.Get <SliderWidget>("OPTION");
                            slider.MinimumValue = so.MinValue;
                            slider.MaximumValue = so.MaxValue;
                            slider.Ticks        = so.Ticks;

                            var editorActionHandle = new EditorActorOptionActionHandle <float>(so.OnChange, so.GetValue(actor));
                            editActorPreview.Add(editorActionHandle);

                            slider.GetValue  = () => so.GetValue(actor);
                            slider.OnChange += value => so.OnChange(actor, value);
                            slider.OnChange += value => editorActionHandle.OnChange(value);

                            initContainer.AddChild(sliderContainer);
                        }
                        else if (o is EditorActorDropdown)
                        {
                            var ddo = (EditorActorDropdown)o;
                            var dropdownContainer = dropdownOptionTemplate.Clone();
                            dropdownContainer.Bounds.Y   = initContainer.Bounds.Height;
                            initContainer.Bounds.Height += dropdownContainer.Bounds.Height;
                            dropdownContainer.Get <LabelWidget>("LABEL").GetText = () => ddo.Name;

                            var editorActionHandle = new EditorActorOptionActionHandle <string>(ddo.OnChange, ddo.GetValue(actor));
                            editActorPreview.Add(editorActionHandle);

                            var dropdown = dropdownContainer.Get <DropDownButtonWidget>("OPTION");
                            Func <KeyValuePair <string, string>, ScrollItemWidget, ScrollItemWidget> dropdownSetup = (option, template) =>
                            {
                                var item = ScrollItemWidget.Setup(template,
                                                                  () => ddo.GetValue(actor) == option.Key,
                                                                  () =>
                                {
                                    ddo.OnChange(actor, option.Key);
                                    editorActionHandle.OnChange(option.Key);
                                });

                                item.Get <LabelWidget>("LABEL").GetText = () => option.Value;
                                return(item);
                            };

                            dropdown.GetText = () => ddo.Labels[ddo.GetValue(actor)];
                            dropdown.OnClick = () => dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, ddo.Labels, dropdownSetup);

                            initContainer.AddChild(dropdownContainer);
                        }
                    }

                    actorEditPanel.Bounds.Height += initContainer.Bounds.Height - oldInitHeight;
                    buttonContainer.Bounds.Y     += initContainer.Bounds.Height - oldInitHeight;
                }

                // Set the edit panel to the right of the selection border.
                actorEditPanel.Bounds.X = origin.X + editPanelPadding;
                actorEditPanel.Bounds.Y = origin.Y;
            }
            else
            {
                // Selected actor is null, hide the border and edit panel.
                actorIDField.YieldKeyboardFocus();
                CurrentActor = null;
            }
        }