local UICommonGuessingBase = UIViewClass() function UICommonGuessingBase:OnCreated() self.cacheNumStr = "" end function UICommonGuessingBase:OnOpened(context) self:Init() self.selectOptionIndex = 1 self:IsShowKeyPad(false) self:StartRepeatFunc(self.UpdateAllQuizInfoRepeatFunc, 30) -- 30秒刷新一次竞猜信息 end function UICommonGuessingBase:Init() end function UICommonGuessingBase:UpdateAllQuizInfoRepeatFunc(deltaTime, timeSinceUpdate) end function UICommonGuessingBase:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UICommonGuessingBase: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.GuessMoneyID) 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 self:ClickBuy() 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.GuessMoneyID 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.GuessMoneyID 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 UICommonGuessingBase:ClickBuy() end function UICommonGuessingBase:OnCellInit(scrollRect, index, cellTable, data) end function UICommonGuessingBase:OnCellClicked(scrollRect, index, cellTable, target, data) self.selectGuessIndex = index + 1 self.selectOptionIndex = 1 --self.loop_Topic:ReloadAll(self.guessServerInfo) self:RefreshOptionInfo() end function UICommonGuessingBase:RefreshGuessing() end function UICommonGuessingBase: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.GuessMoneyID) 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.GuessMoneyID) UIUtils.SetLabel(self.txt_Number, data.betNum) end --region ******************** 小键盘 ************************** function UICommonGuessingBase: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.GuessMoneyID) 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 UICommonGuessingBase: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.GuessMoneyID) + 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 UICommonGuessingBase:RefreshCount() UIUtils.SetLabel(self.Keypad.txt_NumSelect, self.cacheNumStr) end --endregion ******************** 小键盘 ************************** return UICommonGuessingBase