https checkbox

This commit is contained in:
SpikeHD
2022-06-11 16:14:14 -07:00
parent b8540f0891
commit af56f8ffcb
5 changed files with 53 additions and 21 deletions

View File

@@ -4,6 +4,7 @@
"title": "Cultivation", "title": "Cultivation",
"launch_button": "Launch", "launch_button": "Launch",
"gc_enable": "Connect via Grasscutter", "gc_enable": "Connect via Grasscutter",
"https_enable": "Use HTTPS",
"ip_placeholder": "Server Address...", "ip_placeholder": "Server Address...",
"port_placeholder": "Port...", "port_placeholder": "Port...",
"files_downloading": "Files Downloading: ", "files_downloading": "Files Downloading: ",

View File

@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom/client'
import './index.css' import './index.css'
import App from './ui/App' import App from './ui/App'
import Test from './ui/Debug' //import Test from './ui/Debug'
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement document.getElementById('root') as HTMLElement
@@ -11,8 +11,8 @@ const root = ReactDOM.createRoot(
root.render( root.render(
<React.StrictMode> <React.StrictMode>
{/* <App /> */} <App />
<Test /> {/* <Test /> */}
</React.StrictMode> </React.StrictMode>
) )

View File

@@ -8,7 +8,7 @@
right: 10%; right: 10%;
top: 50%; top: 50%;
width: 30%; width: 32%;
height: 80%; height: 80%;
min-width: 357px; min-width: 357px;
} }
@@ -28,30 +28,36 @@
text-shadow: 1px 1px 8px black; text-shadow: 1px 1px 8px black;
} }
#serverControls .CheckboxDisplay { .BottomSection .CheckboxDisplay {
border-color: #c5c5c5; border-color: #c5c5c5;
background: #fff; background: #fff;
} }
#serverControls .Checkbox { .BottomSection .CheckboxDisplay {
margin-bottom: 6px;
}
#serverControls .CheckboxDisplay {
margin-right: 6px; margin-right: 6px;
box-shadow: 0 0 5px 4px rgba(0, 0, 0, 0.2); box-shadow: 0 0 5px 4px rgba(0, 0, 0, 0.2);
} }
#serverControls .Checkbox label { .BottomSection .Checkbox label {
color: #fff; color: #fff;
font-weight: bold; font-weight: bold;
text-shadow: #222222 1px 0 10px; text-shadow: #222222 1px 0 10px;
} }
#serverControls .Checkbox label span { .BottomSection .Checkbox label span {
padding-left: 4px; padding-left: 4px;
} }
.ServerConfig {
margin-bottom: 6px;
}
.ServerConfig .Checkbox {
display: inline-grid;
vertical-align: middle;
margin-left: 8px;
}
.ServerLaunchButtons { .ServerLaunchButtons {
display: flex; display: flex;
flex-direction: row; flex-direction: row;

View File

@@ -26,6 +26,9 @@ interface IState {
portPlaceholder: string; portPlaceholder: string;
portHelpText: string; portHelpText: string;
httpsLabel: string;
httpsEnabled: boolean;
} }
export default class ServerLaunchSection extends React.Component<IProps, IState> { export default class ServerLaunchSection extends React.Component<IProps, IState> {
@@ -40,13 +43,16 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
port: '', port: '',
ipPlaceholder: '', ipPlaceholder: '',
portPlaceholder: '', portPlaceholder: '',
portHelpText: '' portHelpText: '',
httpsLabel: '',
httpsEnabled: false
} }
this.toggleGrasscutter = this.toggleGrasscutter.bind(this) this.toggleGrasscutter = this.toggleGrasscutter.bind(this)
this.playGame = this.playGame.bind(this) this.playGame = this.playGame.bind(this)
this.setIp = this.setIp.bind(this) this.setIp = this.setIp.bind(this)
this.setPort = this.setPort.bind(this) this.setPort = this.setPort.bind(this)
this.toggleHttps = this.toggleHttps.bind(this)
} }
async componentDidMount() { async componentDidMount() {
@@ -60,7 +66,9 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
port: config.last_port || '', port: config.last_port || '',
ipPlaceholder: await translate('main.ip_placeholder'), ipPlaceholder: await translate('main.ip_placeholder'),
portPlaceholder: await translate('help.port_placeholder'), portPlaceholder: await translate('help.port_placeholder'),
portHelpText: await translate('help.port_help_text') portHelpText: await translate('help.port_help_text'),
httpsLabel: await translate('main.https_enable'),
httpsEnabled: config.https_enabled,
}) })
} }
@@ -165,6 +173,17 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
}) })
} }
async toggleHttps() {
const config = await getConfig()
config.https_enabled = !config.https_enabled
// Set state as well
this.setState({
httpsEnabled: config.https_enabled
})
}
render() { render() {
return ( return (
<div id="playButton"> <div id="playButton">
@@ -174,13 +193,17 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
{ {
this.state.grasscutterEnabled && ( this.state.grasscutterEnabled && (
<div className="ServerConfig"> <div>
<TextInput id="ip" key="ip" placeholder={this.state.ipPlaceholder} onChange={this.setIp} initalValue={this.state.ip} /> <div className="ServerConfig">
<TextInput style={{ <TextInput id="ip" key="ip" placeholder={this.state.ipPlaceholder} onChange={this.setIp} initalValue={this.state.ip} />
width: '10%', <TextInput style={{
}} id="port" key="port" placeholder={this.state.portPlaceholder} onChange={this.setPort} initalValue={this.state.port} /> width: '10%',
<HelpButton contents={this.state.portHelpText} /> }} id="port" key="port" placeholder={this.state.portPlaceholder} onChange={this.setPort} initalValue={this.state.port} />
<HelpButton contents={this.state.portHelpText} />
<Checkbox id="httpsEnable" label={this.state.httpsLabel} onChange={this.toggleHttps} checked={this.state.httpsEnabled} />
</div>
</div> </div>
) )
} }

View File

@@ -18,7 +18,8 @@ let defaultConfig: Configuration
language: 'en', language: 'en',
customBackground: '', customBackground: '',
cert_generated: false, cert_generated: false,
theme: 'default' theme: 'default',
https_enabled: false,
} }
})() })()
@@ -39,6 +40,7 @@ export interface Configuration {
customBackground: string customBackground: string
cert_generated: boolean cert_generated: boolean
theme: string; theme: string;
https_enabled: boolean
} }
export async function setConfigOption(key: string, value: any): Promise<void> { export async function setConfigOption(key: string, value: any): Promise<void> {