Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
70e59cc
starting replacing old resource state by the new one
WeylonSantana Mar 22, 2025
483c1bd
update sprite on server
WeylonSantana Mar 20, 2025
ceba4ea
finished on editor, adding controls and render on map
WeylonSantana Mar 20, 2025
32698cf
finished on client for now
WeylonSantana Mar 20, 2025
5a595ea
fix editor chebox name being cropped
WeylonSantana Mar 20, 2025
bc2c657
finish animation on editor
WeylonSantana Mar 20, 2025
a589b8e
added animation part in client
WeylonSantana Mar 21, 2025
daeec45
rename Graphic to Texture
WeylonSantana Mar 22, 2025
220f35b
renaming resource type enum and state property
WeylonSantana Mar 22, 2025
c5a24a0
renaming min/max hp from state
WeylonSantana Mar 22, 2025
893ef01
renaming tile/map properties in client resource
WeylonSantana Mar 22, 2025
70332a1
rename health to state
WeylonSantana Mar 22, 2025
df02af0
updating resource state type
WeylonSantana Mar 22, 2025
69bb298
add name and id to resouce state
WeylonSantana Mar 22, 2025
bb694de
correct type for current state key
WeylonSantana Mar 22, 2025
5547c9e
trying refactor resource
WeylonSantana Mar 22, 2025
6d90722
select the fullest resource
WeylonSantana Mar 22, 2025
acad5a9
more editor refactor
WeylonSantana Mar 22, 2025
e8d181a
rename controls
WeylonSantana Mar 22, 2025
edd6367
show correct name in editor
WeylonSantana Mar 22, 2025
8becfb8
sort states by health
WeylonSantana Mar 22, 2025
2a3bf37
bring back original code and change only necessary
WeylonSantana Mar 22, 2025
cdae5a4
everything working for tileset and texture
WeylonSantana Mar 22, 2025
031b8e3
undo map instance changes
WeylonSantana Mar 23, 2025
cf5c44b
fix hp bar not showing when has no graphic
WeylonSantana Mar 23, 2025
8207c29
making animations working on client side
WeylonSantana Mar 23, 2025
3101642
renaming state graphics => states
WeylonSantana Mar 23, 2025
1c22193
rename death animation and sort some things on editor
WeylonSantana Mar 23, 2025
e2081df
cache maximum health for states
WeylonSantana Mar 23, 2025
3abb611
dont update state if not necessary
WeylonSantana Mar 23, 2025
d4411f5
renaming current graphic state to current state
WeylonSantana Mar 23, 2025
69bab12
cache animation descriptor
WeylonSantana Mar 23, 2025
ccdd892
cache texture
WeylonSantana Mar 23, 2025
65f458f
cleanup on graphics
WeylonSantana Mar 26, 2025
805cc7b
dont handle resource sprite logic on server
WeylonSantana Mar 26, 2025
4ecf199
cleanup form resource
WeylonSantana Mar 26, 2025
ad72114
fix strings
WeylonSantana Mar 26, 2025
dd0fb5d
change items changed type
WeylonSantana Mar 26, 2025
f65f900
invert undo if
WeylonSantana Mar 26, 2025
63a3905
sort when hp state changes
WeylonSantana Mar 26, 2025
1b48080
renaming Texture => TextureName
WeylonSantana Mar 26, 2025
276e6cf
fix lst state items on editor
WeylonSantana Mar 26, 2025
70bae59
dispose animation when next state no longer uses
WeylonSantana Mar 27, 2025
53a9c39
do not render the white pixel occupying the whole tile when changing …
WeylonSantana Mar 27, 2025
830c6c4
fix rebasing
WeylonSantana Mar 27, 2025
9c2ef67
regenerating migration
WeylonSantana Mar 26, 2025
12b45f6
rename hpregen => HealthRegenPercent
WeylonSantana Mar 27, 2025
891d7e4
sort fields
WeylonSantana Mar 27, 2025
320dc8e
cleanup editor graphics
WeylonSantana Mar 27, 2025
db49e0a
cleanup resource on client
WeylonSantana Mar 27, 2025
f057779
fix small issues
WeylonSantana Mar 27, 2025
21bb25a
update max health on load
WeylonSantana Mar 28, 2025
80bc57b
using cached variables
WeylonSantana Mar 28, 2025
ef8bb4e
reusing position logic
WeylonSantana Mar 28, 2025
4ef0ad5
dont checking is dead twice
WeylonSantana Mar 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public partial class ResourceStateDescriptor

