快速使用相关

This commit is contained in:
2025-11-19 00:08:25 +08:00
parent d18c32211c
commit dcd61c1a88
130 changed files with 687 additions and 58 deletions

View File

@@ -3,8 +3,10 @@
using UnityEngine;
using FairyGUI;
using Fantasy;
using Fantasy.Async;
using NBC;
using NBF.Utils;
using Log = NBC.Log;
namespace NBF
{
@@ -12,23 +14,35 @@ namespace NBF
{
public ItemInfo ItemInfo;
// private string iconStr;
private void OnInited()
{
draggable = true;
onDragStart.Add(context =>
{
context.PreventDefault();
DragDropManager.inst.StartDrag(this, this.icon, this.icon, (int)context.data);
});
onDragStart.Add(DragStart);
}
private void DragStart(EventContext context)
{
context.PreventDefault();
DragDropManager.inst.StartDrag(this, this.icon, this.icon, (int)context.data);
// icon = string.Empty;
}
public virtual void SetData(ItemInfo itemInfo)
{
draggable = false;
ItemInfo = itemInfo;
title = itemInfo.ConfigId.GetName();
this.SetIcon(itemInfo.ConfigId);
Quality.SetQuality(ItemInfo.Config.Quality);
this.SetTitleQuality(ItemInfo.Config.Quality);
// iconStr = icon;
}
public void UpdateIcon()
{
this.SetIcon(ItemInfo.ConfigId);
}
}
}

View File

@@ -11,19 +11,25 @@ namespace NBF
{
public const string URL = "ui://hxr7rc7puiwj1t";
public Controller showType;
public GImage back;
public GTextField TextIndex;
public GTextField TextCount;
public GImage Quality;
public GButton BtnRemove;
public GImage Add;
public override void ConstructFromXML(XML xml)
{
base.ConstructFromXML(xml);
showType = GetController("showType");
back = (GImage)GetChild("back");
TextIndex = (GTextField)GetChild("TextIndex");
TextCount = (GTextField)GetChild("TextCount");
Quality = (GImage)GetChild("Quality");
BtnRemove = (GButton)GetChild("BtnRemove");
Add = (GImage)GetChild("Add");
OnInited();
UILanguage.TrySetComponentLanguage(this);
}

View File

@@ -1,16 +1,78 @@
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
using System;
using UnityEngine;
using FairyGUI;
using Fantasy;
using NBC;
using NBF.Fishing2;
using NBF.Utils;
using Log = NBC.Log;
namespace NBF
{
public partial class BagSlotItem : GButton
{
public int Index { get; private set; }
public Action<int, long> OnChangeSlot;
private void OnInited()
{
onDrop.Add(context => { this.icon = (string)context.data; });
onDrop.Add(OnDrop);
BtnRemove.onClick.Set(OnRemove);
onClick.Add(OnClick);
}
private void OnClick()
{
if (showType.selectedIndex == 0)
{
// Notices.Info("拖拽放入");
}
}
private void OnRemove(EventContext context)
{
context.PreventDefault();
OnChangeSlot?.Invoke(Index, 0);
}
private void OnDrop(EventContext context)
{
var obj = context.initiator;
if (obj is BagItem bagItem)
{
Log.Info($"放下了:{bagItem.ItemInfo.Id}");
OnChangeSlot?.Invoke(Index, bagItem.ItemInfo.Id);
}
}
public void SetData(int index, ItemInfo itemInfo = null)
{
Index = index;
TextIndex.text = (index + 1).ToString();
if (itemInfo != null)
{
showType.selectedIndex = 1;
icon = itemInfo.ConfigId.GetIcon();
if (itemInfo.Count > 1)
{
TextCount.text = itemInfo.Count.ToString();
}
else
{
TextCount.text = string.Empty;
}
Quality.SetQuality(itemInfo.Config.Quality);
}
else
{
showType.selectedIndex = 0;
TextCount.text = string.Empty;
icon = string.Empty;
}
}
}
}

View File

@@ -24,6 +24,8 @@ namespace NBF
public GList SlotList;
[AutoFind(Name = "SlotSeparator")]
public GImage SlotSeparator;
[AutoFind(Name = "Test")]
public GLoader Test;
public override string[] GetDependPackages(){ return new string[] {"Common"}; }
public static void Show(object param = null){ App.UI.OpenUI<BagSlotPanel>(param); }

View File

@@ -14,24 +14,26 @@ namespace NBF
{
private List<ItemInfo> _items = new List<ItemInfo>();
private RoleBag _roleBag;
protected override void OnInit()
{
// List.SetVirtual();
}
protected override void OnShow()
{
var role = App.Main.GetComponent<Role>();
_roleBag = role.GetComponent<RoleBag>();
SetList();
SetSlotList();
}
#region
private void SetList()
{
var role = App.Main.GetComponent<Role>();
var roleBag = role.GetComponent<RoleBag>();
_items.Clear();
foreach (var roleBagItem in roleBag.Items)
foreach (var roleBagItem in _roleBag.Items)
{
if (CanShow(roleBagItem))
{
@@ -51,9 +53,41 @@ namespace NBF
if (obj is BagItem bagItem)
{
bagItem.SetData(itemData);
bagItem.draggable = true;
}
}
#endregion
#region
private void SetSlotList()
{
SlotList.RemoveChildrenToPool();
for (int index = 0; index < 7; index++)
{
if (SlotList.AddItemFromPool() is BagSlotItem slotItem)
{
slotItem.SetData(index, _roleBag.GetSlotItem(index));
slotItem.OnChangeSlot = OnChangeSlotItem;
}
}
}
private void OnChangeSlotItem(int index, long id)
{
_roleBag.SetSlot(index, id).OnCompleted(OnChangeSlotItemDone);
}
private void OnChangeSlotItemDone()
{
SetSlotList();
// SlotList.RefreshVirtualList();
}
#endregion
private bool CanShow(ItemInfo itemInfo)
{
if (itemInfo.ItemType == ItemType.Rod)

View File

@@ -25,6 +25,7 @@ namespace NBF
}
else
{
Log.Info($"LoadExternal={url}");
_texture = Resources.Load<Texture>(url);
if (_texture != null)
onExternalLoadSuccess(new NTexture(_texture));

View File

@@ -31,6 +31,7 @@ namespace NBF
await LoginHelper.Login(InputAccount.text);
BagPanel.Show();
// BagSlotPanel.Show();
// FishingShopPanel.Show();
Del();