/// <summary>
        ///  Gives a mob a permission to place a given Tile.
        /// </summary>
        public void AssignBuildPermissionTile(IEntity mob, int range, string tileType, string alignOption)
        {
            var newPermission = new PlacementInformation
            {
                MobUid          = mob.Uid,
                Range           = range,
                IsTile          = true,
                TileType        = IoCManager.Resolve <ITileDefinitionManager>()[tileType].TileId,
                PlacementOption = alignOption
            };

            IEnumerable <PlacementInformation> mobPermissions = from PlacementInformation permission in BuildPermissions
                                                                where permission.MobUid == mob.Uid
                                                                select permission;

            if (mobPermissions.Any()) //Already has one? Revoke the old one and add this one.
            {
                RevokeAllBuildPermissions(mob);
                BuildPermissions.Add(newPermission);
            }
            else
            {
                BuildPermissions.Add(newPermission);
            }
        }
Esempio n. 2
0
        private void OnItemButtonToggled(BaseButton.ButtonToggledEventArgs args)
        {
            var item = (EntitySpawnButton)args.Button.Parent;

            if (SelectedButton == item)
            {
                SelectedButton = null;
                placementManager.Clear();
                return;
            }
            else if (SelectedButton != null)
            {
                SelectedButton.ActualButton.Pressed = false;
            }

            SelectedButton = null;

            var overrideMode = initOpts[OverrideMenu.SelectedId];
            var newObjInfo   = new PlacementInformation
            {
                PlacementOption = overrideMode.Length > 0 ? overrideMode : item.Prototype.PlacementMode,
                EntityType      = item.PrototypeID,
                Range           = 2,
                IsTile          = false
            };

            placementManager.BeginPlacing(newObjInfo);

            SelectedButton = item;
        }
        /// <summary>
        ///  Gives a mob a permission to place a given Entity.
        /// </summary>
        public void AssignBuildPermission(IEntity mob, int range, string objectType, string alignOption)
        {
            var newPermission = new PlacementInformation
            {
                MobUid          = mob.Uid,
                Range           = range,
                IsTile          = false,
                EntityType      = objectType,
                PlacementOption = alignOption
            };

            IEnumerable <PlacementInformation> mobPermissions = from PlacementInformation permission in BuildPermissions
                                                                where permission.MobUid == mob.Uid
                                                                select permission;

            if (mobPermissions.Any()) //Already has one? Revoke the old one and add this one.
            {
                RevokeAllBuildPermissions(mob);
                BuildPermissions.Add(newPermission);
            }
            else
            {
                BuildPermissions.Add(newPermission);
            }
        }
Esempio n. 4
0
        private void NewButtonClicked(EntitySpawnSelectButton sender, EntityPrototype template, string templateName)
        {
            if (sender.Selected)
            {
                sender.Selected = false;
                _placementManager.Clear();
                return;
            }

            foreach (
                var curr in
                _entityList.Components.Where(curr => curr.GetType() == typeof(EntitySpawnSelectButton)))
            {
                ((EntitySpawnSelectButton)curr).Selected = false;
            }

            var overrideMode = "PlaceFree";

            if (_lstOverride.CurrentlySelected != null)
            {
                overrideMode = _lstOverride.CurrentlySelected.Text;
            }

            var newObjInfo = new PlacementInformation
            {
                PlacementOption = overrideMode.Length > 0 ? overrideMode : template.PlacementMode,
                EntityType      = templateName,
                Range           = 2,
                IsTile          = false
            };

            _placementManager.BeginPlacing(newObjInfo);

            sender.Selected = true; //This needs to be last.
        }
        void OnBuildPressed(BaseButton.ButtonEventArgs args)
        {
            var prototype = (ConstructionPrototype)RecipeList.Selected.Metadata;

            if (prototype == null)
            {
                return;
            }

            if (prototype.Type != ConstructionType.Structure)
            {
                // In-hand attackby doesn't exist so this is the best alternative.
                var loc = Owner.Owner.GetComponent <ITransformComponent>().GridPosition;
                Owner.SpawnGhost(prototype, loc, Direction.North);
                return;
            }

            var hijack = new ConstructionPlacementHijack(prototype, Owner);
            var info   = new PlacementInformation
            {
                IsTile          = false,
                PlacementOption = prototype.PlacementMode,
            };


            Placement.BeginHijackedPlacing(info, hijack);
        }
        public void BeginPlacing(PlacementInformation info)
        {
            Clear();

            IoCManager.Resolve <IUserInterfaceManager>().DragInfo.Reset();

            CurrentPermission = info;

            if (!_modeDictionary.Any(pair => pair.Key.Equals(CurrentPermission.PlacementOption)))
            {
                Clear();
                return;
            }

            Type modeType = _modeDictionary.First(pair => pair.Key.Equals(CurrentPermission.PlacementOption)).Value;

            CurrentMode = (PlacementMode)Activator.CreateInstance(modeType, this);

            if (info.IsTile)
            {
                PreparePlacementTile((Tile)info.TileType);
            }
            else
            {
                PreparePlacement(info.EntityType);
            }
        }
        public override void SetPosition(PlacementInformation info)
        {
            base.SetPosition(info);

            var resizeExtensions = info.Item.Extensions.OfType <ResizeThumbExtension>();

            if (resizeExtensions != null && resizeExtensions.Count() != 0)
            {
                var resizeExtension = resizeExtensions.First();
                _isItemGettingResized = resizeExtension.IsResizing;
            }

            if (_stackPanel != null && !_isItemGettingResized)
            {
                if (_stackPanel.Orientation == Orientation.Vertical)
                {
                    var offset = FindHorizontalRectanglePlacementOffset(info.Bounds);
                    DrawHorizontalRectangle(offset);
                }
                else
                {
                    var offset = FindVerticalRectanglePlacementOffset(info.Bounds);
                    DrawVerticalRectangle(offset);
                }

                ChangePostionTo(info.Item.View, _indexToInsert);
            }
        }
