diff --git a/lua/app/common/bi_report.lua b/lua/app/common/bi_report.lua index c4cfdf42..b0f4b9b2 100644 --- a/lua/app/common/bi_report.lua +++ b/lua/app/common/bi_report.lua @@ -788,4 +788,20 @@ function BIReport:postAccountDelete(loginType) self:report(EVENT_NAME_ACCOUNT_OPT, args) end +function BIReport:postAccountBindClick(loginType) + local args = { + login_type = loginType, + event_type = BIReport.ACCOUNT_OPT_TYPE.BIND_CLICK, + } + self:report(EVENT_NAME_ACCOUNT_OPT, args) +end + +function BIReport:postAccountBindFinish(loginType) + local args = { + login_type = loginType, + event_type = BIReport.ACCOUNT_OPT_TYPE.BIND_FINISH, + } + self:report(EVENT_NAME_ACCOUNT_OPT, args) +end + return BIReport \ No newline at end of file diff --git a/lua/app/common/event_manager.lua b/lua/app/common/event_manager.lua index 092347ef..12cb89c1 100644 --- a/lua/app/common/event_manager.lua +++ b/lua/app/common/event_manager.lua @@ -33,6 +33,7 @@ EventManager.CUSTOM_EVENT = { GO_CHAPTER = "GO_CHAPTER", -- 跳转主线章节 CLOSE_BOX_HERO_UI = "CLOSE_BOX_HERO_UI", CLOSE_BOX_OPEN_UI = "CLOSE_BOX_OPEN_UI", + BIND_ACCOUNT_SUCCESS = "BIND_ACCOUNT_SUCCESS", -- BORAD_TOUCH_BEGIN = "BORAD_TOUCH_BEGIN", -- BORAD_TOUCH_OVER = "BORAD_TOUCH_OVER" } diff --git a/lua/app/common/sdk_manager.lua b/lua/app/common/sdk_manager.lua index 4b56d6b6..06d0f15d 100644 --- a/lua/app/common/sdk_manager.lua +++ b/lua/app/common/sdk_manager.lua @@ -370,7 +370,6 @@ function SDKManager:login(callback, loginType) Logger.log("三方当前正在登陆中") return end - self.isLogining = true self:_login(function(code, msg) if code == SDKManager.BF_LOGIN_RESULT.Success then @@ -388,7 +387,6 @@ function SDKManager:login(callback, loginType) self.isLogining = false return end - local userId = loginResult.UserId local token = loginResult.Token local params = {} @@ -430,12 +428,9 @@ function SDKManager:logout(callback, loginType) Logger.log("当前正在登出中") return end - self.isLogouting = true - - self:_logout(function(code, msg) - if (code == SDKManager.BF_LOGIN_RESULT.Success) then + if code == SDKManager.BF_LOGIN_RESULT.Success then if callback then callback() end @@ -443,9 +438,7 @@ function SDKManager:logout(callback, loginType) if msg and msg ~= "" then local jData = json.decode(msg) if jData then - local type = jData.loginType - local msg = jData.msg - Logger.logError("登出失败 result:%s type:%s msg:%s", code, type, msg) + Logger.logError("登出失败 result:%s type:%s msg:%s", code, jData.loginType, jData.msg) else Logger.logError("登出失败 result:%s", code) end diff --git a/lua/app/module/account/account_manager.lua b/lua/app/module/account/account_manager.lua index eba93751..f99b3a5f 100644 --- a/lua/app/module/account/account_manager.lua +++ b/lua/app/module/account/account_manager.lua @@ -11,6 +11,17 @@ function AccountManager:showDeleteUI() return UIManager:showUI("app/ui/game_setting/account_delete_ui") end +function AccountManager:getIsBinded() + local accountInfo = LocalData:getAccountInfo() + if accountInfo.google_id and accountInfo.google_id ~= "" then + return true + end + if accountInfo.apple_id and accountInfo.apple_id ~= "" then + return true + end + return false +end + function AccountManager:deleteAccount() self:sendMessage(ProtoMsgType.FromMsgEnum.DeleteReq, {}, {}, self.onDeleteAccount, BIReport.ITEM_GET_TYPE.NONE) end @@ -25,4 +36,50 @@ function AccountManager:onDeleteAccount(result) end end +function AccountManager:bindAccount() + local loginType = SDKManager.BF_LOGIN_TYPE.GOOGLE + if Platform:isIosPlatform() then + loginType = SDKManager.BF_LOGIN_TYPE.APPLE + end + + BIReport:postAccountBindClick(loginType) + SDKManager:login(function(params) + if not params.token then + return + end + local args = { + type = SDKManager.LOGIN_TYPE[loginType], + id = params.id, + token = params.token + } + self:sendMessage(ProtoMsgType.FromMsgEnum.BindReq, args, {}, self.onBindAccount, BIReport.ITEM_GET_TYPE.NONE) + end, loginType) +end + +function AccountManager:onBindAccount(result) + if result.err_code == GConst.ERROR_STR.SUCCESS then + local accountInfo = LocalData:getAccountInfo() + local loginType = SDKManager.BF_LOGIN_TYPE.GOOGLE + if Platform:isIosPlatform() then + loginType = SDKManager.BF_LOGIN_TYPE.APPLE + accountInfo.apple_id = result.reqData.id + else + accountInfo.googld_id = result.reqData.id + end + LocalData:setLastLoginInfo(loginType, result.reqData.id, result.reqData.token) + LocalData:setAccountInfo(accountInfo) + LocalData:save() + + BIReport:postAccountBindFinish(loginType) + GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.BIND_ACCOUNT_SUCCESS)) + EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.BIND_ACCOUNT_SUCCESS) + else -- 一些失败的提示 + + end +end + +function AccountManager:changeAccount() + +end + return AccountManager \ No newline at end of file diff --git a/lua/app/ui/game_setting/game_setting_ui.lua b/lua/app/ui/game_setting/game_setting_ui.lua index 65acbbda..477889b4 100644 --- a/lua/app/ui/game_setting/game_setting_ui.lua +++ b/lua/app/ui/game_setting/game_setting_ui.lua @@ -18,7 +18,9 @@ function GameSettingUI:onLoadRootComplete() self.uiMap = self.root:genAllChildren() self:_display() self:_addListeners() - self:_bind() + self:addEventListener(EventManager.CUSTOM_EVENT.BIND_ACCOUNT_SUCCESS, function() + self:refreshAccountInfo() + end) end function GameSettingUI:onPressBackspace() @@ -46,16 +48,27 @@ end function GameSettingUI:initLoginBtn() self.uiMap["game_setting_ui.bg.google_sign_btn"]:addClickListener(function() - + if ModuleManager.AccountManager:getIsBinded() then + GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACCOUNT_ALREADY_BINDED_DESC)) + return + end + ModuleManager.AccountManager:bindAccount() end) - if DataManager.PlayerData:getIsBinded() then - self.uiMap["game_setting_ui.bg.google_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACCOUNT_ALREADY_BINDED_DESC)) - else - self.uiMap["game_setting_ui.bg.google_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BIND_ACCOUNT_DESC)) - end self.uiMap["game_setting_ui.bg.google_switch_btn"]:addClickListener(function() - + if ModuleManager.AccountManager:getIsBinded() then + ModuleManager.AccountManager:changeAccount() + else + local params = { + content = I18N:getGlobalText(I18N.GlobalConst.CHANGE_ACCOUNT_TIPS_DESC), + boxType = GConst.MESSAGE_BOX_TYPE.MB_OK_CANCEL, + okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK), + okFunc = function() + ModuleManager.AccountManager:changeAccount() + end + } + GFunc.showMessageBox(params) + end end) self.uiMap["game_setting_ui.bg.google_switch_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.CHANGE_ACCOUNT_DESC)) @@ -64,6 +77,7 @@ function GameSettingUI:initLoginBtn() deleteTx:addClickListener(function() ModuleManager.AccountManager:showDeleteUI() end) + self:refreshAccountInfo() end function GameSettingUI:_addListeners() @@ -117,9 +131,6 @@ function GameSettingUI:_addListeners() end) end -function GameSettingUI:_bind() -end - function GameSettingUI:refreshMusic() local offIcon = self.uiMap["game_setting_ui.bg.music_bg.off"] local onIcon = self.uiMap["game_setting_ui.bg.music_bg.on"] @@ -138,4 +149,12 @@ function GameSettingUI:refreshVoice() onIcon:setVisible(status == true) end +function GameSettingUI:refreshAccountInfo() + if ModuleManager.AccountManager:getIsBinded() then + self.uiMap["game_setting_ui.bg.google_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACCOUNT_ALREADY_BINDED_DESC)) + else + self.uiMap["game_setting_ui.bg.google_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BIND_ACCOUNT_DESC)) + end +end + return GameSettingUI \ No newline at end of file diff --git a/lua/app/userdata/player/player_data.lua b/lua/app/userdata/player/player_data.lua index 52abf7ca..2dcaffeb 100644 --- a/lua/app/userdata/player/player_data.lua +++ b/lua/app/userdata/player/player_data.lua @@ -121,10 +121,6 @@ function PlayerData:getAcountId() return self:getAccountInfo().id or GConst.EMPTY_STRING end -function PlayerData:getIsBinded() - return false -end - function PlayerData:addVitGemBuyCount() self.data.vitGemCount = self.data.vitGemCount + 1 end