mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2026-02-04 09:25:16 +01:00
optional readonly and fix clear buttons
This commit is contained in:
@@ -14,7 +14,8 @@
|
|||||||
"grasscutter_jar": "Set Grasscutter Jar",
|
"grasscutter_jar": "Set Grasscutter Jar",
|
||||||
"java_path": "Set Custom Java Path",
|
"java_path": "Set Custom Java Path",
|
||||||
"grasscutter_with_game": "Automatically launch Grasscutter with game",
|
"grasscutter_with_game": "Automatically launch Grasscutter with game",
|
||||||
"language": "Select Language (requires restart)"
|
"language": "Select Language (requires restart)",
|
||||||
|
"background": "Set Custom Background (link or image file)"
|
||||||
},
|
},
|
||||||
"downloads": {
|
"downloads": {
|
||||||
"grasscutter_stable_data": "Download Grasscutter Stable Data",
|
"grasscutter_stable_data": "Download Grasscutter Stable Data",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ interface IProps {
|
|||||||
value?: string
|
value?: string
|
||||||
onChange?: (value: string) => void
|
onChange?: (value: string) => void
|
||||||
extensions?: string[]
|
extensions?: string[]
|
||||||
|
readonly?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
@@ -23,10 +24,12 @@ export default class DirInput extends React.Component<IProps, IState> {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
value: props.value || '',
|
value: props.value || '',
|
||||||
placeholder: 'Select file or folder...'
|
placeholder: 'Select file or folder...',
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleIconClick = this.handleIconClick.bind(this)
|
this.handleIconClick = this.handleIconClick.bind(this)
|
||||||
|
|
||||||
|
console.log(this.props)
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props: IProps, state: IState) {
|
static getDerivedStateFromProps(props: IProps, state: IState) {
|
||||||
@@ -66,7 +69,7 @@ export default class DirInput extends React.Component<IProps, IState> {
|
|||||||
value={this.state.value}
|
value={this.state.value}
|
||||||
placeholder={this.state.placeholder}
|
placeholder={this.state.placeholder}
|
||||||
clearable={true}
|
clearable={true}
|
||||||
readOnly={true} onChange={(text: string) => {
|
readOnly={this.props.readonly !== undefined ? this.props.readonly : true } onChange={(text: string) => {
|
||||||
this.setState({ value: text })
|
this.setState({ value: text })
|
||||||
|
|
||||||
if (this.props.onChange) this.props.onChange(text)
|
if (this.props.onChange) this.props.onChange(text)
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ export default class TextInput extends React.Component<IProps, IState> {
|
|||||||
this.setState({ value: '' })
|
this.setState({ value: '' })
|
||||||
|
|
||||||
if (this.props.onChange) this.props.onChange('')
|
if (this.props.onChange) this.props.onChange('')
|
||||||
|
|
||||||
|
this.forceUpdate()
|
||||||
}}>
|
}}>
|
||||||
<img src={Close} className="TextInputClear" />
|
<img src={Close} className="TextInputClear" />
|
||||||
</div> : null
|
</div> : null
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ interface IState {
|
|||||||
grasscutter_with_game: boolean
|
grasscutter_with_game: boolean
|
||||||
language_options: { [key: string]: string }[],
|
language_options: { [key: string]: string }[],
|
||||||
current_language: string
|
current_language: string
|
||||||
|
bg_url_or_path: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Options extends React.Component<IProps, IState> {
|
export default class Options extends React.Component<IProps, IState> {
|
||||||
@@ -31,7 +32,8 @@ export default class Options extends React.Component<IProps, IState> {
|
|||||||
java_path: '',
|
java_path: '',
|
||||||
grasscutter_with_game: false,
|
grasscutter_with_game: false,
|
||||||
language_options: [],
|
language_options: [],
|
||||||
current_language: 'en'
|
current_language: 'en',
|
||||||
|
bg_url_or_path: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +47,8 @@ export default class Options extends React.Component<IProps, IState> {
|
|||||||
java_path: config.java_path || '',
|
java_path: config.java_path || '',
|
||||||
grasscutter_with_game: config.grasscutter_with_game || false,
|
grasscutter_with_game: config.grasscutter_with_game || false,
|
||||||
language_options: languages,
|
language_options: languages,
|
||||||
current_language: config.language || 'en'
|
current_language: config.language || 'en',
|
||||||
|
bg_url_or_path: config.customBackground || ''
|
||||||
})
|
})
|
||||||
|
|
||||||
this.forceUpdate()
|
this.forceUpdate()
|
||||||
@@ -71,6 +74,10 @@ export default class Options extends React.Component<IProps, IState> {
|
|||||||
setConfigOption('grasscutter_with_game', !(await getConfigOption('grasscutter_with_game')))
|
setConfigOption('grasscutter_with_game', !(await getConfigOption('grasscutter_with_game')))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCustomBackground() {
|
||||||
|
setConfigOption('customBackground', this.state.bg_url_or_path)
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Menu closeFn={this.props.closeFn} className="Options" heading="Options">
|
<Menu closeFn={this.props.closeFn} className="Options" heading="Options">
|
||||||
@@ -113,6 +120,15 @@ export default class Options extends React.Component<IProps, IState> {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className='OptionSection'>
|
||||||
|
<div className='OptionLabel'>
|
||||||
|
<Tr text="options.background" />
|
||||||
|
</div>
|
||||||
|
<div className='OptionValue'>
|
||||||
|
<DirInput onChange={this.setCustomBackground} readonly={false} value={this.state?.bg_url_or_path} extensions={['exe']} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className='OptionSection'>
|
<div className='OptionSection'>
|
||||||
<div className='OptionLabel'>
|
<div className='OptionLabel'>
|
||||||
<Tr text="options.language" />
|
<Tr text="options.language" />
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ let defaultConfig: Configuration
|
|||||||
last_ip: '',
|
last_ip: '',
|
||||||
last_port: '',
|
last_port: '',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
|
customBackground: '',
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ export interface Configuration {
|
|||||||
last_ip: string
|
last_ip: string
|
||||||
last_port: string
|
last_port: string
|
||||||
language: string
|
language: string
|
||||||
|
customBackground: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setConfigOption(key: string, value: any): Promise<void> {
|
export async function setConfigOption(key: string, value: any): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user