public string Name { get; set; }

public string TextureName { get; set; } = default;
public string? TextureName { get; set; } = default;

public ResourceTextureSource TextureType { get; set; } = ResourceTextureSource.Resource;

Expand Down
65 changes: 31 additions & 34 deletions Intersect.Client.Core/Entities/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public ResourceDescriptor? Descriptor
get => _descriptor;
set
{
_descriptor = value;
if (value is { } descriptor)
{
_maximumHealthForStates = (int)(descriptor.UseExplicitMaxHealthForResourceStates
Expand All @@ -60,6 +59,14 @@ public ResourceDescriptor? Descriptor
{
_maximumHealthForStates = 0;
}

if (value == _descriptor)
{
return;
}

_descriptor = value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff needs to be before anything else in the setter, it shouldn't be after the new value is being used

UpdateCurrentState();
}
}

Expand Down Expand Up @@ -109,7 +116,7 @@ private void ReloadSpriteTexture()
case ResourceTextureSource.Tileset:
if (GameContentManager.Current.TilesetsLoaded)
{
Texture = GameContentManager.Current.GetTexture(TextureType.Tileset, _sprite);
Texture = GameContentManager.Current.GetTexture(TextureType.Tileset, _currentState?.TextureName);
}
else
{
Expand All @@ -118,7 +125,7 @@ private void ReloadSpriteTexture()
break;

case ResourceTextureSource.Resource:
Texture = GameContentManager.Current.GetTexture(TextureType.Resource, _sprite);
Texture = GameContentManager.Current.GetTexture(TextureType.Resource, _currentState?.TextureName);
break;

case ResourceTextureSource.Animation:
Expand Down Expand Up @@ -189,7 +196,6 @@ public override void Load(EntityPacket? packet)
}

Descriptor = descriptor;
UpdateCurrentState();

if (!justDied)
{
Expand Down Expand Up @@ -240,8 +246,8 @@ public void UpdateCurrentState()
var currentHealthPercentage = Math.Floor((float)Vital[(int)Enums.Vital.Health] / _maximumHealthForStates * 100);

if (_currentState is { } currentState &&
currentHealthPercentage >= _currentState?.MinimumHealth &&
currentHealthPercentage <= _currentState?.MaximumHealth
currentHealthPercentage >= currentState?.MinimumHealth &&
currentHealthPercentage <= currentState?.MaximumHealth
)
{
return;
Expand All @@ -255,16 +261,14 @@ public void UpdateCurrentState()
// but the previous state was an animation
if (
_currentState?.TextureType == ResourceTextureSource.Animation &&
_stateAnimation != default &&
currentState?.TextureType != ResourceTextureSource.Animation
)
)
{
_stateAnimation.Dispose();
_stateAnimation?.Dispose();
_stateAnimation = default;
}

_currentState = currentState;
_sprite = _currentState?.TextureName ?? string.Empty;

if (currentState is { TextureType: ResourceTextureSource.Animation } && currentState.AnimationId != Guid.Empty)
{
Expand Down Expand Up @@ -299,7 +303,6 @@ public override bool Update()
{
_ = ResourceDescriptor.TryGet(deletedDescriptor.Id, out var descriptor);
Descriptor = descriptor;
UpdateCurrentState();
}

if (!Maps.MapInstance.TryGet(MapId, out var map) || !map.InView())
Expand Down Expand Up @@ -338,7 +341,7 @@ public override bool Update()

public override HashSet<Entity>? DetermineRenderOrder(HashSet<Entity>? renderList, IMapInstance? map)
{
if (Descriptor == default || CurrentState is not { } graphicState || !graphicState.RenderBelowEntities)
if (CurrentState is not { } graphicState || !graphicState.RenderBelowEntities)
{
return base.DetermineRenderOrder(renderList, map);
}
Expand Down Expand Up @@ -463,35 +466,29 @@ private void CalculateRenderBounds()
break;

case ResourceTextureSource.Tileset:
if (IsDead)
ResourceStateDescriptor? selectedGraphic = null;

if (IsDead && graphicState is { MaximumHealth: 0 } deadGraphic)
{
if (graphicState is { MaximumHealth: 0 } deadGraphic)
{
_renderBoundsSrc = new(
deadGraphic.X * _tileWidth,
deadGraphic.Y * _tileHeight,
(deadGraphic.Width + 1) * _tileWidth,
(deadGraphic.Height + 1) * _tileHeight
);
}
else
{
_renderBoundsSrc = new();
}
selectedGraphic = deadGraphic;
}
else if (graphicState is { MinimumHealth: > 0 } aliveGraphic)
else if (!IsDead && graphicState is { MinimumHealth: > 0 } aliveGraphic)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsDead shouldn't be getting checked twice.

{
_renderBoundsSrc = new(
aliveGraphic.X * _tileWidth,
aliveGraphic.Y * _tileHeight,
(aliveGraphic.Width + 1) * _tileWidth,
(aliveGraphic.Height + 1) * _tileHeight
);
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 = new();
_renderBoundsSrc = default;
break;

default:
Expand Down
48 changes: 29 additions & 19 deletions Intersect.Editor/Core/Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,9 @@ bool alternate
var x2 = Options.Instance.Map.MapWidth;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.MapWidth should be cached and reused in the instances after this

var y1 = 0;
var y2 = Options.Instance.Map.MapHeight;
var xoffset = CurrentView.Left + gridX * Options.Instance.Map.TileWidth * Options.Instance.Map.MapWidth;
var tileWidth = Options.Instance.Map.TileWidth;
var tileHeight = Options.Instance.Map.TileHeight;
var xoffset = CurrentView.Left + gridX * tileWidth * Options.Instance.Map.MapWidth;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.MapWidth

var yoffset = CurrentView.Top + gridY * Options.Instance.Map.TileHeight * Options.Instance.Map.MapHeight;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.TileHeight and Options.Instance.Map.MapHeight


if (screenShotting)
Expand Down Expand Up @@ -1402,8 +1404,11 @@ bool alternate
continue;
}

float xpos = x * tileWidth + xoffset;
float ypos = y * Options.Instance.Map.TileHeight + yoffset;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.TileHeight


// we have the graphic, now lets build based on type
switch(resourceGraphic.TextureType)
switch (resourceGraphic.TextureType)
{
case ResourceTextureSource.Resource:
{
Expand All @@ -1416,21 +1421,25 @@ bool alternate
continue;
}

float xpos = x * Options.Instance.Map.TileWidth + xoffset;
float ypos = y * Options.Instance.Map.TileHeight + yoffset;

if (texture.Height > Options.Instance.Map.TileHeight)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.TileHeight

{
ypos -= texture.Height - Options.Instance.Map.TileHeight;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.TileHeight

}

if (texture.Width > Options.Instance.Map.TileWidth)
if (texture.Width > tileWidth)
{
xpos -= (texture.Width - Options.Instance.Map.TileWidth) / 2;
xpos -= (texture.Width - tileWidth) / 2;
}

DrawTexture(
texture, xpos, ypos, 0, 0, texture.Width, texture.Height, renderTarget
texture,
xpos,
ypos,
0,
0,
texture.Width,
texture.Height,
renderTarget
);
}
break;
Expand All @@ -1446,24 +1455,25 @@ bool alternate
continue;
}

float xpos = x * Options.Instance.Map.TileWidth + xoffset;
float ypos = y * Options.Instance.Map.TileHeight + yoffset;

if ((resourceGraphic.Height + 1) * Options.Instance.Map.TileHeight > Options.Instance.Map.TileHeight)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.TileHeight

{
ypos -= (resourceGraphic.Height + 1) * Options.Instance.Map.TileHeight - Options.Instance.Map.TileHeight;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.TileHeight

}

if ((resourceGraphic.Width + 1) * Options.Instance.Map.TileWidth > Options.Instance.Map.TileWidth)
if ((resourceGraphic.Width + 1) * tileWidth > tileWidth)
{
xpos -= ((resourceGraphic.Width + 1) * Options.Instance.Map.TileWidth - Options.Instance.Map.TileWidth) / 2;
xpos -= ((resourceGraphic.Width + 1) * tileWidth - tileWidth) / 2;
}

DrawTexture(
texture, xpos, ypos, resourceGraphic.X * Options.Instance.Map.TileWidth,
texture,
xpos,
ypos,
resourceGraphic.X * tileWidth,
resourceGraphic.Y * Options.Instance.Map.TileHeight,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.TileHeight

(resourceGraphic.Width + 1) * Options.Instance.Map.TileWidth,
(resourceGraphic.Height + 1) * Options.Instance.Map.TileHeight, renderTarget
(resourceGraphic.Width + 1) * tileWidth,
(resourceGraphic.Height + 1) * Options.Instance.Map.TileHeight,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.TileHeight

renderTarget
);
}
break;
Expand All @@ -1475,8 +1485,8 @@ bool alternate
continue;
}

float xpos = x * Options.Instance.Map.TileWidth + xoffset + Options.Instance.Map.TileWidth / 2f;
float ypos = y * Options.Instance.Map.TileHeight + yoffset + Options.Instance.Map.TileHeight / 2f;
xpos += tileWidth / 2f;
ypos += Options.Instance.Map.TileHeight / 2f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.TileHeight


var animationInstance = tmpMap.GetAttributeAnimation(tmpMap.Attributes[x, y], animation.Id);

Expand Down Expand Up @@ -1514,7 +1524,7 @@ bool alternate

if (animation != null)
{
float xpos = x * Options.Instance.Map.TileWidth + xoffset + Options.Instance.Map.TileWidth / 2;
float xpos = x * tileWidth + xoffset + tileWidth / 2;
float ypos = y * Options.Instance.Map.TileHeight + yoffset + Options.Instance.Map.TileHeight / 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Instance.Map.TileHeight

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way both of these lines can be written as (base + 0.5f) * multiplier + offset

if (tmpMap.Attributes[x, y] != null)
{
Expand Down
9 changes: 5 additions & 4 deletions Intersect.Editor/Forms/Editors/frmResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ namespace Intersect.Editor.Forms.Editors;

public partial class FrmResource : EditorForm
{
private readonly List<string> _knownFolders = [];
private readonly BindingList<NotifiableDrop> _dropList = [];
private readonly BindingList<ResourceStateDescriptor> _stateList = [];
private readonly Dictionary<Guid, ResourceDescriptor> _changed = [];

private string? _copiedItem;
private ResourceDescriptor? _editorItem;
private Bitmap? _graphicBitmap;
private Bitmap? _resourceGraphic;
private bool _mouseDown;
private readonly List<string> _knownFolders = [];
private readonly BindingList<NotifiableDrop> _dropList = [];
private readonly BindingList<ResourceStateDescriptor> _stateList = [];

public FrmResource()
{
Expand Down Expand Up @@ -246,7 +247,7 @@ private void InitLocalization()
btnDropAdd.Text = Strings.ResourceEditor.dropadd;
btnDropRemove.Text = Strings.ResourceEditor.dropremove;

lblHpRegen.Text = Strings.ResourceEditor.hpregen;
lblHpRegen.Text = Strings.ResourceEditor.HealthRegenPercent;
new ToolTip().SetToolTip(lblHpRegen, Strings.ResourceEditor.regenhint);

grpGraphics.Text = Strings.ResourceEditor.Appearance;
Expand Down
2 changes: 1 addition & 1 deletion Intersect.Editor/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5048,7 +5048,7 @@ public partial struct ResourceEditor

public static LocalizedString StateNameError = @"State Name must be greater than 0 characters.";

public static LocalizedString hpregen = @"HP Regen (%):";
public static LocalizedString HealthRegenPercent = @"HP Regen (%):";

public static LocalizedString maxhp = @"Max HP:";

Expand Down
Loading