Final version

This commit is contained in:
Alessandro Autiero
2023-09-21 16:48:31 +02:00
parent 4bba21c038
commit 73c1cc8526
90 changed files with 3204 additions and 2608 deletions

View File

@@ -0,0 +1,155 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:reboot_common/common.dart';
import 'package:reboot_launcher/src/controller/authenticator_controller.dart';
import 'package:reboot_launcher/src/page/abstract/page.dart';
import 'package:reboot_launcher/src/page/abstract/page_setting.dart';
import 'package:reboot_launcher/src/page/abstract/page_type.dart';
import 'package:reboot_launcher/src/util/translations.dart';
import 'package:reboot_launcher/src/widget/common/setting_tile.dart';
import 'package:reboot_launcher/src/widget/server/start_button.dart';
import 'package:reboot_launcher/src/widget/server/type_selector.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../dialog/implementation/data.dart';
class AuthenticatorPage extends RebootPage {
const AuthenticatorPage({Key? key}) : super(key: key);
@override
String get name => translations.authenticatorName;
@override
String get iconAsset => "assets/images/authenticator.png";
@override
RebootPageType get type => RebootPageType.authenticator;
@override
bool get hasButton => true;
@override
List<PageSetting> get settings => [
PageSetting(
name: translations.authenticatorConfigurationName,
description: translations.authenticatorConfigurationDescription,
children: [
PageSetting(
name: translations.authenticatorConfigurationHostName,
description: translations.authenticatorConfigurationHostDescription
),
PageSetting(
name: translations.authenticatorConfigurationPortName,
description: translations.authenticatorConfigurationPortDescription
),
PageSetting(
name: translations.authenticatorConfigurationDetachedName,
description: translations.authenticatorConfigurationDetachedDescription
)
]
),
PageSetting(
name: translations.authenticatorInstallationDirectoryName,
description: translations.authenticatorInstallationDirectoryDescription,
content: translations.authenticatorInstallationDirectoryContent
),
PageSetting(
name: translations.authenticatorResetDefaultsName,
description: translations.authenticatorResetDefaultsDescription,
content: translations.authenticatorResetDefaultsContent
)
];
@override
RebootPageState<AuthenticatorPage> createState() => _AuthenticatorPageState();
}
class _AuthenticatorPageState extends RebootPageState<AuthenticatorPage> {
final AuthenticatorController _authenticatorController = Get.find<AuthenticatorController>();
@override
List<Widget> get settings => [
_configuration,
_installationDirectory,
_resetDefaults
];
@override
Widget get button => const ServerButton(
authenticator: true
);
SettingTile get _resetDefaults => SettingTile(
title: translations.authenticatorResetDefaultsName,
subtitle: translations.authenticatorResetDefaultsDescription,
content: Button(
onPressed: () => showResetDialog(_authenticatorController.reset),
child: Text(translations.authenticatorResetDefaultsContent),
)
);
SettingTile get _installationDirectory => SettingTile(
title: translations.authenticatorInstallationDirectoryName,
subtitle: translations.authenticatorInstallationDirectoryDescription,
content: Button(
onPressed: () => launchUrl(authenticatorDirectory.uri),
child: Text(translations.authenticatorInstallationDirectoryContent)
)
);
Widget get _configuration => Obx(() => SettingTile(
title: translations.authenticatorConfigurationName,
subtitle: translations.authenticatorConfigurationDescription,
content: const ServerTypeSelector(
authenticator: true
),
expandedContent: [
if(_authenticatorController.type.value == ServerType.remote)
SettingTile(
title: translations.authenticatorConfigurationHostName,
subtitle: translations.authenticatorConfigurationHostDescription,
isChild: true,
content: TextFormBox(
placeholder: translations.authenticatorConfigurationHostName,
controller: _authenticatorController.host
)
),
if(_authenticatorController.type.value != ServerType.embedded)
SettingTile(
title: translations.authenticatorConfigurationPortName,
subtitle: translations.authenticatorConfigurationPortDescription,
isChild: true,
content: TextFormBox(
placeholder: translations.authenticatorConfigurationPortName,
controller: _authenticatorController.port,
keyboardType: TextInputType.number,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly
]
)
),
if(_authenticatorController.type.value == ServerType.embedded)
SettingTile(
title: translations.authenticatorConfigurationDetachedName,
subtitle: translations.authenticatorConfigurationDetachedDescription,
contentWidth: null,
isChild: true,
content: Obx(() => Row(
children: [
Text(
_authenticatorController.detached.value ? translations.on : translations.off
),
const SizedBox(
width: 16.0
),
ToggleSwitch(
checked: _authenticatorController.detached(),
onChanged: (value) => _authenticatorController.detached.value = value
),
],
))
)
],
));
}

View File

