talkGuide.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="talk-guide" v-if="isShow" @click="handleClick">
  3. <view class="guide-content" :class="{ 'right-aligned': currentStep.position === 'right' }">
  4. <view class="character-container" :class="{ 'right-aligned': currentStep.position === 'right' }">
  5. <image
  6. class="character-image"
  7. :class="{ 'mirror': currentStep.isMirror }"
  8. :src="currentStep.characterImage"
  9. mode="aspectFit"
  10. />
  11. </view>
  12. <view class="dialog-box" :class="{ 'right-aligned': currentStep.position === 'right' }">
  13. <view class="character-name" :class="{ 'right-aligned': currentStep.position === 'right' }" v-if="currentStep.characterName">
  14. {{ currentStep.characterName === '我' ? playerName : currentStep.characterName }}
  15. </view>
  16. <view class="dialog-text">{{ currentStep.text }}</view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'TalkGuide',
  24. props: {
  25. guideData: {
  26. type: Array,
  27. default: () => []
  28. },
  29. playerName: {
  30. type: String,
  31. default: '主角'
  32. },
  33. visible: {
  34. type: Boolean,
  35. default: false
  36. }
  37. },
  38. data() {
  39. return {
  40. currentIndex: 0,
  41. isShow: false
  42. }
  43. },
  44. computed: {
  45. currentStep() {
  46. return this.guideData[this.currentIndex] || {}
  47. },
  48. isLastStep() {
  49. return this.currentIndex === this.guideData.length - 1
  50. }
  51. },
  52. watch: {
  53. visible: {
  54. immediate: true,
  55. handler(newVal) {
  56. this.isShow = newVal;
  57. if (newVal) {
  58. this.currentIndex = 0;
  59. }
  60. }
  61. },
  62. guideData: {
  63. handler(newVal) {
  64. if (newVal && newVal.length > 0) {
  65. this.currentIndex = 0;
  66. }
  67. },
  68. deep: true
  69. }
  70. },
  71. methods: {
  72. handleClick() {
  73. if (this.isLastStep) {
  74. this.isShow = false
  75. this.$emit('talk-complete')
  76. } else {
  77. this.nextStep()
  78. }
  79. },
  80. nextStep() {
  81. if (this.currentIndex < this.guideData.length - 1) {
  82. this.currentIndex++
  83. }
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .talk-guide {
  90. position: fixed;
  91. top: 0;
  92. left: 0;
  93. width: 100%;
  94. height: 100%;
  95. background-color: rgba(0, 0, 0, 0.5);
  96. z-index: 999;
  97. .guide-content {
  98. position: absolute;
  99. bottom: 40rpx;
  100. left: 0;
  101. width: 100%;
  102. padding: 0 30rpx;
  103. box-sizing: border-box;
  104. display: flex;
  105. flex-direction: column;
  106. &.right-aligned {
  107. align-items: flex-end;
  108. }
  109. }
  110. .character-container {
  111. width: 300rpx;
  112. height: 358rpx;
  113. margin-bottom: -60rpx;
  114. margin-left: -40rpx;
  115. position: relative;
  116. z-index: 1;
  117. &.right-aligned {
  118. margin-left: 0;
  119. margin-right: -40rpx;
  120. }
  121. .character-image {
  122. height: 100%;
  123. transition: transform 0.3s ease;
  124. &.mirror {
  125. transform: scaleX(-1);
  126. }
  127. }
  128. }
  129. .dialog-box {
  130. background: rgba(255,241,228,0.95);
  131. border-radius: 28rpx 28rpx 28rpx 28rpx;
  132. border: 4rpx solid #E3985A;
  133. padding: 20rpx;
  134. min-height: 120rpx;
  135. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  136. position: relative;
  137. z-index: 2;
  138. padding-top: 30rpx;
  139. width: 100%;
  140. box-sizing: border-box;
  141. &.right-aligned {
  142. border-radius: 28rpx 28rpx 28rpx 28rpx;
  143. }
  144. .character-name {
  145. font-size: 20rpx;
  146. font-weight: bold;
  147. color: #987453;
  148. margin-bottom: 10rpx;
  149. display: inline-block;
  150. background-color: #F8F3E9;
  151. padding: 4rpx 16rpx;
  152. border-radius: 20rpx;
  153. border: 2rpx solid #DEB691;
  154. position: absolute;
  155. top: -25rpx;
  156. left: 5%;
  157. z-index: 3;
  158. width: 156rpx;
  159. height: 48rpx;
  160. text-align: center;
  161. &.right-aligned {
  162. left: auto;
  163. right: 5%;
  164. }
  165. }
  166. .dialog-text {
  167. font-size: 20rpx;
  168. font-weight: bold;
  169. color: #A95F3C;
  170. line-height: 1.5;
  171. padding: 0 20rpx;
  172. }
  173. }
  174. }
  175. </style>