Esempio n. 8
0
        private void OnItemButtonToggled(BaseButton.ButtonToggledEventArgs args)
        {
            var item = (TileSpawnButton)args.Button.Parent;

            if (SelectedButton == item)
            {
                SelectedButton = null;
                placementManager.Clear();
                return;
            }
            else if (SelectedButton != null)
            {
                SelectedButton.ActualButton.Pressed = false;
            }

            SelectedButton = null;

            var newObjInfo = new PlacementInformation
            {
                PlacementOption = "AlignTileAny",
                TileType        = tileDefinitionManager[item.TileDef].TileId,
                Range           = 400,
                IsTile          = true
            };

            placementManager.BeginPlacing(newObjInfo);
            SelectedButton = item;
        }
Esempio n. 9
0
 public virtual void SetPosition(PlacementInformation info)
 {
     if (info.Operation.Type != PlacementType.Move)
     {
         ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
     }
 }
        public override void SetPosition(PlacementInformation info)
        {
            base.SetPosition(info);
            info.Item.Properties[FrameworkElement.MarginProperty].Reset();

            UIElement child       = info.Item.View;
            Rect      newPosition = info.Bounds;

            if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty))
            {
                if (newPosition.Left != GetCanvasProperty(child, Canvas.LeftProperty))
                {
                    info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
                }
            }
            else
            {
                var newR = extendedComponent.ActualWidth - newPosition.Right;
                if (newR != GetCanvasProperty(child, Canvas.RightProperty))
                {
                    info.Item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(newR);
                }
            }


            if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty))
            {
                if (newPosition.Top != GetCanvasProperty(child, Canvas.TopProperty))
                {
                    info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
                }
            }
            else
            {
                var newB = extendedComponent.ActualHeight - newPosition.Bottom;
                if (newB != GetCanvasProperty(child, Canvas.BottomProperty))
                {
                    info.Item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(newB);
                }
            }

            if (info.Item == Services.Selection.PrimarySelection)
            {
                var b = new Rect(0, 0, extendedView.ActualWidth, extendedView.ActualHeight);
                // only for primary selection:
                if (grayOut != null)
                {
                    grayOut.AnimateActiveAreaRectTo(b);
                }
                else
                {
                    GrayOutDesignerExceptActiveArea.Start(ref grayOut, this.Services, this.ExtendedItem.View, b);
                }
            }
        }
Esempio n. 11
0
		public void SetPosition(PlacementInformation info)
		{
			UIElement element = info.Item.View;
			Rect newPosition = info.Bounds;
			if (newPosition.Right != ModelTools.GetWidth(element)) {
				info.Item.Properties[FrameworkElement.WidthProperty].SetValue(newPosition.Right);
			}
			if (newPosition.Bottom != ModelTools.GetHeight(element)) {
				info.Item.Properties[FrameworkElement.HeightProperty].SetValue(newPosition.Bottom);
			}
		}