@@ -0,0 +1,266 @@
import 'dart:collection';
import 'dart:ui';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart' show MaterialPage;
import 'package:get/get.dart';
import 'package:reboot_launcher/src/controller/settings_controller.dart';
import 'package:reboot_launcher/src/dialog/abstract/info_bar.dart';
import 'package:reboot_launcher/src/page/abstract/page.dart';
import 'package:reboot_launcher/src/page/abstract/page_setting.dart';
import 'package:reboot_launcher/src/page/pages.dart';
import 'package:reboot_launcher/src/util/translations.dart';
import 'package:reboot_launcher/src/widget/common/setting_tile.dart';
import 'package:reboot_launcher/src/widget/home/profile.dart';
import 'package:reboot_launcher/src/widget/os/title_bar.dart';
import 'package:window_manager/window_manager.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with WindowListener, AutomaticKeepAliveClientMixin {
static const double _kDefaultPadding = 12.0;
final SettingsController _settingsController = Get.find<SettingsController>();
final GlobalKey _searchKey = GlobalKey();
final FocusNode _searchFocusNode = FocusNode();
final TextEditingController _searchController = TextEditingController();
final RxBool _focused = RxBool(true);
final Queue<int> _pagesStack = Queue();
bool _hitBack = false;
@override
bool get wantKeepAlive => true;
@override
void initState() {
windowManager.addListener(this);
var lastValue = pageIndex.value;
pageIndex.listen((value) {
if(_hitBack) {
_hitBack = false;
return;
}
if(value == lastValue) {
return;
}
_pagesStack.add(lastValue);
WidgetsBinding.instance.addPostFrameCallback((_) {
restoreMessage(value, lastValue);
lastValue = value;
});
});
super.initState();
}
@override
void dispose() {
_searchFocusNode.dispose();
_searchController.dispose();
windowManager.removeListener(this);
super.dispose();
}
@override
void onWindowFocus() {
_focused.value = true;
}
@override
void onWindowBlur() {
_focused.value = false;
}
@override
void onWindowResized() {
_settingsController.saveWindowSize(appWindow.size);
_focused.value = true;
}
@override
void onWindowMoved() {
_settingsController.saveWindowOffset(appWindow.position);
_focused.value = true;
}
@override
void onWindowEnterFullScreen() {
_focused.value = true;
}
@override
void onWindowLeaveFullScreen() {
_focused.value = true;
}
@override
Widget build(BuildContext context) {
super.build(context);
return Obx(() {
_settingsController.language.value;
loadTranslations(context);
return NavigationPaneTheme(
data: NavigationPaneThemeData(
backgroundColor: FluentTheme.of(context).micaBackgroundColor.withOpacity(0.93),
),
child: NavigationView(
paneBodyBuilder: (pane, body) => Navigator(
onPopPage: (page, data) => false,
pages: [
MaterialPage(
child: Padding(
padding: const EdgeInsets.all(_kDefaultPadding),
child: SizedBox(
key: pageKey,
child: body
)
)
)
],
),
appBar: NavigationAppBar(
height: 32,
title: _draggableArea,
actions: WindowTitleBar(focused: _focused()),
leading: _backButton,
automaticallyImplyLeading: false,
),
pane: NavigationPane(
key: appKey,
selected: pageIndex.value,
onChanged: (index) => pageIndex.value = index,
menuButton: const SizedBox(),
displayMode: PaneDisplayMode.open,
items: _items,
header: const ProfileWidget(),
autoSuggestBox: _autoSuggestBox,
indicator: const StickyNavigationIndicator(
duration: Duration(milliseconds: 500),
curve: Curves.easeOut,
indicatorSize: 3.25
)
),
contentShape: const RoundedRectangleBorder(),
onOpenSearch: () => _searchFocusNode.requestFocus(),
transitionBuilder: (child, animation) => child
)
);
});
}
Widget get _backButton => Obx(() {
pageIndex.value;
return Button(
style: ButtonStyle(
padding: ButtonState.all(const EdgeInsets.only(top: 6.0)),
backgroundColor: ButtonState.all(Colors.transparent),
border: ButtonState.all(const BorderSide(color: Colors.transparent))
),
onPressed: _pagesStack.isEmpty ? null : () {
_hitBack = true;
pageIndex.value = _pagesStack.removeLast();
},
child: const Icon(FluentIcons.back, size: 12.0),
);
});
GestureDetector get _draggableArea => GestureDetector(
onDoubleTap: appWindow.maximizeOrRestore,
onHorizontalDragStart: (_) => appWindow.startDragging(),
onVerticalDragStart: (_) => appWindow.startDragging()
);
Widget get _autoSuggestBox => Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: AutoSuggestBox<PageSetting>(
key: _searchKey,
controller: _searchController,
placeholder: translations.find,
focusNode: _searchFocusNode,
selectionHeightStyle: BoxHeightStyle.max,
itemBuilder: (context, item) => Wrap(
children: [
ListTile(
onPressed: () {
pageIndex.value = item.value.pageIndex;
_searchController.clear();
_searchFocusNode.unfocus();
},
leading: item.child,
title: Text(
item.value.name,
overflow: TextOverflow.clip,
maxLines: 1
),
subtitle: item.value.description.isNotEmpty ? Text(
item.value.description,
overflow: TextOverflow.clip,
maxLines: 1
) : null
),
],
),
items: _suggestedItems,
autofocus: true,
trailingIcon: IgnorePointer(
child: IconButton(
onPressed: () {},
icon: Transform.flip(
flipX: true,
child: const Icon(FluentIcons.search)
),
)
),
)
);
List<AutoSuggestBoxItem<PageSetting>> get _suggestedItems => pages.mapMany((page) {
var icon = SizedBox.square(
dimension: 24,
child: Image.asset(page.iconAsset)
);
var outerResults = <AutoSuggestBoxItem<PageSetting>>[];
outerResults.add(AutoSuggestBoxItem(
value: PageSetting(
name: page.name,
description: "",
pageIndex: page.index
),
label: page.name,
child: icon
));
outerResults.addAll(page.settings.mapMany((setting) {
var results = <AutoSuggestBoxItem<PageSetting>>[];
results.add(AutoSuggestBoxItem(
value: setting.withPageIndex(page.index),
label: setting.toString(),
child: icon
));
setting.children?.forEach((childSetting) => results.add(AutoSuggestBoxItem(
value: childSetting.withPageIndex(page.index),
label: childSetting.toString(),
child: icon
)));
return results;
}).toList());
return outerResults;
}).toList();
List<NavigationPaneItem> get _items => pages.map((page) => _createItem(page)).toList();
NavigationPaneItem _createItem(RebootPage page) => PaneItem(
title: Text(page.name),
icon: SizedBox.square(
dimension: 24,
child: Image.asset(page.iconAsset)
),
body: page
);
}

View File

