Skip to content

Commit

Permalink
Merge pull request #669 from SinisterStairs/master
Browse files Browse the repository at this point in the history
Generalized the capability to display framename on mouseover
  • Loading branch information
BinaryConstruct committed Aug 31, 2015
2 parents dd0d663 + b92cff8 commit ad83eff
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
10 changes: 6 additions & 4 deletions TEditXna/Editor/MouseTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ public Tile Tile
if (World.TileProperties.Count > _tile.Type)
{
TEditXNA.Terraria.Objects.TileProperty tileProperty = World.TileProperties[_tile.Type];
string herbKey = World.GetHerbKey(_tile.Type, _tile.U, _tile.V);
if (!tileProperty.IsHerb || !World.HerbNames.ContainsKey(herbKey))
if (!tileProperty.HasFrameName)
{
TileName = tileProperty.Name;
} else {
TileName = World.HerbNames[herbKey];
}
else
{
string frameNameKey = World.GetFrameNameKey(_tile.Type, _tile.U, _tile.V);
TileName = World.FrameNames.ContainsKey(frameNameKey) ? World.FrameNames[frameNameKey] : tileProperty.Name + "*";
}
TileName = _tile.IsActive ? string.Format("{0} ({1})", TileName, _tile.Type) : "[empty]";
}
Expand Down
11 changes: 5 additions & 6 deletions TEditXna/Terraria/Objects/TileProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TileProperty : ObservableObject, ITile
private bool _isGrass; /* Heathtech */
private bool _isPlatform; /* Heathtech */
private bool _isCactus; /* Heathtech */
private bool _isHerb;
private bool _hasFrameName;
private bool _isStone; /* Heathtech */
private bool _canBlend; /* Heathtech */
private int? _mergeWith; /* Heathtech */
Expand All @@ -38,6 +38,7 @@ public TileProperty()
_isGrass = false; /* Heathtech */
_isPlatform = false; /* Heathtech */
_isCactus = false; /* Heathtech */
_hasFrameName = false;
_isStone = false; /* Heathtech */
_canBlend = false; /* Heathtech */
_mergeWith = null; /* Heathtech */
Expand Down Expand Up @@ -77,8 +78,6 @@ public ObservableCollection<FrameProperty> Frames
get { return _frames; }
}



public TileProperty(int id, string name, Color color, bool isFramed = false)
{
_color = color;
Expand Down Expand Up @@ -144,10 +143,10 @@ public bool IsCactus
set { Set("IsCactus", ref _isCactus, value); }
}

public bool IsHerb
public bool HasFrameName
{
get { return _isHerb; }
set { Set("IsHerb", ref _isHerb, value); }
get { return _hasFrameName; }
set { Set("HasFrameName", ref _hasFrameName, value); }
}

/* Heathtech */
Expand Down
54 changes: 30 additions & 24 deletions TEditXna/Terraria/World.Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ public partial class World
private static readonly Dictionary<string, int> _npcIds = new Dictionary<string, int>();
private static readonly Dictionary<int, int> _npcFrames = new Dictionary<int, int>();
private static readonly Dictionary<byte, string> _prefix = new Dictionary<byte, string>();
private static readonly Dictionary<Key, string> _shortcuts = new Dictionary<Key, string>();
private static readonly Dictionary<int, ItemProperty> _itemLookup = new Dictionary<int, ItemProperty>();
private static readonly Dictionary<int, string> _tallynames = new Dictionary<int, string>();
private static readonly Dictionary<string, string> _frameNames = new Dictionary<string, string>();

private static readonly ObservableCollection<ItemProperty> _itemProperties = new ObservableCollection<ItemProperty>();
private static readonly ObservableCollection<ChestProperty> _chestProperties = new ObservableCollection<ChestProperty>();
private static readonly ObservableCollection<SignProperty> _signProperties = new ObservableCollection<SignProperty>();
private static readonly ObservableCollection<TileProperty> _tileProperties = new ObservableCollection<TileProperty>();
private static readonly ObservableCollection<TileProperty> _tileBricks = new ObservableCollection<TileProperty>();
private static readonly ObservableCollection<WallProperty> _wallProperties = new ObservableCollection<WallProperty>();
private static readonly ObservableCollection<PaintProperty> _paintProperties = new ObservableCollection<PaintProperty>();

private static readonly ObservableCollection<Sprite> _sprites = new ObservableCollection<Sprite>();
private static readonly Dictionary<Key, string> _shortcuts = new Dictionary<Key, string>();
private static readonly Dictionary<int, ItemProperty> _itemLookup = new Dictionary<int, ItemProperty>();
private static readonly Dictionary<int, string> _tallynames = new Dictionary<int, string>();
private static readonly Dictionary<string, string> _herbNames = new Dictionary<string, string>();

private static Vector2 _appSize;
internal static string AltC;
internal static int? SteamUserId;
Expand Down Expand Up @@ -157,10 +158,11 @@ private static void LoadObjectDbXml(string file)
curTile.IsStone = (bool?)xElement.Attribute("Stone") ?? false; /* Heathtech */
curTile.CanBlend = (bool?)xElement.Attribute("Blends") ?? false; /* Heathtech */
curTile.MergeWith = (int?)xElement.Attribute("MergeWith") ?? null; /* Heathtech */
curTile.IsHerb = curTile.Id >= 82 && curTile.Id <= 84;
curTile.HasFrameName = curTile.IsFramed && ((bool?)xElement.Attribute("UseFrameName") ?? false);
string frameNamePostfix = (string)xElement.Attribute("FrameNamePostfix") ?? null;

