少年修仙传客户端代码仓库
10268 【越南】【砍树】【英语】新增自选界面, 每个物品后面可自选数量
2个文件已修改
6个文件已添加
480 ■■■■■ 已修改文件
System/KnapSack/Logic/BoxGetItemModel.cs 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/KnapSack/New/ChooseItemsCell.cs 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/KnapSack/New/ChooseItemsCell.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/KnapSack/New/ChooseItemsModel.cs 197 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/KnapSack/New/ChooseItemsModel.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/KnapSack/New/ChooseItemsWin.cs 138 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/KnapSack/New/ChooseItemsWin.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/WindowBase/ModelCenter.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/KnapSack/Logic/BoxGetItemModel.cs
@@ -164,10 +164,11 @@
            bool isSelectItem = IsSelectItemByID(itemId, out selectDict);
            if (isSelectItem)
            {
                if (!WindowCenter.Instance.IsOpen<ChooseItemWin>())
                {
                    WindowCenter.Instance.Open<ChooseItemWin>();
                }
                ModelCenter.Instance.GetModel<ChooseItemsModel>().OpenChooseItemsWin(useCnt);
                //if (!WindowCenter.Instance.IsOpen<ChooseItemWin>())
                //{
                //    WindowCenter.Instance.Open<ChooseItemWin>();
                //}
                return;
            }