@@ -0,0 +1,130 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/gestures.dart';
import 'package:reboot_launcher/src/page/abstract/page.dart';
import 'package:reboot_launcher/src/page/abstract/page_setting.dart';
import 'package:reboot_launcher/src/page/abstract/page_type.dart';
import 'package:reboot_launcher/src/util/translations.dart';
import 'package:reboot_launcher/src/util/tutorial.dart';
import 'package:reboot_launcher/src/widget/common/setting_tile.dart';
class InfoPage extends RebootPage {
const InfoPage({Key? key}) : super(key: key);
@override
RebootPageState<InfoPage> createState() => _InfoPageState();
@override
String get name => translations.infoName;
@override
String get iconAsset => "assets/images/info.png";
@override
bool get hasButton => false;
@override
RebootPageType get type => RebootPageType.info;
@override
List<PageSetting> get settings => [];
}
class _InfoPageState extends RebootPageState<InfoPage> {
@override
Widget? get button => null;
@override
List<SettingTile> get settings => [
SettingTile(
title: 'What is Project Reboot?',
subtitle: 'Project Reboot allows anyone to easily host a game server for most of Fortnite\'s seasons. '
'The project was started on Discord by Milxnor. '
'The project is no longer being actively maintained.',
titleStyle: FluentTheme
.of(context)
.typography
.title,
contentWidth: null,
),
SettingTile(
title: 'What is a game server?',
subtitle: 'When you join a Fortnite Game, your client connects to a game server that allows you to play with others. '
'You can join someone else\'s game server, or host one on your PC by going to the "Host" tab. ',
titleStyle: FluentTheme
.of(context)
.typography
.title,
contentWidth: null,
),
SettingTile(
title: 'What is a client?',
subtitle: 'A client is the actual Fortnite game. '
'You can download any version of Fortnite from the launcher in the "Play" tab. '
'You can also import versions from your local PC, but remember that these may be corrupted. '
'If a local version doesn\'t work, try installing it from the launcher before reporting a bug.',
titleStyle: FluentTheme
.of(context)
.typography
.title,
contentWidth: null,
),
SettingTile(
title: 'What is an authenticator?',
subtitle: 'An authenticator is a program that handles authentication, parties and voice chats. '
'By default, a LawinV1 server will be started for you to play. '
'You can use also use an authenticator running locally(on your PC) or remotely(on another PC). '
'Changing the authenticator settings can break the client and game server: unless you are an advanced user, do not edit, for any reason, these settings! '
'If you need to restore these settings, go to the "Settings" tab and click on "Restore Defaults". ',
titleStyle: FluentTheme
.of(context)
.typography
.title,
contentWidth: null,
),
SettingTile(
title: 'Do I need to update DLLs?',
subtitle: 'No, all the files that the launcher uses are automatically updated. '
'You can use your own DLLs by going to the "Settings" tab, but make sure that they don\'t create a console that reads IO or the launcher will stop working correctly. '
'Unless you are an advanced user, changing these options is not recommended',
titleStyle: FluentTheme
.of(context)
.typography
.title,
contentWidth: null,
),
SettingTile(
title: 'Where can I report bugs or ask for new features?',
subtitle: 'Go to the "Settings" tab and click on report bug. '
'Please make sure to be as specific as possible when filing a report as it\'s crucial to make it as easy to fix/implement',
titleStyle: FluentTheme
.of(context)
.typography
.title,
contentWidth: null,
),
SettingTile(
title: 'How can I make my game server accessible for other players?',
subtitle: Text.rich(
TextSpan(
children: [
TextSpan(
text: 'Follow ',
style: FluentTheme.of(context).typography.body
),
TextSpan(
text: 'this tutorial',
mouseCursor: SystemMouseCursors.click,
style: FluentTheme.of(context).typography.body?.copyWith(color: FluentTheme.of(context).accentColor),
recognizer: TapGestureRecognizer()..onTap = openPortTutorial
)
]
)
),
titleStyle: FluentTheme
.of(context)
.typography
.title,
contentWidth: null,
)
];
}

View File

@@ -0,0 +1,165 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:reboot_common/common.dart';
import 'package:reboot_launcher/src/controller/matchmaker_controller.dart';
import 'package:reboot_launcher/src/dialog/implementation/data.dart';
import 'package:reboot_launcher/src/page/abstract/page.dart';
import 'package:reboot_launcher/src/page/abstract/page_setting.dart';
import 'package:reboot_launcher/src/page/abstract/page_type.dart';
import 'package:reboot_launcher/src/util/translations.dart';
import 'package:reboot_launcher/src/widget/common/setting_tile.dart';
import 'package:reboot_launcher/src/widget/server/start_button.dart';
import 'package:reboot_launcher/src/widget/server/type_selector.dart';
import 'package:url_launcher/url_launcher.dart';
class MatchmakerPage extends RebootPage {
const MatchmakerPage({Key? key}) : super(key: key);
@override
RebootPageState<MatchmakerPage> createState() => _MatchmakerPageState();
@override
String get name => translations.matchmakerName;
@override
String get iconAsset => "assets/images/matchmaker.png";
@override
bool get hasButton => true;
@override
RebootPageType get type => RebootPageType.matchmaker;
@override
List<PageSetting> get settings => [
PageSetting(
name: translations.matchmakerConfigurationName,
description: translations.matchmakerConfigurationDescription,
children: [
PageSetting(
name: translations.matchmakerConfigurationHostName,
description: translations.matchmakerConfigurationHostDescription
),
PageSetting(
name: translations.matchmakerConfigurationPortName,
description: translations.matchmakerConfigurationPortDescription
),
PageSetting(
name: translations.matchmakerConfigurationDetachedName,
description: translations.matchmakerConfigurationDetachedDescription
)
]
),
PageSetting(
name: translations.matchmakerInstallationDirectoryName,
description: translations.matchmakerInstallationDirectoryDescription,
content: translations.matchmakerInstallationDirectoryContent
),
PageSetting(
name: translations.matchmakerResetDefaultsName,
description: translations.matchmakerResetDefaultsDescription,
content: translations.matchmakerResetDefaultsContent
)
];
}
class _MatchmakerPageState extends RebootPageState<MatchmakerPage> {
final MatchmakerController _matchmakerController = Get.find<MatchmakerController>();
@override
Widget? get button => const ServerButton(
authenticator: false
);
@override
List<Widget> get settings => [
_configuration,
_installationDirectory,
_resetDefaults
];
Widget get _configuration => Obx(() => SettingTile(
title: translations.matchmakerConfigurationName,
subtitle: translations.matchmakerConfigurationDescription,
content: const ServerTypeSelector(
authenticator: false
),
expandedContent: [
if(_matchmakerController.type.value == ServerType.remote)
SettingTile(
title: translations.matchmakerConfigurationHostName,
subtitle: translations.matchmakerConfigurationHostDescription,
isChild: true,
content: TextFormBox(
placeholder: translations.matchmakerConfigurationHostName,
controller: _matchmakerController.host
)
),
if(_matchmakerController.type.value != ServerType.embedded)
SettingTile(
title: translations.matchmakerConfigurationPortName,
subtitle: translations.matchmakerConfigurationPortDescription,
isChild: true,
content: TextFormBox(
placeholder: translations.matchmakerConfigurationPortName,
controller: _matchmakerController.port,
keyboardType: TextInputType.number,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly
]
)
),
if(_matchmakerController.type.value == ServerType.embedded)
SettingTile(
title: translations.matchmakerConfigurationAddressName,
subtitle: translations.matchmakerConfigurationAddressDescription,
isChild: true,
content: TextFormBox(
placeholder: translations.matchmakerConfigurationAddressName,
controller: _matchmakerController.gameServerAddress,
focusNode: _matchmakerController.gameServerAddressFocusNode
)
),
if(_matchmakerController.type.value == ServerType.embedded)
SettingTile(
title: translations.matchmakerConfigurationDetachedName,
subtitle: translations.matchmakerConfigurationDetachedDescription,
contentWidth: null,
isChild: true,
content: Obx(() => Row(
children: [
Text(
_matchmakerController.detached.value ? translations.on : translations.off
),
const SizedBox(
width: 16.0
),
ToggleSwitch(
checked: _matchmakerController.detached.value,
onChanged: (value) => _matchmakerController.detached.value = value
),
],
)),
)
]
));
SettingTile get _installationDirectory => SettingTile(
title: translations.matchmakerInstallationDirectoryName,
subtitle: translations.matchmakerInstallationDirectoryDescription,
content: Button(
onPressed: () => launchUrl(matchmakerDirectory.uri),
child: Text(translations.matchmakerInstallationDirectoryContent)
)
);
SettingTile get _resetDefaults => SettingTile(
title: translations.matchmakerResetDefaultsName,
subtitle: translations.matchmakerResetDefaultsDescription,
content: Button(
onPressed: () => showResetDialog(_matchmakerController.reset),
child: Text(translations.matchmakerResetDefaultsContent),
)
);
}

