@vnejs/plugins.view.coralina.interface.controls 0.1.0 → 0.1.2
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/events.js +1 -0
- package/const/params.js +23 -0
- package/index.js +2 -1
- package/modules/controller.js +25 -7
- package/modules/view.js +6 -4
- package/package.json +1 -1
- package/view/index.jsx +44 -57
- package/view/images/Hide.png +0 -0
- package/view/images/Hide_H.png +0 -0
- package/view/images/History.png +0 -0
- package/view/images/History_H.png +0 -0
- package/view/images/Settings.png +0 -0
- package/view/images/Settings_H.png +0 -0
package/const/events.js
CHANGED
package/const/params.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const VIEW_PROPS = {
|
|
2
|
+
adv: {
|
|
3
|
+
icon: { width: 96, height: 96, isOpacityOnHover: true },
|
|
4
|
+
view: { left: 360, bottom: 24, translateX: "calc(1px * var(--vne-length-240))" },
|
|
5
|
+
flex: { gap: 36 },
|
|
6
|
+
},
|
|
7
|
+
line: {
|
|
8
|
+
icon: { width: 96, height: 96, isOpacityOnHover: true },
|
|
9
|
+
view: { left: 360, bottom: 24 },
|
|
10
|
+
flex: { gap: 36 },
|
|
11
|
+
},
|
|
12
|
+
wall: {
|
|
13
|
+
icon: { width: 96, height: 96, isOpacityOnHover: true },
|
|
14
|
+
view: { left: 360, bottom: 24 },
|
|
15
|
+
flex: { gap: 36 },
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const ITEMS = [
|
|
20
|
+
{ icon: "menu", onClick: ({ emit, EVENTS = {} } = {}) => emit(EVENTS.INTERFACE.GAMEMENU) },
|
|
21
|
+
{ icon: "history", onClick: ({ emit, EVENTS = {} } = {}) => emit(EVENTS.INTERFACE.HISTORY) },
|
|
22
|
+
{ icon: "hide", onClick: ({ emit, EVENTS = {} } = {}) => emit(EVENTS.INTERFACE.VISIBLE) },
|
|
23
|
+
];
|
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 { InterfaceControlsController } from "./modules/controller";
|
|
6
7
|
import { InterfaceControlsView } from "./modules/view";
|
|
7
8
|
|
|
8
|
-
regPlugin("
|
|
9
|
+
regPlugin("INTERFACE_CONTROLS_VIEW", { events: SUBSCRIBE_EVENTS, params }, [InterfaceControlsController, InterfaceControlsView]);
|
package/modules/controller.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { ModuleController } from "@vnejs/module.components";
|
|
2
2
|
|
|
3
|
-
import { ZINDEX } from "../view";
|
|
4
|
-
|
|
5
3
|
export class InterfaceControlsController extends ModuleController {
|
|
6
4
|
name = "interface.controls.controller";
|
|
7
5
|
|
|
8
6
|
emitGameMenu = () => this.emit(this.EVENTS.INTERFACE.GAMEMENU);
|
|
9
7
|
|
|
10
|
-
updateEvent = this.EVENTS.
|
|
8
|
+
updateEvent = this.EVENTS.INTERFACE_CONTROLS_VIEW.UPDATE;
|
|
11
9
|
controls = {
|
|
12
10
|
[this.CONST.CONTROLS.BUTTONS.MENU]: this.emitGameMenu,
|
|
13
11
|
[this.CONST.CONTROLS.BUTTONS.GAMEMENU]: this.emitGameMenu,
|
|
@@ -19,22 +17,28 @@ export class InterfaceControlsController extends ModuleController {
|
|
|
19
17
|
[this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE),
|
|
20
18
|
};
|
|
21
19
|
controlsUnvisible = { [this.CONST.CONTROLS.BUTTONS.ANY]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE) };
|
|
22
|
-
controlsIndex = ZINDEX;
|
|
20
|
+
controlsIndex = this.PARAMS.INTERFACE_VIEW.ZINDEX + 100;
|
|
23
21
|
controlsCheckNext = true;
|
|
24
22
|
|
|
25
23
|
subscribe = () => {
|
|
26
|
-
this.on(this.EVENTS.
|
|
27
|
-
this.on(this.EVENTS.
|
|
24
|
+
this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.SHOW, this.onShow);
|
|
25
|
+
this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.HIDE, this.onHide);
|
|
26
|
+
this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.CLICK, this.onClick);
|
|
28
27
|
|
|
29
28
|
this.on(this.EVENTS.INTERFACE.SHOW_CHANGED, this.onShowChanged);
|
|
30
29
|
this.on(this.EVENTS.INTERFACE.VIEW_CHANGED, this.onViewChanged);
|
|
31
30
|
this.on(this.EVENTS.INTERFACE.STATE_CHANGED, this.onStateChanged);
|
|
32
31
|
this.on(this.EVENTS.INTERFACE.VISIBLE_CHANGED, this.onVisibleChanged);
|
|
32
|
+
|
|
33
|
+
this.on(this.EVENTS.SYSTEM.STARTED, this.getIconsSrcs);
|
|
34
|
+
this.on(this.EVENTS.MEMORY.CLEARED, this.getIconsSrcs);
|
|
33
35
|
};
|
|
34
36
|
|
|
37
|
+
beforeShow = async () => this.updateState({ icons: await this.getIconsSrcs() });
|
|
38
|
+
|
|
35
39
|
onShowChanged = ({ isForce = false } = {}) => {
|
|
36
40
|
const { isShow = false } = this.globalState.interface;
|
|
37
|
-
const event = isShow ? this.EVENTS.
|
|
41
|
+
const event = isShow ? this.EVENTS.INTERFACE_CONTROLS_VIEW.SHOW : this.EVENTS.INTERFACE_CONTROLS_VIEW.HIDE;
|
|
38
42
|
|
|
39
43
|
if (this.state.isShow !== isShow) return this.emit(event, { isForce });
|
|
40
44
|
};
|
|
@@ -51,6 +55,8 @@ export class InterfaceControlsController extends ModuleController {
|
|
|
51
55
|
if (this.state.isVisible !== isVisible) return this.updateStateAndView({ isVisible }, isForce, !isForce);
|
|
52
56
|
};
|
|
53
57
|
|
|
58
|
+
onClick = ({ index = 0 } = {}) => this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS?.[index]?.onClick(this);
|
|
59
|
+
|
|
54
60
|
onStateChanged = () => {
|
|
55
61
|
const { isShow = false, isVisible = false, view = "" } = this.globalState.interface;
|
|
56
62
|
|
|
@@ -61,8 +67,20 @@ export class InterfaceControlsController extends ModuleController {
|
|
|
61
67
|
|
|
62
68
|
toggleUnvisibleControls = (isVisible) => {
|
|
63
69
|
const args = { key: `${this.name}-unvisible`, controls: this.controlsUnvisible, index: this.controlsIndex + 500 };
|
|
70
|
+
|
|
64
71
|
return this.emit(isVisible ? this.EVENTS.CONTROLS.POP : this.EVENTS.CONTROLS.PUSH, args);
|
|
65
72
|
};
|
|
66
73
|
|
|
67
74
|
getDefaultState = () => ({ isShow: false, isVisible: false, view: "" });
|
|
75
|
+
|
|
76
|
+
getIconsSrcs = () => Promise.all(this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS.map(this.getOneIconSrcs));
|
|
77
|
+
|
|
78
|
+
getOneIconSrcs = async ({ icon = "", iconHover = "" } = {}) => {
|
|
79
|
+
const [result, quality] = [{}, this.shared.settings[this.SETTINGS.CANVAS.QUALITY]];
|
|
80
|
+
|
|
81
|
+
if (icon) result.src = (await this.loadImageMedia(`interface/${icon}`, "icons", quality, false, false)).src;
|
|
82
|
+
if (iconHover) result.srcHover = (await this.loadImageMedia(`interface/${iconHover}`, "icons", quality, false, false)).src;
|
|
83
|
+
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
68
86
|
}
|
package/modules/view.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ModuleView } from "@vnejs/module.components";
|
|
2
2
|
|
|
3
|
-
import { render
|
|
3
|
+
import { render } from "../view";
|
|
4
4
|
|
|
5
5
|
export class InterfaceControlsView extends ModuleView {
|
|
6
6
|
name = "interface.controls.view";
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
animationTime = this.PARAMS.INTERFACE_VIEW.TRANSITION;
|
|
9
|
+
updateEvent = this.EVENTS.INTERFACE_CONTROLS_VIEW.UPDATE;
|
|
10
|
+
|
|
8
11
|
renderFunc = render;
|
|
9
|
-
|
|
10
|
-
updateHandler = this.onUpdateReactComponent;
|
|
12
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
11
13
|
}
|
package/package.json
CHANGED
package/view/index.jsx
CHANGED
|
@@ -1,61 +1,48 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
|
|
4
4
|
import { Flex, Icon, View } from "@vnejs/uis.base";
|
|
5
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<Icon
|
|
50
|
-
{...ICON_COMMON_PROPS}
|
|
51
|
-
transition={isForce ? 0 : TRANSITION}
|
|
52
|
-
src={hideSrc}
|
|
53
|
-
onClick={this.onHideClick}
|
|
54
|
-
/>
|
|
55
|
-
</Flex>
|
|
56
|
-
</View>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const render = (props, root, resolve) => ReactDOM.render(<InterfaceControls {...props} />, root, resolve);
|
|
6
|
+
const InterfaceControls = ({ store, onMount, ...props } = {}) => {
|
|
7
|
+
const [{ isShow = false, isVisible = false, isForce = false, view = "", icons = [] }, setState] = useState({});
|
|
8
|
+
|
|
9
|
+
useEffect(() => store.subscribe(setState), []);
|
|
10
|
+
useEffect(() => void onMount(), []);
|
|
11
|
+
|
|
12
|
+
const onItemClick = useCallback((index = 0) => props.emit(props.EVENTS.INTERFACE_CONTROLS_VIEW.CLICK, { index }), []);
|
|
13
|
+
|
|
14
|
+
const transition = isForce ? 0 : props.PARAMS.INTERFACE_VIEW.TRANSITION;
|
|
15
|
+
|
|
16
|
+
const propsByView = useMemo(() => props.PARAMS.INTERFACE_CONTROLS_VIEW.VIEW_PROPS[view] || {}, [view]);
|
|
17
|
+
const propsIcon = useMemo(() => ({ ...propsByView.icon, transition }), [propsByView, transition]);
|
|
18
|
+
|
|
19
|
+
const renderedIcons = useMemo(
|
|
20
|
+
() =>
|
|
21
|
+
icons.map(({ src, srcHover }, i) => (
|
|
22
|
+
<Icon
|
|
23
|
+
{...propsIcon}
|
|
24
|
+
srcHover={srcHover}
|
|
25
|
+
src={src}
|
|
26
|
+
onClick={onItemClick}
|
|
27
|
+
value={i}
|
|
28
|
+
key={i}
|
|
29
|
+
/>
|
|
30
|
+
)),
|
|
31
|
+
[propsIcon, icons],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<View
|
|
36
|
+
{...propsByView.view}
|
|
37
|
+
isShow={isShow}
|
|
38
|
+
isForce={isForce}
|
|
39
|
+
isHidden={!isVisible}
|
|
40
|
+
transition={transition}
|
|
41
|
+
zIndex={props.PARAMS.INTERFACE_VIEW.ZINDEX + 100}
|
|
42
|
+
>
|
|
43
|
+
<Flex {...propsByView.flex}>{renderedIcons}</Flex>
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const render = (props, root) => ReactDOM.render(<InterfaceControls {...props} />, root);
|
package/view/images/Hide.png
DELETED
|
Binary file
|
package/view/images/Hide_H.png
DELETED
|
Binary file
|
package/view/images/History.png
DELETED
|
Binary file
|
|
Binary file
|
package/view/images/Settings.png
DELETED
|
Binary file
|
|
Binary file
|