141 lines
4.6 KiB
Lua
141 lines
4.6 KiB
Lua
|
local Object = CS.UnityEngine.Object
|
||
|
local Vector3 = CS.UnityEngine.Vector3
|
||
|
local V3O = Vector3.one
|
||
|
local XUiDormPersonSelectListItem = XClass(nil, "XUiDormPersonSelectListItem")
|
||
|
local TextManager = CS.XTextManager
|
||
|
local XUiDormPersonAttDesItem = require("XUi/XUiDormPerson/XUiDormPersonAttDesItem")
|
||
|
|
||
|
function XUiDormPersonSelectListItem:Ctor(ui)
|
||
|
self.GameObject = ui.gameObject
|
||
|
self.Transform = ui.transform
|
||
|
self.PreSeleState = false
|
||
|
self.BtnClickCb = function() self:OnBtnClick() end
|
||
|
self.Lovetxt = TextManager.GetText("DormLove") or ""
|
||
|
self.Liketxt = TextManager.GetText("DormLike") or ""
|
||
|
XTool.InitUiObject(self)
|
||
|
self.WorkingText.text = TextManager.GetText("DormWorkingText")
|
||
|
end
|
||
|
|
||
|
function XUiDormPersonSelectListItem:Init(ui, uiRoot, dormId)
|
||
|
self.Parent = ui
|
||
|
self.UiRoot = uiRoot
|
||
|
self.DormId = dormId
|
||
|
end
|
||
|
|
||
|
function XUiDormPersonSelectListItem:SetSelectState()
|
||
|
local dormId = self.Parent:GetCurSeleDormId()
|
||
|
local cfg = XDormConfig.GetDormitoryCfgById(dormId)
|
||
|
if not cfg then
|
||
|
return
|
||
|
end
|
||
|
|
||
|
if self.IsWorking then
|
||
|
self.CurSeleState = false
|
||
|
XUiManager.TipText("DormWorkingText")
|
||
|
return
|
||
|
end
|
||
|
|
||
|
self.CurSeleState = not self.CurSeleState
|
||
|
if self.CurSeleState then
|
||
|
local d = self.Parent:GetTotalSeleCharacter()
|
||
|
local selecount = #d
|
||
|
if selecount ~= 0 and selecount >= cfg.CharCapacity then
|
||
|
self.CurSeleState = false
|
||
|
XUiManager.TipText("DormFullPersonTips")
|
||
|
return
|
||
|
end
|
||
|
end
|
||
|
|
||
|
self:SelectState(self.CurSeleState)
|
||
|
end
|
||
|
|
||
|
function XUiDormPersonSelectListItem:SelectState(state)
|
||
|
self.ImgSelect.gameObject:SetActive(state)
|
||
|
self.Parent:UpdateSeleCharacter(self.ItemData, state)
|
||
|
self.ItemData.CurSeleState = state
|
||
|
end
|
||
|
|
||
|
-- 更新数据
|
||
|
function XUiDormPersonSelectListItem:OnRefresh(itemData)
|
||
|
if not itemData then
|
||
|
return
|
||
|
end
|
||
|
|
||
|
self.ItemData = itemData
|
||
|
self.Dormid = itemData.DormitoryId
|
||
|
local characterid = itemData.CharacterId
|
||
|
|
||
|
if self.Dormid == -1 then
|
||
|
if itemData.CurSeleState == nil then
|
||
|
self.CurSeleState = false
|
||
|
else
|
||
|
self.CurSeleState = itemData.CurSeleState
|
||
|
end
|
||
|
self.ImgDorm.gameObject:SetActive(false)
|
||
|
self.ImgSelect.gameObject:SetActive(self.CurSeleState)
|
||
|
if self.CurSeleState then
|
||
|
self.Parent:UpdateSeleCharacter(self.ItemData, self.CurSeleState)
|
||
|
end
|
||
|
else
|
||
|
local curseleDormId = self.Parent:GetCurSeleDormId()
|
||
|
self.ImgDorm.gameObject:SetActive(true)
|
||
|
self.TxtHostelName.text = XDataCenter.DormManager.GetDormName(self.Dormid) or ""
|
||
|
if itemData.CurSeleState == nil then
|
||
|
local state = curseleDormId == self.Dormid
|
||
|
itemData.CurSeleState = state
|
||
|
self.CurSeleState = state
|
||
|
else
|
||
|
self.CurSeleState = itemData.CurSeleState
|
||
|
end
|
||
|
self.ImgSelect.gameObject:SetActive(self.CurSeleState)
|
||
|
if self.CurSeleState then
|
||
|
self.Parent:UpdateSeleCharacter(self.ItemData, self.CurSeleState)
|
||
|
end
|
||
|
end
|
||
|
local charStyleConfig = XDormConfig.GetCharacterStyleConfigById(characterid)
|
||
|
if not charStyleConfig then
|
||
|
return
|
||
|
end
|
||
|
if charStyleConfig then
|
||
|
self.TxtName.text = charStyleConfig.Name
|
||
|
end
|
||
|
|
||
|
if XDataCenter.DormManager.IsWorking(characterid) then
|
||
|
self.ImgWorking.gameObject:SetActive(true)
|
||
|
self.IsWorking = true
|
||
|
else
|
||
|
self.ImgWorking.gameObject:SetActive(false)
|
||
|
self.IsWorking = false
|
||
|
end
|
||
|
|
||
|
local loveicon = XDataCenter.DormManager.GetCharacterLikeIconById(characterid, XDormConfig.CharacterLikeType.LoveType)
|
||
|
local likeicon = XDataCenter.DormManager.GetCharacterLikeIconById(characterid, XDormConfig.CharacterLikeType.LikeType)
|
||
|
|
||
|
if not self.loveitem then
|
||
|
self.loveitem = self:GetItem()
|
||
|
self.loveitem:SetState(true)
|
||
|
end
|
||
|
self.loveitem:OnRefresh(self.Lovetxt, loveicon)
|
||
|
|
||
|
if not self.likeitem then
|
||
|
self.likeitem = self:GetItem()
|
||
|
self.likeitem:SetState(true)
|
||
|
end
|
||
|
self.likeitem:OnRefresh(self.Liketxt, likeicon)
|
||
|
|
||
|
local iconpath = XDormConfig.GetCharacterStyleConfigQIconById(characterid)
|
||
|
if iconpath then
|
||
|
self.ImgIcon:SetRawImage(iconpath, nil, true)
|
||
|
end
|
||
|
self.GameObject.name = characterid
|
||
|
end
|
||
|
|
||
|
function XUiDormPersonSelectListItem:GetItem()
|
||
|
local obj = Object.Instantiate(self.Item)
|
||
|
obj.transform:SetParent(self.DesItems, false)
|
||
|
obj.transform.localScale = V3O
|
||
|
local item = XUiDormPersonAttDesItem.New(obj, self.UiRoot)
|
||
|
return item
|
||
|
end
|
||
|
|
||
|
return XUiDormPersonSelectListItem
|