mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 07:34:36 +01:00
page switching with custom event
This commit is contained in:
@@ -35,12 +35,29 @@ select:focus {
|
|||||||
.TopButton {
|
.TopButton {
|
||||||
height: 60%;
|
height: 60%;
|
||||||
margin: 0px 10px;
|
margin: 0px 10px;
|
||||||
|
|
||||||
|
color: #c5c5c5;
|
||||||
|
transition: color 0.1s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.TopButton span {
|
||||||
|
display: inline-block;
|
||||||
|
line-height: normal;
|
||||||
|
border-bottom: 1px solid #c5c5c5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.TopButton img {
|
||||||
filter: invert(95%) sepia(0%) saturate(18%) hue-rotate(153deg) brightness(88%) contrast(81%);
|
filter: invert(95%) sepia(0%) saturate(18%) hue-rotate(153deg) brightness(88%) contrast(81%);
|
||||||
|
|
||||||
transition: filter 0.1s ease-in-out;
|
transition: filter 0.1s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.TopButton:hover {
|
.TopButton:hover {
|
||||||
|
color: #fff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.TopButton:hover img {
|
||||||
filter: invert(100%) sepia(0%) saturate(18%) hue-rotate(153deg) brightness(100%) contrast(100%);
|
filter: invert(100%) sepia(0%) saturate(18%) hue-rotate(153deg) brightness(100%) contrast(100%);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import { getTheme, loadTheme } from '../utils/themes'
|
|||||||
import { convertFileSrc, invoke } from '@tauri-apps/api/tauri'
|
import { convertFileSrc, invoke } from '@tauri-apps/api/tauri'
|
||||||
import { dataDir } from '@tauri-apps/api/path'
|
import { dataDir } from '@tauri-apps/api/path'
|
||||||
import { Main } from './Main'
|
import { Main } from './Main'
|
||||||
|
import { Mods } from './Mods'
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
moddingOpen: boolean
|
page: string
|
||||||
bgFile: string
|
bgFile: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ class App extends React.Component<Readonly<unknown>, IState> {
|
|||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
moddingOpen: false,
|
page: 'main',
|
||||||
bgFile: DEFAULT_BG,
|
bgFile: DEFAULT_BG,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +86,13 @@ class App extends React.Component<Readonly<unknown>, IState> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.addEventListener('changePage', (e) => {
|
||||||
|
this.setState({
|
||||||
|
// @ts-expect-error - TS doesn't like our custom event
|
||||||
|
page: e.detail,
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -99,11 +107,14 @@ class App extends React.Component<Readonly<unknown>, IState> {
|
|||||||
: {}
|
: {}
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{this.state.moddingOpen ? null : (
|
{(() => {
|
||||||
<>
|
switch (this.state.page) {
|
||||||
<Main downloadHandler={downloadHandler} />
|
case 'modding':
|
||||||
</>
|
return <Mods downloadHandler={downloadHandler} />
|
||||||
)}
|
default:
|
||||||
|
return <Main downloadHandler={downloadHandler} />
|
||||||
|
}
|
||||||
|
})()}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class Debug extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<TopBar optFunc={none} downFunc={none} gameFunc={none} modFunc={none} />
|
<TopBar />
|
||||||
<TextInput readOnly={false} initalValue={'change to set proxy address'} onChange={setProxyAddress} />
|
<TextInput readOnly={false} initalValue={'change to set proxy address'} onChange={setProxyAddress} />
|
||||||
<button onClick={startProxy}>start proxy</button>
|
<button onClick={startProxy}>start proxy</button>
|
||||||
<button onClick={stopProxy}>stop proxy</button>
|
<button onClick={stopProxy}>stop proxy</button>
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ import { appWindow } from '@tauri-apps/api/window'
|
|||||||
import { unpatchGame } from '../utils/metadata'
|
import { unpatchGame } from '../utils/metadata'
|
||||||
import DownloadHandler from '../utils/download'
|
import DownloadHandler from '../utils/download'
|
||||||
|
|
||||||
|
// Graphics
|
||||||
|
import cogBtn from '../resources/icons/cog.svg'
|
||||||
|
import downBtn from '../resources/icons/download.svg'
|
||||||
|
import wrenchBtn from '../resources/icons/wrench.svg'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
downloadHandler: DownloadHandler
|
downloadHandler: DownloadHandler
|
||||||
}
|
}
|
||||||
@@ -45,8 +50,6 @@ export class Main extends React.Component<IProps, IState> {
|
|||||||
moddingOpen: false,
|
moddingOpen: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
invoke('list_submissions')
|
|
||||||
|
|
||||||
listen('lang_error', (payload) => {
|
listen('lang_error', (payload) => {
|
||||||
console.log(payload)
|
console.log(payload)
|
||||||
})
|
})
|
||||||
@@ -111,14 +114,36 @@ export class Main extends React.Component<IProps, IState> {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<TopBar
|
<TopBar>
|
||||||
optFunc={() => {
|
<div
|
||||||
this.setState({ optionsOpen: !this.state.optionsOpen })
|
id="settingsBtn"
|
||||||
}}
|
onClick={() => this.setState({ optionsOpen: !this.state.optionsOpen })}
|
||||||
downFunc={() => this.setState({ downloadsOpen: !this.state.downloadsOpen })}
|
className="TopButton"
|
||||||
gameFunc={() => this.setState({ gameDownloadsOpen: !this.state.gameDownloadsOpen })}
|
>
|
||||||
modFunc={() => this.setState({ moddingOpen: !this.state.moddingOpen })}
|
<img src={cogBtn} alt="settings" />
|
||||||
/>
|
</div>
|
||||||
|
<div
|
||||||
|
id="downloadsBtn"
|
||||||
|
className="TopButton"
|
||||||
|
onClick={() => this.setState({ downloadsOpen: !this.state.downloadsOpen })}
|
||||||
|
>
|
||||||
|
<img src={downBtn} alt="downloads" />
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
id="modsBtn"
|
||||||
|
onClick={() => {
|
||||||
|
// Create and dispatch a custom "openMods" event
|
||||||
|
const event = new CustomEvent('changePage', { detail: 'modding' })
|
||||||
|
window.dispatchEvent(event)
|
||||||
|
}}
|
||||||
|
className="TopButton"
|
||||||
|
>
|
||||||
|
<img src={wrenchBtn} alt="mods" />
|
||||||
|
</div>
|
||||||
|
{/* <div id="gameBtn" className="TopButton" onClick={() => this.setState({ gameDownloadsOpen: !this.state.gameDownloadsOpen })}>
|
||||||
|
<img src={gameBtn} alt="game" />
|
||||||
|
</div> */}
|
||||||
|
</TopBar>
|
||||||
|
|
||||||
<RightBar />
|
<RightBar />
|
||||||
|
|
||||||
|
|||||||
29
src/ui/Mods.tsx
Normal file
29
src/ui/Mods.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import DownloadHandler from '../utils/download'
|
||||||
|
import TopBar from './components/TopBar'
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
downloadHandler: DownloadHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IState {
|
||||||
|
isDownloading: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Mods extends React.Component<IProps, IState> {
|
||||||
|
constructor(props: IProps) {
|
||||||
|
super(props)
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentDidMount() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<TopBar />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,6 @@ import { app } from '@tauri-apps/api'
|
|||||||
import { appWindow } from '@tauri-apps/api/window'
|
import { appWindow } from '@tauri-apps/api/window'
|
||||||
import closeIcon from '../../resources/icons/close.svg'
|
import closeIcon from '../../resources/icons/close.svg'
|
||||||
import minIcon from '../../resources/icons/min.svg'
|
import minIcon from '../../resources/icons/min.svg'
|
||||||
import cogBtn from '../../resources/icons/cog.svg'
|
|
||||||
import downBtn from '../../resources/icons/download.svg'
|
|
||||||
|
|
||||||
import Tr from '../../utils/language'
|
import Tr from '../../utils/language'
|
||||||
|
|
||||||
@@ -12,10 +10,7 @@ import './TopBar.css'
|
|||||||
import { getConfig, setConfigOption } from '../../utils/configuration'
|
import { getConfig, setConfigOption } from '../../utils/configuration'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
optFunc: () => void
|
children?: React.ReactNode[]
|
||||||
downFunc: () => void
|
|
||||||
gameFunc: () => void
|
|
||||||
modFunc: () => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
@@ -111,18 +106,7 @@ export default class TopBar extends React.Component<IProps, IState> {
|
|||||||
<div id="minBtn" onClick={this.handleMinimize} className="TopButton">
|
<div id="minBtn" onClick={this.handleMinimize} className="TopButton">
|
||||||
<img src={minIcon} alt="minimize" />
|
<img src={minIcon} alt="minimize" />
|
||||||
</div>
|
</div>
|
||||||
<div id="settingsBtn" onClick={this.props.optFunc} className="TopButton">
|
{this.props.children}
|
||||||
<img src={cogBtn} alt="settings" />
|
|
||||||
</div>
|
|
||||||
<div id="downloadsBtn" className="TopButton" onClick={this.props.downFunc}>
|
|
||||||
<img src={downBtn} alt="downloads" />
|
|
||||||
</div>
|
|
||||||
<div id="modsBtn" onClick={this.props.modFunc} className="TopButton">
|
|
||||||
MODS
|
|
||||||
</div>
|
|
||||||
{/* <div id="gameBtn" className="TopButton" onClick={this.props.gameFunc}>
|
|
||||||
<img src={gameBtn} alt="game" />
|
|
||||||
</div> */}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user