123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- import { _decorator, CCInteger, CCString, color, Color, Component, EventTouch, find, instantiate, Label, log, Node, Prefab, ScrollView, Sprite, tween, UIOpacity, UITransform, Vec2, Vec3 } from 'cc';
- import EventMgr from '../../script/Manager/EventMgr';
- import { LayerMgr } from '../../script/Manager/LayerMgr';
- import { GameCfg } from '../../script/Config/GameCfg';
- import { AudioManager } from '../../script/Manager/AudioMgr';
- import { BundleName } from '../../script/Config/EnumCfg';
- import { GDM } from './dtta/JsonMgr';
- import PlatformService from '../../script/Platform/PlatformService';
- import { recordedGameScreenParams } from '../../script/Platform/MiniGameApiBase';
- import { page_tishi } from './page/page_tishi';
- const { ccclass, property } = _decorator;
- @ccclass('BaseZhaocha')
- export class BaseZhaocha extends Component {
- arr_node_allitem: Array<Node> = []
- // @property(Prefab)
- // item_cha: Prefab = null
- sv_cha: ScrollView = null
- num_count: number = 0
- arr_areadygetnum: Array<number> = []
- answerName: Array<string> = [
- // "安全带",
- // "可乐",
- // "棒球帽",
- // "蓝牙耳机",
- // "LED",
- // "扶手",
- // "摄像头",
- // "电子屏幕",
- // "平板",
- // "悬浮座椅",
- // "收款机",
- // "万斯板鞋",
- ]
- FindObj() {
- this.sv_cha = this.node.getChildByName("ScrollView").getComponent(ScrollView)
- for (let index = 0; index < this.answerName.length; index++) {
- this.arr_node_allitem.push(this.node.getChildByName("mask").getChildByName("bg").getChildByName("item_" + index))// this.arr_node_allitem = this.node.getChildByName("mask").getChildByName("bg").children
- }
- this.num_count = this.answerName.length
- }
- setActiveItemFrame() {
- for (let index = 0; index < this.answerName.length; index++) {
- this.sv_cha.node.getChildByName("view").getChildByName("content").getChildByName(index.toString()).active = true
- }
- }
- setActiveAllNeedItemFrame() {
- for (let index = 0; index < this.answerName.length; index++) {
- }
- }
- bool_cantouch = true
- bool_needshowX = true
- protected start(): void {
- let data: recordedGameScreenParams = {
- duration: 300 // 10 否 录屏的时长,单位 s,必须大于 3s,最大值 300s(5 分钟)。
- }
- PlatformService.getInstance().platformApi.recordedGameScreenStart(data)
- EventMgr.ins.addEventListener("dontshow_x", () => {
- this.bool_needshowX = false
- this.scheduleOnce(() => {
- this.bool_needshowX = true
- }, 0.1)
- }, this)
- this.FindObj()
- this.setActiveItemFrame()
- this.node.on(Node.EventType.TOUCH_END, (event: EventTouch) => {
- if (this.bool_cantouch == false) return
- this.bool_cantouch = false
- this.scheduleOnce(() => {
- this.bool_cantouch = true
- }, 0.1)
- if (this.bool_needshowX) {
- // AudioManager.instance.playBundleAudio("false")
- let worldpos = event.getUILocation()
- let localpos = this.arr_node_allitem[0].parent.getComponent(UITransform).convertToNodeSpaceAR(new Vec3(worldpos.x, worldpos.y))
- LayerMgr.instance.ShowPrefab(BundleName.hall, "prefab/x", (node) => {
- node.parent = this.arr_node_allitem[0].parent
- node.setPosition(localpos)
- this.scheduleOnce(() => {
- node?.destroy()
- }, 0.3)
- })
- }
- }, this)
- EventMgr.ins.addEventListener("game_tishi", this.ShowTishi, this)
- for (let i = 0; i < this.arr_node_allitem.length; i++) {
- this.arr_node_allitem[i].on(Node.EventType.TOUCH_END, () => {
- if (this.arr_areadygetnum.indexOf(i) != -1) {
- // AudioManager.instance.playBundleAudio("false")
- return
- }
- AudioManager.instance.playBundleAudio("true")
- this.arr_areadygetnum.push(i)
- this.num_count--
- this.arr_node_allitem[i].getComponent(UIOpacity).opacity = 255
- this.arr_node_allitem[i].getComponent(Sprite).color = Color.RED
- LayerMgr.instance.ShowPrefab(BundleName.hall, "prefab/item_cha", (item) => {
- item.getChildByName("Label").getComponent(Label).string = this.answerName[i]
- let parent = this.getNullItem()
- item.parent = this.node
- let point = (this.arr_areadygetnum.length - 1) * 1.2 / this.answerName.length
- this.sv_cha.scrollToPercentHorizontal(point, 0.3, true)
- // 获取点击项的世界坐标,并转换为当前节点下的局部坐标
- let worldpos = this.arr_node_allitem[i].getWorldPosition()
- let localpos = this.node.getComponent(UITransform).convertToNodeSpaceAR(worldpos)
- item.setPosition(localpos)
- // 获取目标位置的世界坐标,并转换为 ScrollView 视口下的局部坐标
- let worldpos2 = parent.getWorldPosition()
- let scrollViewContainer = this.sv_cha.node.parent as Node // 假设 sv_cha 的父节点是视口容器
- let localpos2 = scrollViewContainer.getComponent(UITransform).convertToNodeSpaceAR(worldpos2)
- let gamecfg = GDM.gamecfgMgr.paixuLevelinfo.length > 0 ? GDM.gamecfgMgr.paixuLevelinfo[GameCfg.CurUnit] : GDM.gamecfgMgr.data[GameCfg.CurUnit]
- LayerMgr.instance.ShowSprite2("unit" + gamecfg.unit, "image/item" + i, item.getComponent(Sprite), (res) => {
- item.getComponent(Sprite).spriteFrame = res
- })
- // 开始动画,移动到目标位置
- tween(item)
- .to(0.3, { position: new Vec3(localpos2.x, localpos2.y, 0) })
- .call(() => {
- item.parent = parent
- item.setPosition(Vec3.ZERO)
- })
- .start()
- // 判断是否完成所有操作
- if (this.num_count == 0) {
- EventMgr.ins.dispatchEvent("game_win")
- }
- })
- }, this)
- }
- }
- getNullItem() {
- // for (let index = 0; index < this.sv_cha.content.children.length; index++) {
- // if (this.sv_cha.content.children[index].children.length == 0) {
- // return this.sv_cha.content.children[index]
- // }
- // }
- return this.sv_cha.content.children[this.arr_areadygetnum.length - 1]
- }
- ShowTishi() {
- console.log(this.num_showTip)
- for (let index = 0; index < this.answerName.length; index++) {
- if (this.arr_areadygetnum.indexOf(index) == -1 && !this.arr_node_allitem[index].getComponent(Sprite).color.equals(Color.GREEN)) {
- if (this.tishi_indexs.length != 0) {
- let idx = this.tishi_indexs.pop()
- this.ShowTishiView2(this.arr_tishi[idx])
- }
- else if (this.num_showTip == index) {
- // if (this.arr_node_allitem[index].active) {
- // this.arr_node_allitem[index].getComponent(Sprite).color = Color.YELLOW//new Color(57, 226, 42, 255)
- // console.log("active = true")
- // } else {
- // this.arr_node_allitem[index].active = true
- // this.arr_node_allitem[index].getComponent(Sprite).color = Color.YELLOW//new Color(57, 226, 42, 255)
- // this.scheduleOnce(() => {
- // // this.arr_node_allitem[index].active = false
- // }, 0)
- // console.log("active = false")
- // }
- this.arr_node_allitem[index].getComponent(Sprite).color = new Color(57, 226, 42, 255)
- this.arr_node_allitem[index].getComponent(UIOpacity).opacity = 255
- this.ShowTishiView()
- } else {
- this.arr_node_allitem[index].getComponent(UIOpacity).opacity = 255
- this.arr_node_allitem[index].getComponent(Sprite).color = Color.GREEN
- }
- return
- }
- }
- }
- num_showTip = -1
- protected str_tishi = ""
- @property([CCString])
- public arr_tishi: Array<string> = []
- @property([CCInteger])
- public tishi_indexs: Array<number> = []
- ShowTishiView() {
- LayerMgr.instance.ShowPrefab(BundleName.hall, "prefab/page_tishi", (node) => {
- node.getComponent(page_tishi).Init(this.str_tishi)
- })
- }
- ShowTishiView2(str: string) {
- LayerMgr.instance.ShowPrefab(BundleName.hall, "prefab/page_tishi", (node) => {
- node.getComponent(page_tishi).Init(str)
- })
- }
- protected onDestroy(): void {
- console.log("退出关卡")
- this.unscheduleAllCallbacks()
- }
- }
|