logo selecting

This commit is contained in:
muerwre 2018-08-27 12:00:43 +07:00
parent 898176a68f
commit 0c6dc387de
12 changed files with 104 additions and 17 deletions

View file

@ -1,8 +1,13 @@
import React from 'react'; import React from 'react';
import { LOGOS } from '$constants/logos'; import { LOGOS } from '$constants/logos';
import { Icon } from '$components/panels/Icon'; import { Icon } from '$components/panels/Icon';
import classnames from 'classnames';
export class LogoDialog extends React.Component { export class LogoDialog extends React.Component {
changeLogo = logo => {
this.props.editor.changeLogo(logo);
};
render() { render() {
return ( return (
<div className="helper logo-helper"> <div className="helper logo-helper">
@ -11,7 +16,11 @@ export class LogoDialog extends React.Component {
</div> </div>
{ {
Object.keys(LOGOS).map(logo => ( Object.keys(LOGOS).map(logo => (
<div className="helper-menu-item" key={logo}> <div
className={classnames('helper-menu-item', { active: (logo === this.props.logo) })}
onClick={() => this.changeLogo(logo)}
key={logo}
>
{LOGOS[logo][0]} {LOGOS[logo][0]}
</div> </div>
)) ))

View file

@ -0,0 +1,13 @@
import React from 'react';
import { LOGOS } from '$constants/logos';
export const LogoPreview = ({ logo }) => (
<div
className="logo-preview"
style={{
backgroundImage: logo
? `url(${LOGOS[logo][1]})`
: 'none'
}}
/>
);

View file

@ -7,7 +7,7 @@ import { TrashDialog } from '$components/trash/TrashDialog';
import { LogoDialog } from '$components/logo/LogoDialog'; import { LogoDialog } from '$components/logo/LogoDialog';
export const EditorDialog = ({ export const EditorDialog = ({
mode, routerPoints, editor, activeSticker mode, routerPoints, editor, activeSticker, logo
}) => { }) => {
const showDialog = ( const showDialog = (
mode === MODES.ROUTER mode === MODES.ROUTER
@ -22,7 +22,7 @@ export const EditorDialog = ({
{ mode === MODES.ROUTER && <RouterDialog routerPoints={routerPoints} editor={editor} /> } { mode === MODES.ROUTER && <RouterDialog routerPoints={routerPoints} editor={editor} /> }
{ mode === MODES.STICKERS && <StickersDialog editor={editor} /> } { mode === MODES.STICKERS && <StickersDialog editor={editor} /> }
{ mode === MODES.TRASH && <TrashDialog editor={editor} /> } { mode === MODES.TRASH && <TrashDialog editor={editor} /> }
{ mode === MODES.LOGO && <LogoDialog editor={editor} /> } { mode === MODES.LOGO && <LogoDialog editor={editor} logo={logo} /> }
</div> </div>
); );
}; };

View file

@ -6,6 +6,7 @@ import { toHours } from '$utils/time';
import { Icon } from '$components/panels/Icon'; import { Icon } from '$components/panels/Icon';
import { EditorDialog } from '$components/panels/EditorDialog'; import { EditorDialog } from '$components/panels/EditorDialog';
import { LogoPreview } from '$components/logo/LogoPreview';
export class EditorPanel extends React.PureComponent { export class EditorPanel extends React.PureComponent {
startPolyMode = () => this.props.editor.changeMode(MODES.POLY); startPolyMode = () => this.props.editor.changeMode(MODES.POLY);
@ -22,7 +23,7 @@ export class EditorPanel extends React.PureComponent {
render() { render() {
const { const {
mode, routerPoints, editor, totalDistance, estimateTime, activeSticker mode, routerPoints, editor, totalDistance, estimateTime, activeSticker, logo,
} = this.props; } = this.props;
return ( return (
@ -33,8 +34,11 @@ export class EditorPanel extends React.PureComponent {
routerPoints={routerPoints} routerPoints={routerPoints}
activeSticker={activeSticker} activeSticker={activeSticker}
editor={editor} editor={editor}
logo={logo}
/> />
<LogoPreview logo={logo} />
<div className="panel"> <div className="panel">
<div className="control-bar"> <div className="control-bar">
<button <button
@ -56,7 +60,10 @@ export class EditorPanel extends React.PureComponent {
(estimateTime > 0) && (estimateTime > 0) && <span>{toHours(estimateTime)}</span> (estimateTime > 0) && (estimateTime > 0) && <span>{toHours(estimateTime)}</span>
} }
</React.Fragment> </React.Fragment>
: <div onClick={() => editor.changeMode(MODES.ROUTER)}>Начать рисовать</div> :
<div onClick={() => editor.changeMode(MODES.ROUTER)}>
<div className="button danger">Начать рисовать</div>
</div>
} }
</div> </div>

View file

@ -1,10 +1,12 @@
export const LOGOS = { export const LOGOS = {
default: ['Без логотипа', null, 'bottom-right'], default: ['Без логотипа', null, 'bottom-right'],
nvs: ['НВС', '/misc/lgo.png', 'bottom-right'], nvs: ['НВС', 'http://map.vault48.org/misc/lgo.png', 'bottom-right'],
pinmix: ['Пин-Микс', '/misc/pin-mix.png', 'top-right'], pinmix: ['Пин-Микс', 'http://map.vault48.org/misc/pin-mix.png', 'top-right'],
jolly: ['Пин-Микс + JW', '/misc/jw.png', 'top-right'], jolly: ['Пин-Микс + JW', 'http://map.vault48.org/misc/jw.png', 'top-right'],
pedals: ['Усталые Педальки', '/misc/pedals.png', 'bottom-right'], pedals: ['Усталые Педальки', 'http://map.vault48.org/misc/pedals.png', 'bottom-right'],
rider: ['Райдер', '/misc/rider.png', 'bottom-right'], rider: ['Райдер', 'http://map.vault48.org/misc/rider.png', 'bottom-right'],
// rider_evening: ['Вечерние городские', '/misc/rider_evening.png', 'top-right'], // rider_evening: ['Вечерние городские', '/misc/rider_evening.png', 'top-right'],
// fas: ['Алкоспорт', '/misc/fas.png', 'bottom-right'], // fas: ['Алкоспорт', '/misc/fas.png', 'bottom-right'],
}; };
export const DEFAULT_LOGO = 'nvs';

View file

@ -3,10 +3,12 @@ import React from 'react';
import { Editor } from '$modules/Editor'; import { Editor } from '$modules/Editor';
import { EditorPanel } from '$components/panels/EditorPanel'; import { EditorPanel } from '$components/panels/EditorPanel';
import { Fills } from '$components/Fills'; import { Fills } from '$components/Fills';
import { DEFAULT_LOGO } from '$constants/logos';
export class App extends React.Component { export class App extends React.Component {
state = { state = {
mode: 'none', mode: 'none',
logo: DEFAULT_LOGO,
routerPoints: 0, routerPoints: 0,
totalDistance: 0, totalDistance: 0,
estimateTime: 0, estimateTime: 0,
@ -31,6 +33,10 @@ export class App extends React.Component {
this.setState({ activeSticker }); this.setState({ activeSticker });
}; };
setLogo = logo => {
this.setState({ logo });
};
editor = new Editor({ editor = new Editor({
container: 'map', container: 'map',
mode: this.state.mode, mode: this.state.mode,
@ -38,13 +44,14 @@ export class App extends React.Component {
setRouterPoints: this.setRouterPoints, setRouterPoints: this.setRouterPoints,
setTotalDist: this.setTotalDist, setTotalDist: this.setTotalDist,
setActiveSticker: this.setActiveSticker, setActiveSticker: this.setActiveSticker,
setLogo: this.setLogo,
}); });
render() { render() {
const { const {
editor, editor,
state: { state: {
mode, routerPoints, totalDistance, estimateTime, activeSticker mode, routerPoints, totalDistance, estimateTime, activeSticker, logo,
}, },
} = this; } = this;
@ -59,6 +66,7 @@ export class App extends React.Component {
totalDistance={totalDistance} totalDistance={totalDistance}
estimateTime={estimateTime} estimateTime={estimateTime}
activeSticker={activeSticker} activeSticker={activeSticker}
logo={logo}
/> />
</div> </div>
); );

View file

@ -4,7 +4,7 @@ import { MODES } from '$constants/modes';
import { Stickers } from '$modules/Stickers'; import { Stickers } from '$modules/Stickers';
import { Router } from '$modules/Router'; import { Router } from '$modules/Router';
import { Shotter } from '$modules/Shotter'; import { Shotter } from '$modules/Shotter';
import { LOGOS } from '$constants/logos'; import { DEFAULT_LOGO } from '$constants/logos';
export class Editor { export class Editor {
constructor({ constructor({
@ -14,7 +14,10 @@ export class Editor {
setRouterPoints, setRouterPoints,
setTotalDist, setTotalDist,
setActiveSticker, setActiveSticker,
setLogo,
}) { }) {
this.logo = DEFAULT_LOGO;
this.map = new Map({ container }); this.map = new Map({ container });
const { const {
@ -30,9 +33,6 @@ export class Editor {
}); });
this.shotter = new Shotter({ map }); this.shotter = new Shotter({ map });
this.setMode = setMode;
this.mode = mode;
this.switches = { this.switches = {
[MODES.POLY]: { [MODES.POLY]: {
start: this.poly.continue, start: this.poly.continue,
@ -56,6 +56,9 @@ export class Editor {
this.activeSticker = null; this.activeSticker = null;
this.setActiveSticker = setActiveSticker; this.setActiveSticker = setActiveSticker;
this.setLogo = setLogo;
this.setMode = setMode;
this.mode = mode;
map.addEventListener('mouseup', this.onClick); map.addEventListener('mouseup', this.onClick);
map.addEventListener('dragstart', () => lockMapClicks(true)); map.addEventListener('dragstart', () => lockMapClicks(true));
@ -152,5 +155,11 @@ export class Editor {
this.setSticker(null); this.setSticker(null);
this.changeMode(MODES.NONE); this.changeMode(MODES.NONE);
};
changeLogo = logo => {
this.logo = logo;
this.setLogo(logo);
this.changeMode(MODES.NONE);
} }
} }

View file

@ -11,6 +11,7 @@
cursor: pointer; cursor: pointer;
user-select: none; user-select: none;
box-shadow: inset rgba(100,100,100, 0.3) 1px 0, inset rgba(0,0,0, 0.1) -1px 0; box-shadow: inset rgba(100,100,100, 0.3) 1px 0, inset rgba(0,0,0, 0.1) -1px 0;
color: white;
&.primary { &.primary {
background: #3c78db; background: #3c78db;

2
src/styles/colors.less Normal file
View file

@ -0,0 +1,2 @@
@blue_primary: #55ddff;
@blue_secondary: #7137c8;

19
src/styles/logo.less Normal file
View file

@ -0,0 +1,19 @@
.logo-preview {
position: fixed;
right: 0;
bottom: 58px;
width: 400px;
height: 100%;
opacity: 0.5;
pointer-events: none;
z-index: 2;
background: 100% 100% no-repeat;
&.top {
background-position: 100% 0;
}
}

View file

@ -1,8 +1,11 @@
@import 'colors.less';
@import 'map.less'; @import 'map.less';
@import 'panel.less'; @import 'panel.less';
@import 'router.less'; @import 'router.less';
@import 'stickers.less'; @import 'stickers.less';
@import 'button.less'; @import 'button.less';
@import 'logo.less';
body { body {
font-family: sans-serif; font-family: sans-serif;

View file

@ -78,7 +78,8 @@
} }
&.highlighted { &.highlighted {
background: linear-gradient(150deg, #05a4ff, #7137c8); background: linear-gradient(150deg, @blue_primary, @blue_secondary) 50% 50% no-repeat;
background-size: 100% 100%;
} }
svg { svg {
@ -107,7 +108,7 @@
right: 10px; right: 10px;
bottom: 12px; bottom: 12px;
border-radius: 3px; border-radius: 3px;
z-index: 2; z-index: 3;
color: white; color: white;
box-sizing: border-box; box-sizing: border-box;
padding-bottom: 48px; padding-bottom: 48px;
@ -157,8 +158,21 @@
padding: 8px 20px; padding: 8px 20px;
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
position: relative;
&:hover { &:hover {
background: rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.1);
} }
&.active {
&::after {
content: ' ';
width: 16px;
height: 4px;
left: 0;
top: 14px;
position: absolute;
background: white;
}
}
} }