foreach (var elementFrame in xElement.Elements("Frames").Elements("Frame"))
{

var curFrame = new FrameProperty();
// Read XML attributes
curFrame.Name = (string)elementFrame.Attribute("Name");
Expand All @@ -183,22 +185,26 @@ private static void LoadObjectDbXml(string file)
Tile = (ushort)curTile.Id, /* SBlogic */
TileName = curTile.Name
});
if (curTile.IsHerb)
if (curTile.HasFrameName)
{
string herbName = curFrame.Name;
if (curTile.Id == 82)
{
herbName += " Seed";
}
else if (curTile.Id == 83)
string frameName = curFrame.Name;
if (frameNamePostfix != null)
frameName += " (" + frameNamePostfix + ")";
if (curFrame.Variety != null)
frameName += ", " + curFrame.Variety;

// TODO: There must be a more efficient way than to store each frame...
for (int x = 0, mx = curTile.FrameSize.X; x < mx; x++)
{
herbName += " Mature";
}
else if (curTile.Id == 84)
{
herbName += " Bloom";
for (int y = 0, my = curTile.FrameSize.Y; y < my; y++)
{
string frameNameKey = GetFrameNameKey(curTile.Id, (short)(curFrame.UV.X + (x * 18)), (short)(curFrame.UV.Y + (y * 18)));
if (!FrameNames.ContainsKey(frameNameKey))
FrameNames.Add(frameNameKey, frameName);
else
System.Diagnostics.Debug.WriteLine(curFrame.Name + " collided with " + frameNameKey);
}
}
HerbNames.Add(GetHerbKey(curTile.Id, curFrame.UV.X, curFrame.UV.Y), herbName);
}
}
if (curTile.Frames.Count == 0 && curTile.IsFramed)
Expand Down Expand Up @@ -491,19 +497,19 @@ public static Dictionary<int, string> TallyNames
get { return _tallynames; }
}

public static Dictionary<string, string> HerbNames
public static Dictionary<string, string> FrameNames
{
get { return _herbNames; }
get { return _frameNames; }
}

internal static Vector2 AppSize
{
get { return _appSize; }
}

public static string GetHerbKey(int id, short u, short v)
public static string GetFrameNameKey(int id, short u, short v)
{
return id + "," + u + "," + v;
return id + ":" + u + "," + v;
}
}
}
11 changes: 7 additions & 4 deletions TEditXna/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ PLEASE KEEP FORMATTING IF SUBMITTING PULL REQUEST FOR THIS FILE. THANKS!
<Frame UV="36,0" Anchor="Right" />
</Frames>
</Tile>
<Tile Color="#FFE9CF5E" Placement="floor" Size="2,2" Id="21" Name="Chest" Framed="true">
<Tile Color="#FFE9CF5E" Placement="floor" Size="2,2" Id="21" Name="Chest" Framed="true" UseFrameName="true">
<Frames>
<Frame UV="0,0" Name="Chest" />
<Frame UV="36,0" Name="Gold Chest" />
Expand Down Expand Up @@ -2133,7 +2133,7 @@ PLEASE KEEP FORMATTING IF SUBMITTING PULL REQUEST FOR THIS FILE. THANKS!
<Frame UV="130,0" Variety="Sponge" />
</Frames>
</Tile>
<Tile Color="#FFFF7800" Id="82" Name="Daybloom Seeds" Framed="true">
<Tile Color="#FFFF7800" Id="82" Name="Daybloom Seeds" Framed="true" UseFrameName="true" FrameNamePostfix="seed">
<Frames>
<Frame UV="0,0" Name="Daybloom" growsOn="2,78" />
<Frame UV="18,0" Name="Moonglow" growsOn="60,78" />
Expand All @@ -2144,7 +2144,7 @@ PLEASE KEEP FORMATTING IF SUBMITTING PULL REQUEST FOR THIS FILE. THANKS!
<Frame UV="108,0" Name="Shiverthorn" growsOn="147,161" />
</Frames>
</Tile>
<Tile Name="Herb Mature" Color="#FFFF7800" Id="83" Framed="true" Light="true">
<Tile Name="Herb Mature" Color="#FFFF7800" Id="83" Framed="true" UseFrameName="true" Light="true">
<Frames>
<Frame UV="0,0" Name="Daybloom" growsOn="2,78" />
<Frame UV="18,0" Name="Moonglow" growsOn="60,78" />
Expand All @@ -2155,7 +2155,7 @@ PLEASE KEEP FORMATTING IF SUBMITTING PULL REQUEST FOR THIS FILE. THANKS!
<Frame UV="108,0" Name="Shiverthorn" growsOn="147,161" />
</Frames>
</Tile>
<Tile Name="Herb Bloom" Color="#FFFF7800" Id="84" Framed="true" Light="true">
<Tile Name="Herb Bloom" Color="#FFFF7800" Id="84" Framed="true" UseFrameName="true" FrameNamePostfix="bloom" Light="true">
<Frames>
<Frame UV="0,0" Name="Daybloom" growsOn="2,78" />
<Frame UV="18,0" Name="Moonglow" growsOn="60,78" />
Expand Down Expand Up @@ -8376,6 +8376,9 @@ Single tile object; may contain Frame tags. Has the following properties:
always have isFramed set, though some single-tiled objects also have frames. Furthermore,
some XNB tiles with frames actually don't need frame coordinations. (Yes, it's confusing;
it usually boils Top to trial-and-error and seeing if the world file can't be read.)
* useFrameName - Default is false; if true, isFramed is required. When mousing over tiles, display the frame name rather than the tile name.
* frameNamePostfix - Default is empty. When useFrameName is true, append a postfix to the display name.
* size - Required if not default; default is "1,1". This is the width and height of tile
objects that span multiple tiles. If this property is beyond "1,1", then isFramed MUST be true.
Expand Down

0 comments on commit ad83eff

Please sign in to comment.