@vnejs/plugins.view.coralina.mainmenu 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/const/params.js +14 -0
- package/index.js +2 -1
- package/modules/controller.js +12 -15
- package/modules/view.js +6 -4
- package/package.json +1 -1
- package/view/index.jsx +43 -22
package/const/params.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const BACKGROUND = "Menu/loading";
|
|
2
|
+
|
|
3
|
+
export const VIEW_PROPS = {
|
|
4
|
+
background: { withDark: false, withBlur: false },
|
|
5
|
+
|
|
6
|
+
controls: {
|
|
7
|
+
position: { bottom: 240, left: 240 },
|
|
8
|
+
props: { textSize: 96, flexGap: 60, flexDirection: "column" },
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const TRANSITION = 500;
|
|
13
|
+
export const ZINDEX = 3000;
|
|
14
|
+
export const LOC_LABEL = "mainMenu";
|
package/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { regPlugin } from "@vnejs/shared";
|
|
2
2
|
|
|
3
3
|
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
4
|
+
import * as params from "./const/params";
|
|
4
5
|
|
|
5
6
|
import { MainMenuController } from "./modules/controller";
|
|
6
7
|
import { MainMenuView } from "./modules/view";
|
|
7
8
|
|
|
8
|
-
regPlugin("MAINMENU_VIEW", { events: SUBSCRIBE_EVENTS }, [MainMenuController, MainMenuView]);
|
|
9
|
+
regPlugin("MAINMENU_VIEW", { events: SUBSCRIBE_EVENTS, params }, [MainMenuController, MainMenuView]);
|
package/modules/controller.js
CHANGED
|
@@ -3,20 +3,21 @@ import { ModuleController } from "@vnejs/module.components";
|
|
|
3
3
|
const toStateItem = ({ onClick, ...item }) => item;
|
|
4
4
|
const onRealItems = (item) => !item.isDisabled && !item.isHide;
|
|
5
5
|
|
|
6
|
-
window.VneMainMenuBg = "Menu/loading";
|
|
7
|
-
|
|
8
6
|
export class MainMenuController extends ModuleController {
|
|
9
7
|
name = "mainmenu.controller";
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
emitAccept = () => this.emit(this.EVENTS.MAINMENU_VIEW.ACCEPT);
|
|
10
|
+
|
|
11
|
+
bgName = this.PARAMS.MAINMENU_VIEW.BACKGROUND;
|
|
12
12
|
|
|
13
13
|
updateEvent = this.EVENTS.MAINMENU_VIEW.UPDATE;
|
|
14
14
|
controls = {
|
|
15
15
|
[this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decCurrentItem,
|
|
16
16
|
[this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incCurrentItem,
|
|
17
|
-
[this.CONST.CONTROLS.BUTTONS.ACCEPT]:
|
|
17
|
+
[this.CONST.CONTROLS.BUTTONS.ACCEPT]: this.emitAccept,
|
|
18
|
+
[this.CONST.CONTROLS.BUTTONS.INTERACT]: this.emitAccept,
|
|
18
19
|
};
|
|
19
|
-
controlsIndex =
|
|
20
|
+
controlsIndex = this.PARAMS.MAINMENU_VIEW.ZINDEX;
|
|
20
21
|
|
|
21
22
|
subscribe = () => {
|
|
22
23
|
this.on(this.EVENTS.MAINMENU.SHOW, this.onShow);
|
|
@@ -27,26 +28,22 @@ export class MainMenuController extends ModuleController {
|
|
|
27
28
|
|
|
28
29
|
this.on(this.EVENTS.LOCS.LANG_CHANGED, this.updateView);
|
|
29
30
|
|
|
30
|
-
this.on(this.EVENTS.STATE.CLEAR, this.onHideForce);
|
|
31
31
|
this.on(this.EVENTS.STATE.SET, this.onHideForce);
|
|
32
|
-
|
|
33
|
-
this.on(this.EVENTS.SYSTEM.STARTED, this.loadBgMedia);
|
|
32
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onHideForce);
|
|
34
33
|
this.on(this.EVENTS.STATE.CLEAR, this.loadBgMedia);
|
|
34
|
+
this.on(this.EVENTS.SYSTEM.STARTED, this.loadBgMedia);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
beforeShow = async () => {
|
|
38
|
-
const items = (await this.
|
|
38
|
+
const items = (await this.emitOne(this.EVENTS.MAINMENU.ITEMS)).map(toStateItem);
|
|
39
39
|
|
|
40
40
|
this.updateState({ items, realItems: items.filter(onRealItems), bgSrc: (await this.loadBgMedia()).src });
|
|
41
41
|
|
|
42
42
|
this.maxCurrentItem = this.state.realItems.length - 1;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
onAccept = async () => this.click(await this.
|
|
46
|
-
onClick = async ({ index } = {}) => this.click(await this.
|
|
47
|
-
|
|
48
|
-
click = (items, index) => index !== null && items[index] && items[index].onClick && items[index].onClick();
|
|
45
|
+
onAccept = async () => this.click((await this.emitOne(this.EVENTS.MAINMENU.ITEMS)).filter(onRealItems), this.currentItem);
|
|
46
|
+
onClick = async ({ index } = {}) => this.click(await this.emitOne(this.EVENTS.MAINMENU.ITEMS), index);
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
getRealItems = async () => (await this.getItems()).filter(onRealItems);
|
|
48
|
+
click = (items, index) => index !== null && items[index]?.onClick?.();
|
|
52
49
|
}
|
package/modules/view.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ModuleView } from "@vnejs/module.components";
|
|
2
2
|
|
|
3
|
-
import { render
|
|
3
|
+
import { render } from "../view";
|
|
4
4
|
|
|
5
5
|
export class MainMenuView extends ModuleView {
|
|
6
6
|
name = "mainmenu.view";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
locLabel = this.PARAMS.MAINMENU_VIEW.LOC_LABEL;
|
|
9
|
+
animationTime = this.PARAMS.MAINMENU_VIEW.TRANSITION;
|
|
10
10
|
updateEvent = this.EVENTS.MAINMENU_VIEW.UPDATE;
|
|
11
|
+
|
|
12
|
+
renderFunc = render;
|
|
11
13
|
updateHandler = this.onUpdateReactComponent;
|
|
12
14
|
}
|
package/package.json
CHANGED
package/view/index.jsx
CHANGED
|
@@ -1,41 +1,62 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { PositionBox, Screen, TextControls } from "@vnejs/uis.base";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
class MainMenuControls extends React.Component {
|
|
7
|
+
state = {};
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
componentDidUpdate(props) {
|
|
10
|
+
const { items = [] } = this.props;
|
|
11
|
+
|
|
12
|
+
if (items !== props.items || this.props.realItems !== props.realItems || this.props.locs !== props.locs) this.setState({ texts: items.map(this.mapItems) });
|
|
13
|
+
if (this.props.currentItem !== props.currentItem) this.setState({ selectedIndex: items.findIndex(this.findSelectedIndex) });
|
|
14
|
+
}
|
|
15
|
+
componentDidMount() {
|
|
16
|
+
this.setState({ texts: this.props.items.map(this.mapItems), selectedIndex: this.props.items.findIndex(this.findSelectedIndex) });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
mapItems = ({ locKey, isDisabled, isHide }, i) => ({ text: this.props.locs[locKey], isDisabled, isNotRender: isHide, value: i });
|
|
20
|
+
findSelectedIndex = (value) => this.props.realItems[this.props.currentItem]?.locKey === value?.locKey;
|
|
10
21
|
|
|
11
22
|
onClick = (index) => this.props.emit(this.props.EVENTS.MAINMENU_VIEW.CLICK, { index });
|
|
12
|
-
mapItems = ({ locKey, isDisabled, isHide }, i) => ({ text: this.state.locs[locKey], isDisabled, isNotRender: isHide, value: i });
|
|
13
|
-
findSelectedIndex = (value) => this.state.realItems[this.state.currentItem]?.locKey === value?.locKey;
|
|
14
23
|
|
|
15
24
|
render() {
|
|
16
|
-
const {
|
|
25
|
+
const { texts = [], selectedIndex = null } = this.state;
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
return (
|
|
28
|
+
<TextControls
|
|
29
|
+
selectedIndex={selectedIndex}
|
|
30
|
+
texts={texts}
|
|
31
|
+
onClick={this.onClick}
|
|
32
|
+
{...this.props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.controls.props}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class MainMenu extends React.Component {
|
|
39
|
+
state = {};
|
|
40
|
+
|
|
41
|
+
render() {
|
|
42
|
+
const { isShow = false, items = [], bgSrc = "", currentItem = null, realItems = [], locs = {} } = this.state;
|
|
20
43
|
|
|
21
44
|
return (
|
|
22
45
|
<Screen
|
|
23
|
-
zIndex={3000}
|
|
24
46
|
isShow={isShow}
|
|
25
47
|
bgSrc={bgSrc}
|
|
26
|
-
|
|
48
|
+
zIndex={this.props.PARAMS.MAINMENU_VIEW.ZINDEX}
|
|
49
|
+
transition={this.props.PARAMS.MAINMENU_VIEW.TRANSITION}
|
|
50
|
+
withBackgroundDark={this.props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.background.withDark}
|
|
51
|
+
withBackgroundBlur={this.props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.background.withBlur}
|
|
27
52
|
>
|
|
28
|
-
<PositionBox
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
onClick={this.onClick}
|
|
36
|
-
textSize={96}
|
|
37
|
-
flexGap={60}
|
|
38
|
-
flexDirection={Flex.DIRECTION.COLUMN}
|
|
53
|
+
<PositionBox {...this.props.PARAMS.MAINMENU_VIEW.VIEW_PROPS.controls.position}>
|
|
54
|
+
<MainMenuControls
|
|
55
|
+
{...this.props}
|
|
56
|
+
items={items}
|
|
57
|
+
realItems={realItems}
|
|
58
|
+
currentItem={currentItem}
|
|
59
|
+
locs={locs}
|
|
39
60
|
/>
|
|
40
61
|
</PositionBox>
|
|
41
62
|
</Screen>
|