Skip to content

Commit

Permalink
Merge pull request #6846 from planetarium/feature/synthesis-polishing
Browse files Browse the repository at this point in the history
Feature/synthesis polishing
  • Loading branch information
eugene-doobu authored Feb 10, 2025
2 parents 8f148ac + 4e66a92 commit c60ab3f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
21 changes: 21 additions & 0 deletions nekoyume/Assets/_Scripts/UI/Model/SynthesizeModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Nekoyume.Model.EnumType;
using Nekoyume.Model.Item;

Expand All @@ -17,5 +18,25 @@ public SynthesizeModel(Grade grade, ItemSubType itemSubType, int inventoryItemCo
InventoryItemCount = inventoryItemCount;
RequiredItemCount = requiredItemCount;
}

public static bool operator ==(SynthesizeModel obj1, SynthesizeModel obj2)
{
if (obj1 is null)
{
return obj2 is null;
}

if (obj2 is null)
{
return false;
}

return obj1.Grade == obj2.Grade && obj1.ItemSubType == obj2.ItemSubType;
}

public static bool operator!= (SynthesizeModel obj1, SynthesizeModel obj2)
{
return !(obj1 == obj2);
}
}
}
15 changes: 4 additions & 11 deletions nekoyume/Assets/_Scripts/UI/Module/SynthesisInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class SynthesisInventory : MonoBehaviour
private SynthesizeModel? _selectedModel;
private Action<InventoryItem>? _onClickItem;

private readonly List<IDisposable> _disposables = new();
private readonly List<InventoryItem> _items = new();

private List<InventoryItem>? _cachedInventoryItems;
Expand Down Expand Up @@ -57,21 +56,15 @@ private void Awake()
.AddTo(gameObject);
}

private void OnEnable()
public void UpdateInventory()
{
ReactiveAvatarState.Inventory
.Subscribe(UpdateInventory)
.AddTo(_disposables);
}

private void OnDisable()
{
_disposables.DisposeAllAndClear();
ClearSelectedItems();
var inventory = Game.Game.instance.States.CurrentAvatarState.inventory;
UpdateInventory(inventory);
}

public void Show(SynthesizeModel requiredItem)
{
ClearSelectedItems();
_selectedModel = requiredItem;
_cachedInventoryItems = GetModels(requiredItem);
scroll.UpdateData(_cachedInventoryItems, true);
Expand Down
3 changes: 3 additions & 0 deletions nekoyume/Assets/_Scripts/UI/Module/SynthesisModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ private void ClearScrollData()

numberSynthesisText.text = L10nManager.Localize("UI_NUMBER_SYNTHESIS", 0);
successRateText.text = L10nManager.Localize("UI_SYNTHESIZE_SUCCESS_RATE", 0);

var registrationPopup = Widget.Find<SynthesisRegistrationPopup>();
registrationPopup.Clear();
}

private void SetSynthesisButtonState(bool possibleSynthesis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class SynthesisRegistrationPopup : PopupWidget

private SynthesizeModel? _synthesizeModel;

public bool HasModel(SynthesizeModel model) => _synthesizeModel != null && _synthesizeModel == model;

#region MonoBehaviour

protected override void Awake()
Expand Down Expand Up @@ -204,6 +206,15 @@ public void Show(
Action<IList<InventoryItem>, SynthesizeModel> registerAction,
bool ignoreShowAnimation = false)
{
var isSameModel = _synthesizeModel == model;
if (isSameModel)
{
base.Show(ignoreShowAnimation);
_registerMaterials = registerAction;
synthesisInventory.Show(model);
return;
}

_synthesizeModel = model;
_registerMaterials = registerAction;

Expand All @@ -213,6 +224,14 @@ public void Show(
SetHeaderText(model);

synthesisInventory.Show(model);
synthesisInventory.UpdateInventory();
}

public void Clear()
{
_registerMaterials = null;
_synthesizeModel = null;
synthesisInventory.UpdateInventory();
}

private void SetAutoSelectButtonText(SynthesizeModel model)
Expand Down Expand Up @@ -267,7 +286,11 @@ private void ShowItemTooltip(InventoryItem item)
return;
}

equipmentTooltip.Show(item, string.Empty, false, null);
if (equipmentTooltip.gameObject.activeSelf)
{
equipmentTooltip.Show(item, string.Empty, false, null);
}

equipmentTooltip.OnEnterButtonArea(true);
}

Expand Down
5 changes: 3 additions & 2 deletions nekoyume/Assets/_Scripts/UI/Widget/Workshop/Synthesis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ public void OnClickGradeItem(SynthesizeModel? model)
return;
}

System.Action showRegistrationPopup = () => Find<SynthesisRegistrationPopup>().Show(model, RegisterItems);
var registrationPopup = Find<SynthesisRegistrationPopup>();
System.Action showRegistrationPopup = () => registrationPopup.Show(model, RegisterItems);

if (synthesisModule.PossibleSynthesis)
if (synthesisModule.PossibleSynthesis && !registrationPopup.HasModel(model))
{
Find<TwoButtonSystem>().Show(
L10nManager.Localize("UI_SYNTHESIZE_MATERIAL_CHANGE"),
Expand Down

0 comments on commit c60ab3f

Please sign in to comment.