快速使用相关
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
6
Assets/Scripts/UI/Bag/BagSlotItem.Designer.cs
generated
6
Assets/Scripts/UI/Bag/BagSlotItem.Designer.cs
generated
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/Bag/BagSlotPanel.Designer.cs
generated
2
Assets/Scripts/UI/Bag/BagSlotPanel.Designer.cs
generated
@@ -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); }
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace NBF
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Info($"LoadExternal={url}");
|
||||
_texture = Resources.Load<Texture>(url);
|
||||
if (_texture != null)
|
||||
onExternalLoadSuccess(new NTexture(_texture));
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace NBF
|
||||
await LoginHelper.Login(InputAccount.text);
|
||||
|
||||
BagPanel.Show();
|
||||
// BagSlotPanel.Show();
|
||||
// FishingShopPanel.Show();
|
||||
|
||||
Del();
|
||||
|
||||
Reference in New Issue
Block a user