Improve weapon identification for designs for unknown weapons.

This commit is contained in:
Ottermandias 2023-10-05 17:18:42 +02:00
parent 06299d1966
commit 8b6e819fcd
3 changed files with 67 additions and 26 deletions

View file

@ -333,7 +333,7 @@ public class DesignBase
if (id == ItemManager.NothingId(EquipSlot.OffHand)) if (id == ItemManager.NothingId(EquipSlot.OffHand))
id = ItemManager.NothingId(FullEquipType.Shield); id = ItemManager.NothingId(FullEquipType.Shield);
PrintWarning(items.ValidateWeapons(id.Item, idOff.Item, out var main, out var off)); PrintWarning(items.ValidateWeapons(id, idOff, out var main, out var off, allowUnknown));
PrintWarning(items.ValidateStain(stain, out stain, allowUnknown)); PrintWarning(items.ValidateStain(stain, out stain, allowUnknown));
PrintWarning(items.ValidateStain(stainOff, out stainOff, allowUnknown)); PrintWarning(items.ValidateStain(stainOff, out stainOff, allowUnknown));
design.DesignData.SetItem(EquipSlot.MainHand, main); design.DesignData.SetItem(EquipSlot.MainHand, main);

View file

@ -185,6 +185,7 @@ public class EquipmentDrawer
} }
label = combo.Label; label = combo.Label;
var unknown = !_gPose.InGPose && current.Type is FullEquipType.Unknown; var unknown = !_gPose.InGPose && current.Type is FullEquipType.Unknown;
var ret = false; var ret = false;
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemInnerSpacing); using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemInnerSpacing);
@ -198,6 +199,7 @@ public class EquipmentDrawer
weapon = combo.CurrentSelection; weapon = combo.CurrentSelection;
} }
} }
if (unknown && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) if (unknown && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
ImGui.SetTooltip("The weapon type could not be identified, thus changing it to other weapons of that type is not possible."); ImGui.SetTooltip("The weapon type could not be identified, thus changing it to other weapons of that type is not possible.");
@ -488,7 +490,7 @@ public class EquipmentDrawer
return changes; return changes;
} }
private static void WeaponHelpMarker(string label) private static void WeaponHelpMarker(string label, string? type = null)
{ {
ImGui.SameLine(); ImGui.SameLine();
ImGuiComponents.HelpMarker( ImGuiComponents.HelpMarker(
@ -496,6 +498,12 @@ public class EquipmentDrawer
+ "thus it is only allowed to change weapons to other weapons of the same type."); + "thus it is only allowed to change weapons to other weapons of the same type.");
ImGui.SameLine(); ImGui.SameLine();
ImGui.TextUnformatted(label); ImGui.TextUnformatted(label);
if (type != null)
{
var pos = ImGui.GetItemRectMin();
pos.Y += ImGui.GetFrameHeightWithSpacing();
ImGui.GetWindowDrawList().AddText(pos, ImGui.GetColorU32(ImGuiCol.Text), $"({type})");
}
} }
private DataChange DrawWeaponsSmall(EquipItem cMainhand, out EquipItem rMainhand, EquipItem cOffhand, out EquipItem rOffhand, private DataChange DrawWeaponsSmall(EquipItem cMainhand, out EquipItem rMainhand, EquipItem cOffhand, out EquipItem rOffhand,
@ -534,8 +542,10 @@ public class EquipmentDrawer
rApplyMainhandStain = true; rApplyMainhandStain = true;
} }
if (allWeapons)
mainhandLabel += $" ({cMainhand.Type.ToName()})";
WeaponHelpMarker(mainhandLabel); WeaponHelpMarker(mainhandLabel);
if (rOffhand.Type is FullEquipType.Unknown) if (rOffhand.Type is FullEquipType.Unknown)
{ {
rOffhandStain = cOffhandStain; rOffhandStain = cOffhandStain;
@ -607,7 +617,7 @@ public class EquipmentDrawer
rApplyMainhand = true; rApplyMainhand = true;
} }
WeaponHelpMarker(mainhandLabel); WeaponHelpMarker(mainhandLabel, allWeapons ? cMainhand.Type.ToName() : null);
if (DrawStain(EquipSlot.MainHand, cMainhandStain, out rMainhandStain, locked, false)) if (DrawStain(EquipSlot.MainHand, cMainhandStain, out rMainhandStain, locked, false))
changes |= DataChange.Stain; changes |= DataChange.Stain;

View file

