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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"use strict";
cc._RF.push(module, '4865ccAO3RNXbVPMI4RA662', 'commonalertwin');
// Scripts/common/commonalertwin.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      通用提示框
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var CommonAlertWin = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("common", "common_alert");
    this.viewTag = arguments[0] || SCENE_TAG.dialogue;
  },
  openCallBack: function openCallBack() {
    this.main_panel = this.root_wnd.getChildByName("main_panel");
    this.background = this.seekChild("background");
    this.background.scale = FIT_SCALE;
    this.ok_btn = this.main_panel.getChildByName("ok_btn").getComponent(cc.Button);
    this.ok_btn_lb = this.seekChild("ok_txt", cc.Label);
    this.ok_btn_lo = this.seekChild("ok_txt", cc.LabelOutline);
    this.cancel_btn = this.main_panel.getChildByName("cancel_btn");
    this.cancel_btn_lb = this.seekChild("cancel_txt", cc.Label);
    this.close_btn = this.main_panel.getChildByName("close_btn");
    this.title_lb = this.seekChild("title_label", cc.Label);
    this.aler_des_rt = this.seekChild("aler_des", cc.RichText);
    this.click_jump_rt = this.seekChild("jumpBtn", cc.RichText);
    this.ok_btn.node.on("click", this.didClickOkBtn, this);
    this.cancel_btn.on("click", this.didClickCancleBtn, this);
  },
  registerEvent: function registerEvent() {
    this.close_btn.on(cc.Node.EventType.TOUCH_END, function (event) {
      if (this.close_callback) {
        this.close_callback();
      }
 
      Utils.playButtonSound(2);
      this.close();
    }.bind(this));
  },
  openRootWnd: function openRootWnd(params) {
    this.aler_des_rt.string = params.str;
    var resArr = [];
 
    if (params.other_args && params.other_args.resArr) {
      resArr = params.other_args.resArr;
    }
 
    if (resArr && resArr.length > 0) {
      for (var i = 0; i < resArr.length; ++i) {
        this.loadRes(resArr[i], function (resObject) {
          this.aler_des_rt.addSpriteFrame(resObject);
        }.bind(this));
      }
    }
 
    if (params.confirm_label) this.ok_btn_lb.string = params.confirm_label;
    if (params.cancel_label) this.cancel_btn_lb.string = params.cancel_label;
    this.confirm_callback = params.confirm_callback;
    this.cancel_callback = params.cancel_callback;
    this.close_callback = params.close_callback;
    this.main_panel.runAction(cc.scaleTo(0.1, 1));
 
    if (params.other_args && params.other_args.title) {
      this.title_lb.string = params.other_args.title;
    }
 
    if (params.other_args && params.other_args.extend_str) {
      this.aler_des_rt.node.y = 44;
 
      if (params.other_args.callFunc) {
        this.click_jump_rt.addTouchHandler("handler", params.other_args.callFunc);
      }
 
      this.click_jump_rt.string = params.other_args.extend_str;
    }
 
    if (params.other_args && params.other_args.maxWidth) {
      this.aler_des_rt.maxWidth = params.other_args.maxWidth;
    }
 
    if (params.other_args && params.other_args.align != null) {
      this.aler_des_rt.horizontalAlign = params.other_args.align;
    }
 
    if (params.other_args && params.other_args.delayS) {
      this.ok_btn.interactable = false;
      this.ok_btn.enableAutoGrayEffect = true;
      var s = params.other_args.delayS;
      var self = this;
 
      if (s > 0) {
        this.ok_btn_lo.color = new cc.Color(125, 125, 125);
        self.ok_btn_lb.string = params.confirm_label + "(" + s + ")";
        this.ok_btn.schedule(function () {
          s--;
 
          if (s <= 0) {
            self.ok_btn_lo.color = new cc.Color(106, 43, 0);
            self.ok_btn.unscheduleAllCallbacks();
            self.ok_btn.interactable = true;
            self.ok_btn.enableAutoGrayEffect = false;
            self.ok_btn_lb.string = params.confirm_label;
          } else {
            self.ok_btn_lb.string = params.confirm_label + "(" + s + ")";
          }
        }, 1);
      }
    }
  },
  closeCallBack: function closeCallBack() {
    this.ok_btn.unscheduleAllCallbacks();
  },
  didClickOkBtn: function didClickOkBtn() {
    Utils.playButtonSound(1);
    this.close();
    if (this.confirm_callback) this.confirm_callback();
  },
  didClickCancleBtn: function didClickCancleBtn() {
    Utils.playButtonSound(1);
    this.close();
    if (this.cancel_callback) this.cancel_callback();
  }
});
module.exports = CommonAlertWin;
 
cc._RF.pop();