View File

@@ -0,0 +1,143 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:get/get.dart';
import 'package:reboot_common/common.dart';
import 'package:reboot_launcher/src/controller/hosting_controller.dart';
import 'package:reboot_launcher/src/controller/matchmaker_controller.dart';
import 'package:reboot_launcher/src/page/abstract/page.dart';
import 'package:reboot_launcher/src/page/abstract/page_setting.dart';
import 'package:reboot_launcher/src/page/abstract/page_type.dart';
import 'package:reboot_launcher/src/page/pages.dart';
import 'package:reboot_launcher/src/util/translations.dart';
import 'package:reboot_launcher/src/widget/common/setting_tile.dart';
import 'package:reboot_launcher/src/widget/game/start_button.dart';
import 'package:reboot_launcher/src/widget/version/version_selector_tile.dart';
class PlayPage extends RebootPage {
const PlayPage({Key? key}) : super(key: key);
@override
RebootPageState<PlayPage> createState() => _PlayPageState();
@override
bool get hasButton => true;
@override
String get name => translations.playName;
@override
String get iconAsset => "assets/images/play.png";
@override
RebootPageType get type => RebootPageType.play;
@override
List<PageSetting> get settings => [
versionSelectorRebootSetting,
PageSetting(
name: translations.playGameServerName,
description: translations.playGameServerDescription,
content: translations.playGameServerContentLocal,
children: [
PageSetting(
name: translations.playGameServerHostName,
description: translations.playGameServerHostDescription,
content: translations.playGameServerHostName
),
PageSetting(
name: translations.playGameServerBrowserName,
description: translations.playGameServerBrowserDescription,
content: translations.playGameServerBrowserName
),
PageSetting(
name: translations.playGameServerCustomName,
description: translations.playGameServerCustomDescription,
content: translations.playGameServerCustomContent
)
]
)
];
}
class _PlayPageState extends RebootPageState<PlayPage> {
final MatchmakerController _matchmakerController = Get.find<MatchmakerController>();
final HostingController _hostingController = Get.find<HostingController>();
late final RxBool _selfServer;
@override
void initState() {
_selfServer = RxBool(_isLocalPlay);
_matchmakerController.gameServerAddress.addListener(() => _selfServer.value = _isLocalPlay);
_hostingController.started.listen((_) => _selfServer.value = _isLocalPlay);
super.initState();
}
bool get _isLocalPlay => isLocalHost(_matchmakerController.gameServerAddress.text)
&& !_hostingController.started.value;
@override
Widget? get button => LaunchButton(
startLabel: translations.launchFortnite,
stopLabel: translations.closeFortnite,
host: false
);
@override
List<SettingTile> get settings => [
versionSelectorSettingTile,
_gameServerSelector
];
SettingTile get _gameServerSelector => SettingTile(
title: translations.playGameServerName,
subtitle: translations.playGameServerDescription,
content: IgnorePointer(
child: Button(
style: ButtonStyle(
backgroundColor: ButtonState.all(FluentTheme.of(context).resources.controlFillColorDefault)
),
onPressed: () {},
child: Obx(() {
var address = _matchmakerController.gameServerAddress.text;
var owner = _matchmakerController.gameServerOwner.value;
return Text(
isLocalHost(address) ? translations.playGameServerContentLocal : owner != null ? translations.playGameServerContentBrowser(owner) : address,
textAlign: TextAlign.start
);
})
),
),
expandedContent: [
SettingTile(
title: translations.playGameServerHostName,
subtitle: translations.playGameServerHostDescription,
content: Button(
onPressed: () => pageIndex.value = RebootPageType.host.index,
child: Text(translations.playGameServerHostName)
),
isChild: true
),
SettingTile(
title: translations.playGameServerBrowserName,
subtitle: translations.playGameServerBrowserDescription,
content: Button(
onPressed: () => pageIndex.value = RebootPageType.browser.index,
child: Text(translations.playGameServerBrowserName)
),
isChild: true
),
SettingTile(
title: translations.playGameServerCustomName,
subtitle: translations.playGameServerCustomDescription,
content: Button(
onPressed: () {
pageIndex.value = RebootPageType.matchmaker.index;
WidgetsBinding.instance.addPostFrameCallback((_) => _matchmakerController.gameServerAddressFocusNode.requestFocus());
},
child: Text(translations.playGameServerCustomContent)
),
isChild: true
)
]
);
}