Esempio n. 12
0
        public virtual void SetPosition(PlacementInformation info)
        {
            if (info.Operation.Type != PlacementType.Move &&
                info.Operation.Type != PlacementType.MovePoint &&
                info.Operation.Type != PlacementType.MoveAndIgnoreOtherContainers)
            {
                ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
            }

            //if (info.Operation.Type == PlacementType.MovePoint)
            //	ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
        }
 public void Clear()
 {
     CurrentBaseSprite = null;
     CurrentPrototype  = null;
     CurrentPermission = null;
     CurrentMode       = null;
     if (PlacementCanceled != null && IsActive && !Eraser)
     {
         PlacementCanceled(this, null);
     }
     IsActive = false;
     Eraser   = false;
 }
        private void HandleStartPlacement(MsgPlacement msg)
        {
            CurrentPermission = new PlacementInformation
            {
                Range  = msg.Range,
                IsTile = msg.IsTile,
            };

            CurrentPermission.EntityType      = msg.ObjType; // tile or ent type
            CurrentPermission.PlacementOption = msg.AlignOption;

            BeginPlacing(CurrentPermission);
        }
Esempio n. 15
0
        public void SetPosition(PlacementInformation info)
        {
            UIElement element     = info.Item.View;
            Rect      newPosition = info.Bounds;

            if (newPosition.Right != ModelTools.GetWidth(element))
            {
                info.Item.Properties[FrameworkElement.WidthProperty].SetValue(newPosition.Right);
            }
            if (newPosition.Bottom != ModelTools.GetHeight(element))
            {
                info.Item.Properties[FrameworkElement.HeightProperty].SetValue(newPosition.Bottom);
            }
        }
        private void TileListOnOnItemSelected(ItemList.ItemListSelectedEventArgs args)
        {
            var definition = _shownItems[args.ItemIndex];

            var newObjInfo = new PlacementInformation
            {
                PlacementOption = "AlignTileAny",
                TileType        = definition.TileId,
                Range           = 400,
                IsTile          = true
            };

            _placementManager.BeginPlacing(newObjInfo);
        }
		public override void SetPosition(PlacementInformation info)
		{
			base.SetPosition(info);
			info.Item.Properties[FrameworkElement.MarginProperty].Reset();

			UIElement child = info.Item.View;
			Rect newPosition = info.Bounds;

			if (newPosition.Left != GetLeft(child)) {
				info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
			}
			if (newPosition.Top != GetTop(child)) {
				info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
			}
		}
Esempio n. 18
0
		public override void SetPosition(PlacementInformation info)
		{
			base.SetPosition(info);
			info.Item.Properties[FrameworkElement.MarginProperty].Reset();

			UIElement child = info.Item.View;
			Rect newPosition = info.Bounds;

			if (IsPropertySet(child, Canvas.RightProperty))
			{
				var newR = ((Canvas) ExtendedItem.Component).ActualWidth - newPosition.Right;
				if (newR != GetCanvasProperty(child, Canvas.RightProperty))
					info.Item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(newR);
			}
			else if (newPosition.Left != GetCanvasProperty(child, Canvas.LeftProperty))
			{
				info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
			}


			if (IsPropertySet(child, Canvas.BottomProperty))
			{
				var newB = ((Canvas)ExtendedItem.Component).ActualHeight - newPosition.Bottom;
				if (newB != GetCanvasProperty(child, Canvas.BottomProperty))
					info.Item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(newB);
			}
			else if (newPosition.Top != GetCanvasProperty(child, Canvas.TopProperty))
			{
				info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
			}

			if (info.Item == Services.Selection.PrimarySelection)
			{
				var cv = this.ExtendedItem.View as Canvas;
				var b = new Rect(0, 0, cv.ActualWidth, cv.ActualHeight);
				// only for primary selection:
				if (grayOut != null)
				{
					grayOut.AnimateActiveAreaRectTo(b);
				}
				else
				{
					GrayOutDesignerExceptActiveArea.Start(ref grayOut, this.Services, this.ExtendedItem.View, b);
				}
			}
		}
        public override void SetPosition(PlacementInformation info)
        {
            base.SetPosition(info);
            info.Item.Properties[FrameworkElement.MarginProperty].Reset();

            UIElement child       = info.Item.View;
            Rect      newPosition = info.Bounds;

            if (newPosition.Left != GetLeft(child))
            {
                info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
            }
            if (newPosition.Top != GetTop(child))
            {
                info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
            }
        }
