360 lines
8.4 KiB
JavaScript
360 lines
8.4 KiB
JavaScript
import GameModel from "../ts/core/GameModel";
|
|
import MsgAlert from "../ts/game/msg/MsgAlert";
|
|
|
|
let CPubFunction = require('../game/PubFunction');
|
|
let GoodsMgr = require('../game/GoodsMgr');
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
properties: {
|
|
item_prefab: cc.Prefab,
|
|
item_layout: cc.Node,
|
|
runSprite: cc.Node,
|
|
},
|
|
|
|
start () {
|
|
this.color_index1 = 0;
|
|
this.color_index2 = 0;
|
|
this.costs = {};
|
|
CPubFunction.runAnimation(this.runSprite);
|
|
let right = cc.find('Right', this.node);
|
|
if (right) {
|
|
right.runAction(cc.flipX(true));
|
|
}
|
|
this.setCurColor();
|
|
this.onColorClick();
|
|
},
|
|
|
|
/*
|
|
* 當前染色方案
|
|
*/
|
|
setCurColor () {
|
|
let color1 = GameModel.player.color1;
|
|
let color2 = GameModel.player.color2;
|
|
this.cur_color_index1 = this.color_index1;
|
|
this.cur_color_index2 = this.color_index2;
|
|
let data = GameModel.conf_role_color[GameModel.player.resid];
|
|
for (let key in data) {
|
|
if (key.indexOf('color1_') != -1) {
|
|
if (parseInt(data[key].color, 16) == color1) {
|
|
this.cur_color_index1 = parseInt(key.split('_')[1]);
|
|
}
|
|
}
|
|
if (key.indexOf('color2_') != -1) {
|
|
if (parseInt(data[key].color, 16) == color2) {
|
|
this.cur_color_index2 = parseInt(key.split('_')[1]);
|
|
}
|
|
}
|
|
}
|
|
this.color_index1 = this.cur_color_index1;
|
|
this.color_index2 = this.cur_color_index2;
|
|
this.setColor();
|
|
this.setTipLabel();
|
|
this.setCost();
|
|
},
|
|
|
|
/*
|
|
* 自選
|
|
*/
|
|
onColorClick () {
|
|
let node = cc.find('BtnColor', this.node);
|
|
if (node) {
|
|
node.setScale(1.2);
|
|
}
|
|
},
|
|
|
|
/*
|
|
* 定制
|
|
*/
|
|
onSaveClick () {
|
|
MsgAlert.addMsg('暫時未開放');
|
|
},
|
|
|
|
/*
|
|
* 左點擊
|
|
*/
|
|
onLeftRoleClick () {
|
|
let role = cc.find('role', this.node);
|
|
if (role) {
|
|
let logic = role.getComponent('ColoringRole');
|
|
logic.playNextAction(-1);
|
|
}
|
|
},
|
|
|
|
/*
|
|
* 右點擊
|
|
*/
|
|
onRightRoleClick () {
|
|
let role = cc.find('role', this.node);
|
|
if (role) {
|
|
let logic = role.getComponent('ColoringRole');
|
|
logic.playNextAction(1);
|
|
}
|
|
},
|
|
|
|
/*
|
|
* 部位一左點擊
|
|
*/
|
|
onLeftColor1Click () {
|
|
-- this.color_index1;
|
|
if (this.color_index1 < 0) {
|
|
this.color_index1 = 77;
|
|
}
|
|
this.setColor();
|
|
this.setTipLabel();
|
|
this.setCost();
|
|
},
|
|
|
|
/*
|
|
* 部位一右點擊
|
|
*/
|
|
onRightColor1Click () {
|
|
++ this.color_index1;
|
|
if (this.color_index1 > 77) {
|
|
this.color_index1 = 0;
|
|
}
|
|
this.setColor();
|
|
this.setTipLabel();
|
|
this.setCost();
|
|
},
|
|
|
|
/*
|
|
* 部位二左點擊
|
|
*/
|
|
onLeftColor2Click () {
|
|
-- this.color_index2;
|
|
if (this.color_index2 < 0) {
|
|
this.color_index2 = 77;
|
|
}
|
|
this.setColor();
|
|
this.setTipLabel();
|
|
this.setCost();
|
|
},
|
|
|
|
/*
|
|
* 部位二右點擊
|
|
*/
|
|
onRightColor2Click () {
|
|
++ this.color_index2;
|
|
if (this.color_index2 > 77) {
|
|
this.color_index2 = 0;
|
|
}
|
|
this.setColor();
|
|
this.setTipLabel();
|
|
this.setCost();
|
|
},
|
|
|
|
/*
|
|
* 部位顏色顯示
|
|
*/
|
|
setColor () {
|
|
let data = GameModel.conf_role_color[GameModel.player.resid];
|
|
if(!data){
|
|
console.log(data)
|
|
return
|
|
}
|
|
let color1 = this.hxcolorTransfrom('000000'), color2 = this.hxcolorTransfrom('000000');
|
|
if (this.color_index1 > 0 && this.color_index1 <= 77) {
|
|
color1 = this.hxcolorTransfrom(data['color1_'+(this.color_index1)].color);
|
|
}
|
|
if (this.color_index2 > 0 && this.color_index2 <= 77) {
|
|
color2 = this.hxcolorTransfrom(data['color2_'+(this.color_index2)].color);
|
|
}
|
|
|
|
cc.find('Color1/ImageColour', this.node).color = color1;
|
|
cc.find('Color2/ImageColour', this.node).color = color2;
|
|
cc.find('Color1/ImageCover', this.node).color = color1;
|
|
cc.find('Color2/ImageCover', this.node).color = color2;
|
|
|
|
let logic = cc.find('role', this.node).getComponent('ColoringRole');
|
|
if (this.color_index1 == 0 && this.color_index2 == 0) {
|
|
logic.unshowColorMask();
|
|
}
|
|
else {
|
|
logic.showColorMask(color1, color2);
|
|
}
|
|
},
|
|
|
|
/*
|
|
* 部位顏色提示
|
|
*/
|
|
setTipLabel () {
|
|
let data = GameModel.conf_role_color[GameModel.player.resid];
|
|
let tiplabel1 = cc.find('TipLabel1', this.node);
|
|
let tiplabel2 = cc.find('TipLabel2', this.node);
|
|
let colorlabel1 = cc.find('Color1/TextColourName', this.node);
|
|
let colorlabel2 = cc.find('Color2/TextColourName', this.node);
|
|
if (tiplabel1) {
|
|
let str = "部\n位\n一";
|
|
if (this.color_index1 != 0) {
|
|
str += "\n" + (this.color_index1);
|
|
}
|
|
tiplabel1.getComponent(cc.Label).string = str;
|
|
}
|
|
if (tiplabel2) {
|
|
let str = "部\n位\n二";
|
|
if (this.color_index2 != 0) {
|
|
str += "\n" + (this.color_index2);
|
|
}
|
|
tiplabel2.getComponent(cc.Label).string = str;
|
|
}
|
|
if (colorlabel1) {
|
|
let str = "原色";
|
|
if (this.color_index1 != 0) {
|
|
str = data['color1_'+(this.color_index1)].colorname;
|
|
}
|
|
colorlabel1.getComponent(cc.Label).string = str;
|
|
}
|
|
if (colorlabel2) {
|
|
let str = "原色";
|
|
if (this.color_index2 != 0) {
|
|
str = data['color2_'+(this.color_index2)].colorname;
|
|
}
|
|
colorlabel2.getComponent(cc.Label).string = str;
|
|
}
|
|
},
|
|
|
|
/*
|
|
* 消耗顯示
|
|
*/
|
|
setCost () {
|
|
let cost_node = cc.find('Cost', this.node);
|
|
if (!cost_node) { return; }
|
|
if ((this.color_index1 == 0 && this.color_index2 == 0) || (this.color_index1 == this.cur_color_index1 && this.color_index2 == this.cur_color_index2)) {
|
|
cost_node.active = false;
|
|
}
|
|
else {
|
|
cost_node.active = true;
|
|
let costs = {};
|
|
if ((this.color_index1 != 0) && (this.color_index1 != this.cur_color_index1)) {
|
|
let item = GameModel.conf_role_color[GameModel.player.resid]['color1_'+this.color_index1];
|
|
costs[item.itemid] = item.count;
|
|
}
|
|
if ((this.color_index2 != 0) && (this.color_index2 != this.cur_color_index2)) {
|
|
let item = GameModel.conf_role_color[GameModel.player.resid]['color2_'+this.color_index2];
|
|
if (!costs[item.itemid]) {
|
|
costs[item.itemid] = 0;
|
|
}
|
|
costs[item.itemid] += item.count;
|
|
}
|
|
|
|
for (let node of this.item_layout.children) {
|
|
let logic = node.getComponent('BagItem');
|
|
let count = costs[logic.getItemid()];
|
|
if (count) {
|
|
logic.setItemCount(count);
|
|
delete costs[logic.getItemid()];
|
|
}
|
|
else {
|
|
node.destroy();
|
|
}
|
|
}
|
|
for (let key in costs) {
|
|
let node = cc.instantiate(this.item_prefab);
|
|
node.setScale(0.5);
|
|
node.parent = this.item_layout;
|
|
let logic = node.getComponent('BagItem');
|
|
logic.rmSelectedNode();
|
|
logic.loadInfo({
|
|
itemid: key,
|
|
count: parseInt(costs[key]),
|
|
});
|
|
}
|
|
}
|
|
},
|
|
|
|
/*
|
|
* 本色
|
|
*/
|
|
onOriginClick () {
|
|
this.color_index1 = 0;
|
|
this.color_index2 = 0;
|
|
this.setColor();
|
|
this.setTipLabel();
|
|
this.setCost();
|
|
},
|
|
|
|
/*
|
|
* 還原本色
|
|
*/
|
|
onUseOriginClick () {
|
|
GameModel.notice.addMsg(1, '確定要還原未原始的顏色嗎! ', () => {
|
|
this.onOriginClick();
|
|
if (this.cur_color_index1 != this.color_index1 || this.cur_color_index2 != this.color_index2) {
|
|
GameModel.send('c2s_change_role_color', {
|
|
index1: this.color_index1,
|
|
index2: this.color_index2,
|
|
});
|
|
}
|
|
}, () => {});
|
|
},
|
|
|
|
/*
|
|
* 顏色轉換
|
|
*/
|
|
hxcolorTransfrom (color) {
|
|
let num = parseInt(color, 16);
|
|
let r = Math.floor(num/256/256);
|
|
let g = Math.floor(num/256%256);
|
|
let b = Math.floor(num%256);
|
|
return new cc.Color(r, g, b);
|
|
},
|
|
|
|
onCloseClick () {
|
|
// console.log('close ColoringRolePanel');
|
|
this.node.destroy();
|
|
},
|
|
|
|
/*
|
|
* 點擊變色
|
|
*/
|
|
onChangeClick () {
|
|
let rolecolor = GameModel.conf_role_color[GameModel.player.resid];
|
|
let data1, data2;
|
|
if (this.color_index1 != 0) {
|
|
data1 = rolecolor['color1_'+this.color_index1];
|
|
if (parseInt(data1.color, 16) != GameModel.player.color) {
|
|
let info = GoodsMgr.getItem(data1.itemid);
|
|
if (info.count < data1.count) {
|
|
MsgAlert.addMsg(`${info.name}數量不夠`);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if (this.color_index2 != 0) {
|
|
data2 = rolecolor['color2_'+this.color_index2];
|
|
if (parseInt(data2.color, 16) != GameModel.player.color) {
|
|
let info = GoodsMgr.getItem(data2.itemid);
|
|
if (info.count < data2.count) {
|
|
MsgAlert.addMsg(`${info.name}數量不夠`);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* 不可以改會原色 */
|
|
/* if (this.color_index1 == 0) {
|
|
for (let key in rolecolor) {
|
|
let item = rolecolor[key];
|
|
if (parseInt(item.color, 16) == GameModel.player.color1 && key.indexOf('color1') != -1) {
|
|
this.color_index1 = parseInt(key.split('_')[1]);
|
|
}
|
|
}
|
|
} */
|
|
|
|
/* 不可以改會原色 */
|
|
/* if (this.color_index2 == 0) {
|
|
for (let key in rolecolor) {
|
|
let item = rolecolor[key];
|
|
if (parseInt(item.color, 16) == GameModel.player.color2 && key.indexOf('color2') != -1) {
|
|
this.color_index2 = parseInt(key.split('_')[1]);
|
|
}
|
|
}
|
|
} */
|
|
|
|
GameModel.send('c2s_change_role_color', {
|
|
index1: this.color_index1,
|
|
index2: this.color_index2,
|
|
});
|
|
},
|
|
});
|