Exemplo n.º 1
0
        public bool CanPlace(Microsoft.Xna.Framework.Rectangle area, bool[] validTiles, int padding = 0)
        {
            if (area.X < 0 || area.Y < 0 ||
                (area.X + area.Width > Main.maxTilesX - 1 || area.Y + area.Height > Main.maxTilesY - 1))
            {
                return(false);
            }
            var rectangle = new Microsoft.Xna.Framework.Rectangle(area.X - padding,
                                                                  area.Y - padding, area.Width + padding * 2, area.Height + padding * 2);

            for (var index = 0; index < this._structures.Count; ++index)
            {
                if (rectangle.Intersects(this._structures[index]))
                {
                    return(false);
                }
            }

            for (var x = rectangle.X; x < rectangle.X + rectangle.Width; ++x)
            {
                for (var y = rectangle.Y; y < rectangle.Y + rectangle.Height; ++y)
                {
                    if (Main.tile[x, y].active())
                    {
                        var type = Main.tile[x, y].type;
                        if (!validTiles[(int)type])
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
 public bool CanPlace(Microsoft.Xna.Framework.Rectangle area, bool[] validTiles, int padding = 0)
 {
     if (area.X < 0 || area.Y < 0 || (area.X + area.Width > Main.maxTilesX - 1 || area.Y + area.Height > Main.maxTilesY - 1))
     {
         return(false);
     }
     Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle(area.X - padding, area.Y - padding, area.Width + padding * 2, area.Height + padding * 2);
     for (int index = 0; index < this._structures.Count; ++index)
     {
         if (rectangle.Intersects(this._structures[index]))
         {
             return(false);
         }
     }
     for (int index1 = rectangle.X; index1 < rectangle.X + rectangle.Width; ++index1)
     {
         for (int index2 = rectangle.Y; index2 < rectangle.Y + rectangle.Height; ++index2)
         {
             if (Main.tile[index1, index2].active())
             {
                 ushort num = Main.tile[index1, index2].type;
                 if (!validTiles[(int)num])
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Exemplo n.º 3
0
        public override void UpdateAccessory(Player player, bool hideVisual)
        {
            player.jumpBoost = true;
            player.autoJump  = true;
            player.noFallDmg = true;

            if (!player.mount.Active && player.velocity.Y > 0f)
            {
                Microsoft.Xna.Framework.Rectangle checkDamagePlayer = player.getRect();
                checkDamagePlayer.Offset(0, player.height - 1);
                checkDamagePlayer.Height = 2;
                checkDamagePlayer.Inflate(12, 6);
                for (int i = 0; i < 200; i++)
                {
                    NPC npc = Main.npc[i];
                    if (npc.active && !npc.dontTakeDamage && !npc.friendly && npc.immune[player.whoAmI] == 0)
                    {
                        Microsoft.Xna.Framework.Rectangle checkDamageNPC = npc.getRect();
                        if (checkDamagePlayer.Intersects(checkDamageNPC) && (npc.noTileCollide || Collision.CanHit(player.position, player.width, player.height, npc.position, npc.width, npc.height)))
                        {
                            var   damage    = 20f * player.meleeDamage;
                            float knockBack = 5f;
                            int   direction = npc.direction;
                            if (npc.velocity.X < 0f)
                            {
                                direction = -1;
                            }
                            if (npc.velocity.X > 0f)
                            {
                                direction = 1;
                            }
                            npc.StrikeNPC((int)damage, knockBack, direction, Main.rand.Next(2) == 0 ? true : false, false, false);
                            if (Main.netMode != NetmodeID.SinglePlayer)
                            {
                                NetMessage.SendData(MessageID.StrikeNPC, -1, -1, NetworkText.FromLiteral(""), npc.whoAmI, 1, knockBack, direction, (int)damage);
                            }
                            npc.immune[player.whoAmI] = 10;
                            player.velocity.Y         = -10f;
                            player.immune             = true;
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 public bool CanPlace(Microsoft.Xna.Framework.Rectangle area, bool[] validTiles, int padding = 0)
 {
     if (area.X < 0 || area.Y < 0 || (area.X + area.Width > Main.maxTilesX - 1 || area.Y + area.Height > Main.maxTilesY - 1))
         return false;
     Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle(area.X - padding, area.Y - padding, area.Width + padding * 2, area.Height + padding * 2);
     for (int index = 0; index < this._structures.Count; ++index)
     {
         if (rectangle.Intersects(this._structures[index]))
             return false;
     }
     for (int index1 = rectangle.X; index1 < rectangle.X + rectangle.Width; ++index1)
     {
         for (int index2 = rectangle.Y; index2 < rectangle.Y + rectangle.Height; ++index2)
         {
             if (Main.tile[index1, index2].active())
             {
                 ushort num = Main.tile[index1, index2].type;
                 if (!validTiles[(int)num])
                     return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 5
0
 public override void PostUpdate()
 {
     if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F11))
     {
         hideMode = Main.hideUI;
     }
     if (Main.hideUI)
     {
         if (PlayerInput.Triggers.JustPressed.Inventory)
         {
             IngameOptions.Open();
             Main.hideUI = false;
         }
         #region talkNPC
         Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle((int)((float)Main.mouseX + Main.screenPosition.X), (int)((float)Main.mouseY + Main.screenPosition.Y), 1, 1);
         if (Main.player[Main.myPlayer].gravDir == -1f)
         {
             rectangle.Y = (int)Main.screenPosition.Y + Main.screenHeight - Main.mouseY;
         }
         for (int k = 0; k < 200; k++)
         {
             if (Main.npc[k].active)
             {
                 int type = Main.npc[k].type;
                 Main.instance.LoadNPC(type);
                 Microsoft.Xna.Framework.Rectangle value3 = new Microsoft.Xna.Framework.Rectangle((int)Main.npc[k].Bottom.X - Main.npc[k].frame.Width / 2, (int)Main.npc[k].Bottom.Y - Main.npc[k].frame.Height, Main.npc[k].frame.Width, Main.npc[k].frame.Height);
                 if (Main.npc[k].type >= 87 && Main.npc[k].type <= 92)
                 {
                     value3 = new Microsoft.Xna.Framework.Rectangle((int)((double)Main.npc[k].position.X + (double)Main.npc[k].width * 0.5 - 32.0), (int)((double)Main.npc[k].position.Y + (double)Main.npc[k].height * 0.5 - 32.0), 64, 64);
                 }
                 bool flag = rectangle.Intersects(value3);
                 if (flag && ((Main.npc[k].type != 85 && Main.npc[k].type != 341 && Main.npc[k].aiStyle != 87) || Main.npc[k].ai[0] != 0f) && Main.npc[k].type != 488)
                 {
                     bool flag3 = Main.SmartInteractShowingGenuine && Main.SmartInteractNPC == k;
                     if (Main.npc[k].townNPC || Main.npc[k].type == 105 || Main.npc[k].type == 106 || Main.npc[k].type == 123 || Main.npc[k].type == 354 || Main.npc[k].type == 376 || Main.npc[k].type == 579 || Main.npc[k].type == 453)
                     {
                         Microsoft.Xna.Framework.Rectangle rectangle2 = new Microsoft.Xna.Framework.Rectangle((int)(Main.player[Main.myPlayer].position.X + (float)(Main.player[Main.myPlayer].width / 2) - (float)(Player.tileRangeX * 16)), (int)(Main.player[Main.myPlayer].position.Y + (float)(Main.player[Main.myPlayer].height / 2) - (float)(Player.tileRangeY * 16)), Player.tileRangeX * 16 * 2, Player.tileRangeY * 16 * 2);
                         Microsoft.Xna.Framework.Rectangle value4     = new Microsoft.Xna.Framework.Rectangle((int)Main.npc[k].position.X, (int)Main.npc[k].position.Y, Main.npc[k].width, Main.npc[k].height);
                         if (rectangle2.Intersects(value4))
                         {
                             flag3 = true;
                         }
                     }
                     if (Main.player[Main.myPlayer].ownedProjectileCounts[651] > 0)
                     {
                         flag3 = false;
                     }
                     if (flag3 && !Main.player[Main.myPlayer].dead)
                     {
                         PlayerInput.SetZoom_MouseInWorld();
                         Main.HoveringOverAnNPC = true;
                         Main.instance.currentNPCShowingChatBubble = k;
                         if (Main.mouseRight && Main.mouseRightRelease)
                         {
                             Main.npcChatRelease = false;
                             if (PlayerInput.UsingGamepad)
                             {
                                 Main.player[Main.myPlayer].releaseInventory = false;
                             }
                             if (Main.player[Main.myPlayer].talkNPC != k)
                             {
                                 Main.CancelHairWindow();
                                 Main.npcShop          = 0;
                                 Main.InGuideCraftMenu = false;
                                 Main.player[Main.myPlayer].dropItemCheck();
                                 Main.npcChatCornerItem          = 0;
                                 Main.player[Main.myPlayer].sign = -1;
                                 Main.editSign = false;
                                 Main.player[Main.myPlayer].talkNPC = k;
                                 Main.playerInventory             = false;
                                 Main.player[Main.myPlayer].chest = -1;
                                 Recipe.FindRecipes();
                                 Main.npcChatText = Main.npc[k].GetChat();
                                 break;
                                 //Main.PlaySound(24, -1, -1, 1, 1f, 0f);
                             }
                         }
                     }
                 }
             }
         }
         #endregion
     }
     if (Main.playerInventory && hideMode)
     {
         Main.playerInventory = false;
         Main.hideUI          = true;
     }
     //random buy item
     if (player.talkNPC >= 0)
     {
         setNPCShop();
         if (Main.npcShop > 0)
         {
             Chest.SetupTravelShop();
             Main.instance.shop[Main.npcShop].SetupShop(Main.npcShop);
             List <int> tryBuyIndex = new List <int>();
             Item[]     shopItem    = Main.instance.shop[Main.npcShop].item;
             int        length      = shopItem.Length;
             for (int i = 0; i < length; i++)
             {
                 if (shopItem[i].type != 0 && shopItem[i].stack != 0)
                 {
                     tryBuyIndex.Add(i);
                 }
             }
             int n = tryBuyIndex.Count;
             while (n > 1)
             {
                 n--;
                 int k     = Main.rand.Next(n + 1);
                 int value = tryBuyIndex[k];
                 tryBuyIndex[k] = tryBuyIndex[n];
                 tryBuyIndex[n] = value;
             }
             for (int i = 0; i < n; i++)
             {
                 if (player.BuyItem(shopItem[tryBuyIndex[i]].GetStoreValue(), shopItem[tryBuyIndex[i]].shopSpecialCurrency))
                 {
                     Item.NewItem(player.position + player.Size / 2, shopItem[tryBuyIndex[i]].type, shopItem[tryBuyIndex[i]].stack, false, shopItem[tryBuyIndex[i]].prefix, true);
                     player.talkNPC = -1;
                     Main.npcShop   = 0;
                     Main.PlaySound(18);
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
        public override void DrawUI()
        {
            if (IsWindowOpen)
            {
                ImGui.Begin("Tilemap Editor");

                if (Input.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.D))
                {
                    ActiveTool = Tools.Delete;
                }
                else if (Input.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.B))
                {
                    ActiveTool = Tools.Brush;
                }
                else if (Input.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.G))
                {
                    ActiveTool = Tools.Bucket;
                }
                else if (ImGui.IsMouseClicked(ImGuiMouseButton.Middle))
                {
                    ActiveTool = Tools.None;
                }
                //else if (Input.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.S))
                //    ActiveTool = Tools.Select;
                //else if (Input.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.C))
                //    ActiveTool = Tools.CustomBrush;

                Vector2 ThisWindowPos  = ImGui.GetWindowPos();
                Vector2 ThisWindowSize = ImGui.GetWindowSize();

                MultiSelectRect.X += (int)(ThisWindowPos.X - LastWindPos.X);
                MultiSelectRect.Y += (int)(ThisWindowPos.Y - LastWindPos.Y);
                LastWindPos        = ThisWindowPos;

                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Escape)))
                {
                    IsWindowOpen = false;
                }

                if (ImGui.BeginCombo("TileSets", ChosenTileSet))
                {
                    for (int i = 0; i < TileSets.Count; i++)
                    {
                        if (ImGui.Selectable(TileSets[i].Name))
                        {
                            ChosenTileSet = TileSets[i].Name;
                            ActiveTileSet = i;
                        }
                    }

                    ImGui.EndCombo();
                }

                ImGui.SameLine();
                ImGui.Checkbox("Show Utils", ref ShowUtils);

                ImGui.Separator();

                ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0.4f, 0.4f, 0.4f, 1));

                if (ImGui.Button("New Tileset"))
                {
                    ActiveTileSet = TileSets.Count;

                    string[] TilesetNames = new string[TileSets.Count];
                    for (int i = 0; i < TilesetNames.Length; i++)
                    {
                        TilesetNames[i] = TileSets[i].Name;
                    }

                    ChosenTileSet = Utility.UniqueName(ChosenTileSet, TilesetNames);
                    TileSets.Add(new TileSetClass()
                    {
                        Name = ChosenTileSet
                    });
                }

                ImGui.SameLine();

                if (ImGui.Button("Delete Tileset") && ActiveTileSet != -1)
                {
                    ImGui.OpenPopup("Are You Sure?" + "##2");
                    EnsureClipDeletion = true;
                }

                string activeTilemap = ActiveTilemap != null ? ActiveTilemap.Name : "Drag a tilemap gameobject here!";
                ImGui.InputText("Active Tilemap", ref activeTilemap, 50, ImGuiInputTextFlags.ReadOnly);

                if (ImGui.BeginDragDropTarget() && ImGui.IsMouseReleased(ImGuiMouseButton.Left))
                {
                    if (GameObjects_Tab.DraggedGO != null && GameObjects_Tab.DraggedGO.GetComponent <Tilemap>() != null)
                    {
                        ActiveTilemap = GameObjects_Tab.DraggedGO;
                    }

                    ImGui.EndDragDropTarget();
                }

                ImGui.SameLine();

                ContentWindow.HelpMarker("Drag a gameobject having a Tilemap component here!", true);

                if (ActiveTilemap != null && (ActiveTilemap.ShouldBeDeleted || ActiveTilemap.ShouldBeRemoved))
                {
                    ActiveTilemap = null;
                }

                if (ActiveTileSet != -1)
                {
                    ImGui.InputText("Name", ref ChosenTileSet, 50);

                    if (ImGui.IsItemDeactivatedAfterEdit())
                    {
                        string[] TilesetNames = new string[TileSets.Count];
                        for (int i = 0; i < TilesetNames.Length; i++)
                        {
                            TilesetNames[i] = TileSets[i].Name;
                        }

                        ChosenTileSet = TileSets[ActiveTileSet].Name.Equals(ChosenTileSet)? ChosenTileSet : Utility.UniqueName(ChosenTileSet, TilesetNames);
                        TileSets[ActiveTileSet].Name = ChosenTileSet;
                    }

                    ImGui.InputText("Tileset", ref TilesetName, 50, ImGuiInputTextFlags.ReadOnly);

                    if (ImGui.BeginDragDropTarget() && ImGui.IsMouseReleased(ImGuiMouseButton.Left) && ContentWindow.DraggedAsset != null && ActiveTileSet != -1)
                    {
                        if (ContentWindow.DraggedAsset is KeyValuePair <string, Vector4> )
                        {
                            KeyValuePair <string, Vector4> KVP = (KeyValuePair <string, Vector4>)ContentWindow.DraggedAsset;
                            TileSetClass tileset = new TileSetClass();
                            tileset.Tex    = Setup.Content.Load <Texture2D>(KVP.Key);
                            tileset.Name   = "TileSet";
                            tileset.TexPtr = Scene.GuiRenderer.BindTexture(tileset.Tex);

                            int TileSetColumnCount = (int)Math.Round(10000.0f / KVP.Value.Z);
                            int TileSetRowCount    = (int)Math.Round(10000.0f / KVP.Value.W);

                            tileset.Rects = new Vector4[TileSetRowCount * TileSetColumnCount];

                            for (int i = 0; i < TileSetRowCount; i++)
                            {
                                for (int j = 0; j < TileSetColumnCount; j++)
                                {
                                    tileset.Rects[i * TileSetColumnCount + j] = new Vector4(j * KVP.Value.Z, i * KVP.Value.W, KVP.Value.Z, KVP.Value.W) / 10000.0f;
                                }
                            }

                            TileSets[ActiveTileSet] = tileset;
                            TilesetName             = tileset.Name;

                            ContentWindow.DraggedAsset = null;
                        }

                        ImGui.EndDragDropTarget();
                    }

                    float UpperGroupCursPos = ImGui.GetCursorPosY() + ImGui.GetWindowPos().Y;

                    ImGui.BeginChild("SpriteSheet", new Vector2(ImGui.GetWindowSize().X * 0.95f, 64 * 5.1f), false, ImGuiWindowFlags.AlwaysHorizontalScrollbar);
                    if (ActiveTileSet != -1 && TileSets[ActiveTileSet].Rects != null)
                    {
                        ImGui.Separator();

                        TileSets[ActiveTileSet].TexPtr = TileSets[ActiveTileSet].TexPtr == IntPtr.Zero ? Scene.GuiRenderer.BindTexture(TileSets[ActiveTileSet].Tex) : TileSets[ActiveTileSet].TexPtr;

                        //MultiSelect
                        Vector2 MousePos = ImGui.GetMousePos();
                        Microsoft.Xna.Framework.Point ScrollPos = new Microsoft.Xna.Framework.Point((int)ImGui.GetScrollX(), (int)ImGui.GetScrollY());
                        if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                        {
                            WindowHoveredLastClick = ImGui.IsWindowHovered() && MousePos.Y > UpperGroupCursPos;

                            if (WindowHoveredLastClick)
                            {
                                VisualizeMultiSelect = false;
                                MultiSelectRect      = new Microsoft.Xna.Framework.Rectangle((int)MousePos.X + ScrollPos.X, (int)MousePos.Y + ScrollPos.Y, 0, 0);
                            }
                        }

                        if (ImGui.IsMouseDown(ImGuiMouseButton.Left) && WindowHoveredLastClick)
                        {
                            VisualizeMultiSelect = true;
                            MultiSelectRect      = new Microsoft.Xna.Framework.Rectangle(MultiSelectRect.X, MultiSelectRect.Y, (int)MousePos.X - MultiSelectRect.X + ScrollPos.X, (int)MousePos.Y - MultiSelectRect.Y + ScrollPos.Y);

                            Microsoft.Xna.Framework.Rectangle AdjustedRect = new Microsoft.Xna.Framework.Rectangle(Math.Min(MultiSelectRect.X, MultiSelectRect.X + MultiSelectRect.Width), Math.Min(MultiSelectRect.Y, MultiSelectRect.Y + MultiSelectRect.Height), Math.Abs(MultiSelectRect.Width), Math.Abs(MultiSelectRect.Height));
                            MultiSelectRect = AdjustedRect;
                        }

                        int     ID      = 0;
                        Vector2 WindPos = ImGui.GetWindowPos();
                        Vector2 Min     = new Vector2(int.MaxValue, int.MaxValue);
                        Vector2 Max     = new Vector2(int.MinValue, int.MinValue);
                        Vector2 Size    = new Vector2(TileSets[ActiveTileSet].Rects[0].Z * TileSets[ActiveTileSet].Tex.Width, TileSets[ActiveTileSet].Rects[0].W * TileSets[ActiveTileSet].Tex.Height);
                        Size = new Vector2((float)Math.Round(Size.X), (float)Math.Round(Size.Y));

                        Vector2 InnserSpacingOld = ImGui.GetStyle().ItemSpacing;

                        ImGui.GetStyle().ItemSpacing = Vector2.Zero;
                        Vector4 SelectedRect         = Vector4.Zero;

                        for (int j = 0; j < TileSets[ActiveTileSet].Rects.Length; j++)
                        {
                            Vector2 CursPos  = ImGui.GetCursorPos();
                            Vector4 Rect     = TileSets[ActiveTileSet].Rects[j];
                            Vector2 RealSize = new Vector2(64, Size.X / Size.Y * 64);

                            bool MultiSelected = VisualizeMultiSelect && MultiSelectRect.Intersects(new Microsoft.Xna.Framework.Rectangle((int)(CursPos.X + WindPos.X), (int)(CursPos.Y + WindPos.Y), (int)RealSize.X, (int)RealSize.Y));

                            if (MultiSelected)
                            {
                                if (CursPos.X < Min.X)
                                {
                                    SelectedRect.X = Rect.X;
                                    Min.X          = CursPos.X;
                                }
                                if (CursPos.Y < Min.Y)
                                {
                                    SelectedRect.Y = Rect.Y;
                                    Min.Y          = CursPos.Y;
                                }
                                if (CursPos.X + RealSize.X > Max.X)
                                {
                                    SelectedRect.Z = Rect.X + Rect.Z;
                                    Max.X          = CursPos.X + RealSize.X;
                                }
                                if (CursPos.Y + RealSize.Y > Max.Y)
                                {
                                    SelectedRect.W = Rect.Y + Rect.W;
                                    Max.Y          = CursPos.Y + RealSize.Y;
                                }
                            }

                            ImGui.PushID(ID++);
                            ImGui.Image(TileSets[ActiveTileSet].TexPtr, RealSize, new Vector2(Rect.X, Rect.Y), new Vector2(Rect.Z + Rect.X, Rect.W + Rect.Y), (SelectedTile == j || MultiSelected) ? new Vector4(1f, 1f, 1f, 0.5f) : Vector4.One);
                            ImGui.PopID();

                            if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
                            {
                                SelectedTile = j;
                            }

                            if (ImGui.IsItemHovered())
                            {
                                HitBoxDebuger.DrawNonFilledRectangle_Effect(new Microsoft.Xna.Framework.Rectangle((int)(CursPos.X + WindPos.X - ImGui.GetScrollX()), (int)(CursPos.Y + WindPos.Y - ImGui.GetScrollY()), (int)RealSize.X, (int)RealSize.Y));
                            }

                            ImGui.SameLine();

                            if ((j + 1) * Size.X % TileSets[ActiveTileSet].Tex.Width == 0)
                            {
                                ImGui.NewLine();
                            }
                        }

                        ImGui.GetStyle().ItemSpacing = InnserSpacingOld;

                        ImGui.EndChild();

                        if (ImGui.BeginPopupModal("Are You Sure?" + "##2", ref EnsureClipDeletion, ImGuiWindowFlags.AlwaysAutoResize))
                        {
                            if (ImGui.Button("Yes, delete this"))
                            {
                                TileSets.RemoveAt(ActiveTileSet);
                                ActiveTileSet = -1;
                                ChosenTileSet = "";

                                ImGui.CloseCurrentPopup();
                            }

                            if (ImGui.Button("No"))
                            {
                                ImGui.CloseCurrentPopup();
                            }

                            ImGui.EndPopup();
                        }

                        if (ActiveTilemap != null) //Edit mode
                        {
                            if (GizmosVisualizer.IsThisWindowHovered && !ImGui.IsAnyItemHovered())
                            {
                                Tilemap tilemap = ActiveTilemap.GetComponent <Tilemap>();

                                if (tilemap != null)
                                {
                                    var Bias     = Setup.Camera.Position - ResolutionIndependentRenderer.GetVirtualRes() * 0.5f - new Microsoft.Xna.Framework.Vector2(GizmosVisualizer.SceneWindow.X + 7, GizmosVisualizer.SceneWindow.Y + 28);
                                    var GridSize = tilemap.TileSize.ToVector2() * tilemap.GridSize.ToVector2() * tilemap.gameObject.Transform.Scale;
                                    var MapRect  = new Microsoft.Xna.Framework.Rectangle((tilemap.gameObject.Transform.Position - GridSize * 0.5f).ToPoint(), GridSize.ToPoint());

                                    bool InsideBoundaries = MapRect.Contains(Bias + Input.GetMousePosition());

                                    ImGui.Text(InsideBoundaries.ToString());

                                    if (InsideBoundaries)
                                    {
                                        switch (ActiveTool)
                                        {
                                        case Tools.Brush:
                                            if (Min.X == int.MaxValue)
                                            {
                                                break;
                                            }

                                            if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                                            {
                                                HandyList.Clear();
                                                HandyList2.Clear();
                                            }
                                            else if (ImGui.IsMouseReleased(ImGuiMouseButton.Left))
                                            {
                                                //Undo action
                                                if (HandyList2.Count != 0)
                                                {
                                                    GameObjects_Tab.AddToACircularBuffer(GameObjects_Tab.Undo_Buffer, new KeyValuePair <object, Operation>(HandyList2.ToArray(), Operation.Delete));
                                                }
                                                if (HandyList.Count != 0)
                                                {
                                                    GameObjects_Tab.AddToACircularBuffer(GameObjects_Tab.Undo_Buffer, new KeyValuePair <object, Operation>(HandyList.ToArray(), Operation.Create));
                                                }
                                                GameObjects_Tab.Redo_Buffer.Clear();
                                            }
                                            else if (!ImGui.IsMouseDown(ImGuiMouseButton.Left))
                                            {
                                                break;
                                            }

                                            Microsoft.Xna.Framework.Point tileSize = (tilemap.TileSize.ToVector2() * tilemap.gameObject.Transform.Scale).ToPoint();

                                            GameObject NewTile = new GameObject();
                                            NewTile.Name  = Utility.UniqueGameObjectName("Tile");
                                            NewTile.Layer = ActiveTilemap.Layer;
                                            NewTile.AddComponent(new Transform());
                                            NewTile.AddComponent(new SpriteRenderer());
                                            NewTile.Start();

                                            NewTile.GetComponent <SpriteRenderer>().Sprite.Texture  = TileSets[ActiveTileSet].Tex;
                                            NewTile.GetComponent <SpriteRenderer>().SourceRectangle = new Microsoft.Xna.Framework.Rectangle((int)Math.Round(SelectedRect.X * TileSets[ActiveTileSet].Tex.Width), (int)Math.Round(SelectedRect.Y * TileSets[ActiveTileSet].Tex.Height), (int)Math.Round((SelectedRect.Z - SelectedRect.X) * TileSets[ActiveTileSet].Tex.Width), (int)Math.Round((SelectedRect.W - SelectedRect.Y) * TileSets[ActiveTileSet].Tex.Height));
                                            var RealTileSize = NewTile.GetComponent <SpriteRenderer>().SourceRectangle.Size.ToVector2() * tilemap.gameObject.Transform.Scale;
                                            var NewPos       = (Input.GetMousePosition() + Bias - MapRect.Location.ToVector2()) / MapRect.Size.ToVector2() / (RealTileSize / MapRect.Size.ToVector2());
                                            NewPos  *= RealTileSize / tileSize.ToVector2();
                                            NewPos.X = (int)NewPos.X;
                                            NewPos.Y = (int)NewPos.Y;

                                            NewTile.Transform.Scale    = tilemap.gameObject.Transform.Scale;
                                            NewTile.Transform.Position = MapRect.Location.ToVector2() + tileSize.ToVector2() * NewPos + RealTileSize * 0.5f * Microsoft.Xna.Framework.Vector2.One;

                                            bool ShouldBreak = false;
                                            foreach (GameObject Child in ActiveTilemap.Children)
                                            {
                                                if (Utility.Vector2Int(Child.Transform.Position) == NewTile.Transform.Position)
                                                {
                                                    SpriteRenderer DeletedOBJ_SR = Child.GetComponent <SpriteRenderer>();
                                                    SpriteRenderer NewOBJ_SR     = NewTile.GetComponent <SpriteRenderer>();

                                                    if (DeletedOBJ_SR.TextureName == NewOBJ_SR.TextureName && DeletedOBJ_SR.SourceRectangle == NewOBJ_SR.SourceRectangle)
                                                    {
                                                        ShouldBreak = true;
                                                        break;
                                                    }
                                                    else
                                                    {
                                                        HandyList2.Add(Child);
                                                    }

                                                    Child.ShouldBeRemoved = true;

                                                    break;
                                                }
                                            }

                                            if (ShouldBreak)
                                            {
                                                break;
                                            }

                                            HandyList.Add(NewTile);

                                            SceneManager.ActiveScene.AddGameObject_Recursive(NewTile);
                                            ActiveTilemap.AddChild(NewTile);

                                            break;

                                        case Tools.Delete:

                                            if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                                            {
                                                HandyList2.Clear();
                                            }
                                            else if (ImGui.IsMouseReleased(ImGuiMouseButton.Left))
                                            {
                                                if (HandyList2.Count != 0)
                                                {
                                                    GameObjects_Tab.AddToACircularBuffer(GameObjects_Tab.Undo_Buffer, new KeyValuePair <object, Operation>(HandyList2.ToArray(), Operation.Delete));
                                                    GameObjects_Tab.Redo_Buffer.Clear();
                                                }
                                            }

                                            if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
                                            {
                                                tileSize = (tilemap.TileSize.ToVector2() * tilemap.gameObject.Transform.Scale).ToPoint();

                                                foreach (GameObject Child in ActiveTilemap.Children)
                                                {
                                                    if (new Microsoft.Xna.Framework.Rectangle(Child.Transform.Position.ToPoint() - (tileSize.ToVector2() * 0.5f).ToPoint(), tileSize).Contains(Input.GetMousePosition() + Bias))
                                                    {
                                                        Child.ShouldBeRemoved = true;
                                                        HandyList2.Add(Child);
                                                        break;
                                                    }
                                                }
                                            }

                                            break;

                                        case Tools.Bucket:     //remember to take another look at the logic (Solved!)

                                            if (Min.X == int.MaxValue)
                                            {
                                                break;
                                            }

                                            if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                                            {
                                                HandyList.Clear();
                                                HandyList2.Clear();

                                                foreach (GameObject Child in ActiveTilemap.Children)
                                                {
                                                    Child.ShouldBeRemoved = true;
                                                    HandyList2.Add(Child);
                                                }

                                                tileSize = (tilemap.TileSize.ToVector2() * tilemap.gameObject.Transform.Scale).ToPoint();
                                                var SrcRect = new Microsoft.Xna.Framework.Rectangle((int)Math.Round(SelectedRect.X * TileSets[ActiveTileSet].Tex.Width), (int)Math.Round(SelectedRect.Y * TileSets[ActiveTileSet].Tex.Height), (int)Math.Round((SelectedRect.Z - SelectedRect.X) * TileSets[ActiveTileSet].Tex.Width), (int)Math.Round((SelectedRect.W - SelectedRect.Y) * TileSets[ActiveTileSet].Tex.Height));
                                                RealTileSize = SrcRect.Size.ToVector2() * tilemap.gameObject.Transform.Scale;
                                                var Ratio = new Microsoft.Xna.Framework.Point((int)Math.Round(RealTileSize.X / tileSize.X), (int)Math.Round(RealTileSize.Y / tileSize.Y));

                                                for (int i = 0; i < tilemap.GridSize.X / Ratio.Y; i++)
                                                {
                                                    for (int j = 0; j < tilemap.GridSize.Y / Ratio.X; j++)
                                                    {
                                                        NewTile       = new GameObject();
                                                        NewTile.Name  = Utility.UniqueGameObjectName("Tile");
                                                        NewTile.Layer = ActiveTilemap.Layer;
                                                        NewTile.AddComponent(new Transform());
                                                        NewTile.AddComponent(new SpriteRenderer());
                                                        NewTile.Start();

                                                        NewTile.GetComponent <SpriteRenderer>().Sprite.Texture  = TileSets[ActiveTileSet].Tex;
                                                        NewTile.GetComponent <SpriteRenderer>().SourceRectangle = SrcRect;
                                                        NewPos   = new Microsoft.Xna.Framework.Vector2(j * RealTileSize.X, i * RealTileSize.Y);
                                                        NewPos.X = (int)NewPos.X;
                                                        NewPos.Y = (int)NewPos.Y;

                                                        NewTile.Transform.Scale    = tilemap.gameObject.Transform.Scale;
                                                        NewTile.Transform.Position = MapRect.Location.ToVector2() + NewPos + RealTileSize * 0.5f;

                                                        SceneManager.ActiveScene.AddGameObject_Recursive(NewTile);
                                                        ActiveTilemap.AddChild(NewTile);

                                                        HandyList.Add(NewTile);
                                                    }
                                                }

                                                //Undo action
                                                if (HandyList2.Count != 0)
                                                {
                                                    GameObjects_Tab.AddToACircularBuffer(GameObjects_Tab.Undo_Buffer, new KeyValuePair <object, Operation>(HandyList2.ToArray(), Operation.Delete));
                                                }
                                                if (HandyList.Count != 0)
                                                {
                                                    GameObjects_Tab.AddToACircularBuffer(GameObjects_Tab.Undo_Buffer, new KeyValuePair <object, Operation>(HandyList.ToArray(), Operation.Create));
                                                }
                                                GameObjects_Tab.Redo_Buffer.Clear();
                                            }

                                            break;
                                            //case Tools.Select:

                                            //    tileSize = (tilemap.TileSize.ToVector2() * tilemap.gameObject.Transform.Scale).ToPoint();
                                            //    NewPos = (Input.GetMousePosition() + Bias - MapRect.Location.ToVector2()) / MapRect.Size.ToVector2() / (tileSize.ToVector2() / MapRect.Size.ToVector2());
                                            //    NewPos.X = (int)NewPos.X;
                                            //    NewPos.Y = (int)NewPos.Y;

                                            //    var TPos = MapRect.Location.ToVector2() + tileSize.ToVector2() * NewPos;

                                            //    if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                                            //        TileMapSelectionArea = new Microsoft.Xna.Framework.Rectangle(TPos.ToPoint(), Microsoft.Xna.Framework.Point.Zero);
                                            //    else if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
                                            //    {
                                            //        TileMapSelectionArea.Size = (TPos + tileSize.ToVector2() - TileMapSelectionArea.Location.ToVector2()).ToPoint();
                                            //        TileMapSelectionArea.Size = MathCompanion.Abs(TileMapSelectionArea.Size);
                                            //        TileMapSelectionArea.Location = new Microsoft.Xna.Framework.Point(Math.Min(TileMapSelectionArea.X, TileMapSelectionArea.X + TileMapSelectionArea.Width), Math.Min(TileMapSelectionArea.Y, TileMapSelectionArea.Y + TileMapSelectionArea.Height));
                                            //    }

                                            //    break;
                                        }
                                    }
                                    //else if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                                    //    TileMapSelectionArea = Microsoft.Xna.Framework.Rectangle.Empty;
                                }
                                else if (tilemap == null)
                                {
                                    ActiveTilemap = null;
                                }
                            }
                        }
                    }

                    ImGui.EndChild();
                }

                ImGui.PopStyleColor();

                ImGui.End();

                if (ShowUtils)
                {
                    ImGui.Begin("Utils", ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoMove);

                    ContentWindow.HelpMarker("Handy Shortcuts: \nBrush(B)\nBucket(G)\nDelete(D)", true);

                    ImGui.SetWindowPos(new Vector2(ThisWindowPos.X + ThisWindowSize.X, ThisWindowPos.Y));

                    ImGui.PushStyleColor(ImGuiCol.Button, 0);

                    if (ImGui.ImageButton(TexPtrs[0], new Vector2(32, 32))) //Brush
                    {
                        ActiveTool = Tools.Brush;
                    }

                    if (ImGui.ImageButton(TexPtrs[1], new Vector2(32, 32))) //Bucket
                    {
                        ActiveTool = Tools.Bucket;
                    }

                    if (ImGui.ImageButton(TexPtrs[2], new Vector2(32, 32))) //Delete
                    {
                        ActiveTool = Tools.Delete;
                    }

                    ImGui.PopStyleColor();

                    ImGui.End();
                }
            }
        }
Exemplo n.º 7
0
 public override void Update(Player player, ref int buffIndex)
 {
     player.mount.SetMount(ModContent.MountType <EmeraldSlime>(), player);
     player.buffTime[buffIndex]   = 10;
     player.armorEffectDrawShadow = true;
     if (player.wet)
     {
         player.wetSlime = 30;
         if (player.velocity.Y > 2f)
         {
             player.velocity.Y = player.velocity.Y * 0.9f;
         }
         player.velocity.Y = player.velocity.Y - 1f;
         if (player.velocity.Y < -5f)
         {
             player.velocity.Y = -5f;
         }
         if (player.controlJump)
         {
             player.velocity.Y = -20f;
         }
     }
     Microsoft.Xna.Framework.Rectangle checkDamagePlayer = player.getRect();
     checkDamagePlayer.Offset(0, player.height - 1);
     checkDamagePlayer.Height = 2;
     checkDamagePlayer.Inflate(12, 6);
     for (int i = 0; i < 200; i++)
     {
         NPC npc = Main.npc[i];
         if (npc.active && !npc.dontTakeDamage && !npc.friendly && npc.immune[player.whoAmI] == 0)
         {
             Microsoft.Xna.Framework.Rectangle checkDamageNPC = npc.getRect();
             if (checkDamagePlayer.Intersects(checkDamageNPC) && (npc.noTileCollide || Collision.CanHit(player.position, player.width, player.height, npc.position, npc.width, npc.height)))
             {
                 var   damage    = 60f * player.meleeDamage;
                 float knockBack = 5f;
                 int   direction = player.direction;
                 if (player.velocity.X < 0f)
                 {
                     direction = -1;
                 }
                 if (player.velocity.X > 0f)
                 {
                     direction = 1;
                 }
                 if (player.whoAmI == Main.myPlayer)
                 {
                     npc.StrikeNPC((int)damage, knockBack, direction, false, false, false);
                     if (Main.netMode != NetmodeID.SinglePlayer)
                     {
                         NetMessage.SendData(MessageID.StrikeNPC, -1, -1, NetworkText.FromLiteral(""), npc.whoAmI, 1, knockBack, direction, (int)damage);
                     }
                 }
                 npc.immune[player.whoAmI] = 10;
                 player.velocity.Y         = -20f;
                 player.immune             = true;
                 break;
             }
         }
     }
 }