Esempio n. 20
0
        private void OnOverrideMenuItemSelected(OptionButton.ItemSelectedEventArgs args)
        {
            OverrideMenu.SelectId(args.Id);

            if (placementManager.CurrentMode != null)
            {
                var newObjInfo = new PlacementInformation
                {
                    PlacementOption = initOpts[args.Id],
                    EntityType      = placementManager.CurrentPermission.EntityType,
                    Range           = 2,
                    IsTile          = placementManager.CurrentPermission.IsTile
                };

                placementManager.Clear();
                placementManager.BeginPlacing(newObjInfo);
            }
        }
Esempio n. 21
0
        private void _lstOverride_ItemSelected(Label item, Listbox sender)
        {
            var pMan = (PlacementManager)_placementManager;

            if (pMan.CurrentMode != null)
            {
                var newObjInfo = new PlacementInformation
                {
                    PlacementOption = item.Text.Text,
                    EntityType      = pMan.CurrentPermission.EntityType,
                    Range           = -1,
                    IsTile          = pMan.CurrentPermission.IsTile
                };

                _placementManager.Clear();
                _placementManager.BeginPlacing(newObjInfo);
            }
        }
Esempio n. 22
0
        private void TileLabelClicked(Label sender, MouseButtonEventArgs e)
        {
            foreach (GuiComponent curr in _tileList.components.Where(curr => curr.GetType() == typeof(Label)))
            {
                ((Label)curr).BackgroundColor = new SFML.Graphics.Color(128, 128, 128);
            }

            var newObjInfo = new PlacementInformation
            {
                PlacementOption = "AlignTileAny",
                TileType        = IoCManager.Resolve <ITileDefinitionManager>()[sender.Text.Text].TileId,
                Range           = 400,
                IsTile          = true
            };

            _placementManager.BeginPlacing(newObjInfo);

            sender.BackgroundColor = new SFML.Graphics.Color(34, 139, 34);
        }
Esempio n. 23
0
        private void TileLabelClicked(Label sender, MouseButtonEventArgs e)
        {
            foreach (var curr in _tileList.Container.Children.Where(curr => curr.GetType() == typeof(Label)))
            {
                ((Label)curr).BackgroundColor = Color4.Gray;
            }

            var newObjInfo = new PlacementInformation
            {
                PlacementOption = "AlignTileAny",
                TileType        = IoCManager.Resolve <ITileDefinitionManager>()[sender.Text].TileId,
                Range           = 400,
                IsTile          = true
            };

            _placementManager.BeginPlacing(newObjInfo);

            sender.BackgroundColor = new Color4(34, 139, 34, 255);
        }
        private void HandleStartPlacement(NetIncomingMessage msg)
        {
            CurrentPermission = new PlacementInformation
            {
                Range  = msg.ReadInt32(),
                IsTile = msg.ReadBoolean()
            };

            if (CurrentPermission.IsTile)
            {
                CurrentPermission.TileType = msg.ReadUInt16();
            }
            else
            {
                CurrentPermission.EntityType = msg.ReadString();
            }
            CurrentPermission.PlacementOption = msg.ReadString();

            BeginPlacing(CurrentPermission);
        }
Esempio n. 25
0
        private void HandleStartPlacement(NetIncomingMessage msg)
        {
            CurrentPermission = new PlacementInformation
            {
                Range  = msg.ReadInt32(),
                IsTile = msg.ReadBoolean()
            };

            var mapMgr = (MapManager)IoCManager.Resolve <IMapManager>();

            if (CurrentPermission.IsTile)
            {
                CurrentPermission.TileType = mapMgr.GetTileString(msg.ReadByte());
            }
            else
            {
                CurrentPermission.EntityType = msg.ReadString();
            }
            CurrentPermission.PlacementOption = msg.ReadString();

            BeginPlacing(CurrentPermission);
        }
