mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 15:44:35 +01:00
Merge pull request #177 from wehigami/main
Final pull request for set game path notification
This commit is contained in:
@@ -13,6 +13,7 @@ import Game from './components/menu/Game'
|
|||||||
import RightBar from './components/RightBar'
|
import RightBar from './components/RightBar'
|
||||||
import { ExtrasMenu } from './components/menu/ExtrasMenu'
|
import { ExtrasMenu } from './components/menu/ExtrasMenu'
|
||||||
import Notification from './components/common/Notification'
|
import Notification from './components/common/Notification'
|
||||||
|
import GamePathNotify from './components/menu/GamePathNotify'
|
||||||
|
|
||||||
import { getConfigOption, setConfigOption } from '../utils/configuration'
|
import { getConfigOption, setConfigOption } from '../utils/configuration'
|
||||||
import { invoke } from '@tauri-apps/api'
|
import { invoke } from '@tauri-apps/api'
|
||||||
@@ -42,6 +43,8 @@ interface IState {
|
|||||||
migotoSet: boolean
|
migotoSet: boolean
|
||||||
playGame: (exe?: string, proc_name?: string) => void
|
playGame: (exe?: string, proc_name?: string) => void
|
||||||
notification: React.ReactElement | null
|
notification: React.ReactElement | null
|
||||||
|
isGamePathSet: boolean
|
||||||
|
game_install_path: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Main extends React.Component<IProps, IState> {
|
export class Main extends React.Component<IProps, IState> {
|
||||||
@@ -59,6 +62,8 @@ export class Main extends React.Component<IProps, IState> {
|
|||||||
alert('Error launching game')
|
alert('Error launching game')
|
||||||
},
|
},
|
||||||
notification: null,
|
notification: null,
|
||||||
|
isGamePathSet: true,
|
||||||
|
game_install_path: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
listen('lang_error', (payload) => {
|
listen('lang_error', (payload) => {
|
||||||
@@ -122,8 +127,13 @@ export class Main extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
|
const game_path = await getConfigOption('game_install_path')
|
||||||
const cert_generated = await getConfigOption('cert_generated')
|
const cert_generated = await getConfigOption('cert_generated')
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
game_install_path: game_path,
|
||||||
|
})
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
migotoSet: !!(await getConfigOption('migoto_path')),
|
migotoSet: !!(await getConfigOption('migoto_path')),
|
||||||
})
|
})
|
||||||
@@ -185,6 +195,33 @@ export class Main extends React.Component<IProps, IState> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async componentDidUpdate(prevProps: Readonly<IProps>, prevState: Readonly<IState>) {
|
||||||
|
const game_path = await getConfigOption('game_install_path')
|
||||||
|
|
||||||
|
// Check if game exists at set location
|
||||||
|
const game_exists: boolean = (await invoke('dir_exists', {
|
||||||
|
path: game_path,
|
||||||
|
})) as boolean
|
||||||
|
path: game_path,
|
||||||
|
})) as boolean)
|
||||||
|
|
||||||
|
// Set no game path so the user understands it doesn't exist there
|
||||||
|
if (!game_exists) {
|
||||||
|
setConfigOption('game_install_path', '')
|
||||||
|
}
|
||||||
|
|
||||||
|
//if previous state is not equal the current one - update the game_install_path to be the current game path
|
||||||
|
if (prevState.game_install_path != game_path) {
|
||||||
|
this.setState({
|
||||||
|
game_install_path: game_path,
|
||||||
|
})
|
||||||
|
|
||||||
|
this.state.game_install_path === ''
|
||||||
|
? this.setState({ isGamePathSet: false })
|
||||||
|
: this.setState({ isGamePathSet: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -223,6 +260,8 @@ export class Main extends React.Component<IProps, IState> {
|
|||||||
|
|
||||||
<Notification show={!!this.state.notification}>{this.state.notification}</Notification>
|
<Notification show={!!this.state.notification}>{this.state.notification}</Notification>
|
||||||
|
|
||||||
|
{this.state.isGamePathSet ? <></> : <GamePathNotify />}
|
||||||
|
|
||||||
<RightBar />
|
<RightBar />
|
||||||
|
|
||||||
<NewsSection />
|
<NewsSection />
|
||||||
|
|||||||
11
src/ui/components/menu/GamePathNotify.css
Normal file
11
src/ui/components/menu/GamePathNotify.css
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
.GameInstallNotify {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
background-color: rgb(39, 39, 39);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pointer {
|
||||||
|
position: absolute;
|
||||||
|
right: 85px;
|
||||||
|
}
|
||||||
13
src/ui/components/menu/GamePathNotify.tsx
Normal file
13
src/ui/components/menu/GamePathNotify.tsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import './GamePathNotify.css'
|
||||||
|
|
||||||
|
export default class GamePathNotify extends React.Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div className="GameInstallNotify">
|
||||||
|
<span>You need to set your game path in the options!</span>
|
||||||
|
<span id="pointer">here ^</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user