mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-14 03:32:23 +01:00
update
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:bitsdojo_window/bitsdojo_window.dart' hide WindowBorder;
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get_rx/src/rx_types/rx_types.dart';
|
||||
import 'package:reboot_launcher/src/controller/game_controller.dart';
|
||||
import 'package:reboot_launcher/src/controller/server_controller.dart';
|
||||
import 'package:reboot_launcher/src/dialog/dialog.dart';
|
||||
import 'package:reboot_launcher/src/dialog/dialog_button.dart';
|
||||
import 'package:reboot_launcher/src/page/settings_page.dart';
|
||||
import 'package:reboot_launcher/src/page/launcher_page.dart';
|
||||
import 'package:reboot_launcher/src/page/server_page.dart';
|
||||
@@ -9,6 +17,7 @@ import 'package:reboot_launcher/src/widget/os/window_border.dart';
|
||||
import 'package:reboot_launcher/src/widget/os/window_buttons.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../controller/settings_controller.dart';
|
||||
import 'info_page.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
@@ -20,117 +29,294 @@ class HomePage extends StatefulWidget {
|
||||
|
||||
class _HomePageState extends State<HomePage> with WindowListener {
|
||||
static const double _headerSize = 48.0;
|
||||
static const double _sectionSize = 94.0;
|
||||
static const double _sectionSize = 100.0;
|
||||
static const double _defaultPadding = 12.0;
|
||||
static const double _openMenuSize = 320.0;
|
||||
static const int _headerButtonCount = 3;
|
||||
static const int _sectionButtonCount = 4;
|
||||
|
||||
bool _focused = true;
|
||||
final GameController _gameController = Get.find<GameController>();
|
||||
final SettingsController _settingsController = Get.find<SettingsController>();
|
||||
final ServerController _serverController = Get.find<ServerController>();
|
||||
|
||||
final GlobalKey _searchKey = GlobalKey();
|
||||
final FocusNode _searchFocusNode = FocusNode();
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final Rxn<List<NavigationPaneItem>> _searchItems = Rxn();
|
||||
final RxBool _focused = RxBool(true);
|
||||
final RxInt _index = RxInt(0);
|
||||
|
||||
bool _shouldMaximize = false;
|
||||
int _index = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
windowManager.addListener(this);
|
||||
_searchController.addListener(() {
|
||||
if (searchValue.isEmpty) {
|
||||
_searchItems.value = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_searchItems.value = _allItems.whereType<PaneItem>()
|
||||
.where((item) => (item.title as Text).data!.toLowerCase().contains(searchValue.toLowerCase()))
|
||||
.toList()
|
||||
.cast<NavigationPaneItem>();
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
windowManager.removeListener(this);
|
||||
_searchFocusNode.dispose();
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowFocus() {
|
||||
setState(() => _focused = true);
|
||||
_focused.value = true;
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowBlur() {
|
||||
setState(() => _focused = !_focused);
|
||||
_focused.value = false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
void onWindowMoved() {
|
||||
_settingsController.saveWindowOffset(appWindow.position);
|
||||
super.onWindowMoved();
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowClose() async {
|
||||
if(!_gameController.started() || !_serverController.started()) {
|
||||
windowManager.destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) {
|
||||
return InfoDialog(
|
||||
text: "Closing the launcher while a backend is running may make the game not work correctly. Are you sure you want to proceed?",
|
||||
buttons: [
|
||||
DialogButton(
|
||||
type: ButtonType.secondary,
|
||||
text: "Don't close",
|
||||
),
|
||||
|
||||
DialogButton(
|
||||
type: ButtonType.primary,
|
||||
onTap: () => windowManager.destroy(),
|
||||
text: "Close",
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => NotificationListener<SizeChangedLayoutNotification>(
|
||||
onNotification: (notification) => _calculateSize(),
|
||||
child: SizeChangedLayoutNotifier(
|
||||
child: Obx(() => Stack(
|
||||
children: [
|
||||
_createNavigationView(),
|
||||
_createTitleBar(),
|
||||
if(_settingsController.displayType() == PaneDisplayMode.top)
|
||||
_createTopDisplayGestures(),
|
||||
if(_focused() && isWin11)
|
||||
const WindowBorder()
|
||||
])
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
Padding _createTopDisplayGestures() => Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: _sectionSize * _sectionButtonCount,
|
||||
right: _headerSize * _headerButtonCount,
|
||||
),
|
||||
child: SizedBox(
|
||||
height: _headerSize,
|
||||
child: _createWindowGestures()
|
||||
)
|
||||
);
|
||||
|
||||
GestureDetector _createWindowGestures({Widget? child}) => GestureDetector(
|
||||
onDoubleTap: () {
|
||||
if(!_shouldMaximize){
|
||||
return;
|
||||
}
|
||||
|
||||
appWindow.maximizeOrRestore();
|
||||
_shouldMaximize = false;
|
||||
},
|
||||
onDoubleTapDown: (details) => _shouldMaximize = true,
|
||||
onHorizontalDragStart: (event) => appWindow.startDragging(),
|
||||
onVerticalDragStart: (event) => appWindow.startDragging(),
|
||||
child: child
|
||||
);
|
||||
|
||||
NavigationView _createNavigationView() => NavigationView(
|
||||
paneBodyBuilder: (body) => _createPage(body),
|
||||
pane: NavigationPane(
|
||||
size: const NavigationPaneSize(
|
||||
topHeight: _headerSize
|
||||
),
|
||||
selected: _selectedIndex,
|
||||
onChanged: (index) {
|
||||
_settingsController.player?.pause();
|
||||
_index.value = index;
|
||||
},
|
||||
displayMode: _settingsController.displayType(),
|
||||
indicator: const EndNavigationIndicator(),
|
||||
items: _createItems(),
|
||||
footerItems: _createFooterItems(),
|
||||
header: _settingsController.displayType() != PaneDisplayMode.open ? null : const SizedBox(height: _defaultPadding),
|
||||
autoSuggestBox: _settingsController.displayType() == PaneDisplayMode.top ? null : TextBox(
|
||||
key: _searchKey,
|
||||
controller: _searchController,
|
||||
placeholder: 'Search',
|
||||
focusNode: _searchFocusNode
|
||||
),
|
||||
autoSuggestBoxReplacement: _settingsController.displayType() == PaneDisplayMode.top ? null : const Icon(FluentIcons.search),
|
||||
),
|
||||
onOpenSearch: () => _searchFocusNode.requestFocus(),
|
||||
transitionBuilder: _settingsController.displayType() == PaneDisplayMode.top ? null : (child, animation) => child
|
||||
);
|
||||
|
||||
RenderObjectWidget _createPage(Widget? body) => Padding(
|
||||
padding: _createPagePadding(),
|
||||
child: body
|
||||
);
|
||||
|
||||
EdgeInsets _createPagePadding() {
|
||||
if (_settingsController.displayType() == PaneDisplayMode.top) {
|
||||
return const EdgeInsets.all(_defaultPadding);
|
||||
}
|
||||
|
||||
return const EdgeInsets.only(
|
||||
top: 32,
|
||||
left: _defaultPadding,
|
||||
right: _defaultPadding,
|
||||
bottom: _defaultPadding
|
||||
);
|
||||
}
|
||||
|
||||
int? get _selectedIndex {
|
||||
var searchItems = _searchItems();
|
||||
if (searchItems == null) {
|
||||
return _index();
|
||||
}
|
||||
|
||||
if(_index() >= _allItems.length){
|
||||
return null;
|
||||
}
|
||||
|
||||
var indexOnScreen = searchItems.indexOf(_allItems[_index()]);
|
||||
if (indexOnScreen.isNegative) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return indexOnScreen;
|
||||
}
|
||||
|
||||
List<NavigationPaneItem> get _allItems => [..._createItems(), ..._createFooterItems()];
|
||||
|
||||
List<NavigationPaneItem> _createFooterItems() => searchValue.isNotEmpty ? [] : [
|
||||
if(_settingsController.displayType() != PaneDisplayMode.top)
|
||||
PaneItem(
|
||||
title: const Text("Tutorial"),
|
||||
icon: const Icon(FluentIcons.info),
|
||||
body: const InfoPage()
|
||||
)
|
||||
];
|
||||
|
||||
List<NavigationPaneItem> _createItems() => _searchItems() ?? [
|
||||
PaneItem(
|
||||
title: const Text("Home"),
|
||||
icon: const Icon(FluentIcons.game),
|
||||
body: const LauncherPage()
|
||||
),
|
||||
|
||||
PaneItem(
|
||||
title: const Text("Backend"),
|
||||
icon: const Icon(FluentIcons.server_enviroment),
|
||||
body: ServerPage()
|
||||
),
|
||||
|
||||
PaneItem(
|
||||
title: const Text("Settings"),
|
||||
icon: const Icon(FluentIcons.settings),
|
||||
body: SettingsPage()
|
||||
),
|
||||
|
||||
if(_settingsController.displayType() == PaneDisplayMode.top)
|
||||
PaneItem(
|
||||
title: const Text("Tutorial"),
|
||||
icon: const Icon(FluentIcons.info),
|
||||
body: const InfoPage()
|
||||
)
|
||||
];
|
||||
|
||||
bool _calculateSize() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_settingsController.saveWindowSize();
|
||||
var width = window.physicalSize.width;
|
||||
PaneDisplayMode? newType;
|
||||
if (width <= 1000) {
|
||||
newType = PaneDisplayMode.top;
|
||||
} else if (width >= 1500) {
|
||||
newType = PaneDisplayMode.open;
|
||||
} else if (width > 1000) {
|
||||
newType = PaneDisplayMode.compact;
|
||||
}
|
||||
|
||||
if(newType == null || newType == _settingsController.displayType()){
|
||||
return;
|
||||
}
|
||||
|
||||
_settingsController.displayType.value = newType;
|
||||
_searchItems.value = null;
|
||||
_searchController.text = "";
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget _createTitleBar() => Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: _createTitleBarContent(),
|
||||
);
|
||||
|
||||
Widget _createTitleBarContent() {
|
||||
if(_settingsController.displayType() == PaneDisplayMode.top) {
|
||||
return WindowTitleBar(focused: _focused());
|
||||
}
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
NavigationView(
|
||||
pane: NavigationPane(
|
||||
size: const NavigationPaneSize(
|
||||
topHeight: _headerSize
|
||||
),
|
||||
selected: _index,
|
||||
onChanged: (index) => setState(() => _index = index),
|
||||
displayMode: PaneDisplayMode.top,
|
||||
indicator: const EndNavigationIndicator(),
|
||||
items: [
|
||||
PaneItem(
|
||||
title: const Text("Home"),
|
||||
icon: const Icon(FluentIcons.game),
|
||||
body: const LauncherPage()
|
||||
),
|
||||
|
||||
PaneItem(
|
||||
title: const Text("Lawin"),
|
||||
icon: const Icon(FluentIcons.server_enviroment),
|
||||
body: ServerPage()
|
||||
),
|
||||
|
||||
PaneItem(
|
||||
title: const Text("Settings"),
|
||||
icon: const Icon(FluentIcons.settings),
|
||||
body: SettingsPage()
|
||||
),
|
||||
|
||||
PaneItem(
|
||||
title: const Text("Info"),
|
||||
icon: const Icon(FluentIcons.info),
|
||||
body: const InfoPage()
|
||||
)
|
||||
]
|
||||
),
|
||||
SizedBox(
|
||||
width: _settingsController.displayType() == PaneDisplayMode.open ? _openMenuSize : _headerSize,
|
||||
height: _headerSize
|
||||
),
|
||||
|
||||
_createTitleBar(),
|
||||
|
||||
_createGestureHandler(),
|
||||
|
||||
if(_focused && isWin11)
|
||||
const WindowBorder()
|
||||
Expanded(
|
||||
child: _createWindowGestures(
|
||||
child: Container(
|
||||
height: _headerSize,
|
||||
color: Colors.transparent
|
||||
)
|
||||
)
|
||||
),
|
||||
WindowTitleBar(focused: _focused())
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Align _createTitleBar() {
|
||||
return Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: WindowTitleBar(focused: _focused),
|
||||
);
|
||||
}
|
||||
|
||||
// Hacky way to get it to work while having maximum performance and no modifications to external libs
|
||||
Padding _createGestureHandler() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: _sectionSize * _sectionButtonCount,
|
||||
right: _headerSize * _headerButtonCount,
|
||||
),
|
||||
child: SizedBox(
|
||||
height: _headerSize,
|
||||
child: GestureDetector(
|
||||
onDoubleTap: () {
|
||||
if(!_shouldMaximize){
|
||||
return;
|
||||
}
|
||||
|
||||
appWindow.maximizeOrRestore();
|
||||
_shouldMaximize = false;
|
||||
},
|
||||
onDoubleTapDown: (details) => _shouldMaximize = true,
|
||||
onHorizontalDragStart: (event) => appWindow.startDragging(),
|
||||
onVerticalDragStart: (event) => appWindow.startDragging()
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
String get searchValue => _searchController.text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user