Esempio n. 26
0
        private void TileLabelClicked(Label sender, MouseInputEventArgs e)
        {
            foreach (GuiComponent curr in _tileList.components.Where(curr => curr.GetType() == typeof(Label)))
            {
                ((Label)curr).BackgroundColor = Color.Gray;
            }

            var newObjInfo = new PlacementInformation
            {
                PlacementOption = "AlignTileAny",
                TileType        = sender.Text.Text,
                Range           = 400,
                IsTile          = true
            };

            if (sender.Text.Text == "Wall")
            {
                newObjInfo.PlacementOption = "AlignWallPlace";
            }

            _placementManager.BeginPlacing(newObjInfo);

            sender.BackgroundColor = Color.ForestGreen;
        }
		public virtual void SetPosition(PlacementInformation info)
		{
			ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
		}
Esempio n. 28
0
 public virtual void SetPosition(PlacementInformation info)
 {
     ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
 }
 public virtual void SetPosition(PlacementInformation info)
 {
 }
Esempio n. 30
0
        public void HandlePlacementRequest(MsgPlacement msg)
        {
            var alignRcv = msg.Align;
            var isTile   = msg.IsTile;
            var mapMgr   = IoCManager.Resolve <IMapManager>();

            ushort tileType           = 0;
            var    entityTemplateName = "";

            if (isTile)
            {
                tileType = msg.TileType;
            }
            else
            {
                entityTemplateName = msg.EntityTemplateName;
            }

            float xRcv   = msg.XRcv;
            float yRcv   = msg.YRcv;
            var   dirRcv = msg.DirRcv;

            IPlayerSession session = IoCManager.Resolve <IPlayerManager>().GetSessionById(msg.MsgChannel.NetworkId);

            if (session.attachedEntity == null)
            {
                return; //Don't accept placement requests from nobodys
            }
            PlacementInformation permission = GetPermission(session.attachedEntity.Uid, alignRcv);

            float   a       = (float)Math.Floor(xRcv);
            float   b       = (float)Math.Floor(yRcv);
            Vector2 tilePos = new Vector2(a, b);

            if (permission != null || true)
            //isAdmin) Temporarily disable actual permission check / admin check. REENABLE LATER
            {
                if (permission != null)
                {
                    if (permission.Uses > 0)
                    {
                        permission.Uses--;
                        if (permission.Uses <= 0)
                        {
                            BuildPermissions.Remove(permission);
                            SendPlacementCancel(session.attachedEntity);
                        }
                    }
                    else
                    {
                        BuildPermissions.Remove(permission);
                        SendPlacementCancel(session.attachedEntity);
                        return;
                    }
                }

                if (!isTile)
                {
                    var manager = IoCManager.Resolve <IServerEntityManager>();
                    if (manager.TrySpawnEntityAt(entityTemplateName, new Vector2(xRcv, yRcv), out IEntity created))
                    {
                        created.GetComponent <TransformComponent>().Position =
                            new Vector2(xRcv, yRcv);
                        if (created.TryGetComponent <TransformComponent>(out var component))
                        {
                            component.Rotation = dirRcv.ToAngle();
                        }
                    }
                }
                else
                {
                    mapMgr.GetGrid(mapMgr.DefaultGridId).SetTile(tilePos, new Tile(tileType));
                }
            }
        }
        public void HandlePlacementRequest(MsgPlacement msg)
        {
            var alignRcv = msg.Align;
            var isTile   = msg.IsTile;
            var mapMgr   = (MapManager)IoCManager.Resolve <IMapManager>();

            ushort tileType           = 0;
            var    entityTemplateName = "";

            if (isTile)
            {
                tileType = msg.TileType;
            }
            else
            {
                entityTemplateName = msg.EntityTemplateName;
            }

            float xRcv   = msg.XRcv;
            float yRcv   = msg.YRcv;
            var   dirRcv = msg.DirRcv;

            IPlayerSession session = IoCManager.Resolve <IPlayerManager>().GetSessionById(msg.MsgChannel.NetworkId);

            if (session.attachedEntity == null)
            {
                return; //Don't accept placement requests from nobodys
            }
            PlacementInformation permission = GetPermission(session.attachedEntity.Uid, alignRcv);

            float    a       = (float)Math.Floor(xRcv);
            float    b       = (float)Math.Floor(yRcv);
            Vector2f tilePos = new Vector2f(a, b);

            if (permission != null || true)
            //isAdmin) Temporarily disable actual permission check / admin check. REENABLE LATER
            {
                if (permission != null)
                {
                    if (permission.Uses > 0)
                    {
                        permission.Uses--;
                        if (permission.Uses <= 0)
                        {
                            BuildPermissions.Remove(permission);
                            SendPlacementCancel(session.attachedEntity);
                        }
                    }
                    else
                    {
                        BuildPermissions.Remove(permission);
                        SendPlacementCancel(session.attachedEntity);
                        return;
                    }
                }

                if (!isTile)
                {
                    var     manager = IoCManager.Resolve <IServerEntityManager>();
                    IEntity created = manager.SpawnEntityAt(entityTemplateName, new Vector2f(xRcv, yRcv));
                    if (created != null)
                    {
                        created.GetComponent <ITransformComponent>().Position =
                            new Vector2f(xRcv, yRcv);
                        if (created.TryGetComponent <IDirectionComponent>(out var component))
                        {
                            component.Direction = dirRcv;
                        }
                    }
                }
                else
                {
                    mapMgr.Tiles[tilePos] = new Tile(tileType);
                }
            }

            /*
             * else //They are not allowed to request this. Send 'PlacementFailed'. TBA
             * {
             *  Logger.Log("Invalid placement request: "
             + IoCManager.Resolve<IPlayerManager>().GetSessionByConnection(msg.SenderConnection).name +
             +                 " - " +
             +                 IoCManager.Resolve<IPlayerManager>().GetSessionByConnection(msg.SenderConnection).
             +                     attachedEntity.Uid.ToString() +
             +                 " - " + alignRcv.ToString());
             +
             +  SendPlacementCancel(
             +      IoCManager.Resolve<IPlayerManager>().GetSessionByConnection(msg.SenderConnection).attachedEntity);
             + }
             */
        }
