• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import router from '@ohos.router'
17import VideoListLayout from '../component/VideoPreview'
18import RacingLayout from '../component/Racing'
19import BattleLayout from '../component/Battle'
20import ShootLayout from '../component/Shooting'
21import InstrumentLayout from '../component/Instrument'
22import RealisticLayout from '../component/Realistic'
23import FootstepLayout from '../component/Footstep'
24import EnvironmentLayout from '../component/Environment'
25import ExerciseLayout from '../component/Exercise'
26import InteractionLayout from '../component/Interaction'
27import Logger from './Logger'
28import TabBar from './TabBar'
29
30const TAG = '[DisplayModule]'
31
32export enum TabIndex {
33  RACING = 0,
34  BATTLE,
35  SHOOT,
36  INSTRUMENT,
37  REALISTIC,
38  FOOTSTEP,
39  ENVIRONMENT,
40  EXERCISE,
41  INTERACTION,
42}
43
44@Component
45export default struct DisplayModule {
46  @State titleArr: Resource[] = [
47  $r("app.string.display_racing"), $r("app.string.display_battle"), $r("app.string.display_shoot"),
48  $r("app.string.display_instrument"), $r("app.string.display_realistic"), $r("app.string.display_footstep"),
49  $r("app.string.display_environment"), $r("app.string.display_exercise"), $r("app.string.display_interaction")
50  ]
51  @State currentIndex: number = 0
52  private swiperController: SwiperController = new SwiperController()
53  private tabHeight = 50
54  @State playDis: boolean = false
55  @Link vibrationIntensity: string
56  @Link php: string
57  private controller: TabsController = new TabsController();
58
59  build() {
60    Column({ space: 10 }) {
61      Row() {
62        Text($r("app.string.display_haptic_video"))
63          .width('50%')
64          .fontSize(24)
65          .fontColor('#ffffffff')
66          .fontWeight(FontWeight.Normal)
67          .textAlign(TextAlign.Start)
68          .layoutWeight(7)
69          .padding({ left: 10 })
70        Button($r("app.string.display_show_more"))
71          .id('showMore')
72          .backgroundColor("#00d613ca")
73          .layoutWeight(3)
74          .height(35)
75          .fontColor('#919191')
76          .onClick(() => {
77            Logger.info(TAG, 'Show more pressed')
78            router.pushUrl({
79              url: 'module/VideoListModule',
80              params: {php: this.php}
81            })
82          })
83      }
84      .padding({ top: 5 })
85
86      VideoListLayout({php: $php})
87
88      Text($r("app.string.display_haptic_library"))
89        .width('100%')
90        .fontSize(24)
91        .fontColor('#ffffffff')
92        .fontWeight(FontWeight.Normal)
93        .textAlign(TextAlign.Start)
94        .padding({ left: 10 })
95
96      Row() {
97        TabBar({
98          titleArr: $titleArr,
99          currentIndex: $currentIndex,
100          tabSelected: (position: number, title: string) => {
101            this.currentIndex = position
102            Logger.info(TAG, 'onTabSelected position = ' + position + ', title = ' + title)
103            this.swiperController.showNext()
104          },
105        })
106      }
107      .width('100%')
108      .height(this.tabHeight)
109      .zIndex(10)
110
111      Scroll() {
112        Column() {
113          Swiper(this.swiperController) {
114            ForEach(this.titleArr, (item: string) => {
115              Column() {
116                if (this.currentIndex === TabIndex.RACING) {
117                  RacingLayout({
118                    vibrationIntensity: $vibrationIntensity,
119                    php: $php
120                  })
121                } else if (this.currentIndex === TabIndex.BATTLE) {
122                  BattleLayout({
123                    vibrationIntensity: $vibrationIntensity,
124                    php: $php
125                  })
126                } else if (this.currentIndex === TabIndex.SHOOT) {
127                  ShootLayout({
128                    vibrationIntensity: $vibrationIntensity,
129                    php: $php
130                  })
131                } else if (this.currentIndex === TabIndex.INSTRUMENT) {
132                  InstrumentLayout({
133                    vibrationIntensity: $vibrationIntensity,
134                    php: $php
135                  })
136                } else if (this.currentIndex === TabIndex.REALISTIC) {
137                  RealisticLayout({
138                    vibrationIntensity: $vibrationIntensity,
139                    php: $php
140                  })
141                } else if (this.currentIndex === TabIndex.FOOTSTEP) {
142                  FootstepLayout({
143                    vibrationIntensity: $vibrationIntensity,
144                    php: $php
145                  })
146                } else if (this.currentIndex === TabIndex.ENVIRONMENT) {
147                  EnvironmentLayout({
148                    vibrationIntensity: $vibrationIntensity,
149                    php: $php
150                  })
151                } else if (this.currentIndex === TabIndex.EXERCISE) {
152                  ExerciseLayout({
153                    vibrationIntensity: $vibrationIntensity,
154                    php: $php
155                  })
156                } else if (this.currentIndex === TabIndex.INTERACTION) {
157                  InteractionLayout({
158                    php: $php
159                  })
160                } else {
161                  Text('Please Waiting!')
162                    .fontSize(48)
163                    .fontColor(Color.Black)
164                    .width("100%")
165                    .height("100%")
166                }
167              }
168            }, (item: string) => item)
169          }
170          .index(0)
171          .autoPlay(false)
172          .indicator(false)
173          .loop(false)
174          .vertical(false)
175          .itemSpace(0)
176          .index(this.currentIndex)
177          .flexGrow(1)
178          .width('100%')
179          .onChange((index: number) => {
180            Logger.info(TAG, index.toString())
181            this.currentIndex = index
182          })
183        }
184      }
185      .scrollBar(BarState.Off)
186    }
187    .width('100%')
188    .height('100%')
189    .backgroundColor('#f2191a32')
190  }
191}
192