diff --git a/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceDescriptor.cs b/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceDescriptor.cs index 09bacf6a8a..bb6e8d7835 100644 --- a/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceDescriptor.cs +++ b/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceDescriptor.cs @@ -3,7 +3,6 @@ using Intersect.Framework.Core.GameObjects.Conditions; using Intersect.Framework.Core.GameObjects.Events; using Intersect.Framework.Core.GameObjects.Items; -using Intersect.GameObjects; using Intersect.Models; using Newtonsoft.Json; @@ -23,32 +22,35 @@ public partial class ResourceDescriptor : DatabaseObject, IF public ResourceDescriptor(Guid id) : base(id) { Name = "New Resource"; - Initial = new ResourceStateDescriptor(); - Exhausted = new ResourceStateDescriptor(); } //EF wants NO PARAMETERS!!!!! public ResourceDescriptor() { Name = "New Resource"; - Initial = new ResourceStateDescriptor(); - Exhausted = new ResourceStateDescriptor(); } - // Graphics - public ResourceStateDescriptor Initial { get; set; } + public bool UseExplicitMaxHealthForResourceStates { get; set; } - public ResourceStateDescriptor Exhausted { get; set; } + [NotMapped, JsonIgnore] + public Dictionary States { get; set; } = []; - [Column("Animation")] - public Guid AnimationId { get; set; } + [Column(nameof(States))] + public string JsonStates + { + get => JsonConvert.SerializeObject(States); + set => States = JsonConvert.DeserializeObject>(value); + } + + [Column(nameof(DeathAnimation))] + public Guid DeathAnimationId { get; set; } [NotMapped] [JsonIgnore] - public AnimationDescriptor Animation + public AnimationDescriptor DeathAnimation { - get => AnimationDescriptor.Get(AnimationId); - set => AnimationId = value?.Id ?? Guid.Empty; + get => AnimationDescriptor.Get(DeathAnimationId); + set => DeathAnimationId = value?.Id ?? Guid.Empty; } // Drops diff --git a/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceStateDescriptor.cs b/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceStateDescriptor.cs index 53264d952b..2a151c1a42 100644 --- a/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceStateDescriptor.cs +++ b/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceStateDescriptor.cs @@ -1,15 +1,22 @@ -using Microsoft.EntityFrameworkCore; - namespace Intersect.Framework.Core.GameObjects.Resources; -[Owned] public partial class ResourceStateDescriptor { - public string Graphic { get; set; } = null; + public Guid Id { get; set; } + + public string Name { get; set; } + + public string? TextureName { get; set; } = default; + + public ResourceTextureSource TextureType { get; set; } = ResourceTextureSource.Resource; public bool RenderBelowEntities { get; set; } - public bool GraphicFromTileset { get; set; } + public Guid AnimationId { get; set; } + + public int MinimumHealth { get; set; } + + public int MaximumHealth { get; set; } public int X { get; set; } diff --git a/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceTextureSource.cs b/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceTextureSource.cs new file mode 100644 index 0000000000..8bec0ce3b7 --- /dev/null +++ b/Framework/Intersect.Framework.Core/GameObjects/Resources/ResourceTextureSource.cs @@ -0,0 +1,8 @@ +namespace Intersect.Framework.Core.GameObjects.Resources; + +public enum ResourceTextureSource +{ + Resource, + Tileset, + Animation, +} diff --git a/Intersect.Client.Core/Entities/Resource.cs b/Intersect.Client.Core/Entities/Resource.cs index fc3b079300..d911ebfcc6 100644 --- a/Intersect.Client.Core/Entities/Resource.cs +++ b/Intersect.Client.Core/Entities/Resource.cs @@ -1,4 +1,5 @@ using Intersect.Client.Core; +using Intersect.Client.Framework.Content; using Intersect.Client.Framework.Entities; using Intersect.Client.Framework.File_Management; using Intersect.Client.Framework.GenericClasses; @@ -6,8 +7,8 @@ using Intersect.Client.General; using Intersect.Core; using Intersect.Enums; +using Intersect.Framework.Core.GameObjects.Animations; using Intersect.Framework.Core.GameObjects.Resources; -using Intersect.GameObjects; using Intersect.Network.Packets.Server; using Microsoft.Extensions.Logging; @@ -18,13 +19,25 @@ public partial class Resource : Entity, IResource private FloatRect _renderBoundsDest = FloatRect.Empty; private FloatRect _renderBoundsSrc = FloatRect.Empty; - private bool _recalculateRenderBounds; private bool _waitingForTilesets; + private bool _recalculateRenderBounds; private bool _isDead; - private Guid _descriptorId; + private int _maximumHealthForStates; + private ResourceStateDescriptor? _currentState; private ResourceDescriptor? _descriptor; + private AnimationDescriptor? _animationDescriptor; private IAnimation? _activeAnimation; + private IAnimation? _stateAnimation; + + private readonly int _tileWidth = Options.Instance.Map.TileWidth; + private readonly int _tileHeight = Options.Instance.Map.TileHeight; + private readonly int _mapHeight = Options.Instance.Map.MapHeight; + + /// + public override bool CanBeAttacked => !IsDead; + + public ResourceStateDescriptor? CurrentState => _currentState; public Resource(Guid id, ResourceEntityPacket packet) : base(id, packet, EntityType.Resource) { @@ -34,10 +47,17 @@ public Resource(Guid id, ResourceEntityPacket packet) : base(id, packet, EntityT public ResourceDescriptor? Descriptor { get => _descriptor; - set => _descriptor = value; - } + set + { + if (value == _descriptor) + { + return; + } - public bool IsDepleted => IsDead; + _descriptor = value; + UpdateCurrentState(); + } + } public bool IsDead { @@ -50,7 +70,6 @@ public bool IsDead } _isDead = value; - _recalculateRenderBounds = true; } } @@ -81,21 +100,54 @@ private void ReloadSpriteTexture() return; } - if (IsDead && Descriptor.Exhausted.GraphicFromTileset || - !IsDead && Descriptor.Initial.GraphicFromTileset) + switch (_currentState?.TextureType) { - if (GameContentManager.Current.TilesetsLoaded) - { - Texture = Globals.ContentManager.GetTexture(Framework.Content.TextureType.Tileset, _sprite); - } - else - { - _waitingForTilesets = true; - } + case ResourceTextureSource.Tileset: + if (GameContentManager.Current.TilesetsLoaded) + { + Texture = GameContentManager.Current.GetTexture(TextureType.Tileset, _currentState?.TextureName); + } + else + { + _waitingForTilesets = true; + } + break; + + case ResourceTextureSource.Resource: + Texture = GameContentManager.Current.GetTexture(TextureType.Resource, _currentState?.TextureName); + break; + + case ResourceTextureSource.Animation: + if (_stateAnimation?.Descriptor?.Id == _currentState.AnimationId) + { + return; + } + + _stateAnimation?.Dispose(); + _stateAnimation = null; + + if (MapInstance is not { } mapInstance) + { + return; + } + + if (_animationDescriptor is not { } animationDescriptor) + { + return; + } + + var animation = mapInstance.AddTileAnimation(animationDescriptor, X, Y, Direction.Up); + if (animation is { IsDisposed: false }) + { + animation.InfiniteLoop = true; + } + _stateAnimation = animation; + break; } - else + + if (Texture == default) { - Texture = Globals.ContentManager.GetTexture(Framework.Content.TextureType.Resource, _sprite); + Texture = Graphics.Renderer.WhitePixel; } _recalculateRenderBounds = true; @@ -104,7 +156,6 @@ private void ReloadSpriteTexture() public override void Load(EntityPacket? packet) { base.Load(packet); - _recalculateRenderBounds = true; if (packet is not ResourceEntityPacket resourceEntityPacket) @@ -116,7 +167,6 @@ public override void Load(EntityPacket? packet) IsDead = resourceEntityPacket.IsDead; var descriptorId = resourceEntityPacket.ResourceId; - _descriptorId = descriptorId; var justDied = !wasDead && resourceEntityPacket.IsDead; if (!ResourceDescriptor.TryGet(descriptorId, out var descriptor)) @@ -134,8 +184,11 @@ public override void Load(EntityPacket? packet) return; } - _descriptor = descriptor; - UpdateFromDescriptor(_descriptor); + _maximumHealthForStates = (int)(descriptor.UseExplicitMaxHealthForResourceStates + ? descriptor.MaxHp + : MaxVital[(int)Enums.Vital.Health]); + + Descriptor = descriptor; if (!justDied) { @@ -144,7 +197,7 @@ public override void Load(EntityPacket? packet) if (MapInstance is { } mapInstance) { - var animation = mapInstance.AddTileAnimation(descriptor.AnimationId, X, Y, Direction.Up); + var animation = mapInstance.AddTileAnimation(descriptor.DeathAnimationId, X, Y, Direction.Up); if (animation is { IsDisposed: false }) { animation.Finished += OnAnimationDisposedOrFinished; @@ -175,15 +228,46 @@ private void OnAnimationDisposedOrFinished(IAnimation animation) animation.Finished -= OnAnimationDisposedOrFinished; } - private void UpdateFromDescriptor(ResourceDescriptor? descriptor) + public void UpdateCurrentState() { - if (descriptor == null) + if (Descriptor == default) + { + return; + } + + var graphicStates = Descriptor.States; + var currentHealthPercentage = Math.Floor((float)Vital[(int)Enums.Vital.Health] / _maximumHealthForStates * 100); + + if (_currentState is { } currentState && + currentHealthPercentage >= currentState?.MinimumHealth && + currentHealthPercentage <= currentState?.MaximumHealth + ) { return; } - var updatedSprite = IsDead ? descriptor.Exhausted.Graphic : descriptor.Initial.Graphic; - _sprite = updatedSprite; + currentState = graphicStates.Values.FirstOrDefault( + s => currentHealthPercentage >= s.MinimumHealth && currentHealthPercentage <= s.MaximumHealth + ); + + // dispose animation if animation is not used in this current state, + // but the previous state was an animation + if ( + _currentState?.TextureType == ResourceTextureSource.Animation && + currentState?.TextureType != ResourceTextureSource.Animation + ) + { + _stateAnimation?.Dispose(); + _stateAnimation = default; + } + + _currentState = currentState; + + if (currentState is { TextureType: ResourceTextureSource.Animation } && currentState.AnimationId != Guid.Empty) + { + _ = AnimationDescriptor.TryGet(currentState.AnimationId, out _animationDescriptor); + } + ReloadSpriteTexture(); } @@ -205,21 +289,19 @@ public override bool Update() if (mDisposed) { LatestMap = null; - return false; } if (Descriptor is { IsDeleted: true } deletedDescriptor) { - _ = ResourceDescriptor.TryGet(deletedDescriptor.Id, out _descriptor); - UpdateFromDescriptor(_descriptor); + _ = ResourceDescriptor.TryGet(deletedDescriptor.Id, out var descriptor); + Descriptor = descriptor; } if (!Maps.MapInstance.TryGet(MapId, out var map) || !map.InView()) { LatestMap = map; Globals.EntitiesToDispose.Add(Id); - return false; } @@ -250,15 +332,9 @@ public override bool Update() return result; } - /// - public override bool CanBeAttacked => !IsDead; - public override HashSet? DetermineRenderOrder(HashSet? renderList, IMapInstance? map) { - if (Descriptor == default || - (IsDead && !Descriptor.Exhausted.RenderBelowEntities) || - (!IsDead && !Descriptor.Initial.RenderBelowEntities) - ) + if (CurrentState is not { } graphicState || !graphicState.RenderBelowEntities) { return base.DetermineRenderOrder(renderList, map); } @@ -284,6 +360,11 @@ public override bool Update() return null; } + if (Graphics.RenderingEntities == default) + { + return null; + } + var gridX = Globals.Me.MapInstance.GridX; var gridY = Globals.Me.MapInstance.GridY; for (var x = gridX - 1; x <= gridX + 1; x++) @@ -312,16 +393,15 @@ public override bool Update() } else if (y == gridY) { - renderSet = Graphics.RenderingEntities[priority, Options.Instance.Map.MapHeight + Y]; + renderSet = Graphics.RenderingEntities[priority, _mapHeight + Y]; } else { - renderSet = Graphics.RenderingEntities[priority, Options.Instance.Map.MapHeight * 2 + Y]; + renderSet = Graphics.RenderingEntities[priority, _mapHeight * 2 + Y]; } _ = renderSet.Add(this); renderList = renderSet; - return renderList; } @@ -358,45 +438,69 @@ private void CalculateRenderBounds() } } - if (Texture == null) + if (Texture is not { } texture) { return; } - _renderBoundsSrc.X = 0; - _renderBoundsSrc.Y = 0; - if (IsDead && Descriptor.Exhausted.GraphicFromTileset) + if (CurrentState is not { } graphicState) { - _renderBoundsSrc.X = Descriptor.Exhausted.X * Options.Instance.Map.TileWidth; - _renderBoundsSrc.Y = Descriptor.Exhausted.Y * Options.Instance.Map.TileHeight; - _renderBoundsSrc.Width = (Descriptor.Exhausted.Width + 1) * Options.Instance.Map.TileWidth; - _renderBoundsSrc.Height = (Descriptor.Exhausted.Height + 1) * Options.Instance.Map.TileHeight; - } - else if (!IsDead && Descriptor.Initial.GraphicFromTileset) - { - _renderBoundsSrc.X = Descriptor.Initial.X * Options.Instance.Map.TileWidth; - _renderBoundsSrc.Y = Descriptor.Initial.Y * Options.Instance.Map.TileHeight; - _renderBoundsSrc.Width = (Descriptor.Initial.Width + 1) * Options.Instance.Map.TileWidth; - _renderBoundsSrc.Height = (Descriptor.Initial.Height + 1) * Options.Instance.Map.TileHeight; + return; } - else + + _renderBoundsSrc.X = 0; + _renderBoundsSrc.Y = 0; + + switch(graphicState.TextureType) { - _renderBoundsSrc.Width = Texture.Width; - _renderBoundsSrc.Height = Texture.Height; + case ResourceTextureSource.Resource: + _renderBoundsSrc.Width = texture.Width; + _renderBoundsSrc.Height = texture.Height; + break; + + case ResourceTextureSource.Tileset: + ResourceStateDescriptor? selectedGraphic = null; + + if (IsDead && graphicState is { MaximumHealth: 0 } deadGraphic) + { + selectedGraphic = deadGraphic; + } + else if (graphicState is { MinimumHealth: > 0 } aliveGraphic) + { + selectedGraphic = aliveGraphic; + } + + _renderBoundsSrc = selectedGraphic is null + ? default + : new ( + selectedGraphic.X * _tileWidth, + selectedGraphic.Y * _tileHeight, + (selectedGraphic.Width + 1) * _tileWidth, + (selectedGraphic.Height + 1) * _tileHeight + ); + break; + + case ResourceTextureSource.Animation: + _renderBoundsSrc = default; + break; + + default: + return; } _renderBoundsDest.Width = _renderBoundsSrc.Width; _renderBoundsDest.Height = _renderBoundsSrc.Height; - _renderBoundsDest.Y = (int) (map.Y + Y * Options.Instance.Map.TileHeight + OffsetY); - _renderBoundsDest.X = (int) (map.X + X * Options.Instance.Map.TileWidth + OffsetX); - if (_renderBoundsSrc.Height > Options.Instance.Map.TileHeight) + _renderBoundsDest.Y = (int) (map.Y + Y * _tileHeight + OffsetY); + _renderBoundsDest.X = (int) (map.X + X * _tileWidth + OffsetX); + + if (_renderBoundsSrc.Height > _tileHeight) { - _renderBoundsDest.Y -= _renderBoundsSrc.Height - Options.Instance.Map.TileHeight; + _renderBoundsDest.Y -= _renderBoundsSrc.Height - _tileHeight; } - if (_renderBoundsSrc.Width > Options.Instance.Map.TileWidth) + if (_renderBoundsSrc.Width > _tileWidth) { - _renderBoundsDest.X -= (_renderBoundsSrc.Width - Options.Instance.Map.TileWidth) / 2; + _renderBoundsDest.X -= (_renderBoundsSrc.Width - _tileWidth) / 2; } _recalculateRenderBounds = false; @@ -421,6 +525,6 @@ public override void Draw() return; } - Graphics.DrawGameTexture(Texture, _renderBoundsSrc, _renderBoundsDest, Intersect.Color.White); + Graphics.DrawGameTexture(Texture, _renderBoundsSrc, _renderBoundsDest, Color.White); } } diff --git a/Intersect.Client.Core/Networking/PacketHandler.cs b/Intersect.Client.Core/Networking/PacketHandler.cs index bbf3ffad8a..9e9f95248a 100644 --- a/Intersect.Client.Core/Networking/PacketHandler.cs +++ b/Intersect.Client.Core/Networking/PacketHandler.cs @@ -866,6 +866,11 @@ public void HandlePacket(IPacketSender packetSender, MapEntityVitalsPacket packe Globals.Me.CombatTimer = Timing.Global.Milliseconds + en.CombatTimeRemaining; } } + + if (entity is Resource resourceEntity) + { + resourceEntity.UpdateCurrentState(); + } } } diff --git a/Intersect.Client.Framework/Entities/IResource.cs b/Intersect.Client.Framework/Entities/IResource.cs index 4b2a264ae3..4722c1d12e 100644 --- a/Intersect.Client.Framework/Entities/IResource.cs +++ b/Intersect.Client.Framework/Entities/IResource.cs @@ -1,11 +1,8 @@ using Intersect.Framework.Core.GameObjects.Resources; -using Intersect.GameObjects; namespace Intersect.Client.Framework.Entities; public interface IResource : IEntity { ResourceDescriptor? Descriptor { get; } - - bool IsDepleted { get; } } \ No newline at end of file diff --git a/Intersect.Editor/Core/Graphics.cs b/Intersect.Editor/Core/Graphics.cs index 5c4129a160..03eacf9931 100644 --- a/Intersect.Editor/Core/Graphics.cs +++ b/Intersect.Editor/Core/Graphics.cs @@ -1344,12 +1344,16 @@ bool alternate return; } + var mapWidth = Options.Instance.Map.MapWidth; + var mapHeight = Options.Instance.Map.MapHeight; var x1 = 0; - var x2 = Options.Instance.Map.MapWidth; + var x2 = mapWidth; var y1 = 0; - var y2 = Options.Instance.Map.MapHeight; - var xoffset = CurrentView.Left + gridX * Options.Instance.Map.TileWidth * Options.Instance.Map.MapWidth; - var yoffset = CurrentView.Top + gridY * Options.Instance.Map.TileHeight * Options.Instance.Map.MapHeight; + var y2 = mapHeight; + var tileWidth = Options.Instance.Map.TileWidth; + var tileHeight = Options.Instance.Map.TileHeight; + var xoffset = CurrentView.Left + gridX * tileWidth * mapWidth; + var yoffset = CurrentView.Top + gridY * tileHeight * mapHeight; if (screenShotting) { @@ -1380,6 +1384,9 @@ bool alternate continue; } + float xpos = x * tileWidth + xoffset; + float ypos = y * tileHeight + yoffset; + if (tmpMap.Attributes[x, y].Type == MapAttributeType.Resource && !upper && !alternate) { var resource = ResourceDescriptor.Get(((MapResourceAttribute) tmpMap.Attributes[x, y]).ResourceId); @@ -1388,65 +1395,128 @@ bool alternate continue; } - if (TextUtils.IsNone(resource.Initial.Graphic)) + if (resource.States.Count < 1) { continue; } - if (resource.Initial.GraphicFromTileset) + var fullVitalResourceGraphic = resource.States.Values + .OrderByDescending(g => g.MaximumHealth) + .FirstOrDefault(); + + if (fullVitalResourceGraphic is not { } resourceGraphic) { - var res = GameContentManager.GetTexture( - GameContentManager.TextureType.Tileset, resource.Initial.Graphic - ); + continue; + } - if (res == null) - { - continue; - } + // we have the graphic, now lets build based on type + switch (resourceGraphic.TextureType) + { + case ResourceTextureSource.Resource: + { + var texture = GameContentManager.GetTexture( + GameContentManager.TextureType.Resource, resourceGraphic.TextureName + ); - float xpos = x * Options.Instance.Map.TileWidth + xoffset; - float ypos = y * Options.Instance.Map.TileHeight + yoffset; - if ((resource.Initial.Height + 1) * Options.Instance.Map.TileHeight > Options.Instance.Map.TileHeight) - { - ypos -= (resource.Initial.Height + 1) * Options.Instance.Map.TileHeight - Options.Instance.Map.TileHeight; - } + if (texture == null) + { + continue; + } - if ((resource.Initial.Width + 1) * Options.Instance.Map.TileWidth > Options.Instance.Map.TileWidth) - { - xpos -= ((resource.Initial.Width + 1) * Options.Instance.Map.TileWidth - Options.Instance.Map.TileWidth) / 2; - } + if (texture.Height > tileHeight) + { + ypos -= texture.Height - tileHeight; + } - DrawTexture( - res, xpos, ypos, resource.Initial.X * Options.Instance.Map.TileWidth, - resource.Initial.Y * Options.Instance.Map.TileHeight, - (resource.Initial.Width + 1) * Options.Instance.Map.TileWidth, - (resource.Initial.Height + 1) * Options.Instance.Map.TileHeight, renderTarget - ); - } - else - { - var res = GameContentManager.GetTexture( - GameContentManager.TextureType.Resource, resource.Initial.Graphic - ); + if (texture.Width > tileWidth) + { + xpos -= (texture.Width - tileWidth) / 2; + } - if (res == null) - { - continue; - } + DrawTexture( + texture, + xpos, + ypos, + 0, + 0, + texture.Width, + texture.Height, + renderTarget + ); + } + break; - float xpos = x * Options.Instance.Map.TileWidth + xoffset; - float ypos = y * Options.Instance.Map.TileHeight + yoffset; - if (res.Height > Options.Instance.Map.TileHeight) - { - ypos -= res.Height - Options.Instance.Map.TileHeight; - } + case ResourceTextureSource.Tileset: + { + var texture = GameContentManager.GetTexture( + GameContentManager.TextureType.Tileset, resourceGraphic.TextureName + ); - if (res.Width > Options.Instance.Map.TileWidth) - { - xpos -= (res.Width - Options.Instance.Map.TileWidth) / 2; - } + if (texture == null) + { + continue; + } + + if ((resourceGraphic.Height + 1) * tileHeight > tileHeight) + { + ypos -= (resourceGraphic.Height + 1) * tileHeight - tileHeight; + } + + if ((resourceGraphic.Width + 1) * tileWidth > tileWidth) + { + xpos -= ((resourceGraphic.Width + 1) * tileWidth - tileWidth) / 2; + } + + DrawTexture( + texture, + xpos, + ypos, + resourceGraphic.X * tileWidth, + resourceGraphic.Y * tileHeight, + (resourceGraphic.Width + 1) * tileWidth, + (resourceGraphic.Height + 1) * tileHeight, + renderTarget + ); + } + break; + + case ResourceTextureSource.Animation: + { + if (!AnimationDescriptor.TryGet(resourceGraphic.AnimationId, out var animation)) + { + continue; + } + + xpos += tileWidth / 2f; + ypos += tileHeight / 2f; + + var animationInstance = tmpMap.GetAttributeAnimation(tmpMap.Attributes[x, y], animation.Id); + + //Update if the animation isn't right! + if (animationInstance?.Descriptor != animation) + { + tmpMap.SetAttributeAnimation( + tmpMap.Attributes[x, y], + new Animation(animation, true) + ); + } - DrawTexture(res, xpos, ypos, 0, 0, res.Width, res.Height, renderTarget); + if (animationInstance != null) + { + animationInstance.Update(); + animationInstance.SetPosition((int)xpos, (int)ypos, 0); + animationInstance.Draw(renderTarget, false, alternate); + animationInstance.Draw(renderTarget, true, alternate); + } + } + break; + + default: + throw new ArgumentOutOfRangeException( + nameof(resourceGraphic.TextureType), + resourceGraphic.TextureType, + "Unknown ResourceGraphicType" + ); } } else if (tmpMap.Attributes[x, y].Type == MapAttributeType.Animation) @@ -1456,8 +1526,9 @@ bool alternate if (animation != null) { - float xpos = x * Options.Instance.Map.TileWidth + xoffset + Options.Instance.Map.TileWidth / 2; - float ypos = y * Options.Instance.Map.TileHeight + yoffset + Options.Instance.Map.TileHeight / 2; + xpos += tileWidth / 2f; + ypos += tileHeight / 2f; + if (tmpMap.Attributes[x, y] != null) { var animInstance = tmpMap.GetAttributeAnimation(tmpMap.Attributes[x, y], animation.Id); diff --git a/Intersect.Editor/Core/Main.cs b/Intersect.Editor/Core/Main.cs index 5c65cd0271..acf0800823 100644 --- a/Intersect.Editor/Core/Main.cs +++ b/Intersect.Editor/Core/Main.cs @@ -1,4 +1,4 @@ -using Intersect.Editor.Content; +using Intersect.Editor.Content; using Intersect.Editor.Forms; using Intersect.Editor.General; using Intersect.Editor.Localization; @@ -52,12 +52,6 @@ public static void StartLoop() public static void DrawFrame() { - //Check Editors - if (Globals.ResourceEditor != null && Globals.ResourceEditor.IsDisposed == false) - { - Globals.ResourceEditor.Render(); - } - if (Globals.MapGrid == null) { return; diff --git a/Intersect.Editor/Forms/Editors/frmResource.Designer.cs b/Intersect.Editor/Forms/Editors/frmResource.Designer.cs index abcaa73d8f..e84f021983 100644 --- a/Intersect.Editor/Forms/Editors/frmResource.Designer.cs +++ b/Intersect.Editor/Forms/Editors/frmResource.Designer.cs @@ -37,14 +37,17 @@ private void InitializeComponent() txtSearch = new DarkTextBox(); lstGameObjects = new Controls.GameObjectList(); grpGeneral = new DarkGroupBox(); + nudHpRegen = new DarkNumericUpDown(); + chkUseExplicitMaxHealthForResourceStates = new DarkCheckBox(); + lblHpRegen = new Label(); btnAddFolder = new DarkButton(); lblFolder = new Label(); cmbFolder = new DarkComboBox(); nudMaxHp = new DarkNumericUpDown(); nudMinHp = new DarkNumericUpDown(); nudSpawnDuration = new DarkNumericUpDown(); - cmbAnimation = new DarkComboBox(); - lblAnimation = new Label(); + cmbDeathAnimation = new DarkComboBox(); + lblDeathAnimation = new Label(); lblMaxHp = new Label(); lblSpawnDuration = new Label(); chkWalkableAfter = new DarkCheckBox(); @@ -56,18 +59,25 @@ private void InitializeComponent() txtName = new DarkTextBox(); btnRequirements = new DarkButton(); grpGraphics = new DarkGroupBox(); - chkExhaustedBelowEntities = new DarkCheckBox(); - chkInitialBelowEntities = new DarkCheckBox(); - chkExhaustedFromTileset = new DarkCheckBox(); - chkInitialFromTileset = new DarkCheckBox(); - exhaustedGraphicContainer = new Panel(); - picEndResource = new PictureBox(); - initalGraphicContainer = new Panel(); - picInitialResource = new PictureBox(); - cmbEndSprite = new DarkComboBox(); - lblPic2 = new Label(); - cmbInitialSprite = new DarkComboBox(); - lblPic = new Label(); + btnRemoveState = new DarkButton(); + btnAddState = new DarkButton(); + lblStateName = new Label(); + lstStates = new ListBox(); + txtStateName = new DarkTextBox(); + grpGraphicData = new DarkGroupBox(); + nudStateRangeMax = new DarkNumericUpDown(); + nudStateRangeMin = new DarkNumericUpDown(); + lblStateRange = new Label(); + cmbTextureSource = new DarkComboBox(); + lblTerxtureSource = new Label(); + cmbAnimation = new DarkComboBox(); + lblAnimation = new Label(); + chkRenderBelowEntity = new DarkCheckBox(); + cmbTextureType = new DarkComboBox(); + lblTextureType = new Label(); + lblStates = new Label(); + graphicContainer = new Panel(); + picResource = new PictureBox(); tmrRender = new System.Windows.Forms.Timer(components); pnlContainer = new Panel(); grpRequirements = new DarkGroupBox(); @@ -76,10 +86,6 @@ private void InitializeComponent() grpCommonEvent = new DarkGroupBox(); cmbEvent = new DarkComboBox(); lblEvent = new Label(); - grpRegen = new DarkGroupBox(); - nudHpRegen = new DarkNumericUpDown(); - lblHpRegen = new Label(); - lblRegenHint = new Label(); grpDrops = new DarkGroupBox(); nudDropMinAmount = new DarkNumericUpDown(); lblDropMinAmount = new Label(); @@ -107,19 +113,19 @@ private void InitializeComponent() toolStripItemUndo = new ToolStripButton(); grpResources.SuspendLayout(); grpGeneral.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)nudHpRegen).BeginInit(); ((System.ComponentModel.ISupportInitialize)nudMaxHp).BeginInit(); ((System.ComponentModel.ISupportInitialize)nudMinHp).BeginInit(); ((System.ComponentModel.ISupportInitialize)nudSpawnDuration).BeginInit(); grpGraphics.SuspendLayout(); - exhaustedGraphicContainer.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)picEndResource).BeginInit(); - initalGraphicContainer.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)picInitialResource).BeginInit(); + grpGraphicData.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)nudStateRangeMax).BeginInit(); + ((System.ComponentModel.ISupportInitialize)nudStateRangeMin).BeginInit(); + graphicContainer.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)picResource).BeginInit(); pnlContainer.SuspendLayout(); grpRequirements.SuspendLayout(); grpCommonEvent.SuspendLayout(); - grpRegen.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)nudHpRegen).BeginInit(); grpDrops.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)nudDropMinAmount).BeginInit(); ((System.ComponentModel.ISupportInitialize)nudDropMaxAmount).BeginInit(); @@ -191,14 +197,17 @@ private void InitializeComponent() // grpGeneral.BackColor = System.Drawing.Color.FromArgb(45, 45, 48); grpGeneral.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); + grpGeneral.Controls.Add(nudHpRegen); + grpGeneral.Controls.Add(chkUseExplicitMaxHealthForResourceStates); + grpGeneral.Controls.Add(lblHpRegen); grpGeneral.Controls.Add(btnAddFolder); grpGeneral.Controls.Add(lblFolder); grpGeneral.Controls.Add(cmbFolder); grpGeneral.Controls.Add(nudMaxHp); grpGeneral.Controls.Add(nudMinHp); grpGeneral.Controls.Add(nudSpawnDuration); - grpGeneral.Controls.Add(cmbAnimation); - grpGeneral.Controls.Add(lblAnimation); + grpGeneral.Controls.Add(cmbDeathAnimation); + grpGeneral.Controls.Add(lblDeathAnimation); grpGeneral.Controls.Add(lblMaxHp); grpGeneral.Controls.Add(lblSpawnDuration); grpGeneral.Controls.Add(chkWalkableAfter); @@ -213,11 +222,43 @@ private void InitializeComponent() grpGeneral.Margin = new Padding(4, 3, 4, 3); grpGeneral.Name = "grpGeneral"; grpGeneral.Padding = new Padding(4, 3, 4, 3); - grpGeneral.Size = new Size(260, 324); + grpGeneral.Size = new Size(260, 380); grpGeneral.TabIndex = 15; grpGeneral.TabStop = false; grpGeneral.Text = "General"; // + // nudHpRegen + // + nudHpRegen.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); + nudHpRegen.ForeColor = System.Drawing.Color.Gainsboro; + nudHpRegen.Location = new System.Drawing.Point(108, 173); + nudHpRegen.Margin = new Padding(4, 3, 4, 3); + nudHpRegen.Name = "nudHpRegen"; + nudHpRegen.Size = new Size(138, 23); + nudHpRegen.TabIndex = 30; + nudHpRegen.Value = new decimal(new int[] { 0, 0, 0, 0 }); + nudHpRegen.ValueChanged += nudHpRegen_ValueChanged; + // + // chkUseExplicitMaxHealthForResourceStates + // + chkUseExplicitMaxHealthForResourceStates.Location = new System.Drawing.Point(7, 339); + chkUseExplicitMaxHealthForResourceStates.Margin = new Padding(4, 3, 4, 3); + chkUseExplicitMaxHealthForResourceStates.Name = "chkUseExplicitMaxHealthForResourceStates"; + chkUseExplicitMaxHealthForResourceStates.Size = new Size(246, 34); + chkUseExplicitMaxHealthForResourceStates.TabIndex = 53; + chkUseExplicitMaxHealthForResourceStates.Text = "Use explicit Max Health for Resources States?"; + chkUseExplicitMaxHealthForResourceStates.CheckedChanged += chkUseExplicitMaxHealthForResourceStates_CheckedChanged; + // + // lblHpRegen + // + lblHpRegen.AutoSize = true; + lblHpRegen.Location = new System.Drawing.Point(7, 175); + lblHpRegen.Margin = new Padding(2, 0, 2, 0); + lblHpRegen.Name = "lblHpRegen"; + lblHpRegen.Size = new Size(83, 15); + lblHpRegen.TabIndex = 26; + lblHpRegen.Text = "HP Regen (%):"; + // // btnAddFolder // btnAddFolder.Location = new System.Drawing.Point(224, 52); @@ -291,46 +332,46 @@ private void InitializeComponent() // nudSpawnDuration.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); nudSpawnDuration.ForeColor = System.Drawing.Color.Gainsboro; - nudSpawnDuration.Location = new System.Drawing.Point(144, 174); + nudSpawnDuration.Location = new System.Drawing.Point(108, 202); nudSpawnDuration.Margin = new Padding(4, 3, 4, 3); nudSpawnDuration.Maximum = new decimal(new int[] { int.MaxValue, 0, 0, 0 }); nudSpawnDuration.Name = "nudSpawnDuration"; - nudSpawnDuration.Size = new Size(102, 23); + nudSpawnDuration.Size = new Size(137, 23); nudSpawnDuration.TabIndex = 40; nudSpawnDuration.Value = new decimal(new int[] { 0, 0, 0, 0 }); nudSpawnDuration.ValueChanged += nudSpawnDuration_ValueChanged; // - // cmbAnimation - // - cmbAnimation.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); - cmbAnimation.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); - cmbAnimation.BorderStyle = ButtonBorderStyle.Solid; - cmbAnimation.ButtonColor = System.Drawing.Color.FromArgb(43, 43, 43); - cmbAnimation.DrawDropdownHoverOutline = false; - cmbAnimation.DrawFocusRectangle = false; - cmbAnimation.DrawMode = DrawMode.OwnerDrawFixed; - cmbAnimation.DropDownStyle = ComboBoxStyle.DropDownList; - cmbAnimation.FlatStyle = FlatStyle.Flat; - cmbAnimation.ForeColor = System.Drawing.Color.Gainsboro; - cmbAnimation.FormattingEnabled = true; - cmbAnimation.Location = new System.Drawing.Point(88, 207); - cmbAnimation.Margin = new Padding(4, 3, 4, 3); - cmbAnimation.Name = "cmbAnimation"; - cmbAnimation.Size = new Size(157, 24); - cmbAnimation.TabIndex = 39; - cmbAnimation.Text = null; - cmbAnimation.TextPadding = new Padding(2); - cmbAnimation.SelectedIndexChanged += cmbAnimation_SelectedIndexChanged; - // - // lblAnimation - // - lblAnimation.AutoSize = true; - lblAnimation.Location = new System.Drawing.Point(7, 210); - lblAnimation.Margin = new Padding(4, 0, 4, 0); - lblAnimation.Name = "lblAnimation"; - lblAnimation.Size = new Size(66, 15); - lblAnimation.TabIndex = 36; - lblAnimation.Text = "Animation:"; + // cmbDeathAnimation + // + cmbDeathAnimation.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); + cmbDeathAnimation.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); + cmbDeathAnimation.BorderStyle = ButtonBorderStyle.Solid; + cmbDeathAnimation.ButtonColor = System.Drawing.Color.FromArgb(43, 43, 43); + cmbDeathAnimation.DrawDropdownHoverOutline = false; + cmbDeathAnimation.DrawFocusRectangle = false; + cmbDeathAnimation.DrawMode = DrawMode.OwnerDrawFixed; + cmbDeathAnimation.DropDownStyle = ComboBoxStyle.DropDownList; + cmbDeathAnimation.FlatStyle = FlatStyle.Flat; + cmbDeathAnimation.ForeColor = System.Drawing.Color.Gainsboro; + cmbDeathAnimation.FormattingEnabled = true; + cmbDeathAnimation.Location = new System.Drawing.Point(7, 255); + cmbDeathAnimation.Margin = new Padding(4, 3, 4, 3); + cmbDeathAnimation.Name = "cmbDeathAnimation"; + cmbDeathAnimation.Size = new Size(239, 24); + cmbDeathAnimation.TabIndex = 39; + cmbDeathAnimation.Text = null; + cmbDeathAnimation.TextPadding = new Padding(2); + cmbDeathAnimation.SelectedIndexChanged += cmbDeathAnimation_SelectedIndexChanged; + // + // lblDeathAnimation + // + lblDeathAnimation.AutoSize = true; + lblDeathAnimation.Location = new System.Drawing.Point(8, 232); + lblDeathAnimation.Margin = new Padding(4, 0, 4, 0); + lblDeathAnimation.Name = "lblDeathAnimation"; + lblDeathAnimation.Size = new Size(100, 15); + lblDeathAnimation.TabIndex = 36; + lblDeathAnimation.Text = "Death Animation:"; // // lblMaxHp // @@ -345,7 +386,7 @@ private void InitializeComponent() // lblSpawnDuration // lblSpawnDuration.AutoSize = true; - lblSpawnDuration.Location = new System.Drawing.Point(7, 179); + lblSpawnDuration.Location = new System.Drawing.Point(6, 204); lblSpawnDuration.Margin = new Padding(4, 0, 4, 0); lblSpawnDuration.Name = "lblSpawnDuration"; lblSpawnDuration.Size = new Size(94, 15); @@ -354,7 +395,7 @@ private void InitializeComponent() // // chkWalkableAfter // - chkWalkableAfter.Location = new System.Drawing.Point(7, 264); + chkWalkableAfter.Location = new System.Drawing.Point(7, 314); chkWalkableAfter.Margin = new Padding(4, 3, 4, 3); chkWalkableAfter.Name = "chkWalkableAfter"; chkWalkableAfter.Size = new Size(246, 20); @@ -364,7 +405,7 @@ private void InitializeComponent() // // chkWalkableBefore // - chkWalkableBefore.Location = new System.Drawing.Point(7, 238); + chkWalkableBefore.Location = new System.Drawing.Point(7, 287); chkWalkableBefore.Margin = new Padding(4, 3, 4, 3); chkWalkableBefore.Name = "chkWalkableBefore"; chkWalkableBefore.Size = new Size(246, 20); @@ -451,188 +492,288 @@ private void InitializeComponent() // grpGraphics.BackColor = System.Drawing.Color.FromArgb(45, 45, 48); grpGraphics.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); - grpGraphics.Controls.Add(chkExhaustedBelowEntities); - grpGraphics.Controls.Add(chkInitialBelowEntities); - grpGraphics.Controls.Add(chkExhaustedFromTileset); - grpGraphics.Controls.Add(chkInitialFromTileset); - grpGraphics.Controls.Add(exhaustedGraphicContainer); - grpGraphics.Controls.Add(initalGraphicContainer); - grpGraphics.Controls.Add(cmbEndSprite); - grpGraphics.Controls.Add(lblPic2); - grpGraphics.Controls.Add(cmbInitialSprite); - grpGraphics.Controls.Add(lblPic); + grpGraphics.Controls.Add(btnRemoveState); + grpGraphics.Controls.Add(btnAddState); + grpGraphics.Controls.Add(lblStateName); + grpGraphics.Controls.Add(lstStates); + grpGraphics.Controls.Add(txtStateName); + grpGraphics.Controls.Add(grpGraphicData); + grpGraphics.Controls.Add(lblStates); + grpGraphics.Controls.Add(graphicContainer); grpGraphics.ForeColor = System.Drawing.Color.Gainsboro; - grpGraphics.Location = new System.Drawing.Point(0, 325); + grpGraphics.Location = new System.Drawing.Point(1, 386); grpGraphics.Margin = new Padding(4, 3, 4, 3); grpGraphics.Name = "grpGraphics"; grpGraphics.Padding = new Padding(4, 3, 4, 3); grpGraphics.Size = new Size(824, 524); grpGraphics.TabIndex = 16; grpGraphics.TabStop = false; - grpGraphics.Text = "Graphics"; - // - // chkExhaustedBelowEntities - // - chkExhaustedBelowEntities.Location = new System.Drawing.Point(696, 15); - chkExhaustedBelowEntities.Margin = new Padding(4, 3, 4, 3); - chkExhaustedBelowEntities.Name = "chkExhaustedBelowEntities"; - chkExhaustedBelowEntities.Size = new Size(114, 24); - chkExhaustedBelowEntities.TabIndex = 35; - chkExhaustedBelowEntities.Text = "Below Entities"; - chkExhaustedBelowEntities.CheckedChanged += chkExhaustedBelowEntities_CheckedChanged; - // - // chkInitialBelowEntities - // - chkInitialBelowEntities.Location = new System.Drawing.Point(286, 15); - chkInitialBelowEntities.Margin = new Padding(4, 3, 4, 3); - chkInitialBelowEntities.Name = "chkInitialBelowEntities"; - chkInitialBelowEntities.Size = new Size(114, 24); - chkInitialBelowEntities.TabIndex = 34; - chkInitialBelowEntities.Text = "Below Entities"; - chkInitialBelowEntities.CheckedChanged += chkInitialBelowEntities_CheckedChanged; - // - // chkExhaustedFromTileset - // - chkExhaustedFromTileset.Location = new System.Drawing.Point(696, 37); - chkExhaustedFromTileset.Margin = new Padding(4, 3, 4, 3); - chkExhaustedFromTileset.Name = "chkExhaustedFromTileset"; - chkExhaustedFromTileset.Size = new Size(114, 24); - chkExhaustedFromTileset.TabIndex = 33; - chkExhaustedFromTileset.Text = "From Tileset"; - chkExhaustedFromTileset.CheckedChanged += chkExhaustedFromTileset_CheckedChanged; - // - // chkInitialFromTileset - // - chkInitialFromTileset.Location = new System.Drawing.Point(286, 37); - chkInitialFromTileset.Margin = new Padding(4, 3, 4, 3); - chkInitialFromTileset.Name = "chkInitialFromTileset"; - chkInitialFromTileset.Size = new Size(114, 24); - chkInitialFromTileset.TabIndex = 32; - chkInitialFromTileset.Text = "From Tileset"; - chkInitialFromTileset.CheckedChanged += chkInitialFromTileset_CheckedChanged; - // - // exhaustedGraphicContainer - // - exhaustedGraphicContainer.AutoScroll = true; - exhaustedGraphicContainer.Controls.Add(picEndResource); - exhaustedGraphicContainer.Location = new System.Drawing.Point(426, 72); - exhaustedGraphicContainer.Margin = new Padding(4, 3, 4, 3); - exhaustedGraphicContainer.Name = "exhaustedGraphicContainer"; - exhaustedGraphicContainer.Size = new Size(385, 445); - exhaustedGraphicContainer.TabIndex = 25; - // - // picEndResource - // - picEndResource.Location = new System.Drawing.Point(0, 0); - picEndResource.Margin = new Padding(4, 3, 4, 3); - picEndResource.Name = "picEndResource"; - picEndResource.Size = new Size(212, 335); - picEndResource.TabIndex = 2; - picEndResource.TabStop = false; - picEndResource.MouseDown += picExhustedResource_MouseDown; - picEndResource.MouseMove += picExhaustedResource_MouseMove; - picEndResource.MouseUp += picExhaustedResource_MouseUp; - // - // initalGraphicContainer - // - initalGraphicContainer.AutoScroll = true; - initalGraphicContainer.Controls.Add(picInitialResource); - initalGraphicContainer.Location = new System.Drawing.Point(15, 72); - initalGraphicContainer.Margin = new Padding(4, 3, 4, 3); - initalGraphicContainer.Name = "initalGraphicContainer"; - initalGraphicContainer.Size = new Size(385, 445); - initalGraphicContainer.TabIndex = 24; - // - // picInitialResource - // - picInitialResource.Location = new System.Drawing.Point(0, 0); - picInitialResource.Margin = new Padding(4, 3, 4, 3); - picInitialResource.Name = "picInitialResource"; - picInitialResource.Size = new Size(210, 335); - picInitialResource.TabIndex = 2; - picInitialResource.TabStop = false; - picInitialResource.MouseDown += picInitialResource_MouseDown; - picInitialResource.MouseMove += picInitialResource_MouseMove; - picInitialResource.MouseUp += picInitialResource_MouseUp; - // - // cmbEndSprite - // - cmbEndSprite.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); - cmbEndSprite.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); - cmbEndSprite.BorderStyle = ButtonBorderStyle.Solid; - cmbEndSprite.ButtonColor = System.Drawing.Color.FromArgb(43, 43, 43); - cmbEndSprite.DrawDropdownHoverOutline = false; - cmbEndSprite.DrawFocusRectangle = false; - cmbEndSprite.DrawMode = DrawMode.OwnerDrawFixed; - cmbEndSprite.DropDownStyle = ComboBoxStyle.DropDownList; - cmbEndSprite.FlatStyle = FlatStyle.Flat; - cmbEndSprite.ForeColor = System.Drawing.Color.Gainsboro; - cmbEndSprite.FormattingEnabled = true; - cmbEndSprite.Items.AddRange(new object[] { "None" }); - cmbEndSprite.Location = new System.Drawing.Point(426, 37); - cmbEndSprite.Margin = new Padding(4, 3, 4, 3); - cmbEndSprite.Name = "cmbEndSprite"; - cmbEndSprite.Size = new Size(228, 24); - cmbEndSprite.TabIndex = 16; - cmbEndSprite.Text = "None"; - cmbEndSprite.TextPadding = new Padding(2); - cmbEndSprite.SelectedIndexChanged += cmbEndSprite_SelectedIndexChanged; - // - // lblPic2 - // - lblPic2.AutoSize = true; - lblPic2.Location = new System.Drawing.Point(422, 18); - lblPic2.Margin = new Padding(4, 0, 4, 0); - lblPic2.Name = "lblPic2"; - lblPic2.Size = new Size(104, 15); - lblPic2.TabIndex = 15; - lblPic2.Text = "Removed Graphic:"; - // - // cmbInitialSprite - // - cmbInitialSprite.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); - cmbInitialSprite.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); - cmbInitialSprite.BorderStyle = ButtonBorderStyle.Solid; - cmbInitialSprite.ButtonColor = System.Drawing.Color.FromArgb(43, 43, 43); - cmbInitialSprite.DrawDropdownHoverOutline = false; - cmbInitialSprite.DrawFocusRectangle = false; - cmbInitialSprite.DrawMode = DrawMode.OwnerDrawFixed; - cmbInitialSprite.DropDownStyle = ComboBoxStyle.DropDownList; - cmbInitialSprite.FlatStyle = FlatStyle.Flat; - cmbInitialSprite.ForeColor = System.Drawing.Color.Gainsboro; - cmbInitialSprite.FormattingEnabled = true; - cmbInitialSprite.Items.AddRange(new object[] { "None" }); - cmbInitialSprite.Location = new System.Drawing.Point(15, 37); - cmbInitialSprite.Margin = new Padding(4, 3, 4, 3); - cmbInitialSprite.Name = "cmbInitialSprite"; - cmbInitialSprite.Size = new Size(227, 24); - cmbInitialSprite.TabIndex = 14; - cmbInitialSprite.Text = "None"; - cmbInitialSprite.TextPadding = new Padding(2); - cmbInitialSprite.SelectedIndexChanged += cmbInitialSprite_SelectedIndexChanged; - // - // lblPic - // - lblPic.AutoSize = true; - lblPic.Location = new System.Drawing.Point(12, 18); - lblPic.Margin = new Padding(4, 0, 4, 0); - lblPic.Name = "lblPic"; - lblPic.Size = new Size(83, 15); - lblPic.TabIndex = 13; - lblPic.Text = "Initial Graphic:"; + grpGraphics.Text = "Appearance"; + // + // btnRemoveState + // + btnRemoveState.Location = new System.Drawing.Point(172, 187); + btnRemoveState.Margin = new Padding(4, 3, 4, 3); + btnRemoveState.Name = "btnRemoveState"; + btnRemoveState.Padding = new Padding(6); + btnRemoveState.Size = new Size(88, 27); + btnRemoveState.TabIndex = 67; + btnRemoveState.Text = "Remove"; + btnRemoveState.Click += btnRemoveState_Click; + // + // btnAddState + // + btnAddState.Location = new System.Drawing.Point(7, 187); + btnAddState.Margin = new Padding(4, 3, 4, 3); + btnAddState.Name = "btnAddState"; + btnAddState.Padding = new Padding(6); + btnAddState.Size = new Size(88, 27); + btnAddState.TabIndex = 67; + btnAddState.Text = "Add"; + btnAddState.Click += btnAddState_Click; + // + // lblStateName + // + lblStateName.AutoSize = true; + lblStateName.Location = new System.Drawing.Point(4, 139); + lblStateName.Margin = new Padding(4, 0, 4, 0); + lblStateName.Name = "lblStateName"; + lblStateName.Size = new Size(71, 15); + lblStateName.TabIndex = 56; + lblStateName.Text = "State Name:"; + // + // lstStates + // + lstStates.BackColor = System.Drawing.Color.FromArgb(60, 63, 65); + lstStates.BorderStyle = BorderStyle.FixedSingle; + lstStates.ForeColor = System.Drawing.Color.Gainsboro; + lstStates.FormattingEnabled = true; + lstStates.ItemHeight = 15; + lstStates.Location = new System.Drawing.Point(7, 39); + lstStates.Margin = new Padding(4, 3, 4, 3); + lstStates.Name = "lstStates"; + lstStates.Size = new Size(253, 92); + lstStates.TabIndex = 60; + lstStates.SelectedIndexChanged += lstStates_SelectedIndexChanged; + // + // txtStateName + // + txtStateName.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); + txtStateName.BorderStyle = BorderStyle.FixedSingle; + txtStateName.ForeColor = System.Drawing.Color.FromArgb(220, 220, 220); + txtStateName.Location = new System.Drawing.Point(7, 158); + txtStateName.Margin = new Padding(4, 3, 4, 3); + txtStateName.Name = "txtStateName"; + txtStateName.Size = new Size(253, 23); + txtStateName.TabIndex = 55; + // + // grpGraphicData + // + grpGraphicData.BackColor = System.Drawing.Color.FromArgb(45, 45, 48); + grpGraphicData.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); + grpGraphicData.Controls.Add(nudStateRangeMax); + grpGraphicData.Controls.Add(nudStateRangeMin); + grpGraphicData.Controls.Add(lblStateRange); + grpGraphicData.Controls.Add(cmbTextureSource); + grpGraphicData.Controls.Add(lblTerxtureSource); + grpGraphicData.Controls.Add(cmbAnimation); + grpGraphicData.Controls.Add(lblAnimation); + grpGraphicData.Controls.Add(chkRenderBelowEntity); + grpGraphicData.Controls.Add(cmbTextureType); + grpGraphicData.Controls.Add(lblTextureType); + grpGraphicData.ForeColor = System.Drawing.Color.Gainsboro; + grpGraphicData.Location = new System.Drawing.Point(7, 221); + grpGraphicData.Margin = new Padding(2); + grpGraphicData.Name = "grpGraphicData"; + grpGraphicData.Padding = new Padding(2); + grpGraphicData.Size = new Size(253, 292); + grpGraphicData.TabIndex = 34; + grpGraphicData.TabStop = false; + grpGraphicData.Text = "Graphic Data"; + // + // nudStateRangeMax + // + nudStateRangeMax.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); + nudStateRangeMax.ForeColor = System.Drawing.Color.Gainsboro; + nudStateRangeMax.Location = new System.Drawing.Point(137, 229); + nudStateRangeMax.Margin = new Padding(4, 3, 4, 3); + nudStateRangeMax.Name = "nudStateRangeMax"; + nudStateRangeMax.Size = new Size(102, 23); + nudStateRangeMax.TabIndex = 68; + nudStateRangeMax.Value = new decimal(new int[] { 0, 0, 0, 0 }); + nudStateRangeMax.ValueChanged += nudStateRangeMax_ValueChanged; + // + // nudStateRangeMin + // + nudStateRangeMin.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); + nudStateRangeMin.ForeColor = System.Drawing.Color.Gainsboro; + nudStateRangeMin.Location = new System.Drawing.Point(12, 229); + nudStateRangeMin.Margin = new Padding(4, 3, 4, 3); + nudStateRangeMin.Name = "nudStateRangeMin"; + nudStateRangeMin.Size = new Size(102, 23); + nudStateRangeMin.TabIndex = 67; + nudStateRangeMin.Value = new decimal(new int[] { 0, 0, 0, 0 }); + nudStateRangeMin.ValueChanged += nudStateRangeMin_ValueChanged; + // + // lblStateRange + // + lblStateRange.AutoSize = true; + lblStateRange.Location = new System.Drawing.Point(12, 208); + lblStateRange.Margin = new Padding(4, 0, 4, 0); + lblStateRange.Name = "lblStateRange"; + lblStateRange.Size = new Size(151, 15); + lblStateRange.TabIndex = 58; + lblStateRange.Text = "State Range Min - Max (%):"; + // + // cmbTextureSource + // + cmbTextureSource.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); + cmbTextureSource.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); + cmbTextureSource.BorderStyle = ButtonBorderStyle.Solid; + cmbTextureSource.ButtonColor = System.Drawing.Color.FromArgb(43, 43, 43); + cmbTextureSource.DrawDropdownHoverOutline = false; + cmbTextureSource.DrawFocusRectangle = false; + cmbTextureSource.DrawMode = DrawMode.OwnerDrawFixed; + cmbTextureSource.DropDownStyle = ComboBoxStyle.DropDownList; + cmbTextureSource.FlatStyle = FlatStyle.Flat; + cmbTextureSource.ForeColor = System.Drawing.Color.Gainsboro; + cmbTextureSource.FormattingEnabled = true; + cmbTextureSource.Location = new System.Drawing.Point(12, 119); + cmbTextureSource.Margin = new Padding(4, 3, 4, 3); + cmbTextureSource.Name = "cmbTextureSource"; + cmbTextureSource.Size = new Size(227, 24); + cmbTextureSource.TabIndex = 57; + cmbTextureSource.Text = null; + cmbTextureSource.TextPadding = new Padding(2); + cmbTextureSource.SelectedIndexChanged += cmbGraphicFile_SelectedIndexChanged; + // + // lblTerxtureSource + // + lblTerxtureSource.AutoSize = true; + lblTerxtureSource.Location = new System.Drawing.Point(9, 99); + lblTerxtureSource.Margin = new Padding(4, 0, 4, 0); + lblTerxtureSource.Name = "lblTerxtureSource"; + lblTerxtureSource.Size = new Size(87, 15); + lblTerxtureSource.TabIndex = 56; + lblTerxtureSource.Text = "Texture Source:"; + // + // cmbAnimation + // + cmbAnimation.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); + cmbAnimation.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); + cmbAnimation.BorderStyle = ButtonBorderStyle.Solid; + cmbAnimation.ButtonColor = System.Drawing.Color.FromArgb(43, 43, 43); + cmbAnimation.DrawDropdownHoverOutline = false; + cmbAnimation.DrawFocusRectangle = false; + cmbAnimation.DrawMode = DrawMode.OwnerDrawFixed; + cmbAnimation.DropDownStyle = ComboBoxStyle.DropDownList; + cmbAnimation.FlatStyle = FlatStyle.Flat; + cmbAnimation.ForeColor = System.Drawing.Color.Gainsboro; + cmbAnimation.FormattingEnabled = true; + cmbAnimation.Location = new System.Drawing.Point(12, 175); + cmbAnimation.Margin = new Padding(4, 3, 4, 3); + cmbAnimation.Name = "cmbAnimation"; + cmbAnimation.Size = new Size(227, 24); + cmbAnimation.TabIndex = 55; + cmbAnimation.Text = null; + cmbAnimation.TextPadding = new Padding(2); + cmbAnimation.SelectedIndexChanged += cmbAnimation_SelectedIndexChanged; + // + // lblAnimation + // + lblAnimation.AutoSize = true; + lblAnimation.Location = new System.Drawing.Point(9, 155); + lblAnimation.Margin = new Padding(4, 0, 4, 0); + lblAnimation.Name = "lblAnimation"; + lblAnimation.Size = new Size(66, 15); + lblAnimation.TabIndex = 54; + lblAnimation.Text = "Animation:"; + // + // chkRenderBelowEntity + // + chkRenderBelowEntity.Location = new System.Drawing.Point(12, 71); + chkRenderBelowEntity.Margin = new Padding(4, 3, 4, 3); + chkRenderBelowEntity.Name = "chkRenderBelowEntity"; + chkRenderBelowEntity.Size = new Size(227, 20); + chkRenderBelowEntity.TabIndex = 53; + chkRenderBelowEntity.Text = "Render Below Entity"; + chkRenderBelowEntity.CheckedChanged += chkRenderBelowEntity_CheckedChanged; + // + // cmbTextureType + // + cmbTextureType.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); + cmbTextureType.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); + cmbTextureType.BorderStyle = ButtonBorderStyle.Solid; + cmbTextureType.ButtonColor = System.Drawing.Color.FromArgb(43, 43, 43); + cmbTextureType.DrawDropdownHoverOutline = false; + cmbTextureType.DrawFocusRectangle = false; + cmbTextureType.DrawMode = DrawMode.OwnerDrawFixed; + cmbTextureType.DropDownStyle = ComboBoxStyle.DropDownList; + cmbTextureType.FlatStyle = FlatStyle.Flat; + cmbTextureType.ForeColor = System.Drawing.Color.Gainsboro; + cmbTextureType.FormattingEnabled = true; + cmbTextureType.Location = new System.Drawing.Point(12, 41); + cmbTextureType.Margin = new Padding(4, 3, 4, 3); + cmbTextureType.Name = "cmbTextureType"; + cmbTextureType.Size = new Size(227, 24); + cmbTextureType.TabIndex = 21; + cmbTextureType.Text = null; + cmbTextureType.TextPadding = new Padding(2); + cmbTextureType.SelectedIndexChanged += cmbGraphicType_SelectedIndexChanged; + // + // lblTextureType + // + lblTextureType.AutoSize = true; + lblTextureType.Location = new System.Drawing.Point(9, 21); + lblTextureType.Margin = new Padding(4, 0, 4, 0); + lblTextureType.Name = "lblTextureType"; + lblTextureType.Size = new Size(73, 15); + lblTextureType.TabIndex = 20; + lblTextureType.Text = "Terture Type:"; + // + // lblStates + // + lblStates.AutoSize = true; + lblStates.Location = new System.Drawing.Point(10, 21); + lblStates.Margin = new Padding(4, 0, 4, 0); + lblStates.Name = "lblStates"; + lblStates.Size = new Size(41, 15); + lblStates.TabIndex = 55; + lblStates.Text = "States:"; + // + // graphicContainer + // + graphicContainer.AutoScroll = true; + graphicContainer.Controls.Add(picResource); + graphicContainer.Location = new System.Drawing.Point(270, 22); + graphicContainer.Margin = new Padding(4, 3, 4, 3); + graphicContainer.Name = "graphicContainer"; + graphicContainer.Size = new Size(540, 491); + graphicContainer.TabIndex = 24; + // + // picResource + // + picResource.Location = new System.Drawing.Point(0, 0); + picResource.Margin = new Padding(4, 3, 4, 3); + picResource.Name = "picResource"; + picResource.Size = new Size(540, 491); + picResource.TabIndex = 2; + picResource.TabStop = false; + picResource.MouseDown += picResource_MouseDown; + picResource.MouseMove += picResource_MouseMove; + picResource.MouseUp += picResource_MouseUp; // // tmrRender // tmrRender.Enabled = true; tmrRender.Interval = 10; - tmrRender.Tick += tmrRender_Tick; + tmrRender.Tick += Render; // // pnlContainer // pnlContainer.AutoScroll = true; pnlContainer.Controls.Add(grpRequirements); pnlContainer.Controls.Add(grpCommonEvent); - pnlContainer.Controls.Add(grpRegen); pnlContainer.Controls.Add(grpDrops); pnlContainer.Controls.Add(grpGeneral); pnlContainer.Controls.Add(grpGraphics); @@ -651,11 +792,11 @@ private void InitializeComponent() grpRequirements.Controls.Add(btnRequirements); grpRequirements.Controls.Add(txtCannotHarvest); grpRequirements.ForeColor = System.Drawing.Color.Gainsboro; - grpRequirements.Location = new System.Drawing.Point(539, 218); + grpRequirements.Location = new System.Drawing.Point(539, 0); grpRequirements.Margin = new Padding(2); grpRequirements.Name = "grpRequirements"; grpRequirements.Padding = new Padding(2); - grpRequirements.Size = new Size(285, 106); + grpRequirements.Size = new Size(285, 107); grpRequirements.TabIndex = 33; grpRequirements.TabStop = false; grpRequirements.Text = "Requirements"; @@ -689,7 +830,7 @@ private void InitializeComponent() grpCommonEvent.Controls.Add(cmbEvent); grpCommonEvent.Controls.Add(lblEvent); grpCommonEvent.ForeColor = System.Drawing.Color.Gainsboro; - grpCommonEvent.Location = new System.Drawing.Point(539, 134); + grpCommonEvent.Location = new System.Drawing.Point(539, 114); grpCommonEvent.Margin = new Padding(2); grpCommonEvent.Name = "grpCommonEvent"; grpCommonEvent.Padding = new Padding(2); @@ -711,10 +852,10 @@ private void InitializeComponent() cmbEvent.FlatStyle = FlatStyle.Flat; cmbEvent.ForeColor = System.Drawing.Color.Gainsboro; cmbEvent.FormattingEnabled = true; - cmbEvent.Location = new System.Drawing.Point(9, 40); + cmbEvent.Location = new System.Drawing.Point(9, 39); cmbEvent.Margin = new Padding(4, 3, 4, 3); cmbEvent.Name = "cmbEvent"; - cmbEvent.Size = new Size(227, 24); + cmbEvent.Size = new Size(262, 24); cmbEvent.TabIndex = 19; cmbEvent.Text = null; cmbEvent.TextPadding = new Padding(2); @@ -730,54 +871,6 @@ private void InitializeComponent() lblEvent.TabIndex = 18; lblEvent.Text = "Event:"; // - // grpRegen - // - grpRegen.BackColor = System.Drawing.Color.FromArgb(45, 45, 48); - grpRegen.BorderColor = System.Drawing.Color.FromArgb(90, 90, 90); - grpRegen.Controls.Add(nudHpRegen); - grpRegen.Controls.Add(lblHpRegen); - grpRegen.Controls.Add(lblRegenHint); - grpRegen.ForeColor = System.Drawing.Color.Gainsboro; - grpRegen.Location = new System.Drawing.Point(539, 2); - grpRegen.Margin = new Padding(2); - grpRegen.Name = "grpRegen"; - grpRegen.Padding = new Padding(2); - grpRegen.Size = new Size(285, 127); - grpRegen.TabIndex = 32; - grpRegen.TabStop = false; - grpRegen.Text = "Regen"; - // - // nudHpRegen - // - nudHpRegen.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); - nudHpRegen.ForeColor = System.Drawing.Color.Gainsboro; - nudHpRegen.Location = new System.Drawing.Point(9, 36); - nudHpRegen.Margin = new Padding(4, 3, 4, 3); - nudHpRegen.Name = "nudHpRegen"; - nudHpRegen.Size = new Size(100, 23); - nudHpRegen.TabIndex = 30; - nudHpRegen.Value = new decimal(new int[] { 0, 0, 0, 0 }); - nudHpRegen.ValueChanged += nudHpRegen_ValueChanged; - // - // lblHpRegen - // - lblHpRegen.AutoSize = true; - lblHpRegen.Location = new System.Drawing.Point(6, 20); - lblHpRegen.Margin = new Padding(2, 0, 2, 0); - lblHpRegen.Name = "lblHpRegen"; - lblHpRegen.Size = new Size(47, 15); - lblHpRegen.TabIndex = 26; - lblHpRegen.Text = "HP: (%)"; - // - // lblRegenHint - // - lblRegenHint.Location = new System.Drawing.Point(119, 32); - lblRegenHint.Margin = new Padding(4, 0, 4, 0); - lblRegenHint.Name = "lblRegenHint"; - lblRegenHint.Size = new Size(160, 83); - lblRegenHint.TabIndex = 0; - lblRegenHint.Text = "% of HP to restore per tick.\r\n\r\nTick timer saved in server config.json."; - // // grpDrops // grpDrops.BackColor = System.Drawing.Color.FromArgb(45, 45, 48); @@ -798,7 +891,7 @@ private void InitializeComponent() grpDrops.Margin = new Padding(4, 3, 4, 3); grpDrops.Name = "grpDrops"; grpDrops.Padding = new Padding(4, 3, 4, 3); - grpDrops.Size = new Size(264, 324); + grpDrops.Size = new Size(264, 380); grpDrops.TabIndex = 31; grpDrops.TabStop = false; grpDrops.Text = "Drops"; @@ -807,7 +900,7 @@ private void InitializeComponent() // nudDropMinAmount.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); nudDropMinAmount.ForeColor = System.Drawing.Color.Gainsboro; - nudDropMinAmount.Location = new System.Drawing.Point(10, 200); + nudDropMinAmount.Location = new System.Drawing.Point(10, 254); nudDropMinAmount.Margin = new Padding(4, 3, 4, 3); nudDropMinAmount.Maximum = new decimal(new int[] { 10000000, 0, 0, 0 }); nudDropMinAmount.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); @@ -820,7 +913,7 @@ private void InitializeComponent() // lblDropMinAmount // lblDropMinAmount.AutoSize = true; - lblDropMinAmount.Location = new System.Drawing.Point(10, 182); + lblDropMinAmount.Location = new System.Drawing.Point(10, 236); lblDropMinAmount.Margin = new Padding(4, 0, 4, 0); lblDropMinAmount.Name = "lblDropMinAmount"; lblDropMinAmount.Size = new Size(78, 15); @@ -829,7 +922,7 @@ private void InitializeComponent() // // btnDropRemove // - btnDropRemove.Location = new System.Drawing.Point(168, 287); + btnDropRemove.Location = new System.Drawing.Point(168, 342); btnDropRemove.Margin = new Padding(4, 3, 4, 3); btnDropRemove.Name = "btnDropRemove"; btnDropRemove.Padding = new Padding(6); @@ -840,7 +933,7 @@ private void InitializeComponent() // // btnDropAdd // - btnDropAdd.Location = new System.Drawing.Point(10, 287); + btnDropAdd.Location = new System.Drawing.Point(10, 342); btnDropAdd.Margin = new Padding(4, 3, 4, 3); btnDropAdd.Name = "btnDropAdd"; btnDropAdd.Padding = new Padding(6); @@ -859,7 +952,7 @@ private void InitializeComponent() lstDrops.Location = new System.Drawing.Point(10, 22); lstDrops.Margin = new Padding(4, 3, 4, 3); lstDrops.Name = "lstDrops"; - lstDrops.Size = new Size(246, 107); + lstDrops.Size = new Size(246, 152); lstDrops.TabIndex = 62; lstDrops.SelectedIndexChanged += lstDrops_SelectedIndexChanged; // @@ -867,7 +960,7 @@ private void InitializeComponent() // nudDropMaxAmount.BackColor = System.Drawing.Color.FromArgb(69, 73, 74); nudDropMaxAmount.ForeColor = System.Drawing.Color.Gainsboro; - nudDropMaxAmount.Location = new System.Drawing.Point(169, 200); + nudDropMaxAmount.Location = new System.Drawing.Point(169, 254); nudDropMaxAmount.Margin = new Padding(4, 3, 4, 3); nudDropMaxAmount.Maximum = new decimal(new int[] { 10000000, 0, 0, 0 }); nudDropMaxAmount.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); @@ -883,7 +976,7 @@ private void InitializeComponent() nudDropChance.DecimalPlaces = 2; nudDropChance.ForeColor = System.Drawing.Color.Gainsboro; nudDropChance.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); - nudDropChance.Location = new System.Drawing.Point(10, 253); + nudDropChance.Location = new System.Drawing.Point(10, 307); nudDropChance.Margin = new Padding(4, 3, 4, 3); nudDropChance.Name = "nudDropChance"; nudDropChance.Size = new Size(246, 23); @@ -904,7 +997,7 @@ private void InitializeComponent() cmbDropItem.FlatStyle = FlatStyle.Flat; cmbDropItem.ForeColor = System.Drawing.Color.Gainsboro; cmbDropItem.FormattingEnabled = true; - cmbDropItem.Location = new System.Drawing.Point(10, 153); + cmbDropItem.Location = new System.Drawing.Point(10, 205); cmbDropItem.Margin = new Padding(4, 3, 4, 3); cmbDropItem.Name = "cmbDropItem"; cmbDropItem.Size = new Size(246, 24); @@ -916,7 +1009,7 @@ private void InitializeComponent() // lblDropMaxAmount // lblDropMaxAmount.AutoSize = true; - lblDropMaxAmount.Location = new System.Drawing.Point(169, 182); + lblDropMaxAmount.Location = new System.Drawing.Point(169, 236); lblDropMaxAmount.Margin = new Padding(4, 0, 4, 0); lblDropMaxAmount.Name = "lblDropMaxAmount"; lblDropMaxAmount.Size = new Size(80, 15); @@ -926,7 +1019,7 @@ private void InitializeComponent() // lblDropChance // lblDropChance.AutoSize = true; - lblDropChance.Location = new System.Drawing.Point(10, 230); + lblDropChance.Location = new System.Drawing.Point(10, 284); lblDropChance.Margin = new Padding(4, 0, 4, 0); lblDropChance.Name = "lblDropChance"; lblDropChance.Size = new Size(71, 15); @@ -936,7 +1029,7 @@ private void InitializeComponent() // lblDropItem // lblDropItem.AutoSize = true; - lblDropItem.Location = new System.Drawing.Point(10, 134); + lblDropItem.Location = new System.Drawing.Point(10, 186); lblDropItem.Margin = new Padding(4, 0, 4, 0); lblDropItem.Name = "lblDropItem"; lblDropItem.Size = new Size(34, 15); @@ -1105,23 +1198,23 @@ private void InitializeComponent() grpResources.PerformLayout(); grpGeneral.ResumeLayout(false); grpGeneral.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)nudHpRegen).EndInit(); ((System.ComponentModel.ISupportInitialize)nudMaxHp).EndInit(); ((System.ComponentModel.ISupportInitialize)nudMinHp).EndInit(); ((System.ComponentModel.ISupportInitialize)nudSpawnDuration).EndInit(); grpGraphics.ResumeLayout(false); grpGraphics.PerformLayout(); - exhaustedGraphicContainer.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)picEndResource).EndInit(); - initalGraphicContainer.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)picInitialResource).EndInit(); + grpGraphicData.ResumeLayout(false); + grpGraphicData.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)nudStateRangeMax).EndInit(); + ((System.ComponentModel.ISupportInitialize)nudStateRangeMin).EndInit(); + graphicContainer.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)picResource).EndInit(); pnlContainer.ResumeLayout(false); grpRequirements.ResumeLayout(false); grpRequirements.PerformLayout(); grpCommonEvent.ResumeLayout(false); grpCommonEvent.PerformLayout(); - grpRegen.ResumeLayout(false); - grpRegen.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)nudHpRegen).EndInit(); grpDrops.ResumeLayout(false); grpDrops.PerformLayout(); ((System.ComponentModel.ISupportInitialize)nudDropMinAmount).EndInit(); @@ -1144,15 +1237,10 @@ private void InitializeComponent() private DarkCheckBox chkWalkableBefore; private DarkComboBox cmbToolType; private System.Windows.Forms.Label lblToolType; - private DarkComboBox cmbEndSprite; - private System.Windows.Forms.Label lblPic2; - private DarkComboBox cmbInitialSprite; - private System.Windows.Forms.Label lblPic; private System.Windows.Forms.Label lblSpawnDuration; - public System.Windows.Forms.PictureBox picEndResource; - public System.Windows.Forms.PictureBox picInitialResource; + public System.Windows.Forms.PictureBox picResource; private System.Windows.Forms.Label lblMaxHp; - private System.Windows.Forms.Label lblAnimation; + private System.Windows.Forms.Label lblDeathAnimation; private System.Windows.Forms.Timer tmrRender; private System.Windows.Forms.Panel pnlContainer; private DarkButton btnSave; @@ -1166,10 +1254,9 @@ private void InitializeComponent() public System.Windows.Forms.ToolStripButton toolStripItemPaste; private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; public System.Windows.Forms.ToolStripButton toolStripItemUndo; - private System.Windows.Forms.Panel exhaustedGraphicContainer; - private System.Windows.Forms.Panel initalGraphicContainer; + private System.Windows.Forms.Panel graphicContainer; private DarkButton btnRequirements; - private DarkComboBox cmbAnimation; + private DarkComboBox cmbDeathAnimation; private DarkNumericUpDown nudSpawnDuration; private DarkNumericUpDown nudMaxHp; private DarkNumericUpDown nudMinHp; @@ -1183,17 +1270,10 @@ private void InitializeComponent() private System.Windows.Forms.Label lblDropMaxAmount; private System.Windows.Forms.Label lblDropChance; private System.Windows.Forms.Label lblDropItem; - private DarkCheckBox chkExhaustedFromTileset; - private DarkCheckBox chkInitialFromTileset; - private DarkGroupBox grpRegen; private DarkNumericUpDown nudHpRegen; - private System.Windows.Forms.Label lblHpRegen; - private System.Windows.Forms.Label lblRegenHint; private DarkGroupBox grpCommonEvent; private DarkComboBox cmbEvent; private System.Windows.Forms.Label lblEvent; - private DarkCheckBox chkExhaustedBelowEntities; - private DarkCheckBox chkInitialBelowEntities; private DarkButton btnClearSearch; private DarkTextBox txtSearch; private DarkButton btnAddFolder; @@ -1207,5 +1287,24 @@ private void InitializeComponent() private DarkTextBox txtCannotHarvest; private DarkNumericUpDown nudDropMinAmount; private Label lblDropMinAmount; + private Label lblStates; + private DarkGroupBox grpGraphicData; + private DarkComboBox cmbTextureType; + private Label lblTextureType; + private DarkCheckBox chkRenderBelowEntity; + private DarkComboBox cmbAnimation; + private Label lblAnimation; + private DarkComboBox cmbTextureSource; + private Label lblTerxtureSource; + private ListBox lstStates; + private DarkButton btnRemoveState; + private DarkButton btnAddState; + private Label lblStateName; + private DarkTextBox txtStateName; + private Label lblStateRange; + private DarkNumericUpDown nudStateRangeMax; + private DarkNumericUpDown nudStateRangeMin; + private DarkCheckBox chkUseExplicitMaxHealthForResourceStates; + private Label lblHpRegen; } } \ No newline at end of file diff --git a/Intersect.Editor/Forms/Editors/frmResource.cs b/Intersect.Editor/Forms/Editors/frmResource.cs index 58c4ff5dd6..fc2f4912a7 100644 --- a/Intersect.Editor/Forms/Editors/frmResource.cs +++ b/Intersect.Editor/Forms/Editors/frmResource.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using DarkUI.Forms; using Intersect.Editor.Content; using Intersect.Editor.Core; @@ -7,10 +8,8 @@ using Intersect.Editor.Networking; using Intersect.Enums; using Intersect.Framework.Core.GameObjects.Animations; -using Intersect.Framework.Core.GameObjects.Events; using Intersect.Framework.Core.GameObjects.Items; using Intersect.Framework.Core.GameObjects.Resources; -using Intersect.GameObjects; using Intersect.Utilities; using EventDescriptor = Intersect.Framework.Core.GameObjects.Events.EventDescriptor; using Graphics = System.Drawing.Graphics; @@ -19,29 +18,16 @@ namespace Intersect.Editor.Forms.Editors; public partial class FrmResource : EditorForm { + private readonly List _knownFolders = []; + private readonly BindingList _dropList = []; + private readonly BindingList _stateList = []; + private readonly Dictionary _changed = []; - private List mChanged = []; - - private string mCopiedItem; - - private ResourceDescriptor mEditorItem; - - private Bitmap mEndBitmap; - - private Bitmap mEndGraphic; - - private Bitmap mInitialBitmap; - - private Bitmap mInitialGraphic; - - private List mKnownFolders = []; - - private bool mMouseDown; - - private BindingList _dropList = []; - - //General Editting Variables - bool mTMouseDown; + private string? _copiedItem; + private ResourceDescriptor? _editorItem; + private Bitmap? _graphicBitmap; + private Bitmap? _resourceGraphic; + private bool _mouseDown; public FrmResource() { @@ -60,31 +46,118 @@ public FrmResource() lstDrops.DataSource = _dropList; lstDrops.DisplayMember = nameof(NotifiableDrop.DisplayName); - - lstGameObjects.Init(UpdateToolStripItems, AssignEditorItem, toolStripItemNew_Click, toolStripItemCopy_Click, toolStripItemUndo_Click, toolStripItemPaste_Click, toolStripItemDelete_Click); + lstStates.DataSource = _stateList; + lstStates.DisplayMember = nameof(ResourceStateDescriptor.Name); + lstStates.ValueMember = nameof(ResourceStateDescriptor.Id); + + lstGameObjects.Init( + UpdateToolStripItems, + AssignEditorItem, + toolStripItemNew_Click, + toolStripItemCopy_Click, + toolStripItemUndo_Click, + toolStripItemPaste_Click, + toolStripItemDelete_Click + ); } + + #region Basic Editor Functions + private void AssignEditorItem(Guid id) { - mEditorItem = ResourceDescriptor.Get(id); + if (!ResourceDescriptor.TryGet(id, out _editorItem)) + { + _editorItem = null; + } + UpdateEditor(); } + private void toolStripItemNew_Click(object sender, EventArgs e) + { + PacketSender.SendCreateObject(GameObjectType.Resource); + } + + private void toolStripItemDelete_Click(object sender, EventArgs e) + { + if (_editorItem == null || !lstGameObjects.Focused) + { + return; + } + + if (DarkMessageBox.ShowWarning( + Strings.ResourceEditor.deleteprompt, + Strings.ResourceEditor.deletetitle, + DarkDialogButton.YesNo, + Icon + ) == + DialogResult.Yes) + { + PacketSender.SendDeleteObject(_editorItem); + } + } + + private void toolStripItemCopy_Click(object sender, EventArgs e) + { + if (_editorItem != null && lstGameObjects.Focused) + { + _copiedItem = _editorItem.JsonData; + toolStripItemPaste.Enabled = true; + } + } + + private void toolStripItemPaste_Click(object sender, EventArgs e) + { + if (_editorItem != null && _copiedItem != null && lstGameObjects.Focused) + { + _editorItem.Load(_copiedItem, true); + UpdateEditor(); + } + } + + private void toolStripItemUndo_Click(object sender, EventArgs e) + { + if (_editorItem == null || !_changed.ContainsKey(_editorItem.Id)) + { + return; + } + + if (DarkMessageBox.ShowWarning( + Strings.ResourceEditor.undoprompt, Strings.ResourceEditor.undotitle, DarkDialogButton.YesNo, + Icon + ) == + DialogResult.Yes) + { + _editorItem.RestoreBackup(); + UpdateEditor(); + } + } + + private void UpdateToolStripItems() + { + var shouldEnableToolStripItems = _editorItem != null && lstGameObjects.Focused; + toolStripItemCopy.Enabled = shouldEnableToolStripItems; + toolStripItemPaste.Enabled = shouldEnableToolStripItems && _copiedItem != null; + toolStripItemDelete.Enabled = shouldEnableToolStripItems; + toolStripItemUndo.Enabled = shouldEnableToolStripItems; + } + protected override void GameObjectUpdatedDelegate(GameObjectType type) { if (type == GameObjectType.Resource) { InitEditor(); - if (mEditorItem != null && !ResourceDescriptor.Lookup.Values.Contains(mEditorItem)) + if (_editorItem != null && !ResourceDescriptor.Lookup.Values.Contains(_editorItem)) { - mEditorItem = null; + _editorItem = null; UpdateEditor(); } } } - private void btnCancel_Click(object sender, EventArgs e) + private void btnCancel_Click(object? sender, EventArgs? e) { - foreach (var item in mChanged) + foreach (var item in _changed.Values) { item.RestoreBackup(); item.DeleteBackup(); @@ -98,7 +171,7 @@ private void btnCancel_Click(object sender, EventArgs e) private void btnSave_Click(object sender, EventArgs e) { //Send Changed items - foreach (var item in mChanged) + foreach (var item in _changed.Values) { PacketSender.SendSaveObject(item); item.DeleteBackup(); @@ -109,14 +182,17 @@ private void btnSave_Click(object sender, EventArgs e) Dispose(); } + #endregion + + #region Form Events + private void frmResource_Load(object sender, EventArgs e) { - mInitialBitmap = new Bitmap(picInitialResource.Width, picInitialResource.Height); - mEndBitmap = new Bitmap(picInitialResource.Width, picInitialResource.Height); + _graphicBitmap = new Bitmap(picResource.Width, picResource.Height); - cmbAnimation.Items.Clear(); - cmbAnimation.Items.Add(Strings.General.None); - cmbAnimation.Items.AddRange(AnimationDescriptor.Names); + cmbDeathAnimation.Items.Clear(); + cmbDeathAnimation.Items.Add(Strings.General.None); + cmbDeathAnimation.Items.AddRange(AnimationDescriptor.Names); cmbDropItem.Items.Clear(); cmbDropItem.Items.Add(Strings.General.None); cmbDropItem.Items.AddRange(ItemDescriptor.Names); @@ -124,65 +200,22 @@ private void frmResource_Load(object sender, EventArgs e) UpdateEditor(); } - private void PopulateInitialGraphicList() + private void frmResource_FormClosed(object sender, FormClosedEventArgs e) { - cmbInitialSprite.Items.Clear(); - cmbInitialSprite.Items.Add(Strings.General.None); - var resources = GameContentManager.GetSmartSortedTextureNames(GameContentManager.TextureType.Resource); - if (mEditorItem.Initial.GraphicFromTileset) - { - resources = GameContentManager.GetSmartSortedTextureNames(GameContentManager.TextureType.Tileset); - } - - for (var i = 0; i < resources.Length; i++) - { - cmbInitialSprite.Items.Add(resources[i]); - } - - if (mEditorItem != null) - { - if (mEditorItem.Initial.Graphic != null && cmbInitialSprite.Items.Contains(mEditorItem.Initial.Graphic)) - { - cmbInitialSprite.SelectedIndex = cmbInitialSprite.FindString( - TextUtils.NullToNone(TextUtils.NullToNone(mEditorItem.Initial.Graphic)) - ); - - return; - } - } - - cmbInitialSprite.SelectedIndex = 0; + btnCancel_Click(null, null); } - private void PopulateExhaustedGraphicList() + private void form_KeyDown(object sender, KeyEventArgs e) { - cmbEndSprite.Items.Clear(); - cmbEndSprite.Items.Add(Strings.General.None); - var resources = GameContentManager.GetSmartSortedTextureNames(GameContentManager.TextureType.Resource); - if (mEditorItem.Exhausted.GraphicFromTileset) - { - resources = GameContentManager.GetSmartSortedTextureNames(GameContentManager.TextureType.Tileset); - } - - for (var i = 0; i < resources.Length; i++) + if (e.Control && e.KeyCode == Keys.N) { - cmbEndSprite.Items.Add(resources[i]); + toolStripItemNew_Click(null, null); } + } - if (mEditorItem != null) - { - if (mEditorItem.Exhausted.Graphic != null && cmbEndSprite.Items.Contains(mEditorItem.Exhausted.Graphic)) - { - cmbEndSprite.SelectedIndex = cmbEndSprite.FindString( - TextUtils.NullToNone(TextUtils.NullToNone(mEditorItem.Exhausted.Graphic)) - ); - - return; - } - } + #endregion - cmbEndSprite.SelectedIndex = 0; - } + #region Intersect Setup private void InitLocalization() { @@ -201,9 +234,10 @@ private void InitLocalization() lblHP.Text = Strings.ResourceEditor.minhp; lblMaxHp.Text = Strings.ResourceEditor.maxhp; lblSpawnDuration.Text = Strings.ResourceEditor.spawnduration; - lblAnimation.Text = Strings.ResourceEditor.animation; + lblDeathAnimation.Text = Strings.ResourceEditor.DeathAnimation; chkWalkableBefore.Text = Strings.ResourceEditor.walkablebefore; chkWalkableAfter.Text = Strings.ResourceEditor.walkableafter; + chkUseExplicitMaxHealthForResourceStates.Text = Strings.ResourceEditor.UseExplicitMaxHealthForResourceStates; grpDrops.Text = Strings.ResourceEditor.drops; lblDropItem.Text = Strings.ResourceEditor.dropitem; @@ -213,18 +247,21 @@ private void InitLocalization() btnDropAdd.Text = Strings.ResourceEditor.dropadd; btnDropRemove.Text = Strings.ResourceEditor.dropremove; - grpRegen.Text = Strings.ResourceEditor.regen; - lblHpRegen.Text = Strings.ResourceEditor.hpregen; - lblRegenHint.Text = Strings.ResourceEditor.regenhint; - - grpGraphics.Text = Strings.ResourceEditor.graphics; - lblPic.Text = Strings.ResourceEditor.initialgraphic; - lblPic2.Text = Strings.ResourceEditor.exhaustedgraphic; - - chkExhaustedBelowEntities.Text = Strings.ResourceEditor.belowentities; - chkInitialBelowEntities.Text = Strings.ResourceEditor.belowentities; - chkInitialFromTileset.Text = Strings.ResourceEditor.fromtileset; - chkExhaustedFromTileset.Text = Strings.ResourceEditor.fromtileset; + lblHpRegen.Text = Strings.ResourceEditor.HealthRegenPercent; + new ToolTip().SetToolTip(lblHpRegen, Strings.ResourceEditor.regenhint); + + grpGraphics.Text = Strings.ResourceEditor.Appearance; + lblStates.Text = Strings.ResourceEditor.StatesLabel; + lblStateName.Text = Strings.ResourceEditor.StateName; + btnAddState.Text = Strings.ResourceEditor.AddState; + btnRemoveState.Text = Strings.ResourceEditor.RemoveState; + grpGraphicData.Text = Strings.ResourceEditor.StateProperties; + lblTextureType.Text = Strings.ResourceEditor.TextureSource; + cmbTextureType.Items.Clear(); + cmbTextureType.Items.AddRange([.. Strings.ResourceEditor.TextureSources.Values]); + chkRenderBelowEntity.Text = Strings.ResourceEditor.BelowEntities; + lblTerxtureSource.Text = Strings.ResourceEditor.TextureName; + lblAnimation.Text = Strings.ResourceEditor.Animation; grpCommonEvent.Text = Strings.ResourceEditor.commonevent; lblEvent.Text = Strings.ResourceEditor.harvestevent; @@ -244,36 +281,53 @@ private void InitLocalization() private void UpdateEditor() { - if (mEditorItem != null) + if (_editorItem != null) { pnlContainer.Show(); - txtName.Text = mEditorItem.Name; - cmbFolder.Text = mEditorItem.Folder; - cmbToolType.SelectedIndex = mEditorItem.Tool + 1; - nudSpawnDuration.Value = mEditorItem.SpawnDuration; - cmbAnimation.SelectedIndex = AnimationDescriptor.ListIndex(mEditorItem.AnimationId) + 1; - nudMinHp.Value = mEditorItem.MinHp; - nudMaxHp.Value = mEditorItem.MaxHp; - chkWalkableBefore.Checked = mEditorItem.WalkableBefore; - chkWalkableAfter.Checked = mEditorItem.WalkableAfter; - chkInitialFromTileset.Checked = mEditorItem.Initial.GraphicFromTileset; - chkExhaustedFromTileset.Checked = mEditorItem.Exhausted.GraphicFromTileset; - cmbEvent.SelectedIndex = EventDescriptor.ListIndex(mEditorItem.EventId) + 1; - chkInitialBelowEntities.Checked = mEditorItem.Initial.RenderBelowEntities; - chkExhaustedBelowEntities.Checked = mEditorItem.Exhausted.RenderBelowEntities; - txtCannotHarvest.Text = mEditorItem.CannotHarvestMessage; - - //Regen - nudHpRegen.Value = mEditorItem.VitalRegen; - PopulateInitialGraphicList(); - PopulateExhaustedGraphicList(); + txtName.Text = _editorItem.Name; + cmbFolder.Text = _editorItem.Folder; + cmbToolType.SelectedIndex = _editorItem.Tool + 1; + nudSpawnDuration.Value = _editorItem.SpawnDuration; + cmbDeathAnimation.SelectedIndex = AnimationDescriptor.ListIndex(_editorItem.DeathAnimationId) + 1; + nudMinHp.Value = _editorItem.MinHp; + nudMaxHp.Value = _editorItem.MaxHp; + chkWalkableBefore.Checked = _editorItem.WalkableBefore; + chkWalkableAfter.Checked = _editorItem.WalkableAfter; + chkUseExplicitMaxHealthForResourceStates.Checked = _editorItem.UseExplicitMaxHealthForResourceStates; + cmbEvent.SelectedIndex = EventDescriptor.ListIndex(_editorItem.EventId) + 1; + txtCannotHarvest.Text = _editorItem.CannotHarvestMessage; + nudHpRegen.Value = _editorItem.VitalRegen; + picResource.Hide(); + + _stateList.Clear(); + foreach (var state in _editorItem.States.Values) + { + _stateList.Add(state); + } + + if (lstStates.Items.Count > 0) + { + UpdateStateControls(); + } + else + { + txtStateName.Text = string.Empty; + cmbTextureType.SelectedIndex = (int)ResourceTextureSource.Resource; + chkRenderBelowEntity.Checked = false; + cmbTextureSource.Items.Clear(); + cmbAnimation.Items.Clear(); + nudStateRangeMin.Value = 0; + nudStateRangeMax.Value = 0; + picResource.Hide(); + } + UpdateDropValues(); - Render(); - if (mChanged.IndexOf(mEditorItem) == -1) + + if (!_changed.TryGetValue(_editorItem.Id, out var _)) { - mChanged.Add(mEditorItem); - mEditorItem.MakeBackup(); + _changed.Add(_editorItem.Id, _editorItem); + _editorItem.MakeBackup(); } } else @@ -281,16 +335,50 @@ private void UpdateEditor() pnlContainer.Hide(); } - var hasItem = mEditorItem != null; - - UpdateEditorButtons(hasItem); + UpdateEditorButtons(_editorItem != default); UpdateToolStripItems(); } + #endregion + + #region Helpers + + private bool TryGetCurrentState([NotNullWhen(true)] out ResourceStateDescriptor? state) + { + state = null; + + if (_editorItem is null) + { + return false; + } + + if (lstStates.SelectedIndex < 0) + { + return false; + } + + if (lstStates.SelectedValue is not Guid selectedId) + { + return false; + } + + if (!_editorItem.States.TryGetValue(selectedId, out state)) + { + return false; + } + + return true; + } + private void UpdateDropValues() { + if (_editorItem is null) + { + return; + } + _dropList.Clear(); - foreach (var drop in mEditorItem.Drops) + foreach (var drop in _editorItem.Drops) { _dropList.Add(new NotifiableDrop { @@ -302,151 +390,141 @@ private void UpdateDropValues() } } - private void nudSpawnDuration_ValueChanged(object sender, EventArgs e) + private void OrderStates() { - mEditorItem.SpawnDuration = (int) nudSpawnDuration.Value; - } - - private void cmbToolType_SelectedIndexChanged(object sender, EventArgs e) - { - mEditorItem.Tool = cmbToolType.SelectedIndex - 1; - } + if (_editorItem is null) + { + return; + } - private void chkWalkableBefore_CheckedChanged(object sender, EventArgs e) - { - mEditorItem.WalkableBefore = chkWalkableBefore.Checked; - } + _editorItem.States = _editorItem.States + .OrderBy(s => s.Value.MinimumHealth) + .ThenBy(s => s.Value.MaximumHealth) + .ToDictionary(p => p.Key, p => p.Value); - private void chkWalkableAfter_CheckedChanged(object sender, EventArgs e) - { - mEditorItem.WalkableAfter = chkWalkableAfter.Checked; - } + var selectedItem = (Guid?)lstStates.SelectedValue; - private void cmbInitialSprite_SelectedIndexChanged(object sender, EventArgs e) - { - mInitialGraphic?.Dispose(); - mInitialGraphic = null; - if (cmbInitialSprite.SelectedIndex > 0) + _stateList.Clear(); + foreach (var state in _editorItem.States.Values) { - mEditorItem.Initial.Graphic = cmbInitialSprite.Text; - var graphic = Path.Combine( - "resources", mEditorItem.Initial.GraphicFromTileset ? "tilesets" : "resources", - cmbInitialSprite.Text - ); + _stateList.Add(state); + } - if (File.Exists(graphic)) - { - mInitialGraphic = (Bitmap) Image.FromFile(graphic); - picInitialResource.Width = mInitialGraphic.Width; - picInitialResource.Height = mInitialGraphic.Height; - mInitialBitmap = new Bitmap(picInitialResource.Width, picInitialResource.Height); - } + if (selectedItem.HasValue && (Guid?)lstStates.SelectedValue != selectedItem) + { + lstStates.SelectedValue = selectedItem.Value; } - else + } + + private void UpdateStateControls() + { + if (!TryGetCurrentState(out var currentState)) { - mEditorItem.Initial.Graphic = null; + return; } - picInitialResource.Visible = mInitialGraphic != null; - Render(); + cmbTextureType.SelectedIndex = (int)currentState.TextureType; + chkRenderBelowEntity.Checked = currentState.RenderBelowEntities; + nudStateRangeMin.Value = currentState.MinimumHealth; + nudStateRangeMax.Value = currentState.MaximumHealth; + UpdateGraphicFileControl(currentState); } - private void cmbEndSprite_SelectedIndexChanged(object sender, EventArgs e) + private void UpdateGraphicFileControl(ResourceStateDescriptor currentState) { - mEndGraphic?.Dispose(); - mEndGraphic = null; - if (cmbEndSprite.SelectedIndex > 0) + cmbTextureSource.Items.Clear(); + cmbTextureSource.Items.Add(Strings.General.None); + cmbAnimation.Items.Clear(); + cmbAnimation.Items.Add(Strings.General.None); + + if (currentState.TextureType == ResourceTextureSource.Animation) { - mEditorItem.Exhausted.Graphic = cmbEndSprite.Text; - var graphic = Path.Combine( - "resources", mEditorItem.Exhausted.GraphicFromTileset ? "tilesets" : "resources", cmbEndSprite.Text - ); + cmbTextureSource.Enabled = false; + picResource.Visible = false; + cmbAnimation.Enabled = true; + cmbAnimation.Items.AddRange(AnimationDescriptor.Names); + cmbAnimation.SelectedIndex = AnimationDescriptor.ListIndex(currentState.AnimationId) + 1; + return; + } - if (File.Exists(graphic)) - { - mEndGraphic = (Bitmap) Image.FromFile(graphic); - picEndResource.Width = mEndGraphic.Width; - picEndResource.Height = mEndGraphic.Height; - mEndBitmap = new Bitmap(picEndResource.Width, picEndResource.Height); - } + cmbTextureSource.Enabled = true; + picResource.Visible = true; + cmbAnimation.Enabled = false; + + var resources = GameContentManager.GetSmartSortedTextureNames( + currentState.TextureType == ResourceTextureSource.Tileset + ? GameContentManager.TextureType.Tileset + : GameContentManager.TextureType.Resource + ); + + cmbTextureSource.Items.AddRange(resources); + + if (_editorItem is null) + { + return; } - else + + if (currentState.TextureName != null && cmbTextureSource.Items.Contains(currentState.TextureName)) { - mEditorItem.Exhausted.Graphic = null; + cmbTextureSource.SelectedIndex = cmbTextureSource.FindString(TextUtils.NullToNone(currentState.TextureName)); + return; } - picEndResource.Visible = mEndGraphic != null; - Render(); + cmbTextureSource.SelectedIndex = 0; } - public void Render() + private void Render(object sender, EventArgs e) { - if (mEditorItem == null) + if (_editorItem is null) { return; } - // Initial Sprite - var gfx = Graphics.FromImage(mInitialBitmap); - gfx.FillRectangle(Brushes.Black, new Rectangle(0, 0, picInitialResource.Width, picInitialResource.Height)); - if (cmbInitialSprite.SelectedIndex > 0 && mInitialGraphic != null) + if (_graphicBitmap is null) { - gfx.DrawImage( - mInitialGraphic, new Rectangle(0, 0, mInitialGraphic.Width, mInitialGraphic.Height), - new Rectangle(0, 0, mInitialGraphic.Width, mInitialGraphic.Height), GraphicsUnit.Pixel - ); + return; } - if (mEditorItem.Initial.GraphicFromTileset) + if (_resourceGraphic is null) { - var selX = mEditorItem.Initial.X; - var selY = mEditorItem.Initial.Y; - var selW = mEditorItem.Initial.Width; - var selH = mEditorItem.Initial.Height; - if (selW < 0) - { - selX -= Math.Abs(selW); - selW = Math.Abs(selW); - } + return; + } - if (selH < 0) - { - selY -= Math.Abs(selH); - selH = Math.Abs(selH); - } + if (!TryGetCurrentState(out var currentState)) + { + return; + } - gfx.DrawRectangle( - new Pen(System.Drawing.Color.White, 2f), - new Rectangle( - selX * Options.Instance.Map.TileWidth, selY * Options.Instance.Map.TileHeight, - Options.Instance.Map.TileWidth + selW * Options.Instance.Map.TileWidth, Options.Instance.Map.TileHeight + selH * Options.Instance.Map.TileHeight - ) - ); + if (currentState.TextureName is null) + { + return; } - gfx.Dispose(); - gfx = picInitialResource.CreateGraphics(); - gfx.DrawImageUnscaled(mInitialBitmap, new System.Drawing.Point(0, 0)); + if (currentState.TextureType == ResourceTextureSource.Animation) + { + return; + } - gfx.Dispose(); + var gfx = Graphics.FromImage(_graphicBitmap); + gfx.FillRectangle(Brushes.Black, new Rectangle(0, 0, picResource.Width, picResource.Height)); - // End Sprite - gfx = Graphics.FromImage(mEndBitmap); - gfx.FillRectangle(Brushes.Black, new Rectangle(0, 0, picEndResource.Width, picEndResource.Height)); - if (cmbEndSprite.SelectedIndex > 0 && mEndGraphic != null) + if (cmbTextureSource.SelectedIndex > 0 && cmbTextureSource.SelectedIndex > 0) { gfx.DrawImage( - mEndGraphic, new Rectangle(0, 0, mEndGraphic.Width, mEndGraphic.Height), - new Rectangle(0, 0, mEndGraphic.Width, mEndGraphic.Height), GraphicsUnit.Pixel + _resourceGraphic, + new Rectangle(0, 0, _resourceGraphic.Width, _resourceGraphic.Height), + new Rectangle(0, 0, _resourceGraphic.Width, _resourceGraphic.Height), + GraphicsUnit.Pixel ); } - if (mEditorItem.Exhausted.GraphicFromTileset) + if (currentState.TextureType == ResourceTextureSource.Tileset) { - var selX = mEditorItem.Exhausted.X; - var selY = mEditorItem.Exhausted.Y; - var selW = mEditorItem.Exhausted.Width; - var selH = mEditorItem.Exhausted.Height; + var selX = currentState.X; + var selY = currentState.Y; + var selW = currentState.Width; + var selH = currentState.Height; + if (selW < 0) { selX -= Math.Abs(selW); @@ -459,192 +537,207 @@ public void Render() selH = Math.Abs(selH); } + var tileWidth = Options.Instance.Map.TileWidth; + var tileHeight = Options.Instance.Map.TileHeight; + gfx.DrawRectangle( new Pen(System.Drawing.Color.White, 2f), new Rectangle( - selX * Options.Instance.Map.TileWidth, selY * Options.Instance.Map.TileHeight, - Options.Instance.Map.TileWidth + selW * Options.Instance.Map.TileWidth, Options.Instance.Map.TileHeight + selH * Options.Instance.Map.TileHeight + selX * tileWidth, + selY * tileHeight, + tileWidth + selW * tileWidth, + tileHeight + selH * tileHeight ) ); } gfx.Dispose(); - gfx = picEndResource.CreateGraphics(); - gfx.DrawImageUnscaled(mEndBitmap, new System.Drawing.Point(0, 0)); + gfx = picResource.CreateGraphics(); + gfx.DrawImageUnscaled(_graphicBitmap, new System.Drawing.Point(0, 0)); gfx.Dispose(); } + #endregion + + #region Form Events + private void txtName_TextChanged(object sender, EventArgs e) { - mEditorItem.Name = txtName.Text; - lstGameObjects.UpdateText(txtName.Text); - } + if (_editorItem is null) + { + return; + } - private void frmResource_FormClosed(object sender, FormClosedEventArgs e) - { - btnCancel_Click(null, null); + _editorItem.Name = txtName.Text; + lstGameObjects.UpdateText(txtName.Text); } - private void tmrRender_Tick(object sender, EventArgs e) + private void cmbToolType_SelectedIndexChanged(object sender, EventArgs e) { - Render(); - } + if (_editorItem is null) + { + return; + } - private void toolStripItemNew_Click(object sender, EventArgs e) - { - PacketSender.SendCreateObject(GameObjectType.Resource); + _editorItem.Tool = cmbToolType.SelectedIndex - 1; } - private void toolStripItemDelete_Click(object sender, EventArgs e) + private void nudMinHp_ValueChanged(object sender, EventArgs e) { - if (mEditorItem != null && lstGameObjects.Focused) + if (_editorItem is null) { - if (DarkMessageBox.ShowWarning( - Strings.ResourceEditor.deleteprompt, Strings.ResourceEditor.deletetitle, DarkDialogButton.YesNo, - Icon - ) == - DialogResult.Yes) - { - PacketSender.SendDeleteObject(mEditorItem); - } + return; } + + _editorItem.MinHp = (int)nudMinHp.Value; } - private void toolStripItemCopy_Click(object sender, EventArgs e) + private void nudMaxHp_ValueChanged(object sender, EventArgs e) { - if (mEditorItem != null && lstGameObjects.Focused) + if (_editorItem is null) { - mCopiedItem = mEditorItem.JsonData; - toolStripItemPaste.Enabled = true; + return; } + + _editorItem.MaxHp = (int)nudMaxHp.Value; } - private void toolStripItemPaste_Click(object sender, EventArgs e) + private void nudSpawnDuration_ValueChanged(object sender, EventArgs e) { - if (mEditorItem != null && mCopiedItem != null && lstGameObjects.Focused) + if (_editorItem is null) { - mEditorItem.Load(mCopiedItem, true); - UpdateEditor(); + return; } + + _editorItem.SpawnDuration = (int)nudSpawnDuration.Value; } - private void toolStripItemUndo_Click(object sender, EventArgs e) + private void cmbDeathAnimation_SelectedIndexChanged(object sender, EventArgs e) { - if (mChanged.Contains(mEditorItem) && mEditorItem != null) + if (_editorItem is null) { - if (DarkMessageBox.ShowWarning( - Strings.ResourceEditor.undoprompt, Strings.ResourceEditor.undotitle, DarkDialogButton.YesNo, - Icon - ) == - DialogResult.Yes) - { - mEditorItem.RestoreBackup(); - UpdateEditor(); - } + return; } - } - private void UpdateToolStripItems() - { - toolStripItemCopy.Enabled = mEditorItem != null && lstGameObjects.Focused; - toolStripItemPaste.Enabled = mEditorItem != null && mCopiedItem != null && lstGameObjects.Focused; - toolStripItemDelete.Enabled = mEditorItem != null && lstGameObjects.Focused; - toolStripItemUndo.Enabled = mEditorItem != null && lstGameObjects.Focused; + _editorItem.DeathAnimation = AnimationDescriptor.Get(AnimationDescriptor.IdFromList(cmbDeathAnimation.SelectedIndex - 1)); } - private void form_KeyDown(object sender, KeyEventArgs e) + private void chkWalkableBefore_CheckedChanged(object sender, EventArgs e) { - if (e.Control) + if (_editorItem is null) { - if (e.KeyCode == Keys.N) - { - toolStripItemNew_Click(null, null); - } + return; } - } - private void btnRequirements_Click(object sender, EventArgs e) - { - var frm = new FrmDynamicRequirements(mEditorItem.HarvestingRequirements, RequirementType.Resource); - frm.ShowDialog(); + _editorItem.WalkableBefore = chkWalkableBefore.Checked; } - private void cmbAnimation_SelectedIndexChanged(object sender, EventArgs e) + private void chkWalkableAfter_CheckedChanged(object sender, EventArgs e) { - mEditorItem.Animation = AnimationDescriptor.Get(AnimationDescriptor.IdFromList(cmbAnimation.SelectedIndex - 1)); - } + if (_editorItem is null) + { + return; + } - private void nudMinHp_ValueChanged(object sender, EventArgs e) - { - mEditorItem.MinHp = (int) nudMinHp.Value; + _editorItem.WalkableAfter = chkWalkableAfter.Checked; } - private void nudMaxHp_ValueChanged(object sender, EventArgs e) + private void chkUseExplicitMaxHealthForResourceStates_CheckedChanged(object sender, EventArgs e) { - mEditorItem.MaxHp = (int) nudMaxHp.Value; + if (_editorItem is null) + { + return; + } + + _editorItem.UseExplicitMaxHealthForResourceStates = chkUseExplicitMaxHealthForResourceStates.Checked; } private void lstDrops_SelectedIndexChanged(object sender, EventArgs e) { if (lstDrops.SelectedIndex > -1) { - cmbDropItem.SelectedIndex = ItemDescriptor.ListIndex(mEditorItem.Drops[lstDrops.SelectedIndex].ItemId) + 1; - nudDropMaxAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].MaxQuantity; - nudDropMinAmount.Value = mEditorItem.Drops[lstDrops.SelectedIndex].MinQuantity; - nudDropChance.Value = (decimal)mEditorItem.Drops[lstDrops.SelectedIndex].Chance; + cmbDropItem.SelectedIndex = ItemDescriptor.ListIndex(_editorItem.Drops[lstDrops.SelectedIndex].ItemId) + 1; + nudDropMaxAmount.Value = _editorItem.Drops[lstDrops.SelectedIndex].MaxQuantity; + nudDropMinAmount.Value = _editorItem.Drops[lstDrops.SelectedIndex].MinQuantity; + nudDropChance.Value = (decimal)_editorItem.Drops[lstDrops.SelectedIndex].Chance; } } private void cmbDropItem_SelectedIndexChanged(object sender, EventArgs e) { + if (_editorItem is null) + { + return; + } + int index = lstDrops.SelectedIndex; if (index < 0 || index > lstDrops.Items.Count) { return; } - mEditorItem.Drops[index].ItemId = ItemDescriptor.IdFromList(cmbDropItem.SelectedIndex - 1); - _dropList[index].ItemId = mEditorItem.Drops[index].ItemId; + _editorItem.Drops[index].ItemId = ItemDescriptor.IdFromList(cmbDropItem.SelectedIndex - 1); + _dropList[index].ItemId = _editorItem.Drops[index].ItemId; } private void nudDropMaxAmount_ValueChanged(object sender, EventArgs e) { + if (_editorItem is null) + { + return; + } + int index = lstDrops.SelectedIndex; if (index < 0 || index > lstDrops.Items.Count) { return; } - mEditorItem.Drops[index].MaxQuantity = (int)nudDropMaxAmount.Value; - _dropList[index].MaxQuantity = mEditorItem.Drops[index].MaxQuantity; + _editorItem.Drops[index].MaxQuantity = (int)nudDropMaxAmount.Value; + _dropList[index].MaxQuantity = _editorItem.Drops[index].MaxQuantity; } private void nudDropMinAmount_ValueChanged(object sender, EventArgs e) { + if (_editorItem is null) + { + return; + } + int index = lstDrops.SelectedIndex; if (index < 0 || index > lstDrops.Items.Count) { return; } - mEditorItem.Drops[index].MinQuantity = (int)nudDropMinAmount.Value; - _dropList[index].MinQuantity = mEditorItem.Drops[index].MinQuantity; + _editorItem.Drops[index].MinQuantity = (int)nudDropMinAmount.Value; + _dropList[index].MinQuantity = _editorItem.Drops[index].MinQuantity; } private void nudDropChance_ValueChanged(object sender, EventArgs e) { + if (_editorItem is null) + { + return; + } + int index = lstDrops.SelectedIndex; if (index < 0 || index > lstDrops.Items.Count) { return; } - mEditorItem.Drops[index].Chance = (double)nudDropChance.Value; - _dropList[index].Chance = mEditorItem.Drops[index].Chance; + _editorItem.Drops[index].Chance = (double)nudDropChance.Value; + _dropList[index].Chance = _editorItem.Drops[index].Chance; } private void btnDropAdd_Click(object sender, EventArgs e) { + if (_editorItem is null) + { + return; + } + var drop = new Drop() { ItemId = ItemDescriptor.IdFromList(cmbDropItem.SelectedIndex - 1), @@ -653,7 +746,7 @@ private void btnDropAdd_Click(object sender, EventArgs e) Chance = (double)nudDropChance.Value }; - mEditorItem.Drops.Add(drop); + _editorItem.Drops.Add(drop); _dropList.Add(new NotifiableDrop { @@ -668,163 +761,287 @@ private void btnDropAdd_Click(object sender, EventArgs e) private void btnDropRemove_Click(object sender, EventArgs e) { + if (_editorItem is null) + { + return; + } + if (lstDrops.SelectedIndex < 0) { return; } var index = lstDrops.SelectedIndex; - mEditorItem.Drops.RemoveAt(index); + _editorItem.Drops.RemoveAt(index); _dropList.RemoveAt(index); } - private void chkInitialFromTileset_CheckedChanged(object sender, EventArgs e) + private void nudHpRegen_ValueChanged(object sender, EventArgs e) + { + if (_editorItem is null) + { + return; + } + + _editorItem.VitalRegen = (int)nudHpRegen.Value; + } + + private void cmbEvent_SelectedIndexChanged(object sender, EventArgs e) + { + if (_editorItem is null) + { + return; + } + + _editorItem.Event = EventDescriptor.Get(EventDescriptor.IdFromList(cmbEvent.SelectedIndex - 1)); + } + + private void btnRequirements_Click(object sender, EventArgs e) + { + if (_editorItem is null) + { + return; + } + + var frm = new FrmDynamicRequirements(_editorItem.HarvestingRequirements, RequirementType.Resource); + frm.ShowDialog(); + } + + private void txtCannotHarvest_TextChanged(object sender, EventArgs e) { - mEditorItem.Initial.GraphicFromTileset = chkInitialFromTileset.Checked; - PopulateInitialGraphicList(); + if (_editorItem is null) + { + return; + } + + _editorItem.CannotHarvestMessage = txtCannotHarvest.Text; } - private void chkExhaustedFromTileset_CheckedChanged(object sender, EventArgs e) + private void lstStates_SelectedIndexChanged(object sender, EventArgs e) { - mEditorItem.Exhausted.GraphicFromTileset = chkExhaustedFromTileset.Checked; - PopulateExhaustedGraphicList(); + if (_editorItem is null) + { + return; + } + + if (lstStates.SelectedIndex < 0) + { + return; + } + + UpdateStateControls(); } - private void picInitialResource_MouseDown(object sender, MouseEventArgs e) + private void btnAddState_Click(object sender, EventArgs e) { - if (e.X > picInitialResource.Width || e.Y > picInitialResource.Height) + //alert if name is less than 3 characters + if (txtStateName.Text.Length <= 0) { + DarkMessageBox.ShowError( + Strings.ResourceEditor.StateNameError, + Strings.ResourceEditor.StateErrorTitle + ); return; } - if (!chkInitialFromTileset.Checked) + if (_editorItem is null) { return; } - mMouseDown = true; - mEditorItem.Initial.X = (int) Math.Floor((double) e.X / Options.Instance.Map.TileWidth); - mEditorItem.Initial.Y = (int) Math.Floor((double) e.Y / Options.Instance.Map.TileHeight); - mEditorItem.Initial.Width = 0; - mEditorItem.Initial.Height = 0; - if (mEditorItem.Initial.X < 0) + var state = new ResourceStateDescriptor + { + Id = Guid.NewGuid(), + Name = txtStateName.Text, + }; + + _editorItem.States.Add(state.Id, state); + _stateList.Add(state); + OrderStates(); + lstStates.SelectedIndex = lstStates.Items.IndexOf(state.Name); + txtStateName.Text = string.Empty; + } + + private void btnRemoveState_Click(object sender, EventArgs e) + { + if (_editorItem is null) { - mEditorItem.Initial.X = 0; + return; } - if (mEditorItem.Initial.Y < 0) + var selectedIndex = lstStates.SelectedIndex; + if (selectedIndex < 0) { - mEditorItem.Initial.Y = 0; + return; } - Render(); + var stateKey = _editorItem.States.Keys.ToList()[selectedIndex]; + if (!_editorItem.States.TryGetValue(stateKey, out _)) + { + return; + } + + _editorItem.States.Remove(stateKey); + _stateList.RemoveAt(selectedIndex); + OrderStates(); + if (lstStates.Items.Count > 0) + { + lstStates.SelectedIndex = 0; + } } - private void picInitialResource_MouseUp(object sender, MouseEventArgs e) + private void cmbGraphicType_SelectedIndexChanged(object sender, EventArgs e) { - if (e.X > picInitialResource.Width || e.Y > picInitialResource.Height) + if (!TryGetCurrentState(out var currentState)) { return; } - if (!chkInitialFromTileset.Checked) + currentState.TextureType = (ResourceTextureSource)cmbTextureType.SelectedIndex; + UpdateGraphicFileControl(currentState); + } + + private void chkRenderBelowEntity_CheckedChanged(object sender, EventArgs e) + { + if (!TryGetCurrentState(out var currentState)) { return; } - var selX = mEditorItem.Initial.X; - var selY = mEditorItem.Initial.Y; - var selW = mEditorItem.Initial.Width; - var selH = mEditorItem.Initial.Height; - if (selW < 0) + currentState.RenderBelowEntities = chkRenderBelowEntity.Checked; + } + + private void cmbGraphicFile_SelectedIndexChanged(object sender, EventArgs e) + { + _resourceGraphic?.Dispose(); + _resourceGraphic = null; + + if (!TryGetCurrentState(out var currentState)) { - selX -= Math.Abs(selW); - selW = Math.Abs(selW); + return; } - if (selH < 0) + if (cmbTextureSource.SelectedIndex > 0) { - selY -= Math.Abs(selH); - selH = Math.Abs(selH); + currentState.TextureName = cmbTextureSource.Text; + var graphic = Path.Combine( + "resources", currentState.TextureType == ResourceTextureSource.Tileset ? "tilesets" : "resources", cmbTextureSource.Text + ); + + if (File.Exists(graphic)) + { + _resourceGraphic = (Bitmap)Image.FromFile(graphic); + picResource.Width = _resourceGraphic.Width; + picResource.Height = _resourceGraphic.Height; + _graphicBitmap = new Bitmap(picResource.Width, picResource.Height); + } + } + else + { + currentState.TextureName = null; } - mEditorItem.Initial.X = selX; - mEditorItem.Initial.Y = selY; - mEditorItem.Initial.Width = selW; - mEditorItem.Initial.Height = selH; - mMouseDown = false; - Render(); + picResource.Visible = _resourceGraphic != null; } - private void picInitialResource_MouseMove(object sender, MouseEventArgs e) + private void cmbAnimation_SelectedIndexChanged(object sender, EventArgs e) { - if (e.X > picInitialResource.Width || e.Y > picInitialResource.Height) + if (!TryGetCurrentState(out var currentState)) { return; } - if (!chkInitialFromTileset.Checked) + currentState.AnimationId = AnimationDescriptor.IdFromList(cmbAnimation.SelectedIndex - 1); + } + + private void nudStateRangeMin_ValueChanged(object sender, EventArgs e) + { + if (_editorItem is null) { return; } - if (mMouseDown) + if (!TryGetCurrentState(out var currentState)) { - var tmpX = (int) Math.Floor((double) e.X / Options.Instance.Map.TileWidth); - var tmpY = (int) Math.Floor((double) e.Y / Options.Instance.Map.TileHeight); - mEditorItem.Initial.Width = tmpX - mEditorItem.Initial.X; - mEditorItem.Initial.Height = tmpY - mEditorItem.Initial.Y; + return; } - Render(); + currentState.MinimumHealth = (int)nudStateRangeMin.Value; + OrderStates(); } - private void picExhustedResource_MouseDown(object sender, MouseEventArgs e) + private void nudStateRangeMax_ValueChanged(object sender, EventArgs e) { - if (e.X > picEndResource.Width || e.Y > picEndResource.Height) + if (_editorItem is null) { return; } - if (!chkExhaustedFromTileset.Checked) + if (!TryGetCurrentState(out var currentState)) { return; } - mMouseDown = true; - mEditorItem.Exhausted.X = (int) Math.Floor((double) e.X / Options.Instance.Map.TileWidth); - mEditorItem.Exhausted.Y = (int) Math.Floor((double) e.Y / Options.Instance.Map.TileHeight); - mEditorItem.Exhausted.Width = 0; - mEditorItem.Exhausted.Height = 0; - if (mEditorItem.Exhausted.X < 0) + currentState.MaximumHealth = (int)nudStateRangeMax.Value; + OrderStates(); + } + + private void picResource_MouseDown(object sender, MouseEventArgs e) + { + if (_editorItem is null) { - mEditorItem.Exhausted.X = 0; + return; } - if (mEditorItem.Exhausted.Y < 0) + if (e.X > picResource.Width || e.Y > picResource.Height) { - mEditorItem.Exhausted.Y = 0; + return; } - Render(); + if ((ResourceTextureSource)cmbTextureType.SelectedIndex != ResourceTextureSource.Tileset) + { + return; + } + + if (!TryGetCurrentState(out var currentState)) + { + return; + } + + _mouseDown = true; + currentState.X = Math.Max(0, (int)Math.Floor((double)e.X / Options.Instance.Map.TileWidth)); + currentState.Y = Math.Max(0, (int)Math.Floor((double)e.Y / Options.Instance.Map.TileHeight)); + currentState.Width = 0; + currentState.Height = 0; } - private void picExhaustedResource_MouseUp(object sender, MouseEventArgs e) + private void picResource_MouseUp(object sender, MouseEventArgs e) { - if (e.X > picEndResource.Width || e.Y > picEndResource.Height) + if (_editorItem is null) + { + return; + } + + if (e.X > picResource.Width || e.Y > picResource.Height) + { + return; + } + + if ((ResourceTextureSource)cmbTextureType.SelectedIndex != ResourceTextureSource.Tileset) { return; } - if (!chkExhaustedFromTileset.Checked) + if (!TryGetCurrentState(out var currentState)) { return; } - var selX = mEditorItem.Exhausted.X; - var selY = mEditorItem.Exhausted.Y; - var selW = mEditorItem.Exhausted.Width; - var selH = mEditorItem.Exhausted.Height; + var selX = currentState.X; + var selY = currentState.Y; + var selW = currentState.Width; + var selH = currentState.Height; + if (selW < 0) { selX -= Math.Abs(selW); @@ -837,61 +1054,45 @@ private void picExhaustedResource_MouseUp(object sender, MouseEventArgs e) selH = Math.Abs(selH); } - mEditorItem.Exhausted.X = selX; - mEditorItem.Exhausted.Y = selY; - mEditorItem.Exhausted.Width = selW; - mEditorItem.Exhausted.Height = selH; - mMouseDown = false; - Render(); + currentState.X = selX; + currentState.Y = selY; + currentState.Width = selW; + currentState.Height = selH; + _mouseDown = false; } - private void picExhaustedResource_MouseMove(object sender, MouseEventArgs e) + private void picResource_MouseMove(object sender, MouseEventArgs e) { - if (e.X > picEndResource.Width || e.Y > picEndResource.Height) + if (_editorItem is null) { return; } - if (!chkExhaustedFromTileset.Checked) + if (e.X > picResource.Width || e.Y > picResource.Height) { return; } - if (mMouseDown) + if ((ResourceTextureSource)cmbTextureType.SelectedIndex != ResourceTextureSource.Tileset) { - var tmpX = (int) Math.Floor((double) e.X / Options.Instance.Map.TileWidth); - var tmpY = (int) Math.Floor((double) e.Y / Options.Instance.Map.TileHeight); - mEditorItem.Exhausted.Width = tmpX - mEditorItem.Exhausted.X; - mEditorItem.Exhausted.Height = tmpY - mEditorItem.Exhausted.Y; + return; } - Render(); - } - - private void nudHpRegen_ValueChanged(object sender, EventArgs e) - { - mEditorItem.VitalRegen = (int) nudHpRegen.Value; - } - - private void cmbEvent_SelectedIndexChanged(object sender, EventArgs e) - { - mEditorItem.Event = EventDescriptor.Get(EventDescriptor.IdFromList(cmbEvent.SelectedIndex - 1)); - } - - private void chkInitialBelowEntities_CheckedChanged(object sender, EventArgs e) - { - mEditorItem.Initial.RenderBelowEntities = chkInitialBelowEntities.Checked; - } + if (!TryGetCurrentState(out var currentState)) + { + return; + } - private void chkExhaustedBelowEntities_CheckedChanged(object sender, EventArgs e) - { - mEditorItem.Exhausted.RenderBelowEntities = chkExhaustedBelowEntities.Checked; + if (_mouseDown) + { + var tmpX = Math.Max(0, (int)Math.Floor((double)e.X / Options.Instance.Map.TileWidth)); + var tmpY = Math.Max(0, (int)Math.Floor((double)e.Y / Options.Instance.Map.TileHeight)); + currentState.Width = tmpX - currentState.X; + currentState.Height = tmpY - currentState.Y; + } } - private void txtCannotHarvest_TextChanged(object sender, EventArgs e) - { - mEditorItem.CannotHarvestMessage = txtCannotHarvest.Text; - } + #endregion #region "Item List - Folders, Searching, Sorting, Etc" @@ -901,22 +1102,22 @@ public void InitEditor() var mFolders = new List(); foreach (var itm in ResourceDescriptor.Lookup) { - if (!string.IsNullOrEmpty(((ResourceDescriptor) itm.Value).Folder) && - !mFolders.Contains(((ResourceDescriptor) itm.Value).Folder)) + if (!string.IsNullOrEmpty(((ResourceDescriptor)itm.Value).Folder) && + !mFolders.Contains(((ResourceDescriptor)itm.Value).Folder)) { - mFolders.Add(((ResourceDescriptor) itm.Value).Folder); - if (!mKnownFolders.Contains(((ResourceDescriptor) itm.Value).Folder)) + mFolders.Add(((ResourceDescriptor)itm.Value).Folder); + if (!_knownFolders.Contains(((ResourceDescriptor)itm.Value).Folder)) { - mKnownFolders.Add(((ResourceDescriptor) itm.Value).Folder); + _knownFolders.Add(((ResourceDescriptor)itm.Value).Folder); } } } mFolders.Sort(); - mKnownFolders.Sort(); + _knownFolders.Sort(); cmbFolder.Items.Clear(); cmbFolder.Items.Add(""); - cmbFolder.Items.AddRange(mKnownFolders.ToArray()); + cmbFolder.Items.AddRange(_knownFolders.ToArray()); var items = ResourceDescriptor.Lookup.OrderBy(p => p.Value?.Name).Select(pair => new KeyValuePair>(pair.Key, new KeyValuePair(((ResourceDescriptor)pair.Value)?.Name ?? Models.DatabaseObject.Deleted, ((ResourceDescriptor)pair.Value)?.Folder ?? ""))).ToArray(); @@ -935,7 +1136,7 @@ private void btnAddFolder_Click(object sender, EventArgs e) { if (!cmbFolder.Items.Contains(folderName)) { - mEditorItem.Folder = folderName; + _editorItem.Folder = folderName; lstGameObjects.ExpandFolder(folderName); InitEditor(); cmbFolder.Text = folderName; @@ -945,7 +1146,7 @@ private void btnAddFolder_Click(object sender, EventArgs e) private void cmbFolder_SelectedIndexChanged(object sender, EventArgs e) { - mEditorItem.Folder = cmbFolder.Text; + _editorItem.Folder = cmbFolder.Text; InitEditor(); } diff --git a/Intersect.Editor/Forms/Editors/frmResource.resx b/Intersect.Editor/Forms/Editors/frmResource.resx index c277bbb80b..59159b1071 100644 --- a/Intersect.Editor/Forms/Editors/frmResource.resx +++ b/Intersect.Editor/Forms/Editors/frmResource.resx @@ -1,7 +1,7 @@