@vnejs/plugins.view.coralina.gamemenu 0.0.1 → 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 +4 -9
- package/modules/view.js +8 -6
- package/package.json +5 -6
- package/view/index.jsx +23 -34
- package/view/index.styl +0 -44
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,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
2
|
|
|
3
3
|
const toStateItem = ({ onClick, ...item }) => item;
|
|
4
4
|
const onRealItems = (item) => !item.isDisabled && !item.isHide;
|
|
5
5
|
|
|
6
|
-
export class GameMenuController extends
|
|
6
|
+
export class GameMenuController extends ModuleController {
|
|
7
7
|
name = "gameMenu.controller";
|
|
8
8
|
|
|
9
9
|
updateEvent = this.EVENTS.GAMEMENU_VIEW.UPDATE;
|
|
@@ -15,7 +15,7 @@ export class GameMenuController extends Module.Controller {
|
|
|
15
15
|
[this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decCurrentItem,
|
|
16
16
|
[this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incCurrentItem,
|
|
17
17
|
};
|
|
18
|
-
controlsIndex =
|
|
18
|
+
controlsIndex = this.PARAMS.GAMEMENU_VIEW.ZINDEX;
|
|
19
19
|
|
|
20
20
|
subscribe = () => {
|
|
21
21
|
this.on(this.EVENTS.GAMEMENU_VIEW.CLICK, this.onClick);
|
|
@@ -33,7 +33,6 @@ export class GameMenuController extends Module.Controller {
|
|
|
33
33
|
beforeShow = async () => {
|
|
34
34
|
await this.updateStateItems();
|
|
35
35
|
|
|
36
|
-
this.currentItem = null;
|
|
37
36
|
this.maxCurrentItem = this.state.realItems.length - 1;
|
|
38
37
|
};
|
|
39
38
|
|
|
@@ -44,11 +43,7 @@ export class GameMenuController extends Module.Controller {
|
|
|
44
43
|
|
|
45
44
|
click = (items, index) => index !== null && items[index] && items[index].onClick && items[index].onClick();
|
|
46
45
|
|
|
47
|
-
getItems =
|
|
48
|
-
const [items] = await this.emit(this.EVENTS.GAMEMENU.ITEMS);
|
|
49
|
-
|
|
50
|
-
return items;
|
|
51
|
-
};
|
|
46
|
+
getItems = () => this.emitOne(this.EVENTS.GAMEMENU.ITEMS);
|
|
52
47
|
|
|
53
48
|
updateStateItems = async () => {
|
|
54
49
|
const items = (await this.getItems()).map(toStateItem);
|
package/modules/view.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
2
|
|
|
3
3
|
import { render } from "../view";
|
|
4
4
|
|
|
5
|
-
export class GameMenuView extends
|
|
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
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.view.coralina.gamemenu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major:plugin": "npm run publish:major",
|
|
8
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
9
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
7
10
|
"publish:major": "npm version major && npm publish --access public",
|
|
8
11
|
"publish:minor": "npm version minor && npm publish --access public",
|
|
9
12
|
"publish:patch": "npm version patch && npm publish --access public"
|
|
10
13
|
},
|
|
11
14
|
"author": "",
|
|
12
15
|
"license": "ISC",
|
|
13
|
-
"description": ""
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
"@vnejs/shared": "*",
|
|
16
|
-
"@vnejs/module": "*"
|
|
17
|
-
}
|
|
16
|
+
"description": ""
|
|
18
17
|
}
|
package/view/index.jsx
CHANGED
|
@@ -1,44 +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 {
|
|
4
|
+
import { PositionBox, Screen, TextControls } from "@vnejs/uis.base";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const EMPTY_ARRAY = [];
|
|
7
|
+
const EMPTY_OBJ = {};
|
|
7
8
|
|
|
8
|
-
const
|
|
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([]);
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
useEffect(() => store.subscribe(setState), []);
|
|
14
|
+
useEffect(() => void onMount(), []);
|
|
12
15
|
|
|
13
|
-
onClick = (
|
|
14
|
-
|
|
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]);
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
const { currentItem = null, locs = {}, realItems = [] } = this.state;
|
|
18
|
-
const isCurrent = currentItem !== null && realItems[currentItem].locKey === locKey;
|
|
19
|
+
useEffect(() => void setTexts(items.map(mapItemsToText)), [items, mapItemsToText]);
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
<div
|
|
23
|
-
className={b("button", { isCurrent, isDisabled }, ["textWrap_72"])}
|
|
24
|
-
onClick={isDisabled ? undefined : this.onClick}
|
|
25
|
-
data-index={i}
|
|
26
|
-
key={locKey}
|
|
27
|
-
>
|
|
28
|
-
<span className="text">{locs[locKey]}</span>
|
|
29
|
-
</div>
|
|
30
|
-
);
|
|
31
|
-
};
|
|
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]);
|
|
32
23
|
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
return (
|
|
25
|
+
<Screen {...propsScreen}>
|
|
26
|
+
<PositionBox {...props.PARAMS.GAMEMENU_VIEW.VIEW_PROPS.position}>
|
|
27
|
+
<TextControls {...propsControls} />
|
|
28
|
+
</PositionBox>
|
|
29
|
+
</Screen>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
<div className={b({ isShow, isForce })} data-html2canvas-ignore="1" vne-autoread-disable={isShow ? "1" : ""}>
|
|
38
|
-
<div className={b("menu")}>{items.map(this.renderItem)}</div>
|
|
39
|
-
</div>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const render = (props, root, resolve) => ReactDOM.render(<GameMenu {...props} />, root, resolve);
|
|
33
|
+
export const render = (props, root) => ReactDOM.render(<GameMenu {...props} />, root);
|
package/view/index.styl
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
.GameMenu
|
|
2
|
-
display: flex
|
|
3
|
-
justify-content: center
|
|
4
|
-
align-items: center
|
|
5
|
-
position: absolute
|
|
6
|
-
top: 0
|
|
7
|
-
right: 0
|
|
8
|
-
bottom: 0
|
|
9
|
-
left: 0
|
|
10
|
-
backdrop-filter: blur(5px) brightness(0.5)
|
|
11
|
-
opacity: 0
|
|
12
|
-
z-index: 4000
|
|
13
|
-
pointer-events: none
|
|
14
|
-
font-family: 'Montserrat'
|
|
15
|
-
|
|
16
|
-
&-menu
|
|
17
|
-
display: flex
|
|
18
|
-
flex-direction: column
|
|
19
|
-
justify-content: center
|
|
20
|
-
align-items: center
|
|
21
|
-
height: 100%
|
|
22
|
-
gap: 2.5%
|
|
23
|
-
|
|
24
|
-
&-button
|
|
25
|
-
cursor: pointer
|
|
26
|
-
text-align: center
|
|
27
|
-
box-sizing: border-box
|
|
28
|
-
color: rgba(255,255,255,0.6)
|
|
29
|
-
width: 100%
|
|
30
|
-
font-weight: 400
|
|
31
|
-
transition: transform 300ms, text-shadow 300ms, color 300ms
|
|
32
|
-
|
|
33
|
-
&_isCurrent,
|
|
34
|
-
&:hover
|
|
35
|
-
transform: scale(1.5)
|
|
36
|
-
color: rgba(255,255,255,0.85)
|
|
37
|
-
text-shadow: 0px 5px 25px rgba(255,255,255,0.75)
|
|
38
|
-
|
|
39
|
-
&_isShow
|
|
40
|
-
opacity: 1
|
|
41
|
-
pointer-events: all
|
|
42
|
-
|
|
43
|
-
&:not(&_isForce)
|
|
44
|
-
transition: opacity 500ms
|