local UIHeroMatch3v3Guessing = UIViewClass() function UIHeroMatch3v3Guessing:OnCreated() self.cacheNumStr = "" end function UIHeroMatch3v3Guessing:OnOpened(context) MDL.HeroMatch3v3.HeroMatchGetAllQuizInfoRequest() self:RegistSystemEvent(EventID.UI_HeroMatch3v3_CloseView, self.OnBackButtonPressed) -- 赛程结束关闭界面 self:RegistSystemEvent(EventID.UI_HeroMatch3v3_RefreshGuessing, self.RefreshGuessing) -- 刷新界面信息 self.selectGuessIndex = 1 self.selectOptionIndex = 1 self:IsShowKeyPad(false) self:StartRepeatFunc(self.UpdateAllQuizInfoRepeatFunc, 30) -- 30秒刷新一次竞猜信息 end function UIHeroMatch3v3Guessing:UpdateAllQuizInfoRepeatFunc(deltaTime, timeSinceUpdate) MDL.HeroMatch3v3.HeroMatchGetAllQuizInfoRequest() end function UIHeroMatch3v3Guessing:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIHeroMatch3v3Guessing:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.btn_OpenKeyPad then local data = self.guessServerInfo[self.selectGuessIndex].serverInfo if data.isOverdue then CTL.Tips.AddTipsMsg(Const_IDS.IDS_HeroMatch3v3_PickOutTime1) else self:IsShowKeyPad(true) end elseif comp == self.Keypad.btn_Buy then local curNum = tonumber(self.cacheNumStr) local itemData = DataSheetManager.ItemData:GetDataByID(self.guessServerInfo[self.selectGuessIndex].guessCfg.MoneyID) local itemName = UIUtils.GetLocalizedTxt(Const_IDS[itemData.Name]) if curNum < self.minNum then CTL.Tips.AddTipsMsg(Const_IDS.IDS_HeroMatch3v3_MinMoney, self.minNum..itemName) elseif curNum > self.maxNum then CTL.Tips.AddTipsMsg(Const_IDS.IDS_HeroMatch3v3_MaxMoney, self.maxNum..itemName) else MDL.HeroMatch3v3.HeroMatchQuizBetRequest(self.guessServerInfo[self.selectGuessIndex].guessCfg.ID, self.selectOptionIndex, tonumber(self.cacheNumStr)) self:IsShowKeyPad(false) end elseif comp == self.Keypad.Button1 then self:ExcuteClickNum(1) elseif comp == self.Keypad.Button2 then self:ExcuteClickNum(2) elseif comp == self.Keypad.Button3 then self:ExcuteClickNum(3) elseif comp == self.Keypad.Button4 then self:ExcuteClickNum(4) elseif comp == self.Keypad.Button5 then self:ExcuteClickNum(5) elseif comp == self.Keypad.Button6 then self:ExcuteClickNum(6) elseif comp == self.Keypad.Button7 then self:ExcuteClickNum(7) elseif comp == self.Keypad.Button8 then self:ExcuteClickNum(8) elseif comp == self.Keypad.Button9 then self:ExcuteClickNum(9) elseif comp == self.Keypad.Button10 then self:ExcuteClickNum(0) elseif comp == self.Keypad.ButtonCancel then self:ExcuteClickNum(-1) elseif comp == self.Keypad.ButtonConfirm then self:IsShowKeyPad(false) elseif comp == self.Keypad.TipWindow then self:IsShowKeyPad(false) elseif comp == self.Keypad.event_Plus then local itemID = self.guessServerInfo[self.selectGuessIndex].guessCfg.MoneyID local stockCount = UTL.Item.GetItemStockCount(itemID) + self.guessServerNum if self.cacheNumStr + 1 <= stockCount then self.cacheNumStr = self.cacheNumStr + 1 self:RefreshCount() end elseif comp == self.Keypad.event_Minus then if self.cacheNumStr > 0 then self.cacheNumStr = self.cacheNumStr - 1 self:RefreshCount() end elseif comp == self.Keypad.event_Max then local itemID = self.guessServerInfo[self.selectGuessIndex].guessCfg.MoneyID local stockCount = UTL.Item.GetItemStockCount(itemID) + self.guessServerNum --购买上限 self.cacheNumStr = stockCount >= self.maxNum and self.maxNum or stockCount self:RefreshCount() else local data = self.guessServerInfo[self.selectGuessIndex].serverInfo for k,option_cell in ipairs(self.group_Option) do if comp == option_cell.btn_Selected then self.selectOptionIndex = k end UIUtils.SetActive(option_cell.img_Selected.gameObject, comp == option_cell.btn_Selected) if comp == option_cell.btn_Selected and k ~= data.betOption then option_cell.img_Bg:SetState(comp == option_cell.btn_Selected and 1 or 0) else option_cell.state:SetState(k == data.betOption and 1 or 0) end end end end function UIHeroMatch3v3Guessing:OnCellInit(scrollRect, index, cellTable, data) UTL.Item.MoneyIcon(cellTable.img_Item, data.guessCfg.MoneyID) UIUtils.SetLabelText(cellTable.txt_Topic, Const_IDS[data.guessCfg.QuestionDes]) UIUtils.SetActive(cellTable.img_SelectBg, self.selectGuessIndex == index + 1) local StageCfg = DataSheetManager.TeamMatchStage:GetDataByID(data.guessCfg.TalkGuessEnd) if data.serverInfo.isOverdue then cellTable.state:SetState(1) else if data.serverInfo.betOption > 0 then cellTable.state:SetState(2) else cellTable.state:SetState(0) end end UIUtils.SetLabel(cellTable.txt_Deadline, string.FormatByIdsId(Const_IDS.IDS_HeroMatch3v3_PickTime, string.FormatByIdsId(Const_IDS.IDS_HeroMatch3v3_StopGambling, UIUtils.GetLocalizedTxt(Const_IDS[StageCfg.InterfaceDes])))) -- 话题到期时间 end function UIHeroMatch3v3Guessing:OnCellClicked(scrollRect, index, cellTable, target, data) self.selectGuessIndex = index + 1 self.selectOptionIndex = 1 self.loop_Topic:ReloadAll(self.guessServerInfo) self:RefreshOptionInfo() end function UIHeroMatch3v3Guessing:RefreshGuessing() self.guessServerInfo = MDL.HeroMatch3v3.GetHeroMatch3v3GuessingInfo() self.loop_Topic:ReloadAll(self.guessServerInfo) self:RefreshOptionInfo() end function UIHeroMatch3v3Guessing:RefreshOptionInfo() local data = self.guessServerInfo[self.selectGuessIndex].serverInfo local guessCfg = self.guessServerInfo[self.selectGuessIndex].guessCfg local rightOptionList = {} for k,v in ipairs(data.rightOption) do rightOptionList[v] = v end for k,option_cell in ipairs(self.group_Option) do local optionCfg = guessCfg.Option_Table[k] if optionCfg then UIUtils.SetActive(option_cell.gameObject, true) UIUtils.SetLabel(option_cell.txt_Option, string.FormatByIdsId(Const_IDS[optionCfg.OptionShow], optionCfg.OptionParam1, optionCfg.OptionParam2)) UTL.Item.MoneyIcon(option_cell.img_Item, guessCfg.MoneyID) UIUtils.SetLabel(option_cell.txt_Money, data.totalBet[k]) UIUtils.SetActive(option_cell.img_RightBg, rightOptionList[k] and true or false) UIUtils.SetActive(option_cell.img_Selected, self.selectOptionIndex == k) if k == data.betOption and k ~= data.betOption then option_cell.img_Bg:SetState(self.selectOptionIndex == k and 1 or 0) else option_cell.state:SetState(k == data.betOption and 1 or 0) end else UIUtils.SetActive(option_cell.gameObject, false) end end UTL.Item.MoneyIcon(self.img_Item, guessCfg.MoneyID) UIUtils.SetLabel(self.txt_Number, data.betNum) end --region ******************** 小键盘 ************************** function UIHeroMatch3v3Guessing:IsShowKeyPad(active) UIUtils.SetActive(self.Keypad.gameObject, active) if active then self.isInitNum = true local data = self.guessServerInfo[self.selectGuessIndex].serverInfo local guessCfg = self.guessServerInfo[self.selectGuessIndex].guessCfg local optionCfg = guessCfg.Option_Table[self.selectOptionIndex] UIUtils.SetLabel(self.Keypad.txt_Option, string.FormatByIdsId(Const_IDS[optionCfg.OptionShow], optionCfg.OptionParam1, optionCfg.OptionParam2)) UTL.Item.MoneyIcon(self.Keypad.img_Item, guessCfg.MoneyID) UIUtils.SetLabel(self.Keypad.txt_Number, data.betNum) self.guessServerNum = data.betNum -- 小键盘 self.minNum = guessCfg.SingleBetLowLimit self.maxNum = guessCfg.SingleBetUpLimit self.cacheNumStr = 0 self:RefreshCount() end end function UIHeroMatch3v3Guessing:ExcuteClickNum(num) if num == -1 then local len = string.len(self.cacheNumStr) if len >= 2 then self.cacheNumStr = tonumber(utf8.sub(tostring(self.cacheNumStr), 1, len)) else self.cacheNumStr = 0 end elseif num == 0 and string.isNilOrEmpty(self.cacheNumStr) then return else if self.isInitNum then self.cacheNumStr = 0 self.isInitNum = false end local targetNum = tonumber(self.cacheNumStr .. num) local stockCount = UTL.Item.GetItemStockCount(self.guessServerInfo[self.selectGuessIndex].guessCfg.MoneyID) + self.guessServerNum if targetNum > stockCount then self.cacheNumStr = stockCount else self.cacheNumStr = targetNum end end if tonumber(self.cacheNumStr) < 0 then self.cacheNumStr = 1 end self:RefreshCount() end function UIHeroMatch3v3Guessing:RefreshCount() UIUtils.SetLabel(self.Keypad.txt_NumSelect, self.cacheNumStr) end --endregion ******************** 小键盘 ************************** return UIHeroMatch3v3Guessing