6P 無序背包

/*無序背包,使用須知: * 1.先自行在ps中p好背包中物品的圖片,統(tǒng)一大小,并上傳 * 2、建立兩個數(shù)組 物品 (類型數(shù)值); 物品名 (類型字符); * 3.建立一個變量,物品詳情(類型數(shù)值) *4建立兩個UI,一個無序背包,一個物品詳情 **///背景底圖,自行替換唯一標識await ac.createImage({name: 'image1',index: 0,inlayer: 'window',resId: '$58057502',pos: {x: 640,y: 360,},anchor: {x: 50,y: 50,},opacity:100,scale:100,visible:true,verticalFlip:false,horizontalFlip:false,});//文本樣式await ac.createStyle({name:'style15',font:'方正楷體',bold:false,italic:false,fontSize:24,color:'#000000',speed:9,strokeColor:'#000000',shadowColor:'#000000',shadowPos:{x:0,y:0,},});/*=====================排序勿動=======================*/var paixu = [];// 保存ac.arr.exp到新變量paixu中,并為每個元素添加idpaixu = ac.arr.物品.map(function(value, index) {return {id: index, value: value};});// 對paixu中的數(shù)據(jù)進行從大到小的排序paixu.sort(function(a, b) {?return b.value - a.value;});// 去除所有小于0的數(shù)據(jù)paixu = paixu.filter(function(obj) {?return obj.value > 0;});/*=================按鈕的圖片,按照數(shù)組里物品的順序添加==================*/var tupian = ["","$58060752","$58060749","$58060748","$58060750","$58060747"];//計算滾動視圖高度,自行根據(jù)情況調(diào)整var H = (tupian.length/5+1)*100;//滾動視圖await ac.createScrollView({name:'gdst',index:0,inlayer:'window',visible:true,pos:{x:690,y:346,},anchor:{x:50,y:50,},size:{width:1040,height:544,},innerSize:{width:1072,height:H,},horizontalScroll:false,verticalScroll:true,});//按鈕y軸位子var Y1;if (tupian.length/5+1<3){ Y1 = 290 + H}else if (tupian.length/5+1>=3&&tupian.length/5+1<5){Y1 = 190 + H}else if (tupian.length/5+1>=4&&tupian.length/5+1<6){Y1 = 90 + H}var Y2 ;if (tupian.length/5+1<3){ Y2 = 190 + H}else if (tupian.length/5+1>=3&&tupian.length/5+1<5){Y2 = 90 + H}//按鈕x軸位子,自行更具情況調(diào)整var X0 = 70;var X1 = 270;var X2 = 470;var X3 = 670;var X4 = 870;/*----------------------------------按鈕1-------------------------------------*/var tu0 = paixu[0].id//按鈕圖片1await ac.createImage({name: 'wuping00',index: 0,inlayer: 'gdst',resId: tupian[tu0],pos: {x: X0,y: Y1,},anchor: {x: 51,y: 52,},opacity: 100,scale: 100,visible: true,verticalFlip: false,horizontalFlip: false,});//按鈕點出事件的函數(shù)(勿動)async function wp00() {?ac.var.物品詳情=paixu[0].id;//點擊音效(可自行更改)ac.playAudio({name: 'playAudio8',resId: '$54737155',vol: 80,effect: 'normal',loop: false,});//替換到物品詳情的UI(自行更改)await ac.replaceUI({name: 'replaceUI7',uiId: 'b9tcoazz',});}ac.addEventListener({type: ac.EVENT_TYPES.onTouchEnded,listener: wp00,target: 'wuping00',});//物品名+物品數(shù)量(自行修改xy軸位置,其他勿動。XY軸位置:pos: {x: X0,y: Y1-50,})await ac.createText({name: 'text00',index: 0,inlayer: 'gdst',visible: true,content: `<tag style=style15>${ac.arr.物品名[tu0]} ${ac.arr.物品[tu0]}</tag>`,pos: {x: X0,y: Y1-50,},size: {width: 170,height: 34,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});/*==============以下部分與按鈕1一樣,可復(fù)制按鈕1============ * 具體修改部分看圖片=*/var tu01 = paixu[1].id await ac.createImage({name: 'wuping001',index: 0,inlayer: 'gdst',resId: tupian[tu01],pos: {x: X1,y: Y1,},anchor: {x: 51,y: 52,},opacity: 100,scale: 100,visible: true,verticalFlip: false,horizontalFlip: false,});async function wp001() {?ac.var.物品詳情=paixu[1].id;?ac.playAudio({name: 'playAudio8',resId: '$54737155',vol: 80,effect: 'normal',loop: false,});?await ac.delay({time: 200,});await ac.replaceUI({name: 'replaceUI7',uiId: 'b9tcoazz',});}ac.addEventListener({type: ac.EVENT_TYPES.onTouchEnded,listener: wp001,target: 'wuping001',});await ac.createText({name: 'text001',index: 0,inlayer: 'gdst',visible: true,content: `<tag style=style15>${ac.arr.物品名[tu01]} ${ac.arr.物品[tu01]}</tag>`,pos: {x: X1,y: Y1-50,},size: {width: 170,height: 34,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});var tu02 = paixu[2].idawait ac.createImage({name: 'wuping002',index: 0,inlayer: 'gdst',resId: tupian[tu02],pos: {x: X2,y: Y1,},anchor: {x: 51,y: 52,},opacity: 100,scale: 100,visible: true,verticalFlip: false,horizontalFlip: false,});async function wp002() {?ac.var.物品詳情=paixu[2].id;?ac.playAudio({name: 'playAudio8',resId: '$54737155',vol: 80,effect: 'normal',loop: false,});await ac.delay({time: 200,});?await ac.replaceUI({name: 'replaceUI7',uiId: 'b9tcoazz',});}ac.addEventListener({type: ac.EVENT_TYPES.onTouchEnded,listener: wp002,target: 'wuping002',});await ac.createText({name: 'text002',index: 0,inlayer: 'gdst',visible: true,content: `<tag style=style15>${ac.arr.物品名[tu02]} ${ac.arr.物品[tu02]}</tag>`,pos: {x: X2,y: Y1-50,},size: {width: 170,height: 34,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});var tu03 = paixu[3].idawait ac.createImage({name: 'wuping003',index: 0,inlayer: 'gdst',resId: tupian[tu03],pos: {x: X3,y: Y1,},anchor: {x: 51,y: 52,},opacity: 100,scale: 100,visible: true,verticalFlip: false,horizontalFlip: false,});async function wp003() {?ac.var.物品詳情=paixu[3].id;?ac.playAudio({name: 'playAudio8',resId: '$54737155',vol: 80,effect: 'normal',loop: false,});await ac.delay({time: 200,});?await ac.replaceUI({name: 'replaceUI7',uiId: 'b9tcoazz',});}ac.addEventListener({type: ac.EVENT_TYPES.onTouchEnded,listener: wp003,target: 'wuping003',});await ac.createText({name: 'text003',index: 0,inlayer: 'gdst',visible: true,content: `<tag style=style15>${ac.arr.物品名[tu03]} ${ac.arr.物品[tu03]}</tag>`,pos: {x: X3,y: Y1-50,},size: {width: 170,height: 34,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});var tu04 = paixu[4].idawait ac.createImage({name: 'wuping004',index: 0,inlayer: 'gdst',resId: tupian[tu04],pos: {x: X4,y: Y1,},anchor: {x: 51,y: 52,},opacity: 100,scale: 100,visible: true,verticalFlip: false,horizontalFlip: false,});async function wp004() {?ac.var.物品詳情=paixu[4].id;?ac.playAudio({name: 'playAudio8',resId: '$54737155',vol: 80,effect: 'normal',loop: false,});await ac.delay({time: 200,});?await ac.replaceUI({name: 'replaceUI7',uiId: 'b9tcoazz',});}ac.addEventListener({type: ac.EVENT_TYPES.onTouchEnded,listener: wp004,target: 'wuping004',});await ac.createText({name: 'text004',index: 0,inlayer: 'gdst',visible: true,content: `<tag style=style15>${ac.arr.物品名[tu04]} ${ac.arr.物品[tu04]}</tag>`,pos: {x: X4,y: Y1-50,},size: {width: 170,height: 34,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});/*========================以下部分為物品詳情的UI=========================*///背景圖,自行更改await ac.createImage({name:'image1',index:0,inlayer:'window',resId:'$58057502',pos:{x:640,y:360,},anchor:{x:50,y:50,},opacity:100,scale:100,visible:true,verticalFlip:false,horizontalFlip:false,});await ac.createImage({name:'image2',index:0,inlayer:'window',resId:'$50352556',pos:{x:640,y:360,},anchor:{x:50,y:50,},opacity:100,scale:100,visible:true,verticalFlip:false,horizontalFlip:false,});//返回按鈕 自行更改async function fanhui(){await ac.replaceUI({name:'replaceUI5',uiId:'9qtaensq',});}await ac.createOption({name:'fan',index:0,inlayer:'window',visible:true,nResId:'$50154847',sResId:'$50154845',content:``,pos:{x:1220,y:52,},anchor:{x:50,y:50,},onTouchEnded:fanhui,});//圖片顯示控鍵 物品名,我寫了1~5,按格式自行添加新的物品,位置自行修改await ac.createTextDisplay({name: 'textDisplay6',index: 0,textGroup: [?{text: `${ac.arr.物品名[1]}`,condition: () => ac.var.物品詳情 === 1,},?{text: `${ac.arr.物品名[2]}`,condition: () => ac.var.物品詳情 === 2,},?{text: `${ac.arr.物品名[3]}`,condition: () => ac.var.物品詳情 === 3,},?{text: `${ac.arr.物品名[4]}`,condition: () => ac.var.物品詳情 === 4,},?{text: `${ac.arr.物品名[5]}`,condition: () => ac.var.物品詳情 === 5,},],pos: {x: 632,y: 507,},size: {width: 266,height: 42,},inlayer: 'window',spacing: 1,anchor: {x: 50,y: 50,},visible: true,direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,});//物品描述,按照格式自行修改內(nèi)容,其他的勿改var 描述 = ["",???"一顆又大又圓的養(yǎng)仙丹",//物品1描述???"綠油油的平安扣,像你頭上的草原一樣",//物品2描述???"平安扣同款綠色荷包,你值得擁有!",//物品3描述???"布林布林金光燦燦的梳子,貴就完了。",//物品4描述???"一匹布",//物品5描述];//物品描述的文本框,自行修改位子,其他的勿動await ac.createText({?name: 'xiangq',?index: 0,?inlayer: 'window',?visible: true,?content: `${描述[ac.var.物品詳情]}`,?pos: {??x: 632,??y: 402,?},?size: {??width: 432,??height: 140,?},?direction: ac.TEXT_DIRECTION_TYPES.horizontal,?halign: ac.HALIGN_TYPES.left,?valign: ac.VALIGN_TYPES.center,?spacing: 1.5,?anchor: {??x: 50,??y: 50,?},});//文字樣式await ac.createStyle({?name: 'style8',?font: '思源黑體',?bold: false,?italic: false,?fontSize: 30,?color: '#ffffff',?speed: 9,?strokeColor: '#000000',?shadowColor: '#000000',?shadowPos: {??x: 0,??y: 0,?},});//使用物品/*使用物品的函數(shù)*/async function yong() {?/*判定物品數(shù)量大于等于1*/if(ac.arr.物品[ac.var.物品詳情]>=1){ /*當(dāng)物品數(shù)量大于等于1后,開始接下來的運算*/?if(ac.var.物品詳情===1)/* 當(dāng)打開的是物品1的詳情頁時*/??{ac.arr.物品[1]=ac.arr.物品[1]-1;??/*物品1的數(shù)量減一*/???ac.arr.嬪妃容貌[0]=ac.arr.嬪妃容貌[0]+100;??/*物品1的使用效果,自行修改和添加*/??await ac.createText({name: 'text11',index: 0,inlayer: 'window',visible: true,content: `使用成功,容貌+100\n當(dāng)前容貌:${ac.arr.嬪妃容貌[0]}`,pos: {x: 640,y: 217,},size: {width: 640,height: 76,},direction: ac.TEXT_DIRECTION_TYPES.horizontal,halign: ac.HALIGN_TYPES.middle,valign: ac.VALIGN_TYPES.center,spacing: 1.5,anchor: {x: 50,y: 50,},});??/*文本框——使用后的提示*/await ac.delay({time: 1000,});ac.remove({name: 'text11',effect: 'fadeout',duration: 1000,canskip: false,});}/*延遲一秒后文本框消失*/} }//使用按鈕 await ac.createOption({??name: 'option8',??index: 0,??inlayer: 'window',??visible: true,??nResId: '$436765',??sResId: '$436766',??content: `使用`,??pos: {???x: 646,???y: 123,??},??anchor: {???x: 50,???y: 50,??},??style: 'style8',??clickAudio: {???resId: '$532507',???vol: 80,??},??onTouchEnded: yong,?});