View File

@@ -0,0 +1,247 @@
import 'dart:async';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:reboot_common/common.dart';
import 'package:reboot_launcher/src/controller/hosting_controller.dart';
import 'package:reboot_launcher/src/controller/matchmaker_controller.dart';
import 'package:reboot_launcher/src/dialog/implementation/server.dart';
import 'package:reboot_launcher/src/page/abstract/page.dart';
import 'package:reboot_launcher/src/page/abstract/page_setting.dart';
import 'package:reboot_launcher/src/page/abstract/page_type.dart';
import 'package:reboot_launcher/src/util/translations.dart';
import 'package:reboot_launcher/src/widget/common/setting_tile.dart';
import 'package:skeletons/skeletons.dart';
class BrowsePage extends RebootPage {
const BrowsePage({Key? key}) : super(key: key);
@override
String get name => translations.browserName;
@override
RebootPageType get type => RebootPageType.browser;
@override
String get iconAsset => "assets/images/server_browser.png";
@override
bool get hasButton => false;
@override
RebootPageState<BrowsePage> createState() => _BrowsePageState();
@override
List<PageSetting> get settings => [];
}
class _BrowsePageState extends RebootPageState<BrowsePage> {
final HostingController _hostingController = Get.find<HostingController>();
final MatchmakerController _matchmakerController = Get.find<MatchmakerController>();
final TextEditingController _filterController = TextEditingController();
final StreamController<String> _filterControllerStream = StreamController.broadcast();
@override
Widget build(BuildContext context) {
super.build(context);
return Obx(() {
var data = _hostingController.servers.value
?.where((entry) => (kDebugMode || entry["id"] != _hostingController.uuid) && entry["discoverable"])
.toSet();
if(data == null || data.isEmpty == true) {
return _noServers;
}
return _buildPageBody(data);
});
}
Widget get _noServers => Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
translations.noServersAvailableTitle,
style: FluentTheme.of(context).typography.titleLarge,
),
Text(
translations.noServersAvailableSubtitle,
style: FluentTheme.of(context).typography.body
),
],
);
Widget _buildPageBody(Set<Map<String, dynamic>> data) => Column(
children: [
_searchBar,
const SizedBox(
height: 16,
),
Expanded(
child: StreamBuilder<String?>(
stream: _filterControllerStream.stream,
builder: (context, filterSnapshot) {
var items = data.where((entry) => _isValidItem(entry, filterSnapshot.data)).toSet();
if(items.isEmpty) {
return _noServersByQuery;
}
return _buildPopulatedListBody(items);
}
),
)
],
);
Widget _buildPopulatedListBody(Set<Map<String, dynamic>> items) => ListView.builder(
itemCount: items.length * 2,
itemBuilder: (context, index) {
if(index % 2 != 0) {
return const SizedBox(
height: 8.0
);
}
var entry = items.elementAt(index ~/ 2);
var hasPassword = entry["password"] != null;
return SettingTile(
title: "${_formatName(entry)}${entry["author"]}",
subtitle: "${_formatDescription(entry)}${_formatVersion(entry)}",
content: Button(
onPressed: () => _matchmakerController.joinServer(_hostingController.uuid, entry),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if(hasPassword)
const Icon(FluentIcons.lock),
if(hasPassword)
const SizedBox(width: 8.0),
Text(_matchmakerController.type.value == ServerType.embedded ? translations.joinServer : translations.copyIp),
],
),
)
);
}
);
Widget get _noServersByQuery => Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
translations.noServersAvailableByQueryTitle,
style: FluentTheme.of(context).typography.titleLarge,
),
Text(
translations.noServersAvailableByQuerySubtitle,
style: FluentTheme.of(context).typography.body
),
],
);
bool _isValidItem(Map<String, dynamic> entry, String? filter) =>
filter == null || filter.isEmpty || _filterServer(entry, filter);
bool _filterServer(Map<String, dynamic> element, String filter) {
String? id = element["id"];
if(id?.toLowerCase().contains(filter.toLowerCase()) == true) {
return true;
}
var uri = Uri.tryParse(filter);
if(uri != null
&& uri.host.isNotEmpty
&& id?.toLowerCase().contains(uri.host.toLowerCase()) == true) {
return true;
}
String? name = element["name"];
if(name?.toLowerCase().contains(filter) == true) {
return true;
}
String? author = element["author"];
if(author?.toLowerCase().contains(filter) == true) {
return true;
}
String? description = element["description"];
if(description?.toLowerCase().contains(filter) == true) {
return true;
}
return false;
}
Widget get _searchBar => TextBox(
placeholder: translations.findServer,
controller: _filterController,
autofocus: true,
onChanged: (value) => _filterControllerStream.add(value),
suffix: _searchBarIcon,
);
Widget get _searchBarIcon => Button(
onPressed: _filterController.text.isEmpty ? null : () {
_filterController.clear();
_filterControllerStream.add("");
},
style: ButtonStyle(
backgroundColor: _filterController.text.isNotEmpty ? null : ButtonState.all(Colors.transparent),
border: _filterController.text.isNotEmpty ? null : ButtonState.all(const BorderSide(color: Colors.transparent))
),
child: _searchBarIconData
);
Widget get _searchBarIconData {
var color = FluentTheme.of(context).resources.textFillColorPrimary;
if (_filterController.text.isNotEmpty) {
return Icon(
FluentIcons.clear,
size: 8.0,
color: color
);
}
return Transform.flip(
flipX: true,
child: Icon(
FluentIcons.search,
size: 12.0,
color: color
),
);
}
String _formatName(Map<String, dynamic> entry) {
String result = entry['name'];
return result.isEmpty ? translations.defaultServerName : result;
}
String _formatDescription(Map<String, dynamic> entry) {
String result = entry['description'];
return result.isEmpty ? translations.defaultServerDescription : result;
}
String _formatVersion(Map<String, dynamic> entry) {
var version = entry['version'];
var versionSplit = version.indexOf("-");
var minimalVersion = version = versionSplit != -1 ? version.substring(0, versionSplit) : version;
String result = minimalVersion.endsWith(".0") ? minimalVersion.substring(0, minimalVersion.length - 2) : minimalVersion;
if(result.toLowerCase().startsWith("fortnite ")) {
result = result.substring(0, 10);
}
return "Fortnite $result";
}
@override
Widget? get button => null;
@override
List<Widget> get settings => [];
}