Esempio n. 32
0
		public override void SetPosition(PlacementInformation info)
		{
			base.SetPosition(info);
			int leftColumnIndex = GetColumnIndex(info.Bounds.Left);
			int rightColumnIndex = GetEndColumnIndex(info.Bounds.Right);
			if (rightColumnIndex < leftColumnIndex) rightColumnIndex = leftColumnIndex;
			SetColumn(info.Item, leftColumnIndex, rightColumnIndex - leftColumnIndex + 1);
			int topRowIndex = GetRowIndex(info.Bounds.Top);
			int bottomRowIndex = GetEndRowIndex(info.Bounds.Bottom);
			if (bottomRowIndex < topRowIndex) bottomRowIndex = topRowIndex;
			SetRow(info.Item, topRowIndex, bottomRowIndex - topRowIndex + 1);
			
			Rect availableSpaceRect = new Rect(
				new Point(GetColumnOffset(leftColumnIndex), GetRowOffset(topRowIndex)),
				new Point(GetColumnOffset(rightColumnIndex + 1), GetRowOffset(bottomRowIndex + 1))
			);
			if (info.Item == Services.Selection.PrimarySelection) {
				// only for primary selection:
				if (grayOut != null) {
					grayOut.AnimateActiveAreaRectTo(availableSpaceRect);
				} else {
					GrayOutDesignerExceptActiveArea.Start(ref grayOut, this.Services, this.ExtendedItem.View, availableSpaceRect);
				}
			}
			
			HorizontalAlignment ha = (HorizontalAlignment)info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance;
			VerticalAlignment va = (VerticalAlignment)info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance;
			if(enteredIntoNewContainer){
				ha = SuggestHorizontalAlignment(info.Bounds, availableSpaceRect);
				va = SuggestVerticalAlignment(info.Bounds, availableSpaceRect);
			}
			info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(ha);
			info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(va);
			
			Thickness margin = new Thickness(0, 0, 0, 0);
			if (ha == HorizontalAlignment.Left || ha == HorizontalAlignment.Stretch)
				margin.Left = info.Bounds.Left - GetColumnOffset(leftColumnIndex);
			if (va == VerticalAlignment.Top || va == VerticalAlignment.Stretch)
				margin.Top = info.Bounds.Top - GetRowOffset(topRowIndex);
			if (ha == HorizontalAlignment.Right || ha == HorizontalAlignment.Stretch)
				margin.Right = GetColumnOffset(rightColumnIndex + 1) - info.Bounds.Right;
			if (va == VerticalAlignment.Bottom || va == VerticalAlignment.Stretch)
				margin.Bottom = GetRowOffset(bottomRowIndex + 1) - info.Bounds.Bottom;
			info.Item.Properties[FrameworkElement.MarginProperty].SetValue(margin);
			
			if (ha == HorizontalAlignment.Stretch)
				info.Item.Properties[FrameworkElement.WidthProperty].Reset();
			else
				info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width);
			
			if (va == VerticalAlignment.Stretch)
				info.Item.Properties[FrameworkElement.HeightProperty].Reset();
			else
				info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height);
		}
		public virtual void SetPosition(PlacementInformation info)
		{
			if (info.Operation.Type != PlacementType.Move 
				&& info.Operation.Type != PlacementType.MovePoint
				&& info.Operation.Type != PlacementType.MoveAndIgnoreOtherContainers)
				ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);

			//if (info.Operation.Type == PlacementType.MovePoint)
			//	ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
		}
		public virtual bool CanPlaceItem(PlacementInformation info)
		{
			return true;
		}
