mainLand.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. <template>
  2. <view class="main-land-container">
  3. <!-- <view class="scroll-container" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd" >
  4. <view class="background" :style="{ transform: `translateX(${translateX}px)` }">
  5. <image class="island-image" src="/static/island/island.png" mode="heightFix"></image>
  6. </view>
  7. </view> -->
  8. <!-- 第三层:背景 -->
  9. <view class="background-layer"></view>
  10. <!-- 第二层:地图 -->
  11. <view class="map-layer" id="mapLayer" :style="{ transform: `translateX(${translateX}px)` }"
  12. @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd" @mousedown="onmousedown"
  13. @mousemove="onmousemove" @mouseup="onmouseup">
  14. <!-- 这里可以放置地图元素(示例:一个方块) -->
  15. <!-- <view style="position: absolute; top: 30%; left: 30%; width: 100px; height: 100px; background: green;"></view> -->
  16. <image class="island-image" src="/static/island/mainLand.png" mode="widthFix"
  17. style="width:2048rpx; bottom: 0rpx;left: 0rpx; position: absolute;"></image>
  18. <!-- <view style="position: absolute;width: 300rpx;left: 280rpx; bottom:230rpx;align-items: center;">
  19. <image class="house-image" src="/static/island/building/4.png" mode="widthFix" style="width:300rpx; position: static;" @click="onHouseClick" :animation="houseAnimationData"> </image>
  20. </view> -->
  21. <view style="position: absolute;width: 360rpx;left:782rpx; bottom:385rpx;align-items: center;">
  22. <view style="position: relative;">
  23. <image class="farm-image" src="/static/island/building/3.png" mode="widthFix"
  24. style="width:360rpx; position: static;" @click="onFarmClick" :animation="farmAnimationData">
  25. </image>
  26. <view style="position: absolute; left: 35rpx; bottom: 135rpx; width: 45rpx; height: 130rpx; background: rgba(255,236,219,0.95); box-shadow: 1rpx -1rpx 2rpx 0rpx rgba(0,0,0,0.2); border-radius: 32rpx 32rpx 32rpx 32rpx; border: 2rpx solid #DEB691; writing-mode: vertical-lr; color: #683830; font-size: 28rpx;display: flex; align-items: center; justify-content: center; font-weight: bold;">花 田</view>
  27. </view>
  28. </view>
  29. <view style="position: absolute;width: 360rpx;left: 335rpx; bottom:835rpx;align-items: center;">
  30. <view style="position: relative;">
  31. <image class="mine-image" src="/static/island/building/4.png" mode="widthFix"
  32. style="width:360rpx; position: static;"> </image>
  33. <view style="position: absolute; left: 35rpx; bottom: 135rpx; width: 45rpx; height: 130rpx; background: rgba(255,236,219,0.95); box-shadow: 1rpx -1rpx 2rpx 0rpx rgba(0,0,0,0.2); border-radius: 32rpx 32rpx 32rpx 32rpx; border: 2rpx solid #DEB691; writing-mode: vertical-lr; color: #683830; font-size: 28rpx; display: flex; align-items: center; justify-content: center; font-weight: bold;">矿 场</view>
  34. </view>
  35. </view>
  36. <view style="position: absolute;width: 360rpx;left: 782rpx; bottom:720rpx;align-items: center;">
  37. <view style="position: relative;">
  38. <image class="hall-image" src="/static/island/building/5.png" mode="widthFix"
  39. style="width:360rpx; position: static;"> </image>
  40. <view style="position: absolute; left: 35rpx; bottom: 135rpx; width: 45rpx; height: 130rpx; background: rgba(255,236,219,0.95); box-shadow: 1rpx -1rpx 2rpx 0rpx rgba(0,0,0,0.2); border-radius: 32rpx 32rpx 32rpx 32rpx; border: 2rpx solid #DEB691; writing-mode: vertical-lr; color: #683830; font-size: 28rpx; display: flex; align-items: center; justify-content: center; font-weight: bold;">市政厅</view>
  41. </view>
  42. </view>
  43. <view style="position: absolute;width: 360rpx;left: 248rpx; bottom:488rpx;align-items: center;">
  44. <view style="position: relative;">
  45. <image class="wood-image" src="/static/island/building/6.png" mode="widthFix"
  46. style="width:360rpx; position: static;"> </image>
  47. <view style="position: absolute; left: 35rpx; bottom: 135rpx; width: 45rpx; height: 130rpx; background: rgba(255,236,219,0.95); box-shadow: 1rpx -1rpx 2rpx 0rpx rgba(0,0,0,0.2); border-radius: 32rpx 32rpx 32rpx 32rpx; border: 2rpx solid #DEB691; writing-mode: vertical-lr; color: #683830; font-size: 28rpx; display: flex; align-items: center; justify-content: center; font-weight: bold;">伐木场</view>
  48. </view>
  49. </view>
  50. <view style="position: absolute;width: 360rpx;left: 910rpx; bottom:108rpx;align-items: center;">
  51. <view style="position: relative;">
  52. <image class="shop-image" src="/static/island/building/2.png" mode="widthFix"
  53. style="width:360rpx; position: static;" @click="onShopClick" :animation="shopAnimationData">
  54. </image>
  55. <view style="position: absolute; left: 35rpx; bottom: 135rpx; width: 45rpx; height: 130rpx; background: rgba(255,236,219,0.95); box-shadow: 1rpx -1rpx 2rpx 0rpx rgba(0,0,0,0.2); border-radius: 32rpx 32rpx 32rpx 32rpx; border: 2rpx solid #DEB691; writing-mode: vertical-lr; color: #683830; font-size: 28rpx; display: flex; align-items: center; justify-content: center; font-weight: bold;">花 店</view>
  56. </view>
  57. </view>
  58. <view style="position: absolute;width: 360rpx;left: 1498rpx; bottom:75rpx;align-items: center;">
  59. <view style="position: relative;">
  60. <image class="airport-image" src="/static/island/building/7.png" mode="widthFix"
  61. style="width:360rpx; position: static;"> </image>
  62. <view style="position: absolute; left: 35rpx; bottom: 135rpx; width: 45rpx; height: 130rpx; background: rgba(255,236,219,0.95); box-shadow: 1rpx -1rpx 2rpx 0rpx rgba(0,0,0,0.2); border-radius: 32rpx 32rpx 32rpx 32rpx; border: 2rpx solid #DEB691; writing-mode: vertical-lr; color: #683830; font-size: 28rpx; display: flex; align-items: center; justify-content: center; font-weight: bold;">机 场</view>
  63. </view>
  64. </view>
  65. <view style="position: absolute;width: 360rpx;left: 1400rpx; bottom:380rpx;align-items: center;">
  66. <view style="position: relative;">
  67. <image class="house-image" src="/static/island/building/1.png" mode="widthFix"
  68. style="width:360rpx; position: static;" @click="onHouseClick" :animation="houseAnimationData">
  69. </image>
  70. <view style="position: absolute; left: 35rpx; bottom: 135rpx; width: 45rpx; height: 130rpx; background: rgba(255,236,219,0.95); box-shadow: 1rpx -1rpx 2rpx 0rpx rgba(0,0,0,0.2); border-radius: 32rpx 32rpx 32rpx 32rpx; border: 2rpx solid #DEB691; writing-mode: vertical-lr; color: #683830; font-size: 28rpx; display: flex; align-items: center; justify-content: center; font-weight: bold;">材料店</view>
  71. </view>
  72. </view>
  73. <!-- 引导箭头 -->
  74. <view class="guide-arrow" v-if="showGuideArrow" :style="{ left: guideArrowPosition.x + 'rpx', bottom: guideArrowPosition.y + 'rpx', transform: `rotate(${guideArrowPosition.r}deg)` }">
  75. <image src="/static/island/arrow.png" mode="aspectFit"></image>
  76. </view>
  77. <!-- 回家箭头 -->
  78. <view class="home-arrow" @click="goHome" :animation="homeArrowAnimation"
  79. :style="{ opacity: homeArrowVisible ? 1 : 0 }">
  80. <!-- <image src="/static/island/home_arrow.png" mode="widthFix" style="width: 100rpx;"></image> -->
  81. <view class="arrow"></view>
  82. <text class="home-text">回家</text>
  83. </view>
  84. </view>
  85. <!-- 第一层:UI -->
  86. <!-- <view class="ui-layer"> -->
  87. <view class="ui-content">
  88. <view class="status-bar"></view>
  89. <view class="customHead">
  90. <!-- 添加返回按钮 -->
  91. <view class="back-button" @click="goBack()">
  92. <image src="/static/island/UI/back_button.png" mode="widthFix" style="width:100rpx"></image>
  93. </view>
  94. <!-- 添加货币计数器 -->
  95. <view class="currency-display">
  96. <view class="currency-item">
  97. <image src="/static/island/UI/wd_icon_coin.png" mode="widthFix" class="currency-icon"></image>
  98. <text class="currency-value">{{userInfo.num_gmd}}</text>
  99. </view>
  100. <view class="currency-item">
  101. <image src="/static/island/UI/wd_icon_xingyuan.png" mode="widthFix" class="currency-icon">
  102. </image>
  103. <text class="currency-value">{{userInfo.num_gmg}}</text>
  104. </view>
  105. </view>
  106. </view>
  107. <view class="ui-buttons">
  108. <image src="/static/island/icon_backpack.png" mode="widthFix" style="width:100rpx"
  109. @click="showInventory" class="ui-icon-button"></image>
  110. <!-- <button class="ui-button" @click="showCharacter">角色</button>
  111. <button class="ui-button" @click="showShop">商店</button> -->
  112. </view>
  113. </view>
  114. <!-- </view> -->
  115. <!-- 对话框组件 -->
  116. <backpack-dialog :visible.sync="inventoryVisible" @close="onInventoryClose"></backpack-dialog>
  117. <character-dialog :visible.sync="characterVisible" @close="onCharacterClose"></character-dialog>
  118. <shop-dialog :visible.sync="shopVisible" :shopName="currentShopName" @close="onShopClose" @buy="onShopBuy"></shop-dialog>
  119. <hua-tian :visible.sync="huaTianVisible" @close="onHuaTianClose" ref="huaTian"></hua-tian>
  120. <task-dialog :visible.sync="taskDialogVisible" @close="onTaskDialogClose" type="huatian"></task-dialog>
  121. <!-- 引导对话组件 -->
  122. <talk-guide
  123. v-if="showTalkGuide"
  124. :guide-data="currentTalkData"
  125. :player-name="playerName"
  126. :visible="showTalkGuide"
  127. @talk-complete="onTalkComplete"
  128. ></talk-guide>
  129. <!-- 引导管理器 -->
  130. <guide-manager ref="guideManager"></guide-manager>
  131. </view>
  132. </template>
  133. <script>
  134. import BackpackDialog from '@/components/dialogs/BackpackDialog.vue'
  135. import CharacterDialog from '@/components/dialogs/CharacterDialog.vue'
  136. import ShopDialog from '@/components/dialogs/ShopDialog.vue'
  137. import HuaTian from './HuaTian.vue'
  138. import TaskDialog from './TaskDialog.vue'
  139. import TalkGuide from './talkGuide.vue'
  140. import GuideManager from '@/components/guide/GuideManager.vue'
  141. export default {
  142. components: {
  143. BackpackDialog,
  144. CharacterDialog,
  145. ShopDialog,
  146. HuaTian,
  147. TaskDialog,
  148. TalkGuide,
  149. GuideManager
  150. },
  151. data() {
  152. return {
  153. // // 背景位置控制
  154. translateX: -200,
  155. startX: 0,
  156. currentX: 0,
  157. isDragging: false,
  158. // maxTranslate: 0,
  159. userInfo: {
  160. num_gmd: 0,
  161. num_gmg: 0,
  162. },
  163. moneyTimer: null, // 添加定时器变量
  164. // // 获取屏幕宽度和背景宽度
  165. screenWidth: 0,
  166. backgroundWidth: 0,
  167. islandHeight: 0,
  168. houseAnimationData: {},
  169. farmAnimationData: {},
  170. shopAnimationData: {},
  171. houseAnimating: false,
  172. farmAnimating: false,
  173. shopAnimating: false,
  174. baseTranslate: {
  175. x: -50,
  176. y: 50
  177. },
  178. inventoryVisible: false,
  179. characterVisible: false,
  180. shopVisible: false,
  181. huaTianVisible: false,
  182. taskDialogVisible: false,
  183. homeArrowAnimation: {},
  184. homeArrowAnimating: false,
  185. homeArrowVisible: false,
  186. currentShopName: '商店',
  187. // 引导相关数据
  188. showTalkGuide: false,
  189. currentTalkData: [],
  190. playerName: '梦幻',
  191. // 引导箭头相关
  192. showGuideArrow: false,
  193. guideArrowPosition: { x: 0, y: 0, r: 0 }
  194. }
  195. },
  196. onLoad() {
  197. let self = this;
  198. // 获取屏幕宽度
  199. uni.getSystemInfo({
  200. success: (res) => {
  201. self.screenWidth = res.windowWidth;
  202. console.log('屏幕宽度:', self.screenWidth);
  203. }
  204. });
  205. this.getUserMoney();
  206. // 启动定时器,每2秒更新一次铃钱
  207. this.moneyTimer = setInterval(() => {
  208. this.getUserMoney();
  209. }, 2000);
  210. },
  211. onShow() {
  212. // 检查是否需要显示引导
  213. this.checkAndShowGuide('mainLand');
  214. },
  215. onReady() {
  216. // 在组件渲染完成后获取图片尺寸
  217. setTimeout(() => {
  218. this.getImageSize();
  219. // 延迟1秒后显示箭头并开始动画
  220. setTimeout(() => {
  221. this.homeArrowVisible = true;
  222. this.startHomeArrowAnimation();
  223. }, 1000);
  224. }, 300);
  225. },
  226. onUnload() {
  227. // 清除定时器
  228. if (this.moneyTimer) {
  229. clearInterval(this.moneyTimer);
  230. this.moneyTimer = null;
  231. }
  232. },
  233. methods: {
  234. loadData() {
  235. // 可以在这里加载其他数据
  236. },
  237. getImageSize() {
  238. const query = uni.createSelectorQuery().in(this);
  239. query.select('.island-image').boundingClientRect(data => {
  240. if (data) {
  241. // 获取岛屿图片的宽度和高度
  242. this.backgroundWidth = data.width;
  243. this.islandHeight = data.height;
  244. // this.backgroundWidth = 1536;
  245. // this.islandHeight = 1024;
  246. // 设置背景高度为岛屿高度的两倍(在CSS中实现)
  247. // 计算最大可移动距离
  248. this.maxTranslate = this.backgroundWidth - this.screenWidth;
  249. // 初始位置居中
  250. // this.translateX = -this.maxTranslate / 2;
  251. // 打印调试信息
  252. // console.log('屏幕宽度:', this.screenWidth);
  253. // console.log('背景宽度:', this.backgroundWidth);
  254. // console.log('岛屿高度:', this.islandHeight);
  255. // console.log('屏幕宽度:',this.screenWidth);
  256. // console.log('最大可移动距离:',this.maxTranslate);
  257. // console.log('岛屿data:', data);
  258. } else {
  259. console.error('未能获取岛屿图片的尺寸');
  260. }
  261. }).exec();
  262. },
  263. // 触摸开始
  264. touchStart(e) {
  265. // console.log('----------- touchStart');
  266. this.startX = e.touches[0].clientX;
  267. this.currentX = this.translateX;
  268. console.log('this.startX =', this.startX);
  269. console.log('this.currentX =', this.currentX);
  270. },
  271. // 触摸移动
  272. touchMove(e) {
  273. console.log('----------- touchMove');
  274. const moveX = e.touches[0].clientX - this.startX;
  275. let newTranslateX = this.currentX + moveX;
  276. // 限制移动范围,不让背景两侧露出
  277. if (newTranslateX > 0) {
  278. newTranslateX = 0;
  279. } else if (newTranslateX < -this.maxTranslate) {
  280. newTranslateX = -this.maxTranslate;
  281. }
  282. this.translateX = newTranslateX;
  283. console.log('moveX =', moveX);
  284. console.log('this.translateX =', this.translateX);
  285. },
  286. // 触摸结束
  287. touchEnd() {
  288. console.log('----------- touchEnd');
  289. this.currentX = this.translateX;
  290. console.log('this.currentX =', this.currentX);
  291. },
  292. onmousedown(e) {
  293. console.log('----------- onmousedown');
  294. console.log('----------- e', e);
  295. this.isDragging = true;
  296. this.startX = e.clientX;
  297. this.currentX = this.translateX;
  298. mapLayer.style.cursor = 'grabbing';
  299. },
  300. onmousemove(e) {
  301. if (this.isDragging) {
  302. console.log('----------- onmousemove');
  303. const moveX = e.clientX - this.startX;
  304. let newTranslateX = this.currentX + moveX;
  305. //限制移动范围,不让背景两侧露出
  306. if (newTranslateX > 0) {
  307. newTranslateX = 0;
  308. } else if (newTranslateX < -this.maxTranslate) {
  309. newTranslateX = -this.maxTranslate;
  310. }
  311. this.translateX = newTranslateX;
  312. console.log('moveX =', moveX);
  313. console.log('this.translateX =', this.translateX);
  314. }
  315. },
  316. onmouseup(e) {
  317. console.log('----------- onmouseup');
  318. this.isDragging = false;
  319. mapLayer.style.cursor = 'grab';
  320. },
  321. onHouseClick(event) {
  322. if (this.houseAnimating) return;
  323. // 处理点击事件
  324. console.log('house clicked!');
  325. // 播放房屋的点击动画
  326. this.playAnimation('house');
  327. // 设置商店名称为"房屋商店"
  328. this.currentShopName = '材料商店';
  329. this.shopVisible = true;
  330. },
  331. onFarmClick(event) {
  332. if (this.farmAnimating) return;
  333. // 处理点击事件
  334. console.log('farm clicked!111');
  335. // 播放大厅的点击动画
  336. this.playAnimation('farm');
  337. // 打开花田对话框
  338. this.huaTianVisible = true;
  339. // 将mainLand传递给HuaTian组件
  340. this.$refs.huaTian && this.$refs.huaTian.setMainLand(this);
  341. // 检查是否需要显示引导
  342. this.checkAndShowGuide('mainLand_farm');
  343. },
  344. onShopClick(event) {
  345. if (this.shopAnimating) return;
  346. // 处理点击事件
  347. console.log('shop clicked!');
  348. // 播放商店的点击动画
  349. this.playAnimation('shop');
  350. // 设置商店名称为"花店"
  351. this.currentShopName = '花店';
  352. // 打开商店对话框
  353. this.shopVisible = true;
  354. },
  355. playAnimation(type) {
  356. let self = this;
  357. // 根据类型设置对应的动画状态
  358. if (type === 'house') {
  359. this.houseAnimating = true;
  360. } else if (type === 'farm') {
  361. this.farmAnimating = true;
  362. } else if (type === 'shop') {
  363. this.shopAnimating = true;
  364. }
  365. // 创建动画实例
  366. const animation = uni.createAnimation({
  367. duration: 400,
  368. timingFunction: 'ease',
  369. });
  370. // 定义果冻动画序列
  371. animation.scale(0.95).step({
  372. duration: 100
  373. })
  374. .scale(1.05).step({
  375. duration: 100
  376. })
  377. .scale(0.98).step({
  378. duration: 100
  379. })
  380. .scale(1).step({
  381. duration: 100
  382. });
  383. // 根据类型应用动画到对应的元素
  384. if (type === 'house') {
  385. this.houseAnimationData = animation.export();
  386. } else if (type === 'farm') {
  387. this.farmAnimationData = animation.export();
  388. } else if (type === 'shop') {
  389. this.shopAnimationData = animation.export();
  390. }
  391. // 动画结束后重置状态
  392. setTimeout(() => {
  393. if (type === 'house') {
  394. self.houseAnimating = false;
  395. } else if (type === 'farm') {
  396. self.farmAnimating = false;
  397. } else if (type === 'shop') {
  398. self.shopAnimating = false;
  399. }
  400. }, 800);
  401. },
  402. showInventory() {
  403. console.log('Opening inventory...')
  404. this.inventoryVisible = true
  405. },
  406. onInventoryClose() {
  407. console.log('Closing inventory...')
  408. this.inventoryVisible = false
  409. },
  410. showCharacter() {
  411. console.log('Opening character...')
  412. this.characterVisible = true
  413. },
  414. onCharacterClose() {
  415. console.log('Closing character...')
  416. this.characterVisible = false
  417. },
  418. showShop() {
  419. console.log('Opening shop...')
  420. this.shopVisible = true
  421. },
  422. onShopClose() {
  423. console.log('Closing shop...')
  424. this.shopVisible = false
  425. },
  426. onShopBuy(item) {
  427. console.log('Buying item:', item)
  428. },
  429. onHuaTianClose() {
  430. console.log('Closing hua tian dialog...')
  431. this.huaTianVisible = false
  432. },
  433. startHomeArrowAnimation() {
  434. if (this.homeArrowAnimating) return;
  435. this.homeArrowAnimating = true;
  436. const animation = uni.createAnimation({
  437. duration: 1000,
  438. timingFunction: 'ease-in-out',
  439. });
  440. const animate = () => {
  441. if (!this.homeArrowAnimating) return;
  442. animation.translateY(-20).step({
  443. duration: 1000
  444. });
  445. this.homeArrowAnimation = animation.export();
  446. setTimeout(() => {
  447. animation.translateY(0).step({
  448. duration: 1000
  449. });
  450. this.homeArrowAnimation = animation.export();
  451. setTimeout(() => {
  452. if (this.homeArrowAnimating) {
  453. animate();
  454. }
  455. }, 1000);
  456. }, 1000);
  457. };
  458. animate();
  459. },
  460. goHome() {
  461. uni.navigateTo({
  462. url: '/pages/isLand/homeLand'
  463. });
  464. },
  465. // 打开任务对话框
  466. onTaskClick() {
  467. console.log('Opening task dialog...')
  468. this.taskDialogVisible = true
  469. },
  470. // 关闭任务对话框
  471. onTaskDialogClose() {
  472. console.log('Closing task dialog...')
  473. this.taskDialogVisible = false
  474. },
  475. // 获取用户铃钱
  476. getUserMoney() {
  477. uni.request({
  478. url: this.$apiHost + '/User/getinfo',
  479. method: 'GET',
  480. data: {
  481. uuid: getApp().globalData.uuid
  482. },
  483. header: {
  484. 'Content-Type': 'application/x-www-form-urlencoded',
  485. 'sign': getApp().globalData.headerSign,
  486. },
  487. success: (res) => {
  488. if (res.data) {
  489. console.log("res.getUserMoney", res.data)
  490. this.userInfo = res.data;
  491. }
  492. }
  493. })
  494. },
  495. // 检查并显示引导
  496. checkAndShowGuide(stageId) {
  497. console.log('checkAndShowGuide stageId :', stageId);
  498. // 延迟执行以确保DOM已经渲染
  499. setTimeout(() => {
  500. if (this.$refs.guideManager) {
  501. const hasGuide = this.$refs.guideManager.startGuide(stageId);
  502. console.log('checkAndShowGuide hasGuide :', hasGuide);
  503. if (hasGuide) {
  504. this.currentTalkData = this.$refs.guideManager.getCurrentTalkData();
  505. console.log('checkAndShowGuide currentTalkData :', this.currentTalkData);
  506. if (this.currentTalkData) {
  507. this.showTalkGuide = true;
  508. // 检查是否需要显示引导箭头
  509. this.checkAndShowGuideArrow();
  510. }else{
  511. console.log('currentTalkData err:', this.currentTalkData);
  512. }
  513. }
  514. }
  515. }, 200);
  516. },
  517. // 对话完成回调
  518. onTalkComplete() {
  519. // 调用引导管理器的下一步
  520. console.log('----------- onTalkComplete');
  521. this.$refs.guideManager && this.$refs.guideManager.nextStep();
  522. // 获取新的对话数据
  523. const newTalkData = this.$refs.guideManager.getCurrentTalkData();
  524. console.log('----------- onTalkComplete newTalkData:', newTalkData);
  525. if (newTalkData) {
  526. // 先隐藏对话组件
  527. this.showTalkGuide = false;
  528. // 更新对话数据
  529. this.currentTalkData = newTalkData;
  530. // 使用 nextTick 确保数据更新后再显示对话组件
  531. this.$nextTick(() => {
  532. this.showTalkGuide = true;
  533. // 检查是否需要显示引导箭头
  534. this.checkAndShowGuideArrow();
  535. });
  536. } else {
  537. // 如果没有新的对话数据,隐藏对话组件
  538. this.showTalkGuide = false;
  539. }
  540. },
  541. // 检查并显示引导箭头
  542. checkAndShowGuideArrow() {
  543. if (this.$refs.guideManager) {
  544. const arrowPosition = this.$refs.guideManager.getCurrentArrowPosition();
  545. console.log('----------- checkAndShowGuideArrow arrowPosition:', arrowPosition);
  546. if (arrowPosition) {
  547. // 显示引导箭头
  548. this.showGuideArrow = true;
  549. // 设置箭头位置
  550. this.guideArrowPosition = {
  551. x: arrowPosition.x,
  552. y: arrowPosition.y,
  553. r: arrowPosition.r || 0
  554. };
  555. console.log('----------- guideArrowPosition:', this.guideArrowPosition);
  556. console.log('----------- showGuideArrow:', this.showGuideArrow);
  557. } else {
  558. // 隐藏引导箭头
  559. this.showGuideArrow = false;
  560. }
  561. }
  562. },
  563. goBack() {
  564. uni.navigateBack({
  565. delta: 1
  566. });
  567. }
  568. }
  569. }
  570. </script>
  571. <style lang="scss" scoped>
  572. @import './mainLand.scss';
  573. // .ui-layer {
  574. // position: fixed;
  575. // top: 0;
  576. // left: 0;
  577. // right: 0;
  578. // bottom: 0;
  579. // pointer-events: none;
  580. // z-index: 100;
  581. .ui-content {
  582. position: fixed;
  583. top: 0;
  584. left: 0;
  585. width: 100%;
  586. pointer-events: auto;
  587. z-index: 101;
  588. }
  589. .ui-buttons {
  590. display: flex;
  591. flex-direction: column;
  592. gap: 20rpx;
  593. .ui-icon-button {
  594. transition: transform 0.2s ease;
  595. &:active {
  596. transform: scale(0.9);
  597. opacity: 0.8;
  598. }
  599. }
  600. .ui-button {
  601. // background: rgba(255, 255, 255, 0.9);
  602. // border: none;
  603. width: 120rpx;
  604. padding: 16rpx 32rpx;
  605. border-radius: 8rpx;
  606. font-size: 28rpx;
  607. color: #333;
  608. // box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  609. min-width: 120rpx;
  610. &:active {
  611. opacity: 0.8;
  612. transform: scale(0.95);
  613. }
  614. }
  615. .backpack-button {
  616. background-image: url('/static/island/icon_backpack.png');
  617. background-size: cover;
  618. background-position: center;
  619. background-repeat: no-repeat;
  620. }
  621. }
  622. // }
  623. .map-layer {
  624. position: relative;
  625. z-index: 1;
  626. cursor: grab;
  627. &:active {
  628. cursor: grabbing;
  629. }
  630. }
  631. .guide-arrow {
  632. position: absolute;
  633. z-index: 10;
  634. width: 100rpx;
  635. height: 100rpx;
  636. display: flex;
  637. justify-content: center;
  638. align-items: center;
  639. pointer-events: none; /* 防止箭头阻挡点击事件 */
  640. image {
  641. width: 100rpx;
  642. height: 100rpx;
  643. animation: pulse 1.5s infinite; /* 添加脉冲动画 */
  644. }
  645. }
  646. @keyframes pulse {
  647. 0% {
  648. transform: scale(1);
  649. opacity: 1;
  650. }
  651. 50% {
  652. transform: scale(1.2);
  653. opacity: 0.8;
  654. }
  655. 100% {
  656. transform: scale(1);
  657. opacity: 1;
  658. }
  659. }
  660. .home-arrow {
  661. // background: rgba(255, 255, 255, 0.9);
  662. position: absolute;
  663. left: 40rpx; // 调整到左边位置
  664. bottom: 460rpx;
  665. display: flex;
  666. flex-direction: column;
  667. align-items: center;
  668. cursor: pointer;
  669. z-index: 10;
  670. transition: opacity 0.5s ease-in-out; // 添加淡入效果
  671. .arrow {
  672. content: '';
  673. display: block;
  674. width: 60rpx;
  675. height: 60rpx;
  676. background: url('/static/island/arrow.png') no-repeat center center;
  677. background-size: contain;
  678. transform: rotate(90deg);
  679. }
  680. .home-text {
  681. color: #ffffff;
  682. font-size: 32rpx;
  683. text-shadow: 2rpx 2rpx 4rpx rgba(0, 0, 0, 0.5);
  684. margin-top: 10rpx;
  685. }
  686. }
  687. </style>