View File

@@ -0,0 +1,289 @@
import 'package:clipboard/clipboard.dart';
import 'package:dart_ipify/dart_ipify.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart' show Icons;
import 'package:get/get.dart';
import 'package:reboot_launcher/main.dart';
import 'package:reboot_launcher/src/controller/game_controller.dart';
import 'package:reboot_launcher/src/controller/hosting_controller.dart';
import 'package:reboot_launcher/src/dialog/implementation/data.dart';
import 'package:reboot_launcher/src/dialog/implementation/server.dart';
import 'package:reboot_launcher/src/page/abstract/page.dart';
import 'package:reboot_launcher/src/page/abstract/page_setting.dart';
import 'package:reboot_launcher/src/page/abstract/page_type.dart';
import 'package:reboot_launcher/src/util/translations.dart';
import 'package:reboot_launcher/src/widget/common/setting_tile.dart';
import 'package:reboot_launcher/src/widget/game/start_button.dart';
import 'package:reboot_launcher/src/widget/version/version_selector_tile.dart';
import 'package:sync/semaphore.dart';
class HostPage extends RebootPage {
const HostPage({Key? key}) : super(key: key);
@override
String get name => "Host";
@override
String get iconAsset => "assets/images/host.png";
@override
RebootPageType get type => RebootPageType.host;
@override
bool get hasButton => true;
@override
RebootPageState<HostPage> createState() => _HostingPageState();
@override
List<PageSetting> get settings => [
PageSetting(
name: translations.hostGameServerName,
description: translations.hostGameServerDescription,
children: [
PageSetting(
name: translations.hostGameServerNameName,
description: translations.hostGameServerNameDescription
),
PageSetting(
name: translations.hostGameServerDescriptionName,
description: translations.hostGameServerDescriptionDescription
),
PageSetting(
name: translations.hostGameServerPasswordName,
description: translations.hostGameServerDescriptionDescription
),
PageSetting(
name: translations.hostGameServerDiscoverableName,
description: translations.hostGameServerDiscoverableDescription
)
],
),
versionSelectorRebootSetting,
PageSetting(
name: translations.hostShareName,
description: translations.hostShareDescription,
children: [
PageSetting(
name: translations.hostShareLinkName,
description: translations.hostShareLinkDescription,
content: translations.hostShareLinkContent
),
PageSetting(
name: translations.hostShareIpName,
description: translations.hostShareIpDescription,
content: translations.hostShareIpContent
)
],
),
PageSetting(
name: translations.hostResetName,
description: translations.hostResetDescription,
content: translations.hostResetContent
)
];
}
class _HostingPageState extends RebootPageState<HostPage> {
final GameController _gameController = Get.find<GameController>();
final HostingController _hostingController = Get.find<HostingController>();
final Semaphore _semaphore = Semaphore();
late final RxBool _showPasswordTrailing = RxBool(_hostingController.password.text.isNotEmpty);
@override
void initState() {
if(_hostingController.name.text.isEmpty) {
_hostingController.name.text = translations.defaultServerName;
}
if(_hostingController.description.text.isEmpty) {
_hostingController.description.text = translations.defaultServerDescription;
}
super.initState();
}
@override
Widget get button => const LaunchButton(
host: true
);
@override
List<SettingTile> get settings => [
_gameServer,
versionSelectorSettingTile,
_share,
_resetDefaults
];
SettingTile get _resetDefaults => SettingTile(
title: translations.hostResetName,
subtitle: translations.hostResetDescription,
content: Button(
onPressed: () => showResetDialog(_hostingController.reset),
child: Text(translations.hostResetContent),
)
);
SettingTile get _gameServer => SettingTile(
title: translations.hostGameServerName,
subtitle: translations.hostGameServerDescription,
expandedContent: [
SettingTile(
title: translations.hostGameServerNameName,
subtitle: translations.hostGameServerNameDescription,
isChild: true,
content: TextFormBox(
placeholder: translations.hostGameServerNameName,
controller: _hostingController.name,
onChanged: (_) => _updateServer()
)
),
SettingTile(
title: translations.hostGameServerDescriptionName,
subtitle: translations.hostGameServerDescriptionDescription,
isChild: true,
content: TextFormBox(
placeholder: translations.hostGameServerDescriptionName,
controller: _hostingController.description,
onChanged: (_) => _updateServer()
)
),
SettingTile(
title: translations.hostGameServerPasswordName,
subtitle: translations.hostGameServerDescriptionDescription,
isChild: true,
content: Obx(() => TextFormBox(
placeholder: translations.hostGameServerPasswordName,
controller: _hostingController.password,
autovalidateMode: AutovalidateMode.always,
obscureText: !_hostingController.showPassword.value,
enableSuggestions: false,
autocorrect: false,
onChanged: (text) {
_showPasswordTrailing.value = text.isNotEmpty;
_updateServer();
},
suffix: Button(
onPressed: () => _hostingController.showPassword.value = !_hostingController.showPassword.value,
style: ButtonStyle(
shape: ButtonState.all(const CircleBorder()),
backgroundColor: ButtonState.all(Colors.transparent)
),
child: Icon(
_hostingController.showPassword.value ? Icons.visibility_off : Icons.visibility,
color: _showPasswordTrailing.value ? null : Colors.transparent
),
)
))
),
SettingTile(
title: translations.hostGameServerDiscoverableName,
subtitle: translations.hostGameServerDiscoverableDescription,
isChild: true,
contentWidth: null,
content: Obx(() => Row(
children: [
Text(
_hostingController.discoverable.value ? translations.on : translations.off
),
const SizedBox(
width: 16.0
),
ToggleSwitch(
checked: _hostingController.discoverable(),
onChanged: (value) async {
_hostingController.discoverable.value = value;
await _updateServer();
}
),
],
))
)
]
);
SettingTile get _share => SettingTile(
title: translations.hostShareName,
subtitle: translations.hostShareDescription,
expandedContent: [
SettingTile(
title: translations.hostShareLinkName,
subtitle: translations.hostShareLinkDescription,
isChild: true,
content: Button(
onPressed: () async {
FlutterClipboard.controlC("$kCustomUrlSchema://${_hostingController.uuid}");
_showCopiedLink();
},
child: Text(translations.hostShareLinkContent),
)
),
SettingTile(
title: translations.hostShareIpName,
subtitle: translations.hostShareIpDescription,
isChild: true,
content: Button(
onPressed: () async {
try {
_showCopyingIp();
var ip = await Ipify.ipv4();
FlutterClipboard.controlC(ip);
_showCopiedIp();
}catch(error) {
_showCannotCopyIp(error);
}
},
child: Text(translations.hostShareIpContent),
)
)
],
);
Future<void> _updateServer() async {
if(!_hostingController.published()) {
return;
}
try {
_semaphore.acquire();
_hostingController.publishServer(
_gameController.username.text,
_hostingController.instance.value!.versionName
);
} catch(error) {
_showCannotUpdateGameServer(error);
} finally {
_semaphore.release();
}
}
void _showCopiedLink() => showInfoBar(
translations.hostShareLinkMessageSuccess,
severity: InfoBarSeverity.success
);
void _showCopyingIp() => showInfoBar(
translations.hostShareIpMessageLoading,
loading: true,
duration: null
);
void _showCopiedIp() => showInfoBar(
translations.hostShareIpMessageSuccess,
severity: InfoBarSeverity.success
);
void _showCannotCopyIp(Object error) => showInfoBar(
translations.hostShareIpMessageError(error.toString()),
severity: InfoBarSeverity.error,
duration: snackbarLongDuration
);
void _showCannotUpdateGameServer(Object error) => showInfoBar(
translations.cannotUpdateGameServer(error.toString()),
severity: InfoBarSeverity.success,
duration: snackbarLongDuration
);
}

