Differentiate field item colors

Closes #159
This commit is contained in:
Kurt 2020-05-03 20:17:36 -07:00
parent 0ec40f3b55
commit 7d975a9ea9
3 changed files with 79 additions and 8 deletions

View File

@ -1,9 +1,10 @@
namespace NHSE.Core
{
public class FieldItemDefinition
public class FieldItemDefinition : INamedValue
{
public readonly ushort Index;
public readonly string Name;
public ushort Index { get; }
public string Name { get; }
public readonly FieldItemKind Kind;
public FieldItemDefinition(ushort id, string name, FieldItemKind kind)

View File

@ -1,4 +1,6 @@
namespace NHSE.Core
using static NHSE.Core.FieldItemKind;
namespace NHSE.Core
{
public enum FieldItemKind : byte
{
@ -60,8 +62,12 @@ public enum FieldItemKind : byte
public static class FieldItemKindExtensions
{
public static bool IsWeed(this FieldItemKind type) => FieldItemKind.PltWeedAut0 <= type && type <= FieldItemKind.PltWeedWin1;
public static bool IsPlant(this FieldItemKind type) => FieldItemKind.PltFlwAnemone <= type && type <= FieldItemKind.PltWeedWin1;
public static bool IsFence(this FieldItemKind type) => FieldItemKind.FenceBamboo <= type && type <= FieldItemKind.FenceWoodWhite;
public static bool IsWeed(this FieldItemKind type) => PltWeedAut0 <= type && type <= PltWeedWin1;
public static bool IsPlant(this FieldItemKind type) => PltFlwAnemone <= type && type <= PltWeedWin1;
public static bool IsFence(this FieldItemKind type) => FenceBamboo <= type && type <= FenceWoodWhite;
public static bool IsBush(this FieldItemKind type) => PltBushAzalea <= type && type <= PltBushOsmanthus;
public static bool IsFlower(this FieldItemKind type) => PltFlwAnemone <= type && type <= PltFlwYuri;
public static bool IsTree(this FieldItemKind type) => PltTreeBamboo <= type && type <= PltTreePalm;
public static bool IsStone(this FieldItemKind type) => StoneA <= type && type <= StoneE;
}
}

View File

@ -11,10 +11,74 @@ public static Color GetItemColor(FieldItem item)
{
var kind = ItemInfo.GetItemKind(item);
if (kind == ItemKind.Unknown)
return item.DisplayItemId == FieldItem.NONE ? Color.Transparent : Color.DarkGreen;
return GetItemColor60000(item);
return Colors[(int)kind];
}
private static Color GetItemColor60000(FieldItem item)
{
var id = item.DisplayItemId;
if (id == FieldItem.NONE)
return Color.Transparent;
if (!FieldItemList.Items.TryGetValue(id, out var def))
return Color.DarkGreen;
var kind = def.Kind;
if (kind.IsTree())
return GetTreeColor(id);
if (kind.IsFlower())
return Color.HotPink;
if (kind.IsWeed())
return Color.DarkOliveGreen;
if (kind.IsFence())
return Color.LightCoral;
if (kind == FieldItemKind.UnitIconHole)
return Color.Black;
if (kind.IsBush())
return Color.LightGreen;
if (kind.IsStone())
return Color.LightGray;
return Color.DarkGreen; // shouldn't reach here, but ok
}
private static Color GetTreeColor(ushort id)
{
if (0xEC9C <= id && id <= 0xECA0) // money tree
return Color.Gold;
return id switch
{
// Fruit
0xEA61 => Color.Red, // "PltTreeApple"
0xEA62 => Color.Orange, // "PltTreeOrange"
0xEAC8 => Color.Lime, // "PltTreePear"
0xEAC9 => Color.DarkRed, // "PltTreeCherry"
0xEACA => Color.PeachPuff, // "PltTreePeach"
// Cedar
0xEA69 => Color.SaddleBrown, // "PltTreeCedar4"
0xEAB6 => Color.SaddleBrown, // "PltTreeCedar2"
0xEAB7 => Color.SaddleBrown, // "PltTreeCedar1"
0xEAB8 => Color.SaddleBrown, // "PltTreeCedar3"
// Palm
0xEA77 => Color.LightGoldenrodYellow, // "PltTreePalm4"
0xEAC0 => Color.LightGoldenrodYellow, // "PltTreePalm2"
0xEAC1 => Color.LightGoldenrodYellow, // "PltTreePalm1"
0xEAC2 => Color.LightGoldenrodYellow, // "PltTreePalm3"
0xEA76 => Color.MediumSeaGreen, // "PltTreeBamboo4"
0xEAC4 => Color.MediumSeaGreen, // "PltTreeBamboo0"
0xEAC5 => Color.MediumSeaGreen, // "PltTreeBamboo2"
0xEAC6 => Color.MediumSeaGreen, // "PltTreeBamboo1"
0xEAC7 => Color.MediumSeaGreen, // "PltTreeBamboo3"
_ => Color.SandyBrown,
};
}
private static readonly Color[] Colors = ((KnownColor[])Enum.GetValues(typeof(KnownColor)))
.Select(Color.FromKnownColor).Select(z => ColorUtil.Blend(Color.White, z, 0.5d)).ToArray();
}