二进制位运算符号,与或非,多选框

/**通过二进制测试 遍历背包中选中可以出售的的装备列表 */
    public static getCanSellEquipList(rareList: number, starList: number): cl.Equipment[] {
        let userEquip = EquipData.getUserAllEquipsData()
        let equipList: cl.Equipment[] = []
        //遍历所有rere满足条件的
        for (let index = 1; index <= 5; index++) {
            if ((rareList & (1 << (index - 1))) > 0) {
                for (const equip in userEquip) {
                    if (Object.prototype.hasOwnProperty.call(userEquip, equip)) {
                        let equipConfig = EquipConfigLData.getEquipConfigById(userEquip[equip].id.toNumber())
                        if (index === equipConfig.rare) {
                            equipList.push(userEquip[equip])
                        }
                    }
                }
            }
        }
        //遍历所有rere满足条件的 里面 所有满足star的    如果没有rare,就不再判断star 直接返回空数组
        let sellEquipList: cl.Equipment[] = []
        for (let i = 1; i <= 5; i++) {
            if ((starList & (1 << (i - 1))) > 0) {
                for (const equip in equipList) {
                    if (Object.prototype.hasOwnProperty.call(equipList, equip)) {
                        let equipConfig = EquipConfigLData.getEquipConfigById(equipList[equip].id.toNumber())
                        if (i === equipConfig.star) {
                            sellEquipList.push(equipList[equip])
                        }
                    }
                }
            }
        }
        return sellEquipList
    }
    /*通过Map测试 遍历背包中选中可以出售的的装备列表 /
    public static getCanSellEquipListByMap(rareMap: rareMap, starMap: starMap): cl.Equipment[] {
        let userEquip = EquipData.getUserAllEquipsData()
        let equipList: cl.Equipment[] = []
        //遍历所有rere满足条件的
        for (let index = 0; index < Object.keys(rareMap).length; index++) {
            if (rareMap[index]) {
                for (const equip in userEquip) {
                    if (Object.prototype.hasOwnProperty.call(userEquip, equip)) {
                        let equipConfig = EquipConfigLData.getEquipConfigById(userEquip[equip].id.toNumber())
                        if ((RARE_SELL[index]) === equipConfig.rare) {
                            equipList.push(userEquip[equip])
                        }
                    }
                }
            }
        }
        //遍历所有rere满足条件的 里面 所有满足star的    如果没有rare,就不再判断star 直接返回空数组
        let sellEquipList: cl.Equipment[] = []
        for (let i = 0; i < Object.keys(starMap).length; i++) {
            if (starMap[i]) {
                for (const equip in equipList) {
                    if (Object.prototype.hasOwnProperty.call(equipList, equip)) {
                        let equipConfig = EquipConfigLData.getEquipConfigById(equipList[equip].id.toNumber())
                        if ((STAR_SELL[i]) === equipConfig.rare) {
                            sellEquipList.push(equipList[equip])
                        }
                    }
                }
            }
        }
        return sellEquipList
    }
    /

     * 根据Id获取玩家的装备信息
     * @param equipId
     */
    public static getEquipDataById(equipId: Long): cl.Equipment {
        let equipData: cl.Equipment = undefined
        if (!!equipId) {
            let userEquipData = UserLData.instance.userEquipList
            if (!!userEquipData) {
                for (let index = 0; index < userEquipData.length; index++) {
                    let element = userEquipData[index]
                    if (!!element && element.id.toNumber() === equipId.toNumber()) {
                        equipData = element
                        break
                    }
                }
            }
        }
        return equipData
    }

import { rareMap } from ‘./…/…/data/equip-data’;

import { PrefabBase } from “…/…/base”
import EquipData from “…/…/data/equip-data”
const { ccclass, property, menu } = cc._decorator

interface EnterParams {
callback?: Function
}

