123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- const interactInfo = require('../data/interactInfo');
- var { UserInteractionType } = require('../utils/GameEnum');
- var UserInformationApi = require('../net/UserInformationApi');
- const DWTool = require('../utils/DWTool');
- cc.Class({
- extends: cc.Component,
- properties: {
- //互动次数已满提示
- interactionFullNode: cc.Node,
- //互动CD中提示
- interactionCDNode: cc.Node,
- timeLabel: cc.Label,
- //亲密度显示
- intimacyNode: cc.Node,
- //反抗成功
- revoltSuccessNode: cc.Node,
- //讨好成功
- playUpSuccessNode: cc.Node,
- //互动选项节点
- interactionSelectNode: cc.Node,
- interactionTitleRichText: cc.RichText,
- //互动选项item
- interactionItemPrefab: cc.Prefab,
- },
- // LIFE-CYCLE CALLBACKS:
- init(uid, interactionInfo, userInformation) {
- this.node.parent = cc.find("Canvas");
- this.node.setContentSize(cc.view.getVisibleSize());
- this.node.active = false;
- this.uid = uid;
- this.userInformation = userInformation;
- this.interactionInfo = interactionInfo;
- },
- onLoad () {
- },
- start () {
- },
- onDisable() {
- this.node.zIndex = 0;
- this.hideAllNode();
- //销毁选项
- for (let child of this.interactionSelectNode.children) {
- if (child.getComponent('UserInteractionItem') != undefined) {
- child.destroy();
- }
- }
- this.activeNode = null;
- },
- update (dt) {
- if (this.interactionCDNode.active === true) {
- var curTimestamp = parseInt(new Date().getTime());
- if ((this.cdEnd - curTimestamp) > 0) {
- this.timeLabel.string = DWTool.calculateTime((this.cdEnd - curTimestamp) / 1000);
- } else {
- this.showInteraction();
- }
- }
- },
- closeNodeAction() {
- // this.node.active = false;
- this.hideNodeAnimation();
- },
- hideAllNode() {
- this.interactionFullNode.active = false;
- this.interactionCDNode.active = false;
- this.intimacyNode.active = false;
- this.revoltSuccessNode.active = false;
- this.playUpSuccessNode.active = false;
- this.interactionSelectNode.active = false;
- },
- showNodeAnimation(showNode) {
- this.activeNode = showNode;
- showNode.setScale(0,0);
- let scaleAnimation = cc.scaleTo(0.15,1,1);
- showNode.runAction(scaleAnimation);
- },
- hideNodeAnimation() {
- if (this.activeNode) {
- let scaleAnimation = cc.scaleTo(0.15,0,0);
- let finish = cc.callFunc(() => {
- this.node.active = false;
- }, this);
- let sequenceAcation = cc.sequence(scaleAnimation, finish);
- this.activeNode.runAction(sequenceAcation);
- } else {
- this.node.active = false;
- }
- },
- //亲密度显示
- showIntimacyInfo(isCommon) {
- this.node.zIndex += 1;
- this.node.active = true;
- this.hideAllNode();
- this.intimacyNode.active = true;
- this.showNodeAnimation(this.intimacyNode);
- this.intimacyMng = this.intimacyNode.getComponent('UserIntimacyInfo');
- this.intimacyMng.configIntimacyInfo(this.interactionInfo,true, isCommon);
- },
- //互动操作相关
- showInteraction(interactionType) {
- this.node.zIndex += 1;
- this.node.active = true;
- if (interactionType != undefined) {
- this.interactionType = interactionType;
- }
- if (this.interactionInfo.cnt >= 2) {
- this.interactionIsFull();
- return;
- }
- if (this.interactionIsCD() == true ) {
- return;
- }
- this.hideAllNode();
- this.interactionSelectNode.active = true;
- this.showNodeAnimation(this.interactionSelectNode);
- var originY = (this.interactionSelectNode.height/2) - 85;
- switch (this.interactionType) {
- case UserInteractionType.Common:
- this.interactionTitleRichText.string = "<outline color=#e1596c width=3><b>互 动</b></outline>";
- interactInfo.interactInfo5.forEach(item => {
- var itemNode = cc.instantiate(this.interactionItemPrefab);
- itemNode.parent = this.interactionSelectNode;
- itemNode.y = originY;
- originY -= (18 + 80);
- var itemMng = itemNode.getComponent('UserInteractionItem');
- itemMng.init(this);
- itemMng.configData(item);
- });
- break;
- case UserInteractionType.PlayUp:
- this.interactionTitleRichText.string = "<outline color=#e1596c width=3><b>讨 好</b></outline>";
- interactInfo.interactInfo1.forEach(item => {
- var itemNode = cc.instantiate(this.interactionItemPrefab);
- itemNode.parent = this.interactionSelectNode;
- itemNode.y = originY;
- originY -= (18 + 80);
- var itemMng = itemNode.getComponent('UserInteractionItem');
- itemMng.init(this);
- itemMng.configData(item);
- });
- break;
- case UserInteractionType.Revolt:
- this.interactionTitleRichText.string = "<outline color=#e1596c width=3><b>反 抗</b></outline>";
- interactInfo.interactInfo2.forEach(item => {
- var itemNode = cc.instantiate(this.interactionItemPrefab);
- itemNode.parent = this.interactionSelectNode;
- itemNode.y = originY;
- originY -= (18 + 80);
- var itemMng = itemNode.getComponent('UserInteractionItem');
- itemMng.init(this);
- itemMng.configData(item);
- });
- break;
- case UserInteractionType.Pacify:
- this.interactionTitleRichText.string = "<outline color=#e1596c width=3><b>安 抚</b></outline>";
- interactInfo.interactInfo3.forEach(item => {
- var itemNode = cc.instantiate(this.interactionItemPrefab);
- itemNode.parent = this.interactionSelectNode;
- itemNode.y = originY;
- originY -= (18 + 80);
- var itemMng = itemNode.getComponent('UserInteractionItem');
- itemMng.init(this);
- itemMng.configData(item);
- });
- break;
- case UserInteractionType.Order:
- this.interactionTitleRichText.string = "<outline color=#e1596c width=3><b>使 唤</b></outline>";
- interactInfo.interactInfo4.forEach(item => {
- var itemNode = cc.instantiate(this.interactionItemPrefab);
- itemNode.parent = this.interactionSelectNode;
- itemNode.y = originY;
- originY -= (18 + 80);
- var itemMng = itemNode.getComponent('UserInteractionItem');
- itemMng.init(this);
- itemMng.configData(item);
- });
- break;
- }
- },
- selectInteraction() {
- UserInformationApi.postInteract(this.uid, this.interactionType, (responseData) => {
- console.log('互动操作成功' + JSON.stringify(responseData));
- this.interactionResponse(responseData);
- this.userInformation.configIntimacy(responseData);
- }, (error) => {
- console.log('互动操作失败' + error);
- });
- },
- interactionResponse(responseData) {
- this.hideAllNode();
- switch (this.interactionType) {
- case UserInteractionType.Common:
- this.playUpSuccessNode.active = true;
- this.showNodeAnimation(this.playUpSuccessNode);
- break;
- case UserInteractionType.PlayUp:
- this.playUpSuccessNode.active = true;
- this.showNodeAnimation(this.playUpSuccessNode);
- break;
- case UserInteractionType.Revolt:
- this.revoltSuccessNode.active = true;
- this.showNodeAnimation(this.revoltSuccessNode);
- break;
- case UserInteractionType.Pacify:
- this.playUpSuccessNode.active = true;
- this.showNodeAnimation(this.playUpSuccessNode);
- break;
- case UserInteractionType.Order:
- this.revoltSuccessNode.active = true;
- this.showNodeAnimation(this.revoltSuccessNode);
- break;
- }
- this.interactionInfo.cd = responseData.cd;
- this.interactionInfo.cdEnd = responseData.cdEnd;
- this.interactionInfo.cnt = responseData.cnt;
- this.interactionInfo.heart = responseData.heart;
- this.interactionInfo.intimacy = responseData.intimacy;
- this.playUpSuccessMng = this.playUpSuccessNode.getComponent('UserIntimacyInfo');
- let isCommon = this.interactionType == UserInteractionType.Common ? true : false;
- this.playUpSuccessMng.configIntimacyInfo(this.interactionInfo,false, isCommon);
- },
- //当天互动次数已满
- interactionIsFull() {
- this.hideAllNode();
- this.interactionFullNode.active = true;
- this.showNodeAnimation(this.interactionFullNode);
- },
- //正在CD中
- interactionIsCD() {
- this.hideAllNode();
- var curTimestamp = parseInt(new Date().getTime()); //当前时间戳
- this.cdEnd = this.interactionInfo.cdEnd;
- if ((this.cdEnd - curTimestamp) > 0) {
- this.interactionCDNode.active = true;
- this.showNodeAnimation(this.interactionCDNode);
- this.timeLabel.string = DWTool.calculateTime((this.cdEnd - curTimestamp) / 1000);
- return true;
- } else {
- return false;
- }
- },
- //讨好、安抚成功分享
- playUpShare() {
- if (!CC_WECHATGAME) {
- return;
- }
- var shareTitle = '一起来互动增长亲密度吧!';
- window.wx.shareAppMessage({
- title: shareTitle,
- imageUrl: 'http://t2.hddhhn.com/uploads/tu/201806/9999/eae9e74ec8.jpg',
- });
- },
- //反抗、使唤成功分享
- revoltShare() {
- if (!CC_WECHATGAME) {
- return;
- }
- var shareTitle = '真解气,一起来反抗老板的剥削!';
- if (this.interactionType == UserInteractionType.Order) {
- shareTitle = '真爽,一起来使唤艺人!';
- }
- window.wx.shareAppMessage({
- title: shareTitle,
- imageUrl: 'http://t2.hddhhn.com/uploads/tu/201806/9999/eae9e74ec8.jpg',
- });
- },
- //邀请互动
- inviteInteractionShare() {
- if (!CC_WECHATGAME) {
- return;
- }
- var shareTitle = '一起来互动增长亲密度吧!';
- window.wx.shareAppMessage({
- title: shareTitle,
- imageUrl: 'http://t2.hddhhn.com/uploads/tu/201806/9999/eae9e74ec8.jpg',
- });
- }
- });
|