@vnejs/plugins.view.coralina.gamemenu 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 +9 -0
- package/index.js +2 -1
- package/modules/controller.js +1 -3
- package/modules/view.js +7 -5
- package/package.json +1 -1
- package/view/index.jsx +31 -55
package/const/params.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const TRANSITION = 500;
|
|
2
|
+
export const ZINDEX = 3000;
|
|
3
|
+
export const LOC_LABEL = "gameMenu";
|
|
4
|
+
|
|
5
|
+
export const VIEW_PROPS = {
|
|
6
|
+
screen: { isIgnoreOnScreenshot: true, withBackgroundBlur: true, withBackgroundDark: true, zIndex: ZINDEX, transition: TRANSITION },
|
|
7
|
+
position: { isCentered: true },
|
|
8
|
+
controls: { flexDirection: "column", flexGap: 60, textSize: 96, textAlign: "center" },
|
|
9
|
+
};
|
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 { GameMenuController } from "./modules/controller";
|
|
6
7
|
import { GameMenuView } from "./modules/view";
|
|
7
8
|
|
|
8
|
-
regPlugin("GAMEMENU_VIEW", { events: SUBSCRIBE_EVENTS }, [GameMenuController, GameMenuView]);
|
|
9
|
+
regPlugin("GAMEMENU_VIEW", { events: SUBSCRIBE_EVENTS, params }, [GameMenuController, GameMenuView]);
|
package/modules/controller.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { ModuleController } from "@vnejs/module.components";
|
|
2
2
|
|
|
3
|
-
import { ZINDEX } from "../view";
|
|
4
|
-
|
|
5
3
|
const toStateItem = ({ onClick, ...item }) => item;
|
|
6
4
|
const onRealItems = (item) => !item.isDisabled && !item.isHide;
|
|
7
5
|
|
|
@@ -17,7 +15,7 @@ export class GameMenuController extends ModuleController {
|
|
|
17
15
|
[this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decCurrentItem,
|
|
18
16
|
[this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incCurrentItem,
|
|
19
17
|
};
|
|
20
|
-
controlsIndex = ZINDEX;
|
|
18
|
+
controlsIndex = this.PARAMS.GAMEMENU_VIEW.ZINDEX;
|
|
21
19
|
|
|
22
20
|
subscribe = () => {
|
|
23
21
|
this.on(this.EVENTS.GAMEMENU_VIEW.CLICK, this.onClick);
|
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 GameMenuView extends ModuleView {
|
|
6
6
|
name = "gameMenu.view";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
locLabel = this.PARAMS.GAMEMENU_VIEW.LOC_LABEL;
|
|
9
|
+
animationTime = this.PARAMS.GAMEMENU_VIEW.TRANSITION;
|
|
10
10
|
updateEvent = this.EVENTS.GAMEMENU_VIEW.UPDATE;
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
renderFunc = render;
|
|
13
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
12
14
|
}
|
package/package.json
CHANGED
package/view/index.jsx
CHANGED
|
@@ -1,57 +1,33 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
zIndex={ZINDEX}
|
|
35
|
-
transition={TRANSITION}
|
|
36
|
-
isDisableAutoread={isShow}
|
|
37
|
-
isIgnoreOnScreenshot={true}
|
|
38
|
-
withBlur={true}
|
|
39
|
-
withDark={true}
|
|
40
|
-
>
|
|
41
|
-
<PositionBox isCentered={true}>
|
|
42
|
-
<TextControls
|
|
43
|
-
selectedIndex={currentItem}
|
|
44
|
-
flexDirection={Flex.DIRECTION.COLUMN}
|
|
45
|
-
flexGap={60}
|
|
46
|
-
textSize={96}
|
|
47
|
-
textAlign={Text.ALIGNS.CENTER}
|
|
48
|
-
texts={texts}
|
|
49
|
-
onClick={this.onClick}
|
|
50
|
-
/>
|
|
51
|
-
</PositionBox>
|
|
52
|
-
</Screen>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const render = (props, root, resolve) => ReactDOM.render(<GameMenu {...props} />, root, resolve);
|
|
4
|
+
import { PositionBox, Screen, TextControls } from "@vnejs/uis.base";
|
|
5
|
+
|
|
6
|
+
const EMPTY_ARRAY = [];
|
|
7
|
+
const EMPTY_OBJ = {};
|
|
8
|
+
|
|
9
|
+
const GameMenu = ({ store, onMount, ...props } = {}) => {
|
|
10
|
+
const [{ isShow = false, isForce = false, items = EMPTY_ARRAY, locs = EMPTY_OBJ, currentItem: selectedIndex = null }, setState] = useState({});
|
|
11
|
+
const [texts, setTexts] = useState([]);
|
|
12
|
+
|
|
13
|
+
useEffect(() => store.subscribe(setState), []);
|
|
14
|
+
useEffect(() => void onMount(), []);
|
|
15
|
+
|
|
16
|
+
const onClick = useCallback((index) => props.emit(props.EVENTS.GAMEMENU_VIEW.CLICK, { index }), []);
|
|
17
|
+
const mapItemsToText = useCallback(({ locKey, isDisabled, isHide }, i) => ({ isDisabled, isNotRender: isHide, value: i, text: locs[locKey] }), [locs]);
|
|
18
|
+
|
|
19
|
+
useEffect(() => void setTexts(items.map(mapItemsToText)), [items, mapItemsToText]);
|
|
20
|
+
|
|
21
|
+
const propsScreen = useMemo(() => ({ ...props.PARAMS.GAMEMENU_VIEW.VIEW_PROPS.screen, isShow, isForce, isDisableAutoread: isShow }), [isShow, isForce]);
|
|
22
|
+
const propsControls = useMemo(() => ({ ...props.PARAMS.GAMEMENU_VIEW.VIEW_PROPS.controls, selectedIndex, texts, onClick }), [selectedIndex, texts]);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Screen {...propsScreen}>
|
|
26
|
+
<PositionBox {...props.PARAMS.GAMEMENU_VIEW.VIEW_PROPS.position}>
|
|
27
|
+
<TextControls {...propsControls} />
|
|
28
|
+
</PositionBox>
|
|
29
|
+
</Screen>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const render = (props, root) => ReactDOM.render(<GameMenu {...props} />, root);
|