|
- local UpdateTipsView = {};
- UpdateTipsView.__index = UpdateTipsView;
-
- -- 创建新对象
- function UpdateTipsView:new(...)
- local instance = {};
- setmetatable(instance , UpdateTipsView);
- instance:ctor(...);
- return instance;
- end
-
- -- onOkCallback : funciton(), 点击确定时的处理
- -- onCancelCallback : funciton(), 点击确定时的处理
- -- closeWhenOk :boolean, 点击确定时是否关闭界面
- function UpdateTipsView:ctor(content, onOkCallback, onCancelCallback, closeWhenOk)
- self.content = content;
- self.onOkCallback = onOkCallback;
- self.onCancelCallback = onCancelCallback;
- self.closeWhenOk = closeWhenOk;
- self:onEnter();
- end
-
- function UpdateTipsView:onEnter()
- local ui = loadUI("preload/res/preload_update.ui")
- self.ui = ui;
-
- local function setTextColor(uiText, color)
- local label = uiText:getVirtualRenderer();
- local config = label:getTTFConfig()
- config.texColor = color;
- label:setTTFConfig(config)
- end
-
- -- 强更提示内容模板
- -- json 工具地址: https://www.bejson.com
- --[[
- {"title":{"size":24,"color":"30_42_52","content":["发现有新的版本,请点击“确认更新”按钮开始更新。"]},"content":{"size":24,"color":"30_42_52","content":["更新内容:","1、增加绑定及登录的功能。","2、优化已知bug,提升游戏性能。"]},"warnning":{"size":24,"color":"219_56_35","content":["如遇更新失败,请删除老版本再重新下载,或联系客服ddph8800","处理!"]},"team":"悠闲运营团队","date":"2019-11-25"}
- --]]
-
- local uiLayout = self.ui.Items.Layout_Text
- local uiSpace = self.ui.Items.Layout_Space
- local uiTextLeft = self.ui.Items.Text_Left
- local uiTextRight = self.ui.Items.Text_Right
-
- uiTextLeft:setVisible(false)
- uiTextRight:setVisible(false)
-
- logD("UpdateTipsView:onEnter() self.content = ",self.content)
-
- local jsonData = json.decode(self.content)
-
- if jsonData and type(jsonData) == "table" then
- -- title
- if jsonData.title and type(jsonData.title) == "table" then
- local size = tonumber(jsonData.title.size) or 24
- local colors = split(tostring(jsonData.title.color), "_")
- local color = { r = colors[1], g = colors[2], b = colors[3], a = 255 }
- if jsonData.title.content and type(jsonData.title.content) == "table" then
- for k,v in ipairs(jsonData.title.content) do
- local uiText = uiTextLeft:getCopied()
- uiText:setVisible(true)
- uiText:setString(v)
- setTextColor(uiText, color)
- uiText:setFontSize(size)
- uiLayout:addChild(uiText)
- end
- end
- end
-
- -- 空格
- uiLayout:addChild(uiSpace:getCopied())
-
- -- content
- if jsonData.content and type(jsonData.content) == "table" then
- local size = tonumber(jsonData.content.size) or 24
- local colors = split(tostring(jsonData.content.color), "_")
- local color = { r = colors[1], g = colors[2], b = colors[3], a = 255 }
- if jsonData.content.content and type(jsonData.content.content) == "table" then
- for k,v in ipairs(jsonData.content.content) do
- local uiText = uiTextLeft:getCopied()
- uiText:setVisible(true)
- uiText:setString(v)
- setTextColor(uiText, color)
- uiText:setFontSize(size)
- uiLayout:addChild(uiText)
- end
- end
- end
-
- -- 空格
- uiLayout:addChild(uiSpace:getCopied())
-
- -- warnning
- if jsonData.warnning and type(jsonData.warnning) == "table" then
- local size = tonumber(jsonData.warnning.size) or 24
- local colors = split(tostring(jsonData.warnning.color), "_")
- local color = { r = colors[1], g = colors[2], b = colors[3], a = 255 }
- if jsonData.warnning.content and type(jsonData.warnning.content) == "table" then
- for k,v in ipairs(jsonData.warnning.content) do
- local uiText = uiTextLeft:getCopied()
- uiText:setVisible(true)
- uiText:setString(v)
- setTextColor(uiText, color)
- uiText:setFontSize(size)
- uiLayout:addChild(uiText)
- end
- end
- end
-
- -- 空格
- uiLayout:addChild(uiSpace:getCopied())
-
- -- team
- if jsonData.team then
- local uiText = uiTextRight:getCopied()
- uiText:setVisible(true)
- uiText:setString(jsonData.team)
- uiLayout:addChild(uiText)
- end
- if jsonData.date then
- local uiText = uiTextRight:getCopied()
- uiText:setVisible(true)
- uiText:setString(jsonData.date)
- uiLayout:addChild(uiText)
- end
- else
- local uiText = uiTextLeft:getCopied()
- uiText:setVisible(true)
- uiText:setString("发现新的更新")
- uiLayout:addChild(uiText)
- end
-
- local function onClickOK(sender, eventType)
- if eventType == 2 then
- if self.closeWhenOk then
- self.ui:removeFromParent();
- end
- if self.onOkCallback then
- self.onOkCallback()
- end
- end
- return true;
- end
- ui.Items.Button_Sure:addTouchEventListener(onClickOK)
-
- local function onClickClose(sender, eventType)
- if eventType == 2 then
- ui.Items.Button_Close:setVisible(false)
- self.ui:removeFromParent()
- if self.onCancelCallback then
- self.onCancelCallback()
- end
- end
- return true;
- end
-
- ui.Items.Button_Close:addTouchEventListener(onClickClose)
-
- ui.Items.Button_Close:setVisible(self.onCancelCallback ~= nil)
-
- local scene = cc.Director:getInstance():getRunningScene()
- scene:addChild(ui)
- end
-
- return UpdateTipsView;
|