2025-04-24 17:03:28 +08:00

188 lines
4.7 KiB
JavaScript

import GameModel from "../ts/core/GameModel";
import MsgAlert from "../ts/game/msg/MsgAlert";
import FGHUD from "../ts/gear_2.3.4/fgui/FGHUD";
import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil";
cc.Class({
extends: cc.Component,
properties: {
aimLab: cc.Label,
listItem: cc.Node,
listContent: cc.Node,
searchEdit: cc.EditBox,
},
onLoad() {
this.clickNum = 1;
this.listdata = {};
this.bangdata = {};
this.currentSelected = -1;
this.preitem = null;
},
loadBangList(data) {
// GameModel.player.bangid = 0;
FGHUD.hideLoading();
this.currentSelected = -1;
this.listdata = data;
this.aimLab.string = '';
this.listContent.destroyAllChildren();
this.maxLength = data.length;
this.currentLenth = 7;
this.listContent.height = this.currentLenth * this.listItem.height;
if (this.listContent.height < this.listContent.parent.height) {
this.listContent.height = this.listContent.parent.height;
}
for (let index = 0; index < this.currentLenth; index++) {
if (index >= this.maxLength) {
return;
}
let bang = data[index];
if (bang == null) {
continue;
}
let item = cc.instantiate(this.listItem);
item.active = true;
item.parent = this.listContent;
item.active = true;
item.x = 0;
item.y = -index * item.height;
if (index % 2 == 0) {
item.getChildByName('bg2').active = true;
}
SKUIUtil.setLabel(item, "name", bang.name);
SKUIUtil.setLabel(item, "num", bang.bangid);
SKUIUtil.setLabel(item, "count", bang.rolenum);
SKUIUtil.setLabel(item, "master", bang.mastername);
item.bangtag = index;
this.tagIndex = index;
}
},
onNextBtn(e, d) {
if (this.clickNum >= this.maxLength) return;
if (this.clickNum >= Math.ceil(this.maxLength / 7)){
MsgAlert.addMsg("已經是最後一頁啦")
return
}
this.clickNum = this.clickNum + 1;
this.listContent.destroyAllChildren();
let num = 7;
if (this.listContent.height < this.listContent.parent.height) {
this.listContent.height = this.listContent.parent.height;
}
let y_N = 0;
let dx;
for (let index = 0; index < num; index++) {
dx = this.clickNum * num - num + index;
if (dx >= this.maxLength) {
return;
}
let item = cc.instantiate(this.listItem);
item.active = true;
item.parent = this.listContent;
item.active = true;
item.x = 0;
item.y = -y_N * item.height;
if (index % 2 == 0) {
item.getChildByName('bg2').active = true;
}
SKUIUtil.setLabel(item, "name", this.listdata[dx].name);
SKUIUtil.setLabel(item, "num", this.listdata[dx].bangid);
SKUIUtil.setLabel(item, "count", this.listdata[dx].rolenum);
SKUIUtil.setLabel(item, "master", this.listdata[dx].mastername);
item.bangtag = dx;
this.tagIndex = dx;
y_N = y_N + 1;
}
},
onUpBtn() {
if (this.clickNum == 1) {
MsgAlert.addMsg("已經是第一頁啦")
return;
}
if (this.clickNum > 1) {
this.clickNum = this.clickNum - 1;
}
this.listContent.destroyAllChildren();
let num = 7;
if (this.listContent.height < this.listContent.parent.height) {
this.listContent.height = this.listContent.parent.height;
}
let y_N = 0;
let dx;
for (let index = 0; index < num; index++) {
y_N = y_N + 1;
dx = num * this.clickNum - y_N;
let item = cc.instantiate(this.listItem);
item.parent = this.listContent;
item.active = true;
item.x = 0;
item.y = -(num - y_N) * item.height;
if (index % 2 == 0) {
item.getChildByName('bg2').active = true;
}
SKUIUtil.setLabel(item, "name", this.listdata[dx].name);
SKUIUtil.setLabel(item, "num", this.listdata[dx].bangid);
SKUIUtil.setLabel(item, "count", this.listdata[dx].rolenum);
SKUIUtil.setLabel(item, "master", this.listdata[dx].mastername);
item.bangtag = dx;
this.tagIndex = dx;
}
},
searchBtnClicked(e, d) {
if (this.searchEdit.string == "") {
return;
}
GameModel.send('c2s_searchbang', {
roleid: GameModel.player.roleid,
data: this.searchEdit.string
});
FGHUD.showLoading();
},
joinBtnClicked(e, d) {
if (this.currentSelected == -1) {
return;
}
if (this.bangdata == null) {
return;
}
GameModel.send('c2s_requestbang', {
roleid: GameModel.player.roleid,
bangid: this.bangdata.bangid
});
},
itemClicked(e, d) {
let item = e.target;
if (!item || this.currentSelected == item.bangtag) {
return;
}
let node = null;
if (SKUIUtil.isValid(this.preitem)) {
node = this.preitem.getChildByName("bg3");
if (node) {
node.active = false;
}
}
this.preitem = item;
if (SKUIUtil.isValid(this.preitem)) {
node = this.preitem.getChildByName('bg3');
if (node) {
node.active = true;
}
}
this.currentSelected = item.bangtag;
this.bangdata = this.listdata[this.currentSelected];
if (this.bangdata != null) {
this.aimLab.string = this.bangdata.aim;
}
},
});