ConanServerManager/lib/pages/GameServerPage.dart

147 lines
5.5 KiB
Dart

import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import '../statemachine.dart';
import '../structs/autorestarts.dart';
import '../structs/serversettings.dart';
import '../structs/settings.dart';
class GameServerPage extends StatefulWidget {
Settings settings;
GameServerPage({super.key, required this.settings});
@override
GameServerPageState createState() => GameServerPageState(settings: settings);
}
class GameServerPageState extends State<GameServerPage> {
Settings settings;
GameServerPageState({required this.settings});
var downloading = false;
late Stream<List<int>> download_stream;
TextEditingController ValueControl = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Conan Exiles Server Manager - Game Server"),
backgroundColor: Color.fromARGB(255, 100, 0, 0),
),
body: WillPopScope(
onWillPop: () async {
if (downloading) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Wait until the download completes")));
return false;
} else {
return true;
}
},
child: SingleChildScrollView(
padding: EdgeInsets.all(16),
child: Column(
children: [
ListTile(
title: Text("Mods"),
leading: Icon(Icons.build),
subtitle: Text("Server Mod Management"),
onTap: () {
if (downloading) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Wait until the download completes")));
return;
}
Navigator.pushNamed(context, "/server/mods");
},
),
if (!settings.inst!.downloadMods)
ListTile(
title: Text("Conan Exiles Install Path"),
subtitle:
Text("Set the Steam Library location of Conan Exiles"),
leading: Icon(Icons.folder),
onTap: () async {
// Open the folder select prompt
var path = await getDirectoryPath();
setState(() {
settings.inst!.conanExilesLibraryPath =
path ?? settings.inst!.conanExilesLibraryPath;
if (path == null) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"You must select a valid SteamLibrary folder")));
}
});
},
),
ListTile(
title: Text("Configure AutoRestart"),
leading: Icon(Icons.timer),
onTap: () async {
if (downloading) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Wait until the download completes")));
return;
}
var reply = await Navigator.pushNamed(
context, "/server/autorestart",
arguments: settings.inst!.timer);
setState(() {
settings.inst!.timer = reply as AutomaticRestartInfo;
});
},
),
SwitchListTile(
value: settings.inst!.downloadMods,
onChanged: (value) {
setState(() {
settings.inst!.downloadMods = value;
});
},
title: Text("Automatic Download of Mods"),
subtitle: Text(
"If enabled, downloads mods using steamcmd, if disabled, you must configure the SteamLibrary folder location"),
),
ListTile(
title: Text("Configure Server Ports"),
leading: Icon(Icons.numbers),
onTap: () async {
var reply = await Navigator.pushNamed(
context, "/server/ports",
arguments: settings.inst!.serverSettings);
setState(() {
settings.inst!.serverSettings = reply as ServerSettings;
settings.Write();
});
},
),
ListTile(
title: Text("Status:"),
subtitle: Text(settings.subsys.currentState != States.Inactive
? "Active"
: "Not Running"),
leading: Icon(settings.subsys.currentState != States.Inactive
? Icons.play_arrow
: Icons.error),
onTap: () async {
// Toggle state
setState(() {
if (settings.subsys.currentState == States.Inactive) {
settings.subsys.changeState(States.Starting);
} else
settings.subsys.changeState(States.FullStop);
});
},
),
],
)),
),
);
}
}