示例#1
0
 public void RunOnDifference(GridArea subtract_area, Action <int> action)
 {
     for (int i = min.y; i < max.y; i++)
     {
         for (int j = min.x; j < max.x; j++)
         {
             if (!subtract_area.Contains(j, i))
             {
                 int obj = Grid.XYToCell(j, i);
                 action(obj);
             }
         }
     }
 }
示例#2
0
        /// <summary>
        /// Applied before LateUpdatePos runs.
        /// </summary>
        internal static bool Prefix(bool visibleToZoom, NameDisplayScreen __instance)
        {
            var inst = CameraController.Instance;

            if (inst != null)
            {
                GridArea area         = inst.VisibleArea.CurrentArea;
                var      entries      = __instance.entries;
                var      followTarget = inst.followTarget;
                int      n            = entries.Count;
                Vector3  pos;
                for (int i = 0; i < n; i++)
                {
                    var entry          = entries[i];
                    var go             = entry.world_go;
                    var dg             = entry.display_go;
                    var animController = entry.world_go_anim_controller;
                    if (go != null && dg != null)
                    {
                        // Merely fetching the position appears to take almost 1 us?
                        var  transform = go.transform;
                        bool active    = dg.activeSelf;
                        if (visibleToZoom && area.Contains(pos = transform.position))
                        {
                            // Visible
                            if (followTarget == transform)
                            {
                                pos = inst.followTargetPos;
                            }
                            else if (animController != null)
                            {
                                pos = animController.GetWorldPivot();
                            }
                            entry.display_go_rect.anchoredPosition = __instance.
                                                                     worldSpace ? pos : __instance.WorldToScreen(pos);
                            if (!active)
                            {
                                dg.SetActive(true);
                            }
                        }
                        else if (active)
                        {
                            // Invisible
                            dg.SetActive(false);
                        }
                    }
                }
            }
            return(false);
        }
        public override void Update(GameTime gameTime)
        {
            if (!drag)
            {
                if (Globals.mouseState.LeftButtonHold && startDragGridPosition == Grid.ToGridLocation(Globals.mouseState.Position.ToPoint(), gridLocation, Globals.TileDimensions) && Main.WindowRectangle.Contains(Globals.mouseState.Position))
                {
                    dragHoldTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                    if (!(dragHoldTimer < DRAG_HOLD_TIME))
                    {
                        drag          = true;
                        dragHoldTimer = 0;
                    }
                }
            }

            if (Globals.mouseState.LeftButtonPressed && Main.WindowRectangle.Contains(Globals.mouseState.Position))
            {
                if (selectedCharacter.Hitbox.Contains(Globals.mouseState.Position))
                {
                    drag = true;
                }
                else
                {
                    foreach (Character c in Armies.army)
                    {
                        if (c.Hitbox.Contains(Globals.mouseState.Position))
                        {
                            SelectCharacter(c);
                        }
                    }
                }

                // Check switchable unit
                foreach (KeyValuePair <Character.Rank, Sprite> entry in armyDict)
                {
                    Rectangle hitbox = new Rectangle((int)entry.Value.position.X, (int)entry.Value.position.Y, entry.Value.sourceRectangle.Width, entry.Value.sourceRectangle.Height);

                    if (hitbox.Contains(Globals.mouseState.Position))
                    {
                        if (selectedCharacter.special == Character.Special.None)
                        {
                            if (selectedCharacter.rank == entry.Key)
                            {
                                ChangeCharacter(entry.Key);
                            }
                        }
                        else
                        {
                            switch (entry.Key)
                            {
                            case Character.Rank.Spy:
                            case Character.Rank.Miner:
                            case Character.Rank.Healer:
                                ChangeCharacter(entry.Key);
                                break;

                            case Character.Rank.Bomb:
                                if (selectedCharacter.rank == Character.Rank.Bomb)
                                {
                                    ChangeCharacter(entry.Key);
                                }
                                break;
                            }
                        }
                    }
                }

                if (LeftNextButtonHitbox.Contains(Globals.mouseState.Position))
                {
                    switch (currentArmy)
                    {
                    case Character.Army.Normal: SetArmyDictionary(Character.Army.Sea); break;

                    case Character.Army.Tiki: SetArmyDictionary(Character.Army.Normal); break;

                    case Character.Army.Sea: SetArmyDictionary(Character.Army.Tiki); break;
                    }
                }

                if (RightNextButtonHitbox.Contains(Globals.mouseState.Position))
                {
                    switch (currentArmy)
                    {
                    case Character.Army.Normal: SetArmyDictionary(Character.Army.Tiki); break;

                    case Character.Army.Tiki: SetArmyDictionary(Character.Army.Sea); break;

                    case Character.Army.Sea: SetArmyDictionary(Character.Army.Normal); break;
                    }
                }
            }

            if (drag && Globals.mouseState.LeftButtonReleased)
            {
                Vector2 mouseGridPosition = (Grid.ToGridLocation(Globals.mouseState.Position.ToPoint(), gridLocation, Globals.TileDimensions) * Globals.TileDimensions + gridLocation).ToVector2();

                if (GridArea.Contains(mouseGridPosition))
                {
                    bool overlap = false;

                    // Check for overlapping with another character
                    foreach (Character c in Armies.army)
                    {
                        if (c.position == mouseGridPosition)
                        {
                            overlap = true;

                            // Swap drag Character with overlap character
                            c.position = selectedCharacter.position;
                            selectedCharacter.position = mouseGridPosition;

                            break;
                        }
                    }

                    if (!overlap)
                    {
                        selectedCharacter.position = mouseGridPosition;
                    }
                }

                drag = false;
            }

            statsUI.UpdateAnimation(gameTime);
            statsUI.UpdateWeaponChanging();
        }