Esempio n. 35
0
        public override void SetPosition(PlacementInformation info)
        {
            base.SetPosition(info);
            int leftColumnIndex  = GetColumnIndex(info.Bounds.Left);
            int rightColumnIndex = GetEndColumnIndex(info.Bounds.Right);

            if (rightColumnIndex < leftColumnIndex)
            {
                rightColumnIndex = leftColumnIndex;
            }
            SetColumn(info.Item, leftColumnIndex, rightColumnIndex - leftColumnIndex + 1);
            int topRowIndex    = GetRowIndex(info.Bounds.Top);
            int bottomRowIndex = GetEndRowIndex(info.Bounds.Bottom);

            if (bottomRowIndex < topRowIndex)
            {
                bottomRowIndex = topRowIndex;
            }
            SetRow(info.Item, topRowIndex, bottomRowIndex - topRowIndex + 1);

            Rect availableSpaceRect = new Rect(
                new Point(GetColumnOffset(leftColumnIndex), GetRowOffset(topRowIndex)),
                new Point(GetColumnOffset(rightColumnIndex + 1), GetRowOffset(bottomRowIndex + 1))
                );

            if (info.Item == Services.Selection.PrimarySelection)
            {
                // only for primary selection:
                if (grayOut != null)
                {
                    grayOut.AnimateActiveAreaRectTo(availableSpaceRect);
                }
                else
                {
                    GrayOutDesignerExceptActiveArea.Start(ref grayOut, this.Services, this.ExtendedItem.View,
                                                          availableSpaceRect);
                }
            }

            HorizontalAlignment ha = (HorizontalAlignment)info.Item
                                     .Properties[FrameworkElement.HorizontalAlignmentProperty]
                                     .ValueOnInstance;
            VerticalAlignment va = (VerticalAlignment)info.Item.Properties[FrameworkElement.VerticalAlignmentProperty]
                                   .ValueOnInstance;

            if (enteredIntoNewContainer)
            {
                ha = SuggestHorizontalAlignment(info.Bounds, availableSpaceRect);
                va = SuggestVerticalAlignment(info.Bounds, availableSpaceRect);
            }
            info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(ha);
            info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(va);

            Thickness margin = new Thickness(0, 0, 0, 0);

            if (ha == HorizontalAlignment.Left || ha == HorizontalAlignment.Stretch)
            {
                margin.Left = info.Bounds.Left - GetColumnOffset(leftColumnIndex);
            }
            if (va == VerticalAlignment.Top || va == VerticalAlignment.Stretch)
            {
                margin.Top = info.Bounds.Top - GetRowOffset(topRowIndex);
            }
            if (ha == HorizontalAlignment.Right || ha == HorizontalAlignment.Stretch)
            {
                margin.Right = GetColumnOffset(rightColumnIndex + 1) - info.Bounds.Right;
            }
            if (va == VerticalAlignment.Bottom || va == VerticalAlignment.Stretch)
            {
                margin.Bottom = GetRowOffset(bottomRowIndex + 1) - info.Bounds.Bottom;
            }
            info.Item.Properties[FrameworkElement.MarginProperty].SetValue(margin);

            if (ha == HorizontalAlignment.Stretch)
            {
                info.Item.Properties[FrameworkElement.WidthProperty].Reset();
            }
            //else
            //    info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width);

            if (va == VerticalAlignment.Stretch)
            {
                info.Item.Properties[FrameworkElement.HeightProperty].Reset();
            }
            //else
            //    info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height);
        }
 public virtual bool CanPlaceItem(PlacementInformation info)
 {
     return(true);
 }
        public override void SetPosition(PlacementInformation info)
        {
            base.SetPosition(info);

            var resizeExtensions = info.Item.Extensions.OfType<ResizeThumbExtension>();
            if (resizeExtensions != null && resizeExtensions.Count() != 0) {
                var resizeExtension = resizeExtensions.First();
                _isItemGettingResized = resizeExtension.IsResizing;
            }

            if (_stackPanel != null && !_isItemGettingResized) {
                if (_stackPanel.Orientation == Orientation.Vertical) {
                    var offset = FindHorizontalRectanglePlacementOffset(info.Bounds);
                    DrawHorizontalRectangle(offset);
                } else {
                    var offset = FindVerticalRectanglePlacementOffset(info.Bounds);
                    DrawVerticalRectangle(offset);
                }

                ChangePostionTo(info.Item.View, _indexToInsert);
            }
        }
