@vnejs/plugins.view.coralina.point-and-click 0.0.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/index.js +6 -0
- package/modules/controller.js +32 -0
- package/modules/view.js +11 -0
- package/package.json +18 -0
- package/view/index.jsx +42 -0
- package/view/index.styl +56 -0
package/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
export class PointAndClickController extends Module.Controller {
|
|
4
|
+
name = "point-and-click.controller";
|
|
5
|
+
|
|
6
|
+
maxCurrentItem = 0;
|
|
7
|
+
updateEvent = this.EVENTS.POINT_AND_CLICK.UPDATE;
|
|
8
|
+
|
|
9
|
+
emitGameMenu = () => this.emit(this.EVENTS.INTERFACE.GAMEMENU);
|
|
10
|
+
|
|
11
|
+
controls = {
|
|
12
|
+
[this.CONST.CONTROLS.BUTTONS.MENU]: this.emitGameMenu,
|
|
13
|
+
[this.CONST.CONTROLS.BUTTONS.GAMEMENU]: this.emitGameMenu,
|
|
14
|
+
[this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => this.emit(this.EVENTS.INTERFACE.HISTORY_BACK),
|
|
15
|
+
};
|
|
16
|
+
controlsIndex = 2000;
|
|
17
|
+
|
|
18
|
+
subscribe = () => {
|
|
19
|
+
this.on(this.EVENTS.POINT_AND_CLICK.SHOW, this.onShow);
|
|
20
|
+
this.on(this.EVENTS.POINT_AND_CLICK.HIDE, this.onHide);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
beforeShow = async () => {
|
|
24
|
+
this.updateState({ ...this.globalState["point-and-click"] });
|
|
25
|
+
this.currentItem = null;
|
|
26
|
+
this.maxCurrentItem = this.state.options.length - 1;
|
|
27
|
+
|
|
28
|
+
await this.emit(this.EVENTS.INTERFACE.HIDE);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
getDefaultState = () => ({ options: [], args: {} });
|
|
32
|
+
}
|
package/modules/view.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
import { render } from "../view";
|
|
4
|
+
|
|
5
|
+
export class PointAndClickView extends Module.View {
|
|
6
|
+
name = "point-and-click.view";
|
|
7
|
+
animationTime = 300;
|
|
8
|
+
renderFunc = render;
|
|
9
|
+
updateEvent = this.EVENTS.POINT_AND_CLICK.UPDATE;
|
|
10
|
+
updateHandler = this.onUpdateReactComponent;
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/plugins.view.coralina.point-and-click",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major": "npm version major && npm publish --access public",
|
|
8
|
+
"publish:minor": "npm version minor && npm publish --access public",
|
|
9
|
+
"publish:patch": "npm version patch && npm publish --access public"
|
|
10
|
+
},
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"description": "",
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@vnejs/shared": "*",
|
|
16
|
+
"@vnejs/module": "*"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/view/index.jsx
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import ReactDOM from "react-dom";
|
|
3
|
+
|
|
4
|
+
import { cn } from "@bem-react/classname";
|
|
5
|
+
|
|
6
|
+
import "./index.styl";
|
|
7
|
+
|
|
8
|
+
const b = cn("PointAndClick");
|
|
9
|
+
|
|
10
|
+
class PointAndClick extends React.Component {
|
|
11
|
+
onOptionClick = (e) =>
|
|
12
|
+
this.props.emit(this.props.EVENTS.POINT_AND_CLICK.OPTION, { index: Number(e.currentTarget.dataset.index) });
|
|
13
|
+
|
|
14
|
+
renderOption = ({ disabled, hided, coords: [x, y] }, index) =>
|
|
15
|
+
!hided && (
|
|
16
|
+
<div
|
|
17
|
+
className={b("option", {
|
|
18
|
+
disabled,
|
|
19
|
+
isCurrent: index === this.state.currentItem,
|
|
20
|
+
coords: Boolean(x) && Boolean(y),
|
|
21
|
+
})}
|
|
22
|
+
style={{ left: `${x}%`, top: `${y}%` }}
|
|
23
|
+
data-index={index}
|
|
24
|
+
key={index}
|
|
25
|
+
onClick={disabled ? undefined : this.onOptionClick}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
render() {
|
|
30
|
+
const { isShow = false, options = [], isForce = false } = this.state || {};
|
|
31
|
+
|
|
32
|
+
console.log(99999999999, isShow, options);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div className={b({ isShow, isForce })} vne-autoread-disable={isShow ? "1" : ""}>
|
|
36
|
+
{options.map(this.renderOption)}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const render = (props, root, resolve) => ReactDOM.render(<PointAndClick {...props} />, root, resolve);
|
package/view/index.styl
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.PointAndClick
|
|
2
|
+
position: absolute
|
|
3
|
+
top: 0
|
|
4
|
+
right: 0
|
|
5
|
+
bottom: 0
|
|
6
|
+
left: 0
|
|
7
|
+
display: flex
|
|
8
|
+
justify-content: center
|
|
9
|
+
align-items: center
|
|
10
|
+
z-index: 3000
|
|
11
|
+
opacity: 0
|
|
12
|
+
pointer-events: none
|
|
13
|
+
font-family: Montserrat
|
|
14
|
+
|
|
15
|
+
&-options
|
|
16
|
+
display: flex
|
|
17
|
+
flex-direction: column
|
|
18
|
+
justify-content: center
|
|
19
|
+
align-items: center
|
|
20
|
+
height: 100%
|
|
21
|
+
gap: calc(50 / 2160 * 100%)
|
|
22
|
+
|
|
23
|
+
&-option
|
|
24
|
+
transition: transform 300ms
|
|
25
|
+
|
|
26
|
+
width: 3%
|
|
27
|
+
aspect-ratio: 1
|
|
28
|
+
|
|
29
|
+
background: black
|
|
30
|
+
border-radius: 50%
|
|
31
|
+
|
|
32
|
+
&_coords
|
|
33
|
+
position: absolute
|
|
34
|
+
transform: translate(-50%, -50%)
|
|
35
|
+
|
|
36
|
+
&:not(&_disabled):hover,
|
|
37
|
+
&_isCurrent:not(&_disabled)
|
|
38
|
+
opacity: 0.85
|
|
39
|
+
transform: scale(1.25)
|
|
40
|
+
|
|
41
|
+
&_coords:hover:not(&_disabled)
|
|
42
|
+
&_coords&_isCurrent:not(&_disabled)
|
|
43
|
+
transform: translate(-50%, -50%) scale(1.25)
|
|
44
|
+
|
|
45
|
+
&:not(&_disabled)
|
|
46
|
+
cursor: pointer
|
|
47
|
+
|
|
48
|
+
&_disabled
|
|
49
|
+
opacity: 0.5
|
|
50
|
+
|
|
51
|
+
&_isShow
|
|
52
|
+
opacity: 1
|
|
53
|
+
pointer-events: all
|
|
54
|
+
|
|
55
|
+
&:not(&_isForce)
|
|
56
|
+
transition: opacity 300ms
|