userListInfoItem.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. listItemAddress: {
  5. default: null,
  6. type: cc.Label,
  7. serializable: true,
  8. },
  9. otherUserItem: {
  10. default: null,
  11. serializable: false,
  12. visible: false
  13. },
  14. bLoadUserInfo: false
  15. },
  16. setInfo(context) {
  17. let { item } = context;
  18. this.otherUserItem = item;
  19. this.listItemAddress.string = item.address;
  20. },
  21. /**
  22. * 进入其他用户的农场偷菜
  23. */
  24. onEnterOtherFarm() {
  25. GlobalD.OtherUserInfo = this.otherUserItem;
  26. if (GlobalD.OtherUserInfo.length <= 0) {
  27. console.log('没有用户', GlobalD.OtherUserInfo);
  28. }
  29. if (this.bLoadUserInfo) return;
  30. this.bLoadUserInfo = true;
  31. GlobalD.GameData.getOtherUserLandList(GlobalD.OtherUserInfo.userId, () => {
  32. this.bLoadUserInfo = false;
  33. });
  34. let _dogContainerScript = cc.find("Canvas/DogContainer").getComponent("DogContainer")
  35. _dogContainerScript.onGetOtherUserList();
  36. //不同用户,切换背景
  37. if (GlobalD.dapp && GlobalD.OtherUserInfo.address) {
  38. GlobalD.dapp.userLevel(GlobalD.OtherUserInfo.address).then((data) => {
  39. console.log("场景身份信息:" + JSON.stringify(data));
  40. const { err, res } = data;
  41. if (err === null) {
  42. //成功设置状态,并且更新
  43. GlobalD.GameData.onSwitchAddressBg(res);
  44. } else {
  45. console.log(err) // 申请失败
  46. GlobalD.GameData.showToast(this.ToastParent, err, 3);
  47. }
  48. })
  49. }
  50. }
  51. });