| | |
| | | //-------------------------------------------------------- |
| | | // [Author]: 第二世界 |
| | | // [ Date ]: Sunday, January 21, 2018 |
| | | //-------------------------------------------------------- |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using TableConfig; |
| | | |
| | | namespace Snxxz.UI |
| | | { |
| | | |
| | | public class ItemUseModel : Model, IBeforePlayerDataInitialize, ISwitchAccount |
| | | { |
| | | Dictionary<string, UseItem> itemStack = new Dictionary<string, UseItem>(); |
| | | List<string> itemGuids = new List<string>(); |
| | | |
| | | PlayerPackModel playerPack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } } |
| | | PackModelInterface modelInterface { get { return ModelCenter.Instance.GetModel<PackModelInterface>(); } } |
| | | DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } } |
| | | |
| | | public UseItem currentShowItem { get; private set; } |
| | | public event Action showItemRefreshEvent; |
| | | |
| | | public override void Init() |
| | | { |
| | | playerPack.RefreshPackAct += OnPackageRefresh; |
| | | playerPack.RefreshItemCountAct += OnPackageItemRefresh; |
| | | playerPack.itemUseAct += OnGetUseItem; |
| | | } |
| | | |
| | | public override void UnInit() |
| | | { |
| | | playerPack.RefreshPackAct -= OnPackageRefresh; |
| | | playerPack.RefreshItemCountAct -= OnPackageItemRefresh; |
| | | playerPack.itemUseAct -= OnGetUseItem; |
| | | } |
| | | |
| | | public void OnBeforePlayerDataInitialize() |
| | | { |
| | | } |
| | | |
| | | public void OnSwitchAccount() |
| | | { |
| | | currentShowItem = default(UseItem); |
| | | } |
| | | |
| | | public bool TryGetItem(string _guid, out UseItem _itemModel) |
| | | { |
| | | return itemStack.TryGetValue(_guid, out _itemModel); |
| | | } |
| | | |
| | | public void ReportConfirmUseItem(UseItem _UseItem) |
| | | { |
| | | if (itemGuids.Contains(_UseItem.guid)) |
| | | { |
| | | itemGuids.Remove(_UseItem.guid); |
| | | } |
| | | |
| | | if (itemStack.ContainsKey(_UseItem.guid)) |
| | | { |
| | | itemStack.Remove(_UseItem.guid); |
| | | } |
| | | |
| | | RefreshCurrrentShowUseItem(); |
| | | } |
| | | |
| | | public int GetShowItemId() |
| | | { |
| | | if (currentShowItem == default(UseItem)) |
| | | { |
| | | return 0; |
| | | } |
| | | else |
| | | { |
| | | var item = playerPack.GetItemModelByGUID(currentShowItem.guid); |
| | | return item == null ? 0 : item.chinItemModel.ID; |
| | | } |
| | | } |
| | | |
| | | private void OnGetUseItem(PackType type, string guid) |
| | | { |
| | | var UseItem = new UseItem(type, guid); |
| | | if (!itemGuids.Contains(guid)) |
| | | { |
| | | itemGuids.Add(guid); |
| | | } |
| | | |
| | | itemStack[guid] = UseItem; |
| | | |
| | | RefreshCurrrentShowUseItem(); |
| | | } |
| | | |
| | | private void OnPackageRefresh(PackType _type) |
| | | { |
| | | if (_type != PackType.rptItem) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | RefreshCurrrentShowUseItem(); |
| | | } |
| | | |
| | | private void OnPackageItemRefresh(PackType _type, int _index, int _itemId) |
| | | { |
| | | OnPackageRefresh(_type); |
| | | } |
| | | |
| | | private bool FindLatestItem(out UseItem _item) |
| | | { |
| | | if (itemGuids.Count == 0) |
| | | { |
| | | _item = default(UseItem); |
| | | return false; |
| | | } |
| | | |
| | | var guid = itemGuids[itemGuids.Count - 1]; |
| | | _item = itemStack[guid]; |
| | | return true; |
| | | } |
| | | |
| | | private void Trim() |
| | | { |
| | | for (int i = itemGuids.Count - 1; i >= 0; i--) |
| | | { |
| | | var item = itemStack[itemGuids[i]]; |
| | | if (playerPack.GetItemModelByGUID(item.guid) == null |
| | | || playerPack.GetItemModelByGUID(item.guid).packType != PackType.rptItem) |
| | | { |
| | | itemGuids.RemoveAt(i); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void RefreshCurrrentShowUseItem() |
| | | { |
| | | Trim(); |
| | | |
| | | UseItem tempItem; |
| | | if (FindLatestItem(out tempItem)) |
| | | { |
| | | if (tempItem != currentShowItem) |
| | | { |
| | | currentShowItem = tempItem; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | currentShowItem = default(UseItem); |
| | | } |
| | | |
| | | if (showItemRefreshEvent != null) |
| | | { |
| | | showItemRefreshEvent(); |
| | | } |
| | | } |
| | | |
| | | public bool ShowUseItemAble() |
| | | { |
| | | var mapId = PlayerDatas.Instance.baseData.MapID; |
| | | var lineId = PlayerDatas.Instance.baseData.dungeonLineId; |
| | | var dungeonId = dungeonModel.DungeonMap(dungeonModel.GetDungeonDataIdByMapId(mapId), lineId); |
| | | if (dungeonId == 0) |
| | | { |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | var config = ConfigManager.Instance.GetTemplate<DungeonConfig>(dungeonId); |
| | | return config.ShowNewItemTip == 1; |
| | | } |
| | | } |
| | | |
| | | |
| | | public struct UseItem |
| | | { |
| | | public PackType packType; |
| | | public string guid; |
| | | |
| | | public UseItem(PackType _packType, string _guid) |
| | | { |
| | | this.packType = _packType; |
| | | this.guid = _guid; |
| | | } |
| | | |
| | | public static bool operator ==(UseItem _lhs, UseItem _rhs) |
| | | { |
| | | return _lhs.packType == _rhs.packType && _lhs.guid == _rhs.guid; |
| | | } |
| | | |
| | | public static bool operator !=(UseItem _lhs, UseItem _rhs) |
| | | { |
| | | return _lhs.packType != _rhs.packType || _lhs.guid != _rhs.guid; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | //--------------------------------------------------------
|
| | | // [Author]: 第二世界
|
| | | // [ Date ]: Sunday, January 21, 2018
|
| | | //--------------------------------------------------------
|
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using TableConfig;
|
| | |
|
| | | namespace Snxxz.UI
|
| | | {
|
| | |
|
| | | public class ItemUseModel : Model, IBeforePlayerDataInitialize, ISwitchAccount
|
| | | {
|
| | | Dictionary<string, UseItem> itemStack = new Dictionary<string, UseItem>();
|
| | | List<string> itemGuids = new List<string>();
|
| | |
|
| | | PlayerPackModel playerPack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
|
| | | PackModelInterface modelInterface { get { return ModelCenter.Instance.GetModel<PackModelInterface>(); } }
|
| | | DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
| | |
|
| | | public UseItem currentShowItem { get; private set; }
|
| | | public event Action showItemRefreshEvent;
|
| | |
|
| | | public override void Init()
|
| | | {
|
| | | playerPack.RefreshPackAct += OnPackageRefresh;
|
| | | playerPack.RefreshItemCountAct += OnPackageItemRefresh;
|
| | | playerPack.itemUseAct += OnGetUseItem;
|
| | | }
|
| | |
|
| | | public override void UnInit()
|
| | | {
|
| | | playerPack.RefreshPackAct -= OnPackageRefresh;
|
| | | playerPack.RefreshItemCountAct -= OnPackageItemRefresh;
|
| | | playerPack.itemUseAct -= OnGetUseItem;
|
| | | }
|
| | |
|
| | | public void OnBeforePlayerDataInitialize()
|
| | | {
|
| | | }
|
| | |
|
| | | public void OnSwitchAccount()
|
| | | {
|
| | | currentShowItem = default(UseItem);
|
| | | }
|
| | |
|
| | | public bool TryGetItem(string _guid, out UseItem _itemModel)
|
| | | {
|
| | | return itemStack.TryGetValue(_guid, out _itemModel);
|
| | | }
|
| | |
|
| | | public void ReportConfirmUseItem(UseItem _UseItem)
|
| | | {
|
| | | if (itemGuids.Contains(_UseItem.guid))
|
| | | {
|
| | | itemGuids.Remove(_UseItem.guid);
|
| | | }
|
| | |
|
| | | if (itemStack.ContainsKey(_UseItem.guid))
|
| | | {
|
| | | itemStack.Remove(_UseItem.guid);
|
| | | }
|
| | |
|
| | | RefreshCurrrentShowUseItem();
|
| | | }
|
| | |
|
| | | public int GetShowItemId()
|
| | | {
|
| | | if (currentShowItem == default(UseItem))
|
| | | {
|
| | | return 0;
|
| | | }
|
| | | else
|
| | | {
|
| | | var item = playerPack.GetItemModelByGUID(currentShowItem.guid);
|
| | | return item == null ? 0 : item.chinItemModel.ID;
|
| | | }
|
| | | }
|
| | |
|
| | | private void OnGetUseItem(PackType type, string guid)
|
| | | {
|
| | | var UseItem = new UseItem(type, guid);
|
| | | if (!itemGuids.Contains(guid))
|
| | | {
|
| | | itemGuids.Add(guid);
|
| | | }
|
| | |
|
| | | itemStack[guid] = UseItem;
|
| | |
|
| | | RefreshCurrrentShowUseItem();
|
| | | }
|
| | |
|
| | | private void OnPackageRefresh(PackType _type)
|
| | | {
|
| | | if (_type != PackType.rptItem)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | RefreshCurrrentShowUseItem();
|
| | | }
|
| | |
|
| | | private void OnPackageItemRefresh(PackType _type, int _index, int _itemId)
|
| | | {
|
| | | OnPackageRefresh(_type);
|
| | | }
|
| | |
|
| | | private bool FindLatestItem(out UseItem _item)
|
| | | {
|
| | | if (itemGuids.Count == 0)
|
| | | {
|
| | | _item = default(UseItem);
|
| | | return false;
|
| | | }
|
| | |
|
| | | var guid = itemGuids[itemGuids.Count - 1];
|
| | | _item = itemStack[guid];
|
| | | return true;
|
| | | }
|
| | |
|
| | | private void Trim()
|
| | | {
|
| | | for (int i = itemGuids.Count - 1; i >= 0; i--)
|
| | | {
|
| | | var item = itemStack[itemGuids[i]];
|
| | | if (playerPack.GetItemModelByGUID(item.guid) == null
|
| | | || playerPack.GetItemModelByGUID(item.guid).packType != PackType.rptItem)
|
| | | {
|
| | | itemGuids.RemoveAt(i);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void RefreshCurrrentShowUseItem()
|
| | | {
|
| | | Trim();
|
| | |
|
| | | UseItem tempItem;
|
| | | if (FindLatestItem(out tempItem))
|
| | | {
|
| | | if (tempItem != currentShowItem)
|
| | | {
|
| | | currentShowItem = tempItem;
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | currentShowItem = default(UseItem);
|
| | | }
|
| | |
|
| | | if (showItemRefreshEvent != null)
|
| | | {
|
| | | showItemRefreshEvent();
|
| | | }
|
| | | }
|
| | |
|
| | | public bool ShowUseItemAble()
|
| | | {
|
| | | var mapId = PlayerDatas.Instance.baseData.MapID;
|
| | | var lineId = PlayerDatas.Instance.baseData.dungeonLineId;
|
| | | var dungeonId = dungeonModel.GetDungeonId(dungeonModel.GetDataMapIdByMapId(mapId), lineId);
|
| | | if (dungeonId == 0)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | var config = Config.Instance.Get<DungeonConfig>(dungeonId);
|
| | | return config.ShowNewItemTip == 1;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | public struct UseItem
|
| | | {
|
| | | public PackType packType;
|
| | | public string guid;
|
| | |
|
| | | public UseItem(PackType _packType, string _guid)
|
| | | {
|
| | | this.packType = _packType;
|
| | | this.guid = _guid;
|
| | | }
|
| | |
|
| | | public static bool operator ==(UseItem _lhs, UseItem _rhs)
|
| | | {
|
| | | return _lhs.packType == _rhs.packType && _lhs.guid == _rhs.guid;
|
| | | }
|
| | |
|
| | | public static bool operator !=(UseItem _lhs, UseItem _rhs)
|
| | | {
|
| | | return _lhs.packType != _rhs.packType || _lhs.guid != _rhs.guid;
|
| | | }
|
| | |
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | |
|