View File

@@ -0,0 +1,317 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localized_locales/flutter_localized_locales.dart';
import 'package:get/get.dart';
import 'package:reboot_common/common.dart';
import 'package:reboot_launcher/src/controller/game_controller.dart';
import 'package:reboot_launcher/src/controller/settings_controller.dart';
import 'package:reboot_launcher/src/controller/update_controller.dart';
import 'package:reboot_launcher/src/dialog/abstract/info_bar.dart';
import 'package:reboot_launcher/src/dialog/implementation/data.dart';
import 'package:reboot_launcher/src/page/abstract/page.dart';
import 'package:reboot_launcher/src/page/abstract/page_setting.dart';
import 'package:reboot_launcher/src/page/abstract/page_type.dart';
import 'package:reboot_launcher/src/util/checks.dart';
import 'package:reboot_launcher/src/util/translations.dart';
import 'package:reboot_launcher/src/widget/common/file_selector.dart';
import 'package:reboot_launcher/src/widget/common/setting_tile.dart';
import 'package:flutter_gen/gen_l10n/reboot_localizations.dart';
import 'package:url_launcher/url_launcher.dart';
class SettingsPage extends RebootPage {
const SettingsPage({Key? key}) : super(key: key);
@override
String get name => translations.settingsName;
@override
String get iconAsset => "assets/images/settings.png";
@override
RebootPageType get type => RebootPageType.settings;
@override
bool get hasButton => false;
@override
RebootPageState<SettingsPage> createState() => _SettingsPageState();
@override
List<PageSetting> get settings => [
PageSetting(
name: translations.settingsClientName,
description: translations.settingsClientDescription,
children: [
PageSetting(
name: translations.settingsClientConsoleName,
description: translations.settingsClientConsoleDescription
),
PageSetting(
name: translations.settingsClientAuthName,
description: translations.settingsClientAuthDescription
),
PageSetting(
name: translations.settingsClientMemoryName,
description: translations.settingsClientMemoryDescription
),
PageSetting(
name: translations.settingsClientArgsName,
description: translations.settingsClientArgsDescription
),
],
),
PageSetting(
name: translations.settingsServerName,
description: translations.settingsServerSubtitle,
children: [
PageSetting(
name: translations.settingsServerFileName,
description: translations.settingsServerFileDescription
),
PageSetting(
name: translations.settingsServerPortName,
description: translations.settingsServerPortDescription
),
PageSetting(
name: translations.settingsServerMirrorName,
description: translations.settingsServerMirrorDescription
),
PageSetting(
name: translations.settingsServerTimerName,
description: translations.settingsServerTimerSubtitle
),
],
),
PageSetting(
name: translations.settingsUtilsName,
description: translations.settingsUtilsSubtitle,
children: [
PageSetting(
name: translations.settingsUtilsThemeName,
description: translations.settingsUtilsThemeDescription,
),
PageSetting(
name: translations.settingsUtilsLanguageName,
description: translations.settingsUtilsLanguageDescription,
),
PageSetting(
name: translations.settingsUtilsInstallationDirectoryName,
description: translations.settingsUtilsInstallationDirectorySubtitle,
content: translations.settingsUtilsInstallationDirectoryContent
),
PageSetting(
name: translations.settingsUtilsBugReportName,
description: translations.settingsUtilsBugReportSubtitle,
content: translations.settingsUtilsBugReportContent
),
PageSetting(
name: translations.settingsUtilsResetDefaultsName,
description: translations.settingsUtilsResetDefaultsSubtitle,
content: translations.settingsUtilsResetDefaultsContent
)
],
)
];
}
class _SettingsPageState extends RebootPageState<SettingsPage> {
final GameController _gameController = Get.find<GameController>();
final SettingsController _settingsController = Get.find<SettingsController>();
final UpdateController _updateController = Get.find<UpdateController>();
@override
Widget? get button => null;
@override
List<Widget> get settings => [
_clientSettings,
_gameServerSettings,
_launcherUtilities
];
SettingTile get _clientSettings => SettingTile(
title: translations.settingsClientName,
subtitle: translations.settingsClientDescription,
expandedContent: [
_createFileSetting(
title: translations.settingsClientConsoleName,
description: translations.settingsClientConsoleDescription,
controller: _settingsController.unrealEngineConsoleDll
),
_createFileSetting(
title: translations.settingsClientAuthName,
description: translations.settingsClientAuthDescription,
controller: _settingsController.authenticatorDll
),
_createFileSetting(
title: translations.settingsClientMemoryName,
description: translations.settingsClientMemoryDescription,
controller: _settingsController.memoryLeakDll
),
SettingTile(
title: translations.settingsClientArgsName,
subtitle: translations.settingsClientArgsDescription,
isChild: true,
content: TextFormBox(
placeholder: translations.settingsClientArgsPlaceholder,
controller: _gameController.customLaunchArgs,
)
),
],
);
SettingTile get _gameServerSettings => SettingTile(
title: translations.settingsServerName,
subtitle: translations.settingsServerSubtitle,
expandedContent: [
_createFileSetting(
title: translations.settingsServerFileName,
description: translations.settingsServerFileDescription,
controller: _settingsController.gameServerDll
),
SettingTile(
title: translations.settingsServerPortName,
subtitle: translations.settingsServerPortDescription,
content: TextFormBox(
placeholder: translations.settingsServerPortName,
controller: _settingsController.gameServerPort,
keyboardType: TextInputType.number,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly
]
),
isChild: true
),
SettingTile(
title: translations.settingsServerMirrorName,
subtitle: translations.settingsServerMirrorDescription,
content: TextFormBox(
placeholder: translations.settingsServerMirrorPlaceholder,
controller: _updateController.url,
validator: checkUpdateUrl
),
isChild: true
),
SettingTile(
title: translations.settingsServerTimerName,
subtitle: translations.settingsServerTimerSubtitle,
content: Obx(() => DropDownButton(
leading: Text(_updateController.timer.value.text),
items: UpdateTimer.values.map((entry) => MenuFlyoutItem(
text: Text(entry.text),
onPressed: () {
_updateController.timer.value = entry;
removeMessageByPage(6);
_updateController.update(true);
}
)).toList()
)),
isChild: true
),
],
);
SettingTile get _launcherUtilities => SettingTile(
title: translations.settingsUtilsName,
subtitle: translations.settingsUtilsSubtitle,
expandedContent: [
SettingTile(
title: translations.settingsUtilsLanguageName,
subtitle: translations.settingsUtilsLanguageDescription,
isChild: true,
content: Obx(() => DropDownButton(
leading: Text(_getLocaleName(_settingsController.language.value)),
items: AppLocalizations.supportedLocales.map((locale) => MenuFlyoutItem(
text: Text(_getLocaleName(locale.languageCode)),
onPressed: () => _settingsController.language.value = locale.languageCode
)).toList()
))
),
SettingTile(
title: translations.settingsUtilsThemeName,
subtitle: translations.settingsUtilsThemeDescription,
isChild: true,
content: Obx(() => DropDownButton(
leading: Text(_settingsController.themeMode.value.title),
items: ThemeMode.values.map((themeMode) => MenuFlyoutItem(
text: Text(themeMode.title),
onPressed: () => _settingsController.themeMode.value = themeMode
)).toList()
))
),
SettingTile(
title: translations.settingsUtilsInstallationDirectoryName,
subtitle: translations.settingsUtilsInstallationDirectorySubtitle,
isChild: true,
content: Button(
onPressed: () => launchUrl(installationDirectory.uri),
child: Text(translations.settingsUtilsInstallationDirectoryContent),
)
),
SettingTile(
title: translations.settingsUtilsBugReportName,
subtitle: translations.settingsUtilsBugReportSubtitle,
isChild: true,
content: Button(
onPressed: () => launchUrl(Uri.parse("https://github.com/Auties00/reboot_launcher/issues")),
child: Text(translations.settingsUtilsBugReportContent),
)
),
SettingTile(
title: translations.settingsUtilsResetDefaultsName,
subtitle: translations.settingsUtilsResetDefaultsSubtitle,
isChild: true,
content: Button(
onPressed: () => showResetDialog(_settingsController.reset),
child: Text(translations.settingsUtilsResetDefaultsContent),
)
)
],
);
String _getLocaleName(String locale) {
var result = LocaleNames.of(context)!.nameOf(locale);
if(result != null) {
return "${result.substring(0, 1).toUpperCase()}${result.substring(1).toLowerCase()}";
}
return locale;
}
Widget _createFileSetting({required String title, required String description, required TextEditingController controller}) => SettingTile(
title: title,
subtitle: description,
content: FileSelector(
placeholder: translations.selectPathPlaceholder,
windowTitle: translations.selectPathWindowTitle,
controller: controller,
validator: checkDll,
extension: "dll",
folder: false
),
isChild: true
);
}
extension _UpdateTimerExtension on UpdateTimer {
String get text {
if (this == UpdateTimer.never) {
return translations.updateGameServerDllNever;
}
return translations.updateGameServerDllEvery(name);
}
}
extension _ThemeModeExtension on ThemeMode {
String get title {
switch(this) {
case ThemeMode.system:
return translations.system;
case ThemeMode.dark:
return translations.dark;
case ThemeMode.light:
return translations.light;
}
}
}