Skip to content

Commit

Permalink
New logic for fence variation encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
berichan committed Nov 9, 2021
1 parent 8c07227 commit 27e6c0f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 27 deletions.
20 changes: 15 additions & 5 deletions ACNHMS_Source/Assets/Scripts/ACNHMS/UI_SearchWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public void UpdateSprite()
{
if (CurrentItemID < 0)
return;
Texture2D toSet = SpriteBehaviour.ItemToTexture2D(Convert.ToUInt16(CurrentItemID), Convert.ToUInt16(SetController.FCount.text), out var col);

var toUseVariation = ItemInfo.GetItemKind(Convert.ToUInt16(CurrentItemID)) == ItemKind.Kind_Fence ? SetController.FUses.text : SetController.FCount.text;
Debug.Log(toUseVariation);
Texture2D toSet = SpriteBehaviour.ItemToTexture2D(Convert.ToUInt16(CurrentItemID), Convert.ToUInt16(toUseVariation), out var col);
SpriteImageMain.texture = toSet;
col.a = toSet == null ? 0.0f : 0.75f;
SpriteImageMain.color = col;
Expand Down Expand Up @@ -294,7 +297,8 @@ public void SelectItem(ItemFilter itemF, int id, UI_SearchItem sItem)
}

CurrentSelectedIndex = spawnedObjects.IndexOf(sItem);
if (ItemInfo.GetItemKind(Convert.ToUInt16(CurrentItemID)).IsFlowerGene())
var itemKind = ItemInfo.GetItemKind(Convert.ToUInt16(CurrentItemID));
if (itemKind.IsFlowerGene())
{
FlowerButtonRoot.SetActive(true);
}
Expand All @@ -309,11 +313,13 @@ public void SelectItem(ItemFilter itemF, int id, UI_SearchItem sItem)
else
TreeButtonRoot.gameObject.SetActive(false);*/ //uncomment this if you want star tree editor again for whatever reason