@ -78,7 +78,8 @@ public class ItemManager : IDisposable
return EquipItem.FromId(itemId); return EquipItem.FromId(itemId);
if (item.Type.ToSlot() != slot) if (item.Type.ToSlot() != slot)
return new EquipItem(string.Intern($"Invalid #{itemId}"), itemId, item.IconId, item.ModelId, item.WeaponType, item.Variant, 0, 0, 0, 0); return new EquipItem(string.Intern($"Invalid #{itemId}"), itemId, item.IconId, item.ModelId, item.WeaponType, item.Variant, 0, 0, 0,
0);
return item; return item;
} }
@ -88,11 +89,13 @@ public class ItemManager : IDisposable
if (itemId == NothingId(type)) if (itemId == NothingId(type))
return NothingItem(type); return NothingItem(type);
if (!ItemService.AwaitedService.TryGetValue(itemId, type is FullEquipType.Shield ? EquipSlot.MainHand : EquipSlot.OffHand, out var item)) if (!ItemService.AwaitedService.TryGetValue(itemId, type is FullEquipType.Shield ? EquipSlot.MainHand : EquipSlot.OffHand,
out var item))
return EquipItem.FromId(itemId); return EquipItem.FromId(itemId);
if (item.Type != type) if (item.Type != type)
return new EquipItem(string.Intern($"Invalid #{itemId}"), itemId, item.IconId, item.ModelId, item.WeaponType, item.Variant, 0, 0, 0, 0); return new EquipItem(string.Intern($"Invalid #{itemId}"), itemId, item.IconId, item.ModelId, item.WeaponType, item.Variant, 0, 0, 0,
0);
return item; return item;
} }
@ -164,7 +167,7 @@ public class ItemManager : IDisposable
if (!itemId.IsItem) if (!itemId.IsItem)
{ {
var (id, _, variant, _) = itemId.Split; var (id, _, variant, _) = itemId.Split;
item = Identify(slot, id, variant); item = Identify(slot, id, variant);
return allowUnknown ? string.Empty : $"The item {itemId} yields an unknown item."; return allowUnknown ? string.Empty : $"The item {itemId} yields an unknown item.";
} }
@ -217,33 +220,61 @@ public class ItemManager : IDisposable
/// or the default sword and a nothing offhand. /// or the default sword and a nothing offhand.
/// The return value is an empty string if there was no problem and a warning otherwise. /// The return value is an empty string if there was no problem and a warning otherwise.
/// </summary> /// </summary>
public string ValidateWeapons(ItemId mainId, ItemId offId, out EquipItem main, out EquipItem off) public string ValidateWeapons(CustomItemId mainId, CustomItemId offId, out EquipItem main, out EquipItem off, bool allowUnknown)
{ {
var ret = string.Empty; var ret = string.Empty;
if (!IsItemValid(EquipSlot.MainHand, mainId, out main)) if (!mainId.IsItem)
{
var (id, weapon, variant, _) = mainId.Split;
main = Identify(EquipSlot.MainHand, id, weapon, variant);
if (!allowUnknown)
{
ret = $"The item {mainId} yields an unknown item, reset to default sword.";
main = DefaultSword;
}
}
else if (!IsItemValid(EquipSlot.MainHand, mainId.Item, out main))
{ {
main = DefaultSword; main = DefaultSword;
ret = $"The mainhand weapon {mainId} does not exist, reset to default sword."; ret = $"The mainhand weapon {mainId} does not exist, reset to default sword.";
} }
var offType = main.Type.ValidOffhand(); if (!offId.IsItem)
if (IsOffhandValid(offType, offId, out off))
return ret;
// Try implicit offhand.
// Can not be set to default sword before because then it could not be valid.
if (IsOffhandValid(offType, mainId, out off))
return $"The offhand weapon {offId} does not exist, reset to implied offhand.";
if (FullEquipTypeExtensions.OffhandTypes.Contains(offType))
{ {
main = DefaultSword; var (id, weapon, variant, _) = offId.Split;
off = NothingItem(FullEquipType.Shield); off = Identify(EquipSlot.OffHand, id, weapon, variant, main.Type);
return if (!allowUnknown)
$"The offhand weapon {offId} does not exist, but no default could be restored, reset mainhand to default sword and offhand to nothing."; {
if (!FullEquipTypeExtensions.OffhandTypes.Contains(main.Type.ValidOffhand()))
{
main = DefaultSword;
off = NothingItem(FullEquipType.Shield);
return
$"The offhand weapon {offId} does not exist, but no default could be restored, reset mainhand to default sword and offhand to nothing.";
}
if (ret.Length > 0)
ret += '\n';
ret += $"The item {offId} yields an unknown item, reset to implied offhand.";
off = GetDefaultOffhand(main);
}
}
else if (!IsOffhandValid(main.Type.ValidOffhand(), offId.Item, out off))
{
if (!FullEquipTypeExtensions.OffhandTypes.Contains(main.Type.ValidOffhand()))
{
main = DefaultSword;
off = NothingItem(FullEquipType.Shield);
return
$"The offhand weapon {offId} does not exist, but no default could be restored, reset mainhand to default sword and offhand to nothing.";
}
if (ret.Length > 0)
ret += '\n';
ret += $"The offhand weapon {mainId} does not exist or is of invalid type, reset to default sword.";
off = GetDefaultOffhand(main);
} }
off = NothingItem(offType); return ret;
return ret.Length == 0 ? $"The offhand weapon {offId} does not exist, reset to no offhand." : ret;
} }
} }