Minor fixes

This commit is contained in:
Alessandro Autiero
2023-06-04 01:46:12 +02:00
parent 62611c29a4
commit 1d745f5187
3 changed files with 84 additions and 47 deletions

View File

@@ -23,6 +23,7 @@ class GameController extends GetxController {
late final Rx<List<FortniteVersion>> versions; late final Rx<List<FortniteVersion>> versions;
late final Rxn<FortniteVersion> _selectedVersion; late final Rxn<FortniteVersion> _selectedVersion;
late final RxBool started; late final RxBool started;
late final RxBool autoStartGameServer;
GameInstance? instance; GameInstance? instance;
GameController() { GameController() {
@@ -47,6 +48,8 @@ class GameController extends GetxController {
customLaunchArgs = TextEditingController(text: _storage.read("custom_launch_args" ?? "")); customLaunchArgs = TextEditingController(text: _storage.read("custom_launch_args" ?? ""));
customLaunchArgs.addListener(() => _storage.write("custom_launch_args", customLaunchArgs.text)); customLaunchArgs.addListener(() => _storage.write("custom_launch_args", customLaunchArgs.text));
started = RxBool(false); started = RxBool(false);
autoStartGameServer = RxBool(_storage.read("auto_game_server") ?? true);
autoStartGameServer.listen((value) => _storage.write("auto_game_server", value));
} }
FortniteVersion? getVersionByName(String name) { FortniteVersion? getVersionByName(String name) {

View File

@@ -1,5 +1,7 @@
import 'dart:async';
import 'package:fluent_ui/fluent_ui.dart'; import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart' show Icons; import 'package:flutter/material.dart' show Icons;
import 'package:get/get.dart'; import 'package:get/get.dart';
@@ -11,6 +13,7 @@ import 'package:reboot_launcher/src/ui/widget/home/version_selector.dart';
import 'package:reboot_launcher/src/ui/widget/shared/setting_tile.dart'; import 'package:reboot_launcher/src/ui/widget/shared/setting_tile.dart';
import '../../util/checks.dart'; import '../../util/checks.dart';
import '../../util/os.dart';
class LauncherPage extends StatefulWidget { class LauncherPage extends StatefulWidget {
final GlobalKey<NavigatorState> navigatorKey; final GlobalKey<NavigatorState> navigatorKey;
@@ -66,6 +69,13 @@ class _GamePageState extends State<_GamePage> {
final GameController _gameController = Get.find<GameController>(); final GameController _gameController = Get.find<GameController>();
final SettingsController _settingsController = Get.find<SettingsController>(); final SettingsController _settingsController = Get.find<SettingsController>();
late final RxBool _showPasswordTrailing = RxBool(_gameController.password.text.isNotEmpty); late final RxBool _showPasswordTrailing = RxBool(_gameController.password.text.isNotEmpty);
final StreamController _matchmakingStream = StreamController();
@override
void initState() {
_settingsController.matchmakingIp.addListener(() => _matchmakingStream.add(null));
super.initState();
}
@override @override
Widget build(BuildContext context) => Column( Widget build(BuildContext context) => Column(
@@ -89,58 +99,73 @@ class _GamePageState extends State<_GamePage> {
), ),
), ),
SettingTile( SettingTile(
title: "Password", title: "Password",
subtitle: "The password of your account, only used if the backend requires it", subtitle: "The password of your account, only used if the backend requires it",
isChild: true, isChild: true,
content: Obx(() => TextFormBox( content: Obx(() => TextFormBox(
placeholder: "Password", placeholder: "Password",
controller: _gameController.password, controller: _gameController.password,
autovalidateMode: AutovalidateMode.always, autovalidateMode: AutovalidateMode.always,
obscureText: !_gameController.showPassword.value, obscureText: !_gameController.showPassword.value,
enableSuggestions: false, enableSuggestions: false,
autocorrect: false, autocorrect: false,
onChanged: (text) => _showPasswordTrailing.value = text.isNotEmpty, onChanged: (text) => _showPasswordTrailing.value = text.isNotEmpty,
suffix: Button( suffix: Button(
onPressed: () => _gameController.showPassword.value = !_gameController.showPassword.value, onPressed: () => _gameController.showPassword.value = !_gameController.showPassword.value,
style: ButtonStyle( style: ButtonStyle(
shape: ButtonState.all(const CircleBorder()), shape: ButtonState.all(const CircleBorder()),
backgroundColor: ButtonState.all(Colors.transparent) backgroundColor: ButtonState.all(Colors.transparent)
), ),
child: Icon( child: Icon(
_gameController.showPassword.value ? Icons.visibility_off : Icons.visibility, _gameController.showPassword.value ? Icons.visibility_off : Icons.visibility,
color: _showPasswordTrailing.value ? null : Colors.transparent color: _showPasswordTrailing.value ? null : Colors.transparent
), ),
) )
)) ))
) )
], ],
), ),
const SizedBox( const SizedBox(
height: 16.0, height: 16.0,
), ),
SettingTile( StreamBuilder(
title: "Matchmaking host", stream: _matchmakingStream.stream,
subtitle: "Enter the IP address of the game server hosting the match", builder: (context, value) =>
content: TextFormBox( SettingTile(
placeholder: "IP:PORT", title: "Matchmaking host",
controller: _settingsController.matchmakingIp, subtitle: "Enter the IP address of the game server hosting the match",
validator: checkMatchmaking, content: TextFormBox(
autovalidateMode: AutovalidateMode.always placeholder: "IP:PORT",
), controller: _settingsController.matchmakingIp,
expandedContent: [ validator: checkMatchmaking,
SettingTile( autovalidateMode: AutovalidateMode.always
title: "Browse available servers", ),
subtitle: "Discover new game servers that fit your play-style", expandedContentSpacing: isLocalHost(_settingsController.matchmakingIp.text) ? SettingTile.kDefaultSpacing : 0,
content: Button( expandedContent: [
onPressed: () { !isLocalHost(_settingsController.matchmakingIp.text) ? const SizedBox() : SettingTile(
widget.navigatorKey.currentState?.pushNamed('browse'); title: "Automatically start game server",
widget.nestedNavigation.value = true; subtitle: "This option is available when the matchmaker is set to localhost",
}, contentWidth: null,
child: const Text("Browse") content: Obx(() => ToggleSwitch(
), checked: _gameController.autoStartGameServer(),
isChild: true onChanged: (value) => _gameController.autoStartGameServer.value = value
) )),
] isChild: true
),
SettingTile(
title: "Browse available servers",
subtitle: "Discover new game servers that fit your play-style",
content: Button(
onPressed: () {
widget.navigatorKey.currentState?.pushNamed('browse');
widget.nestedNavigation.value = true;
},
child: const Text("Browse")
),
isChild: true
)
]
)
), ),
const SizedBox( const SizedBox(
height: 16.0, height: 16.0,

View File

@@ -178,6 +178,10 @@ class _LaunchButtonState extends State<LaunchButton> {
return false; return false;
} }
if(!_gameController.autoStartGameServer()){
return false;
}
var version = _gameController.selectedVersion!; var version = _gameController.selectedVersion!;
await _startGameProcesses(version, true, false); await _startGameProcesses(version, true, false);
return true; return true;
@@ -198,7 +202,12 @@ class _LaunchButtonState extends State<LaunchButton> {
return kDefaultPlayerName; return kDefaultPlayerName;
} }
var username = _gameController.username.text.replaceAll(RegExp("[^A-Za-z0-9]"), "").trim(); var username = _gameController.username.text;
if(_gameController.password.text.isNotEmpty){
return username;
}
username = _gameController.username.text.replaceAll(RegExp("[^A-Za-z0-9]"), "").trim();
if(username.isEmpty){ if(username.isEmpty){
return kDefaultPlayerName; return kDefaultPlayerName;
} }