homeLand.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <view class="home-land-container">
  3. <!-- 第三层:背景 -->
  4. <view class="background-layer"></view>
  5. <!-- 第二层:地图 -->
  6. <view class="map-layer" id="mapLayer" :style="{ transform: `translateX(${translateX}px)` }" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd" @mousedown="onmousedown" @mousemove="onmousemove" @mouseup="onmouseup">
  7. <image class="island-image" src="/static/island/island.png" mode="widthFix" style="width:1536rpx; bottom: 0rpx;left: 0rpx; position: absolute;"></image>
  8. <view style="position: absolute;width: 670rpx;left: 340rpx; bottom:320rpx;align-items: center;">
  9. <image class="house-image" src="/static/island/building/home1.png" mode="widthFix" style="width:670rpx; position: static;" @click="onHouseClick" :animation="houseAnimationData"> </image>
  10. </view>
  11. <view style="position: absolute;width: 300rpx;left:280rpx; bottom:200rpx;align-items: center;">
  12. <image class="table-image" src="/static/island/building/workTable.png" mode="widthFix" style="width:670rpx; position: static;" @click="onTableClick" :animation="tableAnimationData"> </image>
  13. </view>
  14. <view style="position: absolute;width:200rpx;left:660rpx; bottom:260rpx;align-items: center;">
  15. <image class="mailBox-image" src="/static/island/building/mailBox.png" mode="widthFix" style="width:670rpx; position: static;" > </image>
  16. </view>
  17. <view style="position: absolute;width:200rpx;left:1000rpx; bottom:450rpx;align-items: center;">
  18. <image class="taskBoard-image" src="/static/island/building/taskBoard.png" mode="widthFix" style="width:670rpx; position: static;" @click="showTask" :animation="taskAnimationData"> </image>
  19. </view>
  20. <!-- 主岛箭头 -->
  21. <view class="main-arrow" @click="goToMainLand" :animation="mainArrowAnimation" :style="{ opacity: mainArrowVisible ? 1 : 0 }">
  22. <!-- <image src="/static/island/main_arrow.png" mode="widthFix" style="width: 100rpx;"></image> -->
  23. <view class="arrow" ></view>
  24. <text class="main-text">主岛</text>
  25. </view>
  26. </view>
  27. <!-- 第一层:UI -->
  28. <view class="ui-layer">
  29. <view class="ui-content">
  30. <!-- 添加货币计数器 -->
  31. <view class="currency-display" >
  32. <view class="currency-item">
  33. <image src="/static/island/UI/wd_icon_coin.png" mode="widthFix" class="currency-icon"></image>
  34. <text class="currency-value">9999</text>
  35. </view>
  36. <view class="currency-item">
  37. <image src="/static/island/UI/wd_icon_xingyuan.png" mode="widthFix" class="currency-icon"></image>
  38. <text class="currency-value">9999</text>
  39. </view>
  40. </view>
  41. <view class="ui-buttons">
  42. <image src="/static/island/icon_backpack.png" mode="widthFix" style="width:100rpx" @click="showInventory"></image>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 对话框组件 -->
  47. <backpack-dialog :visible.sync="inventoryVisible" @close="onInventoryClose"></backpack-dialog>
  48. <character-dialog :visible.sync="characterVisible" @close="onCharacterClose"></character-dialog>
  49. <shop-dialog :visible.sync="shopVisible" @close="onShopClose" @buy="onShopBuy"></shop-dialog>
  50. <task-dialog class="task-dialog" :visible.sync="taskVisible" @close="onTaskClose"></task-dialog>
  51. <!-- 引导对话组件 -->
  52. <talk-guide
  53. :guide-data="guideData"
  54. :player-name="playerName"
  55. @guide-complete="onGuideComplete"
  56. ></talk-guide>
  57. <!-- 制造台对话框组件 -->
  58. <crafting-dialog :visible.sync="craftingVisible" @close="craftingVisible = false"></crafting-dialog>
  59. <!-- 引导管理器 -->
  60. <guide-manager ref="guideManager"></guide-manager>
  61. </view>
  62. </template>
  63. <script>
  64. import BackpackDialog from '@/components/dialogs/BackpackDialog.vue'
  65. import CharacterDialog from '@/components/dialogs/CharacterDialog.vue'
  66. import ShopDialog from '@/components/dialogs/ShopDialog.vue'
  67. import TaskDialog from './TaskDialog.vue'
  68. import TalkGuide from './talkGuide.vue'
  69. import CraftingDialog from '@/components/dialogs/CraftingDialog.vue'
  70. import GuideManager from '@/components/guide/GuideManager.vue'
  71. export default {
  72. components: {
  73. BackpackDialog,
  74. CharacterDialog,
  75. ShopDialog,
  76. TaskDialog,
  77. TalkGuide,
  78. CraftingDialog,
  79. GuideManager
  80. },
  81. data() {
  82. return {
  83. // 背景位置控制
  84. translateX: -141,
  85. startX: 0,
  86. currentX: 0,
  87. isDragging : false,
  88. // 获取屏幕宽度和背景宽度
  89. screenWidth: 0,
  90. backgroundWidth: 0,
  91. islandHeight: 0,
  92. houseAnimationData: {},
  93. tableAnimationData: {},
  94. taskAnimationData: {},
  95. houseAnimating: false,
  96. tableAnimating: false,
  97. taskAnimating: false,
  98. baseTranslate: { x: -50, y: 50 },
  99. inventoryVisible: false,
  100. characterVisible: false,
  101. shopVisible: false,
  102. mainArrowAnimation: {},
  103. mainArrowAnimating: false,
  104. mainArrowVisible: false,
  105. taskVisible: false,
  106. playerName: '梦幻',
  107. guideData: [
  108. {
  109. characterImage: '/static/island/npc.png',
  110. characterName: '罗宾',
  111. text: '这位大人,这里太大了吧....',
  112. position: 'left',
  113. isMirror: true
  114. },
  115. {
  116. characterImage: '/static/island/building/1.png',
  117. characterName: '我',
  118. text: '好的,我马上上会教付清',
  119. position: 'right',
  120. isMirror: false
  121. },
  122. {
  123. characterImage: '/static/island/building/1.png',
  124. characterName: '我',
  125. text: '很奇怪不是吗?',
  126. position: 'right',
  127. isMirror: false
  128. },
  129. {
  130. characterImage: '/static/island/npc.png',
  131. characterName: '罗宾',
  132. text: '怎么回事',
  133. position: 'left',
  134. isMirror: true
  135. }
  136. ],
  137. craftingVisible: false,
  138. guideManager: null,
  139. }
  140. },
  141. onLoad() {
  142. let self = this;
  143. // 获取屏幕宽度
  144. uni.getSystemInfo({
  145. success: (res) => {
  146. self.screenWidth = res.windowWidth;
  147. console.log('屏幕宽度:', self.screenWidth);
  148. }
  149. });
  150. },
  151. onShow() {
  152. // 检查是否需要显示引导
  153. this.checkAndShowGuide();
  154. },
  155. onReady() {
  156. // 在组件渲染完成后获取图片尺寸
  157. setTimeout(() => {
  158. this.getImageSize();
  159. // 延迟1秒后显示箭头并开始动画
  160. setTimeout(() => {
  161. this.mainArrowVisible = true;
  162. this.startMainArrowAnimation();
  163. }, 1000);
  164. }, 300);
  165. },
  166. methods: {
  167. loadData() {
  168. // 可以在这里加载其他数据
  169. },
  170. getImageSize() {
  171. const query = uni.createSelectorQuery().in(this);
  172. query.select('.island-image').boundingClientRect(data => {
  173. if (data) {
  174. // 获取岛屿图片的宽度和高度
  175. this.backgroundWidth = data.width;
  176. this.islandHeight = data.height;
  177. // 计算最大可移动距离
  178. this.maxTranslate = this.backgroundWidth - this.screenWidth;
  179. // 初始位置居中
  180. // this.translateX = -this.maxTranslate / 2;
  181. // this.translateX = 0;
  182. // 打印调试信息
  183. // console.log('屏幕宽度:', this.screenWidth);
  184. // console.log('背景宽度:', this.backgroundWidth);
  185. // console.log('岛屿高度:', this.islandHeight);
  186. // console.log('最大可移动距离:',this.maxTranslate);
  187. // console.log('岛屿data:', data);
  188. } else {
  189. console.error('未能获取岛屿图片的尺寸');
  190. }
  191. }).exec();
  192. },
  193. // 触摸开始
  194. touchStart(e) {
  195. this.startX = e.touches[0].clientX;
  196. this.currentX = this.translateX;
  197. console.log('this.startX =',this.startX);
  198. console.log('this.currentX =',this.currentX);
  199. },
  200. // 触摸移动
  201. touchMove(e) {
  202. console.log('----------- touchMove');
  203. const moveX = e.touches[0].clientX - this.startX;
  204. let newTranslateX = this.currentX + moveX;
  205. // 限制移动范围,不让背景两侧露出
  206. if (newTranslateX > 0) {
  207. newTranslateX = 0;
  208. } else if (newTranslateX < -this.maxTranslate) {
  209. newTranslateX = -this.maxTranslate;
  210. }
  211. this.translateX = newTranslateX;
  212. console.log('moveX =',moveX);
  213. console.log('this.translateX =',this.translateX);
  214. },
  215. // 触摸结束
  216. touchEnd() {
  217. console.log('----------- touchEnd');
  218. this.currentX = this.translateX;
  219. console.log('this.currentX =',this.currentX);
  220. },
  221. onmousedown(e) {
  222. console.log('----------- onmousedown');
  223. console.log('----------- e',e);
  224. this.isDragging = true;
  225. this.startX = e.clientX;
  226. this.currentX = this.translateX;
  227. mapLayer.style.cursor = 'grabbing';
  228. },
  229. onmousemove(e) {
  230. if(this.isDragging){
  231. console.log('----------- onmousemove');
  232. const moveX = e.clientX - this.startX;
  233. let newTranslateX = this.currentX + moveX;
  234. //限制移动范围,不让背景两侧露出
  235. if (newTranslateX > 0) {
  236. newTranslateX = 0;
  237. } else if (newTranslateX < -this.maxTranslate) {
  238. newTranslateX = -this.maxTranslate;
  239. }
  240. this.translateX = newTranslateX;
  241. console.log('moveX =',moveX);
  242. console.log('this.translateX =',this.translateX);
  243. }
  244. },
  245. onmouseup(e) {
  246. console.log('----------- onmouseup');
  247. this.isDragging = false;
  248. mapLayer.style.cursor = 'grab';
  249. },
  250. onHouseClick(event) {
  251. if(this.houseAnimating) return;
  252. // 处理点击事件
  253. console.log('House clicked!');
  254. // 播放房子的点击动画
  255. this.playAnimation('house');
  256. // uni.showToast({
  257. // title: 'House clicked!',
  258. // icon: 'none'
  259. // });
  260. },
  261. onTableClick(event) {
  262. if(this.tableAnimating) return;
  263. console.log('Table clicked!');
  264. // 播放大厅的点击动画
  265. this.playAnimation('table');
  266. // 显示制造台界面
  267. this.craftingVisible = true;
  268. },
  269. onTaskClick(event) {
  270. if(this.taskAnimating) return;
  271. // 处理点击事件
  272. console.log('Task clicked!');
  273. // 播放大厅的点击动画
  274. this.playAnimation('task');
  275. // uni.showToast({
  276. // title: 'task clicked!',
  277. // icon: 'none'
  278. // });
  279. },
  280. playAnimation(type) {
  281. let self = this;
  282. // 根据类型设置对应的动画状态
  283. if (type === 'house') {
  284. this.houseAnimating = true;
  285. } else if (type === 'table') {
  286. this.tableAnimating = true;
  287. } else if (type === 'task') {
  288. this.taskAnimating = true;
  289. }
  290. // 创建动画实例
  291. const animation = uni.createAnimation({
  292. duration: 400,
  293. timingFunction: 'ease',
  294. });
  295. // 定义果冻动画序列
  296. animation.scale(0.95).step({ duration: 100 })
  297. .scale(1.05).step({ duration: 100 })
  298. .scale(0.98).step({ duration: 100 })
  299. .scale(1).step({ duration: 100 });
  300. // 根据类型应用动画到对应的元素
  301. if (type === 'house') {
  302. this.houseAnimationData = animation.export();
  303. } else if (type === 'table') {
  304. this.tableAnimationData = animation.export();
  305. } else if (type === 'task') {
  306. this.taskAnimationData = animation.export();
  307. }
  308. // 动画结束后重置状态
  309. setTimeout(() => {
  310. if (type === 'house') {
  311. self.houseAnimating = false;
  312. } else if (type === 'table') {
  313. self.tableAnimating = false;
  314. } else if (type === 'task') {
  315. self.taskAnimating = false;
  316. }
  317. }, 800);
  318. },
  319. showInventory() {
  320. console.log('Opening inventory...')
  321. this.inventoryVisible = true
  322. },
  323. onInventoryClose() {
  324. console.log('Closing inventory...')
  325. this.inventoryVisible = false
  326. },
  327. showCharacter() {
  328. console.log('Opening character...')
  329. this.characterVisible = true
  330. },
  331. onCharacterClose() {
  332. console.log('Closing character...')
  333. this.characterVisible = false
  334. },
  335. showShop() {
  336. console.log('Opening shop...')
  337. this.shopVisible = true
  338. },
  339. onShopClose() {
  340. console.log('Closing shop...')
  341. this.shopVisible = false
  342. },
  343. onShopBuy(item) {
  344. console.log('Buying item:', item)
  345. },
  346. showTask() {
  347. console.log('Opening task board...')
  348. this.taskVisible = true
  349. },
  350. onTaskClose() {
  351. console.log('Closing task board...')
  352. this.taskVisible = false
  353. },
  354. startMainArrowAnimation() {
  355. if (this.mainArrowAnimating) return;
  356. this.mainArrowAnimating = true;
  357. const animation = uni.createAnimation({
  358. duration: 1000,
  359. timingFunction: 'ease-in-out',
  360. });
  361. const animate = () => {
  362. if (!this.mainArrowAnimating) return;
  363. animation.translateY(-10).step({ duration: 1000 });
  364. this.mainArrowAnimation = animation.export();
  365. setTimeout(() => {
  366. animation.translateY(0).step({ duration: 1000 });
  367. this.mainArrowAnimation = animation.export();
  368. setTimeout(() => {
  369. if (this.mainArrowAnimating) {
  370. animate();
  371. }
  372. }, 1000);
  373. }, 1000);
  374. };
  375. animate();
  376. },
  377. goToMainLand() {
  378. uni.navigateTo({
  379. url: '/pages/isLand/mainLand'
  380. });
  381. },
  382. onGuideComplete() {
  383. console.log('引导完成')
  384. // 这里可以添加引导完成后的逻辑
  385. uni.setStorageSync('isGuideCompleted', true)
  386. },
  387. // 检查并显示引导
  388. checkAndShowGuide() {
  389. // 延迟执行以确保DOM已经渲染
  390. setTimeout(() => {
  391. this.$refs.guideManager && this.$refs.guideManager.startGuide('homeLand');
  392. }, 500);
  393. }
  394. },
  395. beforeDestroy() {
  396. this.mainArrowAnimating = false;
  397. }
  398. }
  399. </script>
  400. <style lang="scss" scoped>
  401. @import './homeLand.scss';
  402. .ui-layer {
  403. position: fixed;
  404. top: 0;
  405. left: 0;
  406. right: 0;
  407. bottom: 0;
  408. pointer-events: none;
  409. z-index: 100;
  410. .ui-content {
  411. position: absolute;
  412. top: 20rpx;
  413. right: 20rpx;
  414. pointer-events: auto;
  415. z-index: 101;
  416. }
  417. .ui-buttons {
  418. display: flex;
  419. flex-direction: column;
  420. gap: 20rpx;
  421. .ui-button {
  422. background: rgba(255, 255, 255, 0.9);
  423. border: none;
  424. padding: 16rpx 32rpx;
  425. border-radius: 8rpx;
  426. font-size: 28rpx;
  427. color: #333;
  428. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  429. min-width: 120rpx;
  430. &:active {
  431. opacity: 0.8;
  432. transform: scale(0.95);
  433. }
  434. }
  435. }
  436. }
  437. .map-layer {
  438. position: relative;
  439. z-index: 1;
  440. cursor: grab;
  441. &:active {
  442. cursor: grabbing;
  443. }
  444. }
  445. .main-arrow {
  446. // background: rgba(255, 255, 255, 0.9);
  447. position: absolute;
  448. height: 190rpx;
  449. right: 50rpx;
  450. bottom: 20rpx; // 改为 bottom 定位
  451. display: flex;
  452. flex-direction: column;
  453. align-items: center;
  454. cursor: pointer;
  455. z-index: 10;
  456. transition: opacity 0.5s ease-in-out;
  457. .arrow {
  458. content: '';
  459. display: block;
  460. width: 60rpx;
  461. height: 60rpx;
  462. background: url('/static/island/arrow.png') no-repeat center center;
  463. background-size: contain;
  464. transform: rotate(270deg);
  465. }
  466. .main-text {
  467. color: #ffffff;
  468. font-size: 32rpx;
  469. text-shadow: 2rpx 2rpx 4rpx rgba(0, 0, 0, 0.5);
  470. margin-top: 10rpx;
  471. }
  472. }
  473. .task-dialog{
  474. ::v-deep.dialog-content{
  475. background: transparent !important;
  476. }
  477. }
  478. </style>