@ccclass
@(CC_EDITOR && menu(“Gamecomponent/CommonSelectContectPrefab”))
export default class CommonSelectContectPrefab extends PrefabBase {
///

///</BINDERS>

///<EVENTS>
static show(params: EnterParams = null, parent: cc.Node = null, callback: (layer: CommonSelectContectPrefab, node: cc.Node) => void = null) {

    PrefabBase.doShow("prefabs/component/common-select-contect-prefab", parent, params, callback);
}

protected onInit(params: EnterParams = null) {
    this._params = params
}

/**u_holder可以直接赋值这个方法,不用show出来一个预制体了 */
public init(params: EnterParams = null) {
    this._params = params
    //设置_rareList 和 _starList的初始
}

start() {
    this._rareList = 1
    this._starList = 1



    for (let index = 0; index < this.centerParent.children.length; index++) {
        this._rareMap[index] = this.centerParent.children[index].getComponent(cc.Toggle).isChecked
    }
    for (let index = 0; index < this.bottomParent.children.length; index++) {
        this._starMap[index] = this.bottomParent.children[index].getComponent(cc.Toggle).isChecked
    }


    this.initListEventListen()
}

private initListEventListen() {


//设置All的回调
private setAllSelected(isAll) {
    if (isAll != null) {
        cc.log("AllCheck", typeof (isAll))
        if (isAll) {
            this._rareList = 31
            this._starList = 31
        } else {
            this._rareList = 0
            this._starList = 0
        }
     

        for (let index = 0; index < this.centerParent.children.length; index++) {
            this._rareMap[index] = isAll.isChecked
        }
        for (let index = 0; index < this.bottomParent.children.length; index++) {
            this._starMap[index] = isAll.isChecked
        }
    }
}

//设置稀有度的回调
private selectCenterOne(isCheck) {
    if (isCheck.isChecked) {
        this._rareList += 1 << 0
    } else {
        this._rareList -= 1 << 0
    }
}
private selectCenterTwo(isCheck) {
    if (isCheck.isChecked) {
        this._rareList += 1 << 1                          (一般都用高级用法   “或”     this._rareList |= 1 << 1)
    } else {
        this._rareList -= 1 << 1                             (一般都用高级用法   “与”     this._rareList  &= 1 << 1)
    }
}
private selectCenterThree(isCheck) {
    if (isCheck.isChecked) {
        this._rareList += 1 << 2                    (一般都用高级用法   “或”     this._rareList |= 1 <<2)
    } else {
        this._rareList -= 1 << 2
    }
}
private selectCenterFour(isCheck) {
    if (isCheck.isChecked) {
        this._rareList += 1 << 3                         (一般都用高级用法   “或”     this._rareList |= 1 << 3)
    } else {
        this._rareList -= 1 << 3
    }
}
private selectCenterFive(isCheck) {
    if (isCheck.isChecked) {
        this._rareList += 1 << 4                      (一般都用高级用法   “或”     this._rareList |= 1 << 4)
    } else {
        this._rareList -= 1 << 4
    }
}

//设置星级的回调
private selectBottomOne(isCheck) {
    if (isCheck.isChecked) {
        this._starList += 1 << 0                               (一般都用高级用法   “非”     this._rareList |= 1 << 0)
    } else {
        this._starList -= 1 << 0
    }
}
private selectBottomTwo(isCheck) {
    if (isCheck.isChecked) {
        this._starList += 1 << 1                            (一般都用高级用法   “或”     this._rareList |= 1 << 1)
    } else {
        this._starList -= 1 << 1
    }
}
private selectBottomThree(isCheck) {
    if (isCheck.isChecked) {
        this._starList += 1 << 2                               (一般都用高级用法   “或”     this._rareList |= 1 << 2)
    } else {
        this._starList -= 1 << 2
    }
}
private selectBottomFour(isCheck) {
    if (isCheck.isChecked) {
        this._starList += 1 << 3                               (一般都用高级用法   “或”     this._rareList |= 1 << 3)
    } else {
        this._starList -= 1 << 3
    }
}
private selectBottomFive(isCheck) {
    if (isCheck.isChecked) {
        this._starList += 1 << 4                                 (一般都用高级用法   “或”     this._rareList |= 1 << 4)
    } else {
        this._starList -= 1 << 4
    }
}




private On_Test_ShowList() {
    cc.log("勾选列表 this._rareList", this._rareList)
    cc.log("勾选列表 this._starList", this._starList)

    cc.log("勾选列表 this._rareMap", this._rareMap)
    cc.log("勾选列表 this._starMap", this._starMap)
    cc.log("出售列表二进制List", EquipData.getCanSellEquipList(this._rareList, this._starList))
    cc.log("出售列表Map", EquipData.getCanSellEquipListByMap(this._rareMap, this._starMap))
}


///</EVENTS>

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值