154 lines
4.7 KiB
C#
154 lines
4.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using Games.Item;
|
|
using System.Collections.Generic;
|
|
using GCGame.Table;
|
|
using Module.Log;
|
|
|
|
public class MarketFindPage : UIControllerBase<MarketFindPage>
|
|
{
|
|
// Use this for initialization
|
|
void OnEnable ()
|
|
{
|
|
SetInstance(this);
|
|
|
|
InitFindInfo();
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
SetInstance(null);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update ()
|
|
{
|
|
|
|
}
|
|
|
|
#region find
|
|
|
|
public InputField _InputField;
|
|
public UIContainerBase _HistoryFindContainer;
|
|
public GameObject _FindSelectPanel;
|
|
public UIContainerBase _FindSelectContainer;
|
|
public Button _BtnSearch;
|
|
public GameObject _BtnSearchDisable;
|
|
|
|
private Tab_CommonItem _SearchCommonItem;
|
|
|
|
public void InitFindInfo()
|
|
{
|
|
var historys = PlayerPreferenceData.GetMarketSearchHistory();
|
|
List<Tab_CommonItem> commonItems = new List<Tab_CommonItem>();
|
|
for (int i = 0; i < historys.Count; ++i)
|
|
{
|
|
var commonItem = TableManager.GetCommonItemByID(historys[i], 0);
|
|
if(commonItem != null)
|
|
commonItems.Add(commonItem);
|
|
}
|
|
Hashtable hash = new Hashtable();
|
|
hash.Add("IsShowInBlack", false);
|
|
_HistoryFindContainer.InitContentItem(commonItems, SearchHistoryItem, hash);
|
|
|
|
_BtnSearch.gameObject.SetActive(false);
|
|
_BtnSearchDisable.SetActive(true);
|
|
_InputField.text = "";
|
|
}
|
|
|
|
public void OnInputChange(string inputStr)
|
|
{
|
|
if (string.IsNullOrEmpty(inputStr))
|
|
return;
|
|
|
|
if (_SearchCommonItem != null && _SearchCommonItem.Name == inputStr)
|
|
return;
|
|
|
|
var findItems = ItemTool.GetFilterSellItem(inputStr);
|
|
if (findItems.Count > 0)
|
|
{
|
|
ShowFindSelect();
|
|
var gridLayout = _FindSelectContainer._ContainerObj.GetComponent<GridLayoutGroup>();
|
|
var bgRect = _FindSelectContainer.GetComponent<RectTransform>();
|
|
if (findItems.Count > 10)
|
|
{
|
|
gridLayout.constraintCount = 3;
|
|
float rowCnt = findItems.Count / 3;
|
|
if (rowCnt > 7)
|
|
{
|
|
rowCnt = 7.5f;
|
|
}
|
|
bgRect.sizeDelta = new Vector2(gridLayout.cellSize.x * gridLayout.constraintCount + gridLayout.spacing.x * (gridLayout.constraintCount - 1) + gridLayout.padding.left + gridLayout.padding.right,
|
|
gridLayout.cellSize.y * rowCnt + gridLayout.spacing.y * (rowCnt - 1) + 22);
|
|
}
|
|
else if (findItems.Count > 5)
|
|
{
|
|
gridLayout.constraintCount = 2;
|
|
float rowCnt = findItems.Count / 2;
|
|
|
|
bgRect.sizeDelta = new Vector2(gridLayout.cellSize.x * gridLayout.constraintCount + gridLayout.spacing.x * (gridLayout.constraintCount - 1) + gridLayout.padding.left + gridLayout.padding.right,
|
|
gridLayout.cellSize.y * rowCnt + gridLayout.spacing.y * (rowCnt - 1) + 22);
|
|
}
|
|
else
|
|
{
|
|
gridLayout.constraintCount = 1;
|
|
float rowCnt = findItems.Count;
|
|
bgRect.sizeDelta = new Vector2(gridLayout.cellSize.x * gridLayout.constraintCount + gridLayout.spacing.x * (gridLayout.constraintCount - 1) + gridLayout.padding.left + gridLayout.padding.right,
|
|
gridLayout.cellSize.y * rowCnt + gridLayout.spacing.y * (rowCnt - 1) + 22);
|
|
}
|
|
_FindSelectContainer.InitContentItem(findItems, SelectFindItem);
|
|
_BtnSearch.gameObject.SetActive(false);
|
|
_BtnSearchDisable.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void SelectFindItem(object selectedObj)
|
|
{
|
|
Tab_CommonItem selectedItem = selectedObj as Tab_CommonItem;
|
|
if (selectedItem == null)
|
|
return;
|
|
|
|
_BtnSearch.gameObject.SetActive(true);
|
|
_BtnSearchDisable.SetActive(false);
|
|
_SearchCommonItem = selectedItem;
|
|
_InputField.text = selectedItem.Name;
|
|
HideFindSelect();
|
|
}
|
|
|
|
private void SearchHistoryItem(object selectedObj)
|
|
{
|
|
Tab_CommonItem selectedItem = selectedObj as Tab_CommonItem;
|
|
if (selectedItem == null)
|
|
return;
|
|
|
|
_SearchCommonItem = selectedItem;
|
|
SearchItem();
|
|
}
|
|
|
|
public void ShowFindSelect()
|
|
{
|
|
_FindSelectPanel.SetActive(true);
|
|
}
|
|
|
|
public void HideFindSelect()
|
|
{
|
|
_FindSelectPanel.SetActive(false);
|
|
}
|
|
|
|
public void OnBtnSearch()
|
|
{
|
|
SearchItem();
|
|
}
|
|
|
|
public void SearchItem()
|
|
{
|
|
LogModule.DebugLog("Search:" + _SearchCommonItem.Id);
|
|
Market.SearchItem(new List<int>() { _SearchCommonItem.Id }, false);
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|