SetController.SpawnVariationsButton.gameObject.SetActive(false);
short remakeIndex = ItemRemakeUtil.GetRemakeIndex(Convert.ToUInt16(CurrentItemID));
if (remakeIndex < 0)
{
SetController.CreateBody(new string[0]);
SetController.CreateBody(new string[0], false);
SetController.CreateFabric(new string[0]);
}
else
Expand All @@ -328,11 +334,11 @@ public void SelectItem(ItemFilter itemF, int id, UI_SearchItem sItem)
"\r",
"\n"
}, StringSplitOptions.None);
SetController.CreateBody(values);
SetController.CreateBody(values, itemKind == ItemKind.Kind_Fence);
}
else
{
SetController.CreateBody(new string[0]);
SetController.CreateBody(new string[0], itemKind == ItemKind.Kind_Fence);
}
string fabricSummary = itemRemakeInfo.GetFabricSummary(GameInfo.Strings, false, false);
if (fabricSummary.Length != 0)
Expand Down Expand Up @@ -416,6 +422,10 @@ public void LoadItem(Item item)
else
{
SetController.FCount.text = item.Count.ToString();

if (itemKind == ItemKind.Kind_Fence)
SetController.FUses.text = item.UseCount.ToString();

SetController.CompileBodyFabricFromCount();
SetController.FUses.text = item.UseCount.ToString();
SetController.FFlagZero.text = item.SystemParam.ToString();
Expand Down
59 changes: 39 additions & 20 deletions ACNHMS_Source/Assets/Scripts/ACNHMS/UI_SetControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ public class UI_SetControl : MonoBehaviour
private float maxStackIntervalTimer = -1;
private int maxStackTapCount = 0;

private Vector3 bCountStartPos;
private Vector3 bCountFencePos;
private bool fenceMode = false;

public static int CurrentVariationCount = 0;

private void Start()
{
bCountStartPos = BCount.transform.position;
bCountFencePos = BUses.transform.position;
BCount.onValueChanged.AddListener(delegate
{
CompileCountFromBodyFabric();
Expand Down Expand Up @@ -119,25 +125,25 @@ public void CompileBodyFabricFromCount() // probably unreadable now due to il re
{
return;
}
int num = int.Parse(FCount.text);
int num2 = -1;
int num3 = -1;
int variation = fenceMode ? int.Parse(FUses.text) : int.Parse(FCount.text);
int selectedVariation = -1;
int selectedFabricVariation = -1;
List<int> list = new List<int>();
if (BCount.gameObject.activeInHierarchy) // if off, this doesn't have any body values
{
for (int i = 0; i < BCount.options.Count; i++)
{
int num4 = int.Parse(GetUntilOrEmpty(BCount.options[i].text));
list.Add(num4);
if (num4 == num)
if (num4 == variation)
{
num2 = i;
}
selectedVariation = i;
}
}
}
if (num2 != -1)
if (selectedVariation != -1)
{
BCount.value=(num2);
BCount.value=selectedVariation;
BCount.RefreshShownValue();
}
if (!BUses.gameObject.activeSelf)
Expand All @@ -149,33 +155,33 @@ public void CompileBodyFabricFromCount() // probably unreadable now due to il re
{
int num5 = int.Parse(GetUntilOrEmpty(BUses.options[j].text));
list2.Add(num5);
if (num5 == num)
if (num5 == variation)
{
num3 = j;
selectedFabricVariation = j;
}
}
if (num3 != -1)
if (selectedFabricVariation != -1)
{
BCount.value=(0);
BCount.value=0;
BCount.RefreshShownValue();
BUses.value=(num3);
BUses.value=(selectedFabricVariation);
BUses.RefreshShownValue();
return;
}
int num6 = 0;
for (int k = 0; k < list2.Count; k++)
{
if (list2[k] > num6 && list2[k] < num)
if (list2[k] > num6 && list2[k] < variation)
{
num6 = list2[k];
}
}
BUses.value=list2.IndexOf(num6);
BUses.RefreshShownValue();
if (num6 == 0)
BCount.value = num;
BCount.value = variation;
else
BCount.value=(num % num6);
BCount.value=(variation % num6);
BCount.RefreshShownValue();
}

Expand All @@ -191,21 +197,31 @@ public void CompileCountFromBodyFabric()
{
num += result;
}
FCount.text=(num.ToString());

if (!fenceMode)
FCount.text = num.ToString();
else
FUses.text = num.ToString();
}

public void CreateBody(string[] values)
public void CreateBody(string[] values, bool fence)
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
fenceMode = fence;
if (values.Length == 0)
{
FCount.gameObject.SetActive(true);
BCount.gameObject.SetActive(false);
return;
}
values = values.TruncateEndInvalidValues();
FCount.gameObject.SetActive(false);

if (!fenceMode)
FCount.gameObject.SetActive(false);
else
FUses.gameObject.SetActive(false);

BCount.gameObject.SetActive(true);
BCount.ClearOptions();
foreach (string text in values)
Expand All @@ -222,6 +238,8 @@ public void CreateBody(string[] values)

CurrentVariationCount = BCount.options.Count;
SpawnVariationsButton.gameObject.SetActive(true);

BCount.transform.position = fenceMode ? bCountFencePos : bCountStartPos;
}

public void CreateFabric(string[] values)
Expand All @@ -230,7 +248,8 @@ public void CreateFabric(string[] values)
//IL_006c: Expected O, but got Unknown
if (values.Length == 0 || values.IsInvalidFabricArray())
{
FUses.gameObject.SetActive(true);
if (!fenceMode)
FUses.gameObject.SetActive(true);
BUses.gameObject.SetActive(false);
return;
}
Expand Down
9 changes: 7 additions & 2 deletions ACNHMS_Source/Assets/Scripts/SpriteLoading/SpriteBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,12 @@ static void InitParser(bool force = false)

public static Texture2D ItemToTexture2D(ushort itemId, ushort count, out Color c)
{
var isFence = ItemInfo.GetItemKind(Convert.ToUInt16(itemId)) == ItemKind.Kind_Fence;
Item tempItem = new Item(itemId);
tempItem.Count = count;
if (!isFence)
tempItem.Count = count;
else
tempItem.UseCount = count;
return ItemToTexture2D(tempItem, out c);
}

Expand Down Expand Up @@ -260,7 +264,8 @@ public static Texture2D ItemToTexture2D(Item tr, out Color c)
if (SpritesExist())
{
InitParser();
var tx = SpriteParser.CurrentInstance.GetTexture(t.ItemId, t.Count);
ItemKind itemKind = ItemInfo.GetItemKind(Convert.ToUInt16(t.ItemId));
var tx = SpriteParser.CurrentInstance.GetTexture(t.ItemId, itemKind == ItemKind.Kind_Fence ? t.UseCount : t.Count);
if (tx != null)
{
toAssignImage = tx;
Expand Down

0 comments on commit 27e6c0f

Please sign in to comment.