Ejemplo n.º 1
0
 public void Update(InputState input, Vector2 offsetFromCenter)
 {
     var aabb = new AABB(offsetFromCenter, offsetFromCenter + _dim);
     if (input.WentActive(Buttons.LeftButton) && aabb.IsPointInside(input.MouseRelativeToCenter))
     {
         _onClick();
     }
 }
Ejemplo n.º 2
0
        public bool Intersects(AABB aabb)
        {
            if (aabb.Area > Area) return aabb.Intersects(this);

            return 
                   IsPointInside(aabb.TopLeft)
                || IsPointInside(aabb.BottomRight)
                || IsPointInside(new Vector2(aabb.TopLeft.X, aabb.BottomRight.Y))
                || IsPointInside(new Vector2(aabb.TopLeft.Y, aabb.BottomRight.X));
        }
Ejemplo n.º 3
0
        public void Update(InputState input)
        {
            if (input.WentActive(Keys.F1))
            {
                _dialogMgr.Add(new Prompt(Console.WriteLine));
            }

            AABB selectionBox = new AABB(_selectionBoxP1, _selectionBoxP2);

            int id;
            if (_provinces.TryGetProvinceFromPoint(input.Mouse, out id))
            {
                if (input.WentActive(Buttons.LeftButton) && 
                    _labelClickableBoundaries.ContainsKey(id) &&
                    _labelClickableBoundaries[id].IsPointInside(input.ScreenMouse) &&
                    _units.IsPlayerArmy(id))
                {
                    _unitsSelection.Select(id, input.IsActive(Keys.LeftControl));    
                }
                // Only handle new selections.
                else if (input.WentActive(Buttons.LeftButton))
                {
                    _provinceSelection.Select(id);
                }
                else if (input.WentInactive(Buttons.LeftButton)
                    && selectionBox.Area < _minimumSelectionSize
                    && _unitsSelection.Count > 0)
                {
                    _units.AddOrder(_unitsSelection.Set, id);
                }
                    
                SwapInstrs(_provinceSelection.Hovering);
                _provinceSelection.Hover(id);
                SwapInstrs(id);
            }
            else
            {
                SwapInstrs(_provinceSelection.Hovering);
                _provinceSelection.StopHovering();    
            }

            if (input.WentActive(Keys.G))      MergeSelectedArmies();
            if (input.WentActive(Keys.Escape)) _unitsSelection.DeselectAll();
            if (input.WentActive(Keys.Delete)) DeleteSelectedArmies();

            if (input.WentInactive(Buttons.LeftButton) && selectionBox.Area > _minimumSelectionSize)
            {
                _unitsSelection.DeselectAll();

                // Find all units within the area and select them.
                _labelClickableBoundaries
                    .FindAll(p => _units.IsPlayerArmy(p.Key) && p.Value.Intersects(selectionBox))
                    .ForEach(p => _unitsSelection.Select(p.Key, true));
            }

            UpdateSelectionBox(input);

            if (_unitsSelection.Count > 0)
            {
                Debug.WriteToScreen("Armies", _unitsSelection.Set.Join(", "));    
            }
        }
Ejemplo n.º 4
0
        private void DrawUnits(SpriteBatch spriteBatch, Renderer renderer)
        {
            // Since we are generating these every time anyway,
            // we clear it so we don't have any label boxes belonging to deleted armies.
            _labelClickableBoundaries.Clear();

            // All realm id's the player is at war with.
            var playerEnemies = _wars.GetAllEnemies(Realms.PlayerID);

            foreach (var pair in _units.Armies)
            {
                AABB box = _labelBoxes[pair.Value.Location];
                AABB screenBox = new AABB(renderer.RenderState.WorldToScreenCoordinates(box.BottomRight),
                    renderer.RenderState.WorldToScreenCoordinates(box.TopLeft));

                string text = pair.Value.NUnits.ToString();

                Vector2 dim    = _unitsFont.MeasureString(text);
                Vector2 center = screenBox.Center - dim / 2;

                Vector2 p1     = (center - 5 * Vector2.UnitX);
                AABB snugBox   = new AABB(p1, p1 + (dim + 10 * Vector2.UnitX));

                Color borderColor;

                if (_unitsSelection.Set.Contains(pair.Key))
                {
                    borderColor = Color.AliceBlue;
                }
                else if (playerEnemies.Contains(pair.Value.Owner))
                {
                    borderColor = Color.Red;
                }
                else
                {
                    borderColor = Color.Black;   
                }
                    
                spriteBatch.Draw(snugBox.Borders(1), borderColor);
                spriteBatch.Draw(snugBox, Color.Black);
                spriteBatch.DrawString(_unitsFont, text, center.Floor(), Color.White);

                _labelClickableBoundaries[pair.Key] = snugBox;
            }     
        }
Ejemplo n.º 5
0
        public void Draw(SpriteBatch spriteBatch, Renderer renderer)
        {
            // Renders provinces
            renderer.DrawToScreen(_standardInstrs.SelectMany(x => x));

//            if (renderer.RenderState.Camera.Zoom < 1.4f)
//            {
                DrawUnits(spriteBatch, renderer);
//            }

            // Selection box
            AABB selectionRect = new AABB(_selectionBoxP1, _selectionBoxP2);
            AABB[] borders = selectionRect.Borders(1);
            spriteBatch.Draw(selectionRect, new Color(Color.Black, 0.4f));
            spriteBatch.Draw(borders, Color.CadetBlue);       
        }
 public static RenderInstruction AABB(AABB aabb, Color c)
 {
     return Rectangle(aabb.BottomRight, aabb.Dim, c);
 }
Ejemplo n.º 7
0
 public static AABB CalculateBox(IDialog dialog)
 {
     Vector2 corner = dialog.Offset - dialog.Dimensions / 2;
     var aabb = new AABB(corner, corner + dialog.Dimensions);
     return aabb;
 }
Ejemplo n.º 8
0
 public void Setup()
 {
     _aabb = new AABB(new Vector2(0, 0), new Vector2(10, 10));
 }