Esempio n. 38
0
        public void HandlePlacementRequest(NetIncomingMessage msg)
        {
            string alignRcv = msg.ReadString();

            Boolean isTile = msg.ReadBoolean();

            var mapMgr = (MapManager)IoCManager.Resolve <IMapManager>();

            ushort tileType = 0;

            string entityTemplateName = "";

            if (isTile)
            {
                tileType = msg.ReadUInt16();
            }
            else
            {
                entityTemplateName = msg.ReadString();
            }

            float xRcv   = msg.ReadFloat();
            float yRcv   = msg.ReadFloat();
            var   dirRcv = (Direction)msg.ReadByte();

            IPlayerSession session = IoCManager.Resolve <IPlayerManager>().GetSessionByConnection(msg.SenderConnection);

            if (session.attachedEntity == null)
            {
                return; //Don't accept placement requests from nobodys
            }
            PlacementInformation permission = GetPermission(session.attachedEntity.Uid, alignRcv);
            Boolean isAdmin =
                IoCManager.Resolve <IPlayerManager>().GetSessionByConnection(msg.SenderConnection).adminPermissions.
                isAdmin;

            float    a       = (float)Math.Floor(xRcv);
            float    b       = (float)Math.Floor(yRcv);
            Vector2f tilePos = new Vector2f(a, b);

            if (permission != null || true)
            //isAdmin) Temporarily disable actual permission check / admin check. REENABLE LATER
            {
                if (permission != null)
                {
                    if (permission.Uses > 0)
                    {
                        permission.Uses--;
                        if (permission.Uses <= 0)
                        {
                            BuildPermissions.Remove(permission);
                            SendPlacementCancel(session.attachedEntity);
                        }
                    }
                    else
                    {
                        BuildPermissions.Remove(permission);
                        SendPlacementCancel(session.attachedEntity);
                        return;
                    }
                }

                if (!isTile)
                {
                    Entity created = _server.EntityManager.SpawnEntityAt(entityTemplateName, new Vector2f(xRcv, yRcv));
                    if (created != null)
                    {
                        created.GetComponent <ITransformComponent>(ComponentFamily.Transform).TranslateTo(
                            new Vector2f(xRcv, yRcv));
                        if (created.HasComponent(ComponentFamily.Direction))
                        {
                            created.GetComponent <IDirectionComponent>(ComponentFamily.Direction).Direction = dirRcv;
                        }
                        if (created.HasComponent(ComponentFamily.WallMounted))
                        {
                            created.GetComponent <IWallMountedComponent>(ComponentFamily.WallMounted).AttachToTile(mapMgr.GetTileRef(tilePos));
                        }
                    }
                }
                else
                {
                    mapMgr.Tiles[tilePos] = new Tile(tileType);
                }
            }
            else //They are not allowed to request this. Send 'PlacementFailed'. TBA
            {
                LogManager.Log("Invalid placement request: "
                               + IoCManager.Resolve <IPlayerManager>().GetSessionByConnection(msg.SenderConnection).name +
                               " - " +
                               IoCManager.Resolve <IPlayerManager>().GetSessionByConnection(msg.SenderConnection).
                               attachedEntity.Uid.ToString() +
                               " - " + alignRcv.ToString());

                SendPlacementCancel(
                    IoCManager.Resolve <IPlayerManager>().GetSessionByConnection(msg.SenderConnection).attachedEntity);
            }
        }