difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"use strict";
cc._RF.push(module, '5d904pE+GpHbbm+7jDBqPPX', 'common_tips');
// Scripts/mod/tips/view/common_tips.js
 
"use strict";
 
var LoaderManager = require("loadermanager");
 
var PathTool = require("pathtool");
 
var CommonTips = cc.Class({
  "extends": BaseClass,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("tips", "common_tips");
    this.delay = arguments[0] || 30;
    this.initConfig();
  },
  initConfig: function initConfig() {
    LoaderManager.getInstance().loadRes(this.prefabPath, function (res_object) {
      var view = res_object;
      this.createRootWnd(view);
    }.bind(this));
  },
  createRootWnd: function createRootWnd(view) {
    this.root_wnd = view;
    this.root_wnd.setAnchorPoint(cc.v2(0.5, 0.5)); // this.root_wnd.setContentSize(cc.size(SCREEN_WIDTH, display.height))
 
    this.root_wnd.setContentSize(cc.size(SCREEN_WIDTH, 1280)); // this.root_wnd.setPosition(SCREEN_WIDTH * 0.5, SCREEN_HEIGHT * 0.5);
 
    this.root_wnd.setPosition(0, 0);
    ViewManager.getInstance().addToSceneNode(this.root_wnd, SCENE_TAG.msg);
    this.main_nd = this.root_wnd.getChildByName("main");
    this.bg_nd = this.main_nd.getChildByName("bg");
    this.label_rt = this.main_nd.getChildByName("label").getComponent(cc.RichText);
    this.registerEvent();
 
    if (this.str != null) {
      this.showTips(this.str, this.width, this.font_size);
    }
  },
  registerEvent: function registerEvent() {
    this.root_wnd.on(cc.Node.EventType.TOUCH_END, function () {
      require("tips_controller").getInstance().closeAllTips();
    }, this);
  },
  setPosition: function setPosition(x, y) {
    // this.main_nd.setAnchorPoint(cc.v2(1, 0));
    this.main_nd.setPosition(cc.v2(x, y));
  },
  addToParent: function addToParent(parent, zindex) {
    cc.log("common_tips");
  },
  setPos: function setPos(x, y) {
    this.main_nd.setPosition(cc.v2(x, y));
  },
  getBgContentSize: function getBgContentSize() {
    if (this.root_wnd) {
      return this.main_nd.getContentSize();
    }
  },
  getScreenBg: function getScreenBg() {
    return this.root_wnd;
  },
  addCallBack: function addCallBack(fun) {
    this.callback = fun;
 
    if (this.root_wnd) {
      this.callback();
    }
  },
  showTips: function showTips(str, width, font_size) {
    if (this.root_wnd == null) {
      this.str = str;
      this.width = width;
      this.font_size = font_size;
      return;
    }
 
    var font_size = font_size || 6;
    this.recoutTextFieldSize(str, width, font_size);
    var size = this.label_rt.node.getContentSize();
    var size_width = Math.max(80 + size.width, this.bg_nd.getContentSize().width);
    var size_height = Math.max(70 + size.height, this.bg_nd.getContentSize().height);
    this.main_nd.setContentSize(cc.size(size_width, size_height));
    this.bg_nd.setContentSize(cc.size(size_width, size_height)); // this.label_rt.node.setPosition(cc.v2(37, size_height - 30));
 
    if (this.callback) {
      this.callback();
    }
  },
  //从新计算文本的大小
  recoutTextFieldSize: function recoutTextFieldSize(str, width, font_size) {
    this.label_rt.maxWidth = width;
    this.label_rt.fontSize = font_size;
    this.label_rt.lineHeight = font_size + 4;
    this.label_rt.string = str;
  },
  setAnchorPoint: function setAnchorPoint(pos) {
    if (this.root_wnd) {
      this.root_wnd.setAnchorPoint(pos);
    }
  },
  open: function open() {
    gcore.Timer.set(function () {
      require("tips_controller").getInstance().closeAllTips();
    }, this.delay * 1000, 1, "close");
  },
  close: function close() {
    if (this.root_wnd) {
      this.root_wnd.destroy();
      this.root_wnd = null;
    }
 
    LoaderManager.getInstance().releasePrefab(this.prefabPath);
    gcore.Timer.del("close");
  }
});
 
cc._RF.pop();