System/KnapSack/New/ChooseItemsCell.cs
New file
@@ -0,0 +1,102 @@
using UnityEngine;
using vnxbqy.UI;
public class ChooseItemsCell : CellView
{
    [SerializeField] ItemCell itemCell;
    [SerializeField] TextEx txtItemName;
    [SerializeField] TextEx txtNumber;
    [SerializeField] TextEx txtHaveCount;
    [SerializeField] ImageEx imgNeed;
    [SerializeField] ButtonEx btnNumber;
    [SerializeField] ButtonEx btnReduce;
    [SerializeField] ButtonEx btnPlus;
    int itemId;
    ChooseItemsModel model { get { return ModelCenter.Instance.GetModel<ChooseItemsModel>(); } }
    BoxGetItemModel boxModel { get { return ModelCenter.Instance.GetModel<BoxGetItemModel>(); } }
    PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
    public void Display(int itemID)
    {
        this.itemId = itemID;
        if (!boxModel.selectDict.ContainsKey(itemID))
            return;
        if (!ItemConfig.Has(itemID))
            return;
        ItemConfig itemConfig = ItemConfig.Get(itemID);
        int count = boxModel.selectDict[itemID];
        itemCell.Init(new ItemCellModel(itemID, false, (ulong)count));
        itemCell.button.SetListener(() =>
        {
            if (ItemLogicUtility.Instance.IsRealmEquip(itemID))
            {
                ItemTipUtility.Show(new ItemTipUtility.ItemViewInfo()
                {
                    itemId = itemID,
                    compare = true
                });
            }
            else
            {
                ItemTipUtility.Show(itemID);
            }
        });
        txtItemName.text = itemConfig.ItemName;
        txtItemName.color = UIHelper.GetUIColor(itemConfig.ItemColor, true);
        txtNumber.text = model.userChooseItemDict.ContainsKey(itemID) ? model.userChooseItemDict[itemID].useCnt.ToString() : 0.ToString();
        if (itemConfig.Effect1 == 220)
        {
            this.itemId = itemConfig.EffectValueA1;
        }
        var packType = GeneralDefine.GetPackTypeByItemType(itemConfig.Type);
        int haveCnt = 0;
        switch (packType)
        {
            case PackType.RunePack:
            case PackType.GatherSoul:
                haveCnt = ModelCenter.Instance.GetModel<VirtualPackModel>().GetItemCountById(packType, itemId);
                break;
            default:
                haveCnt = packModel.GetItemCountByID(packType, itemId) + packModel.GetItemCountByID(PackType.Equip, itemId);
                break;
        }
        txtHaveCount.text = haveCnt.ToString();
        imgNeed.SetActive(ItemLogicUtility.Instance.IsSatisfyEquipBetterEquip(itemId));
        btnPlus.SetListener(OnClickPlus);
        btnReduce.SetListener(OnClickReduce);
        btnNumber.SetListener(OnClickNumber);
    }
    void OnClickPlus()
    {
        ItemModel itemModel = packModel.GetItemByGuid(boxModel.guid);
        if (itemModel == null)
            return;
        if (model.GetNowChooseItemCount() >= model.totalItemCount)
            return;
        model.IncreaseUserChooseItemCount(itemId, itemModel.guid, itemId, true);
    }
    void OnClickReduce()
    {
        ItemModel itemModel = packModel.GetItemByGuid(boxModel.guid);
        if (itemModel == null)
            return;
        if (!model.userChooseItemDict.ContainsKey(itemId))
            return;
        if (model.userChooseItemDict[itemId].useCnt <= 0)
            return;
        model.IncreaseUserChooseItemCount(itemId, itemModel.guid, itemId, false);
    }
    void OnClickNumber()
    {
        model.chooseKeyBoardItemId = itemId;
        model.openKeyBoardAction?.Invoke();
    }
}
System/KnapSack/New/ChooseItemsCell.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 00b242c72c102d747a3339e7260f8aba
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
System/KnapSack/New/ChooseItemsModel.cs
New file
@@ -0,0 +1,197 @@
using System;
using System.Collections.Generic;
using vnxbqy.UI;
public class ChooseItems
{
    public string guid;
    public int useCnt;
    public int extra;
}
public class ChooseItemsModel : Model
{
    public int openBoxCount = 0;      // 开启x个宝箱
    public int boxChooseCount = 0;    // 每个宝箱可以在列表中选择x个
    public int totalItemCount = 0;   // 总共能选x个材料
    public int chooseKeyBoardItemId = 0;    //当前键盘输入哪个ItemId的数量
    //<物品ID,数量>  用户选中物品字典
    public Dictionary<int, ChooseItems> userChooseItemDict = new Dictionary<int, ChooseItems>();
    public Dictionary<int, int> showDict = new Dictionary<int, int>();
    public Action countChangeAction;    //数量发生变化
    public Action openKeyBoardAction;
    BoxGetItemModel boxModel { get { return ModelCenter.Instance.GetModel<BoxGetItemModel>(); } }
    PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
    public override void Init()
    {
    }
    public override void UnInit()
    {
    }
    public int GetAllOtherCount()
    {
        int count = 0;
        List<int> list = new List<int>(userChooseItemDict.Keys);
        for (int i = 0; i < list.Count; i++)
        {
            int itemId = list[i];
            if (!ItemConfig.Has(itemId))
                continue;
            if (itemId == chooseKeyBoardItemId)
                continue;
            count += userChooseItemDict[itemId].useCnt;
        }
        return count;
    }
    public void TryKeyBoardWrite(int value)
    {
        ItemModel itemModel = packModel.GetItemByGuid(boxModel.guid);
        if (itemModel == null)
            return;
        if (GetNowChooseItemCount() >= totalItemCount)
            return;
        if (GetAllOtherCount() + value > totalItemCount)
            return;
        UpdateUserChooseItemDict(boxModel.itemId, itemModel.guid, value, boxModel.itemId);
    }
    // isIncrease 为 true,useCnt +1
    // isIncrease 为 false,useCnt -1
    public void IncreaseUserChooseItemCount(int itemId, string guid, int extra, bool isIncrease)
    {
        if (userChooseItemDict.ContainsKey(itemId))
        {
            userChooseItemDict[itemId].guid = guid;
            userChooseItemDict[itemId].useCnt = isIncrease ? userChooseItemDict[itemId].useCnt + 1 : userChooseItemDict[itemId].useCnt - 1;
            userChooseItemDict[itemId].extra = extra;
        }
        else
        {
            userChooseItemDict[itemId] = new ChooseItems() { guid = guid, useCnt = 1, extra = extra };
        }
        countChangeAction?.Invoke();
    }
    public void UpdateUserChooseItemDict(int itemId, string guid, int useCnt, int extra)
    {
        if (userChooseItemDict.ContainsKey(itemId))
        {
            userChooseItemDict[itemId].guid = guid;
            userChooseItemDict[itemId].useCnt = useCnt;
            userChooseItemDict[itemId].extra = itemId;
        }
        else
        {
            userChooseItemDict[itemId] = new ChooseItems() { guid = guid, useCnt = useCnt, extra = extra };
        }
        countChangeAction?.Invoke();
    }
    //当前选择材料总数量
    public int GetNowChooseItemCount()
    {
        int total = 0;
        if (userChooseItemDict == null && userChooseItemDict.Count == 0)
            return 0;
        List<int> list = new List<int>(userChooseItemDict.Keys);
        for (int i = 0; i < list.Count; i++)
            total += userChooseItemDict[list[i]].useCnt;
        return total;
    }
    public List<int> GetShowList()
    {
        List<int> showList = new List<int>(showDict.Keys);
        showList.Sort(SortShowItem);
        return showList;
    }
    int SortShowItem(int a, int b)
    {
        int quality1 = ItemConfig.Get(a).ItemColor;
        int quality2 = ItemConfig.Get(b).ItemColor;
        //品质高的排在前面
        if (quality1 != quality2)
            return quality2.CompareTo(quality1);
        return 0;
    }
    public bool TrySendUse()
    {
        List<ChooseItems> chooseItemList = GetSendList(userChooseItemDict);
        //一个材料也没选
        if (chooseItemList.Count < 1)
        {
            SysNotifyMgr.Instance.ShowTip("ChooseItems01");
            return false;
        }
        for (int i = 0; i < chooseItemList.Count; i++)
            ItemOperateUtility.Instance.UseItem(chooseItemList[i].guid, chooseItemList[i].useCnt, chooseItemList[i].extra);
        return true;
    }
    List<ChooseItems> GetSendList(Dictionary<int, ChooseItems> userChooseItemDict)
    {
        List<int> list = new List<int>(userChooseItemDict.Keys);
        List<ChooseItems> result = new List<ChooseItems>();
        for (int i = 0; i < list.Count; i++)
        {
            int itemId = list[i];
            ChooseItems chooseItems = userChooseItemDict[itemId];
            if (!ItemConfig.Has(itemId))
                continue;
            if (chooseItems == null || chooseItems.useCnt <= 0)
                continue;
            result.Add(chooseItems);
        }
        return result;
    }
    void ClearAll()
    {
        openBoxCount = 0;
        boxChooseCount = 0;
        totalItemCount = 0;
        userChooseItemDict.Clear();
        showDict.Clear();
    }
    bool TryInitData()
    {
        ClearAll();
        if (boxModel.selectDict == null)
            return false;
        List<int> selectList = new List<int>(boxModel.selectDict.Keys);
        for (int i = 0; i < selectList.Count; i++)
        {
            int nowItemId = selectList[i];
            if (!ItemConfig.Has(nowItemId))
                continue;
            ItemConfig config = ItemConfig.Get(nowItemId);
            // 宝箱根据境界自选,如果展示的境界装备则全显示
            if (config.LV == 1 && Math.Max(PlayerDatas.Instance.baseData.realmLevel + 4, 5) < config.RealmLimit)
                continue;
            showDict[nowItemId] = boxModel.selectDict[nowItemId];
        }
        return true;
    }
    // openBoxCount 开几个宝箱 boxChooseCount 开启宝箱后在列表中能选几个
    public void OpenChooseItemsWin(int openBoxCount = 1, int boxChooseCount = 1)
    {
        if (!TryInitData())
            return;
        this.openBoxCount = openBoxCount;
        this.boxChooseCount = boxChooseCount;
        totalItemCount = openBoxCount * boxChooseCount;
        WindowCenter.Instance.Open<ChooseItemsWin>();
    }
}
System/KnapSack/New/ChooseItemsModel.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2370da43754168b48bb25a75717343a7
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
System/KnapSack/New/ChooseItemsWin.cs
New file
@@ -0,0 +1,138 @@
using vnxbqy.UI;
using UnityEngine;
using UnityEngine.UI;
public class ChooseItemsWin : Window
{
    [SerializeField] TextEx txtName;
    [SerializeField] TextEx txtChooseNum;
    [SerializeField] ButtonEx btnClose;
    [SerializeField] ButtonEx btnUse;
    [SerializeField] ScrollerController scroller;
    [SerializeField] NumKeyBoard numKeyboard;
    [SerializeField] Transform clickOther;
    ChooseItemsModel model { get { return ModelCenter.Instance.GetModel<ChooseItemsModel>(); } }
    BoxGetItemModel boxModel { get { return ModelCenter.Instance.GetModel<BoxGetItemModel>(); } }
    PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
    protected override void BindController()
    {
        btnClose.SetListener(OnClickClose);
        btnUse.SetListener(OnClickUse);
        numKeyboard.onConfirm.AddListener(OnClickConfirmBtn);
        numKeyboard.onValueChange.AddListener(OnClickNum);
    }
    private void OnClickConfirmBtn(bool arg0)
    {
        if (arg0)
        {
            numKeyboard.SetActive(false);
            model.countChangeAction?.Invoke();
        }
    }
    private void OnClickNum()
    {
        ItemModel itemModel = packModel.GetItemByGuid(boxModel.guid);
        if (itemModel == null)
            return;
        int useNum = int.Parse(numKeyboard.Value);
        if (model.GetAllOtherCount() + useNum > model.totalItemCount)
        {
            useNum = model.totalItemCount - model.GetAllOtherCount();
            ServerTipDetails.DisplayNormalTip(Language.Get("MaxUseNum"));
        }
        numKeyboard.Value = useNum.ToString();
        model.UpdateUserChooseItemDict(model.chooseKeyBoardItemId, itemModel.guid, int.Parse(numKeyboard.Value), model.chooseKeyBoardItemId);
    }
    protected override void OnPreOpen()
    {
        model.countChangeAction += OnCountChangeAction;
        model.openKeyBoardAction += OnOpenKeyBoardAction;
        scroller.OnRefreshCell += OnRefreshCell;
        numKeyboard.SetActive(false);
        clickOther.SetActive(false);
        Display();
    }
    protected override void OnPreClose()
    {
        model.countChangeAction -= OnCountChangeAction;
        model.openKeyBoardAction -= OnOpenKeyBoardAction;
        scroller.OnRefreshCell -= OnRefreshCell;
    }
    private void OnOpenKeyBoardAction()
    {
        clickOther.SetActive(true);
        numKeyboard.SetActive(true);
    }
    private void OnCountChangeAction()
    {
        scroller.m_Scorller.RefreshActiveCellViews();
        Display();
    }
    protected override void OnAfterOpen()
    {
        CreateScroller();
    }
    protected override void OnAfterClose()
    {
    }
    protected override void AddListeners()
    {
    }
    private void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell as ChooseItemsCell;
        _cell.Display(_cell.index);
    }
    void Display()
    {
        if (!ItemConfig.Has(boxModel.itemId))
            return;
        ItemConfig itemConfig = ItemConfig.Get(boxModel.itemId);
        txtName.text = itemConfig.ItemName;
        txtName.color = UIHelper.GetUIColor(itemConfig.ItemColor, true);
        int nowChooseItemCount = model.GetNowChooseItemCount();
        int totalItemCount = model.totalItemCount;
        txtChooseNum.text = Language.Get("BlessedLand036", nowChooseItemCount, totalItemCount);
        txtChooseNum.colorType = nowChooseItemCount <= totalItemCount ? TextColType.DarkGreen : TextColType.Red;
    }
    void CreateScroller()
    {
        var list = model.GetShowList();
        scroller.Refresh();
        for (int i = 0; i < list.Count; i++)
        {
            scroller.AddCell(ScrollerDataType.Header, list[i]);
        }
        scroller.Restart();
    }
    void OnClickUse()
    {
        if (model.TrySendUse())
        {
            CloseImmediately();
        }
    }
    void OnClickClose()
    {
        CloseImmediately();
    }
}
System/KnapSack/New/ChooseItemsWin.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 46c1be6aef3343e4093c4968ebe3bc29
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
System/WindowBase/ModelCenter.cs
@@ -277,6 +277,7 @@
            RegisterModel<PetHorseActModel>();
            RegisterModel<MountedPetZhanLingModel>();
            RegisterModel<TreasurePavilionRankActModel>();
            RegisterModel<ChooseItemsModel>();
            inited = true;
        }