Skip to content

Commit

Permalink
make an interface to connect these
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Aug 25, 2024
1 parent 9ff570f commit 7840165
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
Binary file added Winch/Assets/Textures/MaterialsIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion Winch/Data/Item/CrabPotItemData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Winch.Data.Item
{
public class CrabPotItemData : GridConfigDeployableItemData
public class CrabPotItemData : GridConfigDeployableItemData, IAbilityItemData
{
[SerializeField]
public AbilityMode abilityMode = AbilityMode.POT;
Expand All @@ -13,6 +13,10 @@ public class CrabPotItemData : GridConfigDeployableItemData

[SerializeField]
public Sprite qualityIcon;

public AbilityMode AbilityMode => abilityMode;

public Sprite QualityIcon => qualityIcon;
}

public enum PotType
Expand Down
17 changes: 17 additions & 0 deletions Winch/Data/Item/IAbilityItemData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ActiveAbilityInfoPanel;
using UnityEngine;

namespace Winch.Data.Item
{
public interface IAbilityItemData
{
public AbilityMode AbilityMode { get; }

public Sprite QualityIcon { get; }
}
}
6 changes: 5 additions & 1 deletion Winch/Data/Item/TrawlNetItemData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Winch.Data.Item
{
public class TrawlNetItemData : GridConfigDeployableItemData
public class TrawlNetItemData : GridConfigDeployableItemData, IAbilityItemData
{
[SerializeField]
public AbilityMode abilityMode = AbilityMode.TRAWL;
Expand All @@ -17,5 +17,9 @@ public class TrawlNetItemData : GridConfigDeployableItemData

[SerializeField]
public Sprite qualityIcon;

public AbilityMode AbilityMode => abilityMode;

public Sprite QualityIcon => qualityIcon;
}
}
43 changes: 11 additions & 32 deletions Winch/Patches/API/ActiveAbilityInfoPanelPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using Winch.Data.Item;
using static ActiveAbilityInfoPanel;

namespace Winch.Patches.API
{
Expand All @@ -15,43 +16,21 @@ internal static class ActiveAbilityInfoPanelPatcher
[HarmonyPatch(nameof(ActiveAbilityInfoPanel.RefreshUI))]
public static bool ActiveAbilityInfoPanel_RefreshUI_Prefix(ActiveAbilityInfoPanel __instance, SpatialItemData spatialItemData, AbilityData abilityData)
{
if (abilityData.name == __instance.potAbility.name)
if (spatialItemData != null && spatialItemData is IAbilityItemData abilityItemData)
{
if (spatialItemData != null && spatialItemData is CrabPotItemData potData)
__instance.abilityMode = abilityItemData.AbilityMode;
if (abilityItemData.QualityIcon != null)
{
__instance.abilityMode = potData.abilityMode;
if (potData.qualityIcon != null)
{
__instance.qualityIcon.sprite = potData.qualityIcon;
}
else
{
__instance.qualityIcon.sprite = __instance.GetSpriteForAbilityMode(potData.abilityMode);
}
__instance.Show();
__instance.RefreshItemNameField(potData);
__instance.UpdateCatchableSpecies();
return false;
__instance.qualityIcon.sprite = abilityItemData.QualityIcon;
}
}
else if (abilityData.name == __instance.trawlAbility.name)
{
if (spatialItemData != null && spatialItemData is TrawlNetItemData trawlNetData)
else
{
__instance.abilityMode = trawlNetData.abilityMode;
if (trawlNetData.qualityIcon != null)
{
__instance.qualityIcon.sprite = trawlNetData.qualityIcon;
}
else
{
__instance.qualityIcon.sprite = __instance.GetSpriteForAbilityMode(trawlNetData.abilityMode);
}
__instance.Show();
__instance.RefreshItemNameField(trawlNetData);
__instance.UpdateCatchableSpecies();
return false;
__instance.qualityIcon.sprite = __instance.GetSpriteForAbilityMode(abilityItemData.AbilityMode);
}
__instance.Show();
__instance.RefreshItemNameField(spatialItemData);
__instance.UpdateCatchableSpecies();
return false;
}
return true;
}
Expand Down
6 changes: 2 additions & 4 deletions Winch/Util/WinchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,8 @@ public static bool IsItemHarvestable(this PlayerZoneDetector playerZoneDetector,

public static AbilityMode GetAbilityModeFromItemData(this SpatialItemData data)
{
if (data is TrawlNetItemData netData)
return netData.abilityMode;
else if (data is CrabPotItemData potData)
return potData.abilityMode;
if (data is IAbilityItemData abilityItemData)
return abilityItemData.AbilityMode;
else if (data.id == "tir-pot1")
return AbilityMode.POT_MATERIAL;
else if (data.itemSubtype == ItemSubtype.POT)
Expand Down

0 comments on commit 7840165

Please sign in to comment.