源战役客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

329 rindas
11 KiB

pirms 1 mēnesi
  1. CustomRoleHead = CustomRoleHead or BaseClass()
  2. function CustomRoleHead:__init()
  3. if CustomRoleHead.Instance ~= nil then
  4. error("attempt to create singleton(CustomRoleHead) twice!")
  5. return
  6. end
  7. CustomRoleHead.Instance = self
  8. self.image_buff_list = {}
  9. self.cache_data_state = 0
  10. self.sent_data_state = false
  11. local scene_change = function()
  12. self:UpdateData()
  13. end
  14. GlobalEventSystem:Bind(SceneEventType.SCENE_CHANGED, scene_change)
  15. -- local onPhonePhotoLoad = function(image_path)
  16. -- local sent_succeed = function(result, image)
  17. -- if result then
  18. -- Message.show("图片上传成功")
  19. -- GlobalEventSystem:Fire(EventName.ROLEHEAD_UPLOAD_SUCCEED)
  20. -- else
  21. -- Message.show("图片上传失败,请再次尝试")
  22. -- end
  23. -- end
  24. -- local mainrole_vo = RoleManager.Instance.mainRoleInfo
  25. -- if mainrole_vo then
  26. -- CustomRoleHead:getInstance():Sent(sent_succeed, mainrole_vo.picture_ver + 1)
  27. -- end
  28. -- end
  29. -- GlobalEventSystem:Bind(EventName.PHONE_PHOTO_LOADBACK, onPhonePhotoLoad)
  30. end
  31. function CustomRoleHead:getInstance()
  32. if CustomRoleHead.Instance == nil then
  33. CustomRoleHead.New()
  34. end
  35. return CustomRoleHead.Instance
  36. end
  37. -- ref_tar目标
  38. -- raw_image图片容器
  39. -- role_id 角色ID
  40. -- role_career 角色职业
  41. -- role_sex性别
  42. -- role_turn转身数
  43. -- out_server 已不用 可以传 nil
  44. -- head_ver 角色头像版本号
  45. -- picture 角色头像路径,如无可传 nil
  46. -- is_big是否大图
  47. -- local_picture_id 本地图标的id
  48. -- is_ear --是否露头
  49. function CustomRoleHead:Create(ref_tar, raw_image, role_id, role_career, role_sex, role_turn, out_server, head_ver, picture, is_big, local_picture_id, is_ear)
  50. local call_func = function(result, image)
  51. if ref_tar._use_delete_method then
  52. return
  53. end
  54. if result and image and not IsNull(raw_image) then
  55. raw_image.texture = image
  56. else
  57. logWarn("load imagse is null")
  58. end
  59. end
  60. if role_id == "" or not role_id then
  61. logWarn("CustomRoleHead role_id is error")
  62. return
  63. end
  64. -- 兼容聊天AI做的容错,去掉外层的职业性别和转生的判断
  65. role_career = role_career and role_career ~= 0 and role_career or 1
  66. role_sex = role_sex and role_sex ~= 0 and role_sex or 1
  67. role_turn = role_turn and role_turn ~= 0 and role_turn or 1
  68. local now_role_ver = head_ver or ""
  69. local has_load = false
  70. local load_default_res = function()
  71. if has_load then
  72. return
  73. end
  74. has_load = true
  75. local cfg = Config.Transfercareer[role_career .. "@" .. role_turn]
  76. if not cfg then
  77. print("no Transfercareer by roleid:" .. role_id)
  78. return
  79. end
  80. --玩家默认职业相片 加载后可常存
  81. local default_call = function(obj)
  82. if obj and obj[0] then
  83. call_func(true, obj[0], role_id)
  84. else
  85. call_func(false, nil, role_id)
  86. end
  87. end
  88. local res_name
  89. local ab_name
  90. -- if is_big then
  91. res_name = "head_icon_" .. cfg.image_id
  92. ab_name = "icon_head_icon_" .. res_name
  93. -- else
  94. -- if is_ear then
  95. -- res_name = "head_ear_" .. cfg.icon
  96. -- else
  97. -- res_name = "head_circle_" .. cfg.icon
  98. -- end
  99. -- ab_name = "icon_head_" .. res_name
  100. -- end
  101. lua_resM:loadTexture(self, ab_name, {res_name .. ".png"}, default_call, ASSETS_LEVEL.LOW)
  102. end
  103. local load_local_picture_res = function()
  104. if has_load or not local_picture_id then
  105. return
  106. end
  107. has_load = true
  108. --玩家默认职业相片 加载后可常存
  109. local default_call = function(obj)
  110. if obj and obj[0] then
  111. call_func(true, obj[0], role_id)
  112. else
  113. call_func(false, nil, role_id)
  114. end
  115. end
  116. local res_name = ""
  117. local ab_name = ""
  118. -- if is_big then
  119. res_name = "head_icon_" .. local_picture_id
  120. ab_name = "icon_head_icon_" .. res_name
  121. -- else
  122. -- if is_ear then
  123. -- res_name = "head_ear_" .. local_picture_id
  124. -- else
  125. -- res_name = "head_circle_" .. local_picture_id
  126. -- end
  127. -- ab_name = "icon_head_" .. res_name
  128. -- end
  129. lua_resM:loadTexture(self, ab_name, {res_name .. ".png"}, default_call, ASSETS_LEVEL.LOW)
  130. end
  131. -- if (now_role_ver == "" or now_role_ver == 0 or picture == "") and (not local_picture_id or local_picture_id == "" or local_picture_id == 0) then
  132. -- load_default_res()
  133. -- return
  134. -- elseif local_picture_id and (local_picture_id ~= 0 and local_picture_id ~= "") then
  135. if local_picture_id and (local_picture_id ~= 0 and local_picture_id ~= "") then
  136. load_local_picture_res()
  137. return
  138. else
  139. -- setTimeout(load_default_res, 3)
  140. load_default_res()
  141. end
  142. -- local playerInfo = LoginController.Instance:GetPlatUserInfo()
  143. -- local server_id = out_server or playerInfo.server_id
  144. -- local role_info = role_id
  145. -- local role_info_cache = role_info .. now_role_ver
  146. -- self.cache_data_state = self.cache_data_state + 1
  147. -- local res_callback = function(is_succ, is_cache, buffer)
  148. -- local result = false
  149. -- if is_succ and buffer then
  150. -- has_load = true
  151. -- if not is_cache then
  152. -- self.image_buff_list[role_info_cache] = buffer
  153. -- end
  154. -- result = true
  155. -- end
  156. -- if call_func then
  157. -- call_func(result, buffer, role_id)
  158. -- end
  159. -- self.cache_data_state = self.cache_data_state - 1
  160. -- --下载成功 ,头像是自己的,只存拍照和相册的
  161. -- if is_succ and role_id == RoleManager.Instance:GetMainRoleId() and (not local_picture_id or local_picture_id == 0 or local_picture_id == "") then
  162. -- GlobalEventSystem:Fire(EventName.SAVE_CUSTOME_HEAD)
  163. -- end
  164. -- end
  165. -- local res_path, res_name = UtilGetRolePicPath(role_id, server_id, now_role_ver)
  166. -- local save_path = res_path .. res_name
  167. -- local role_image = self.image_buff_list[role_info_cache]
  168. -- if role_image then
  169. -- print("cache role head")
  170. -- res_callback(true, true, role_image)
  171. -- return
  172. -- end
  173. -- local read_local_date = function(result)
  174. -- if not result then
  175. -- return
  176. -- end
  177. -- local load_func = function(image)
  178. -- if image then
  179. -- res_callback(true, false, image)
  180. -- else
  181. -- res_callback(false, false, image)
  182. -- end
  183. -- end
  184. -- Util.LoadRawTexture(save_path, load_func)
  185. -- end
  186. -- local is_exsit = false
  187. -- is_exsit = Util.FileExists(save_path)
  188. -- if is_exsit then
  189. -- print("local role head")
  190. -- read_local_date(true)
  191. -- return
  192. -- end
  193. -- local url = ClientConfig.rolehead_download_url .. "img/" .. role_info .. ".jpg"
  194. -- print("download role head")
  195. -- HttpUtil.HttpDownLoad(url, save_path, read_local_date, timeout)
  196. end
  197. function CustomRoleHead:Sent(sent_callback, head_ver)
  198. local playerInfo = LoginController.Instance:GetPlatUserInfo()
  199. if not playerInfo then
  200. return
  201. end
  202. self.sent_data_state = true
  203. local mainrole_vo = RoleManager.Instance:GetMainRoleVo()
  204. local get_param = {
  205. accname = tostring(playerInfo.account),
  206. platname = ClientConfig.plat_name,
  207. server = tostring(playerInfo.server_id),
  208. player_id = mainrole_vo.role_id,
  209. game = "mrsd",
  210. }
  211. local res_path, res_name = UtilGetRolePicPath(mainrole_vo.role_id, nil, head_ver)
  212. local sent_back_func = function(is_succ, data)
  213. local load_succeed = false
  214. local buffer = nil
  215. local call_back = function()
  216. if sent_callback then
  217. sent_callback(load_succeed, buffer)
  218. end
  219. self.sent_data_state = false
  220. end
  221. if is_succ then
  222. local json_obj = JsonToTable(data)
  223. if json_obj then
  224. local ret = json_obj["ret"]
  225. if tonumber(ret) == 0 then
  226. local load_func = function(image)
  227. if image then
  228. load_succeed = true
  229. buffer = image
  230. end
  231. call_back(load_succeed, buffer)
  232. end
  233. Util.LoadRawTexture(res_path .. res_name, load_func)
  234. return
  235. elseif tonumber(ret) == 2 then --len字节
  236. Message.show("上传图片数据大小超过限制,请重新上传")
  237. return
  238. end
  239. end
  240. end
  241. call_back(load_succeed, buffer)
  242. end
  243. HttpUtil.HttpByteBuffSent(ClientConfig.rolehead_url .. "api/upload.php", get_param, res_path .. res_name, sent_back_func)
  244. end
  245. function CustomRoleHead:ComplainRoleHead(img_name)
  246. if img_name == "" or not img_name then
  247. Message.show("玩家头像数据异常")
  248. return
  249. end
  250. local sent_back_func = function(is_succ, data)
  251. -- local json_obj = JsonToTable(data)
  252. -- if is_succ and json_obj then
  253. -- local ret = json_obj["ret"]
  254. -- if tonumber(ret) == 0 then
  255. -- return
  256. -- end
  257. -- end
  258. if is_succ then
  259. Message.show("举报已经收到,感谢你的反馈")
  260. else
  261. Message.show("举报失败")
  262. end
  263. end
  264. local ticket = "414de19367d6eea5ee1014fa75917aa4"
  265. local now_method = "set_img_status"
  266. local cur_time = tostring(os.time())
  267. local post_param = {
  268. time = cur_time,
  269. method = now_method,
  270. sign = string.lower(Util.md5(ticket .. cur_time .. now_method)),
  271. game = "xjhx",
  272. imgname = img_name,
  273. }
  274. HttpUtil.HttpPostRequest(ClientConfig.rolehead_url.."api/api.php", post_param, sent_back_func, 1000)
  275. end
  276. function CustomRoleHead:UpdateData()
  277. if self.cache_data_state > 0 or self.sent_data_state then
  278. return
  279. end
  280. for role_id, buffer in pairs(self.image_buff_list) do
  281. if buffer then
  282. destroy(buffer)
  283. self.image_buff_list[role_id] = nil
  284. end
  285. end
  286. self.image_buff_list = {}
  287. end