Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
Add maps
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisL61 committed Jul 5, 2022
1 parent ce317d4 commit 46a58fa
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 54 deletions.
9 changes: 8 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ Un simple overlay pour Sea of Thieves
## Fonctionnalités

- Permet de savoir le temps pour cuire un aliment
- Permet de montrer ce que vous faites sur le jeu avec la compatibilité Rich Presence de Discord
- Permet de montrer ce que vous faites sur le jeu avec la compatibilité Rich Presence de Discord
- Permet de voir les différents sites proposant des cartes de Sea of Thieves (rarethief et merfolk's lullaby)

## Crédits

L'overlay utilise les sites suivants pour le module "map" :
- https://www.merfolkslullaby.com/
- https://maps.seaofthieves.rarethief.com/
13 changes: 11 additions & 2 deletions sot_companion/lib/class/module.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import 'package:flutter/widgets.dart';
import 'package:sot_companion/modules/cook_time/pages/food_page.dart';
import 'package:sot_companion/modules/discord_rpc/pages/rpc.dart';
import 'package:sot_companion/modules/maps/pages/map.dart';

class Module {
String name;
String image;
Widget mainPage;
Size size;
StatefulWidget mainPage;

Module(this.name, this.image, this.mainPage);
Module(this.name, this.image, this.size, this.mainPage);

static List<Module> moduleList = [
Module(
"Cuisine",
"https://static.wikia.nocookie.net/seaofthieves_gamepedia/images/c/c6/Food.png/revision/latest/scale-to-width-down/1000?cb=20200116140939",
Size(400, 100),
CookTime_Page()),
Module(
"Discord_rpc",
"https://discord.com/assets/9f6f9cd156ce35e2d94c0e62e3eff462.png",
Size(400, 300),
RPC_Page()),
Module(
"Maps",
"https://static.wikia.nocookie.net/seaofthieves_gamepedia/images/5/5c/Treasure_Map_Icon.png/revision/latest/scale-to-width-down/125?cb=20200923101156",
Size(400, 600),
Map_Page()),
];
}
10 changes: 10 additions & 0 deletions sot_companion/lib/helper/WebviewManager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';
import 'package:webview_windows/webview_windows.dart';

class SOT_WebviewManager {
static final currentController = WebviewController();

static init() async{

}
}
133 changes: 86 additions & 47 deletions sot_companion/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import 'package:dart_discord_rpc/dart_discord_rpc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_acrylic/flutter_acrylic.dart';
import 'package:sot_companion/class/module.dart';
import 'package:sot_companion/helper/WebviewManager.dart';
import 'package:sot_companion/helper/WindowManager.dart';
import 'package:sot_companion/modules/discord_rpc/class/sot_activity.dart';
import 'package:webview_windows/webview_windows.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
Expand All @@ -11,6 +14,7 @@ void main() async {
// Must add this line.
await Window.initialize();
await windowManager.ensureInitialized();
await SOT_WebviewManager.init();

WindowOptions windowOptions = const WindowOptions(
size: Size(100, 50),
Expand Down Expand Up @@ -75,11 +79,23 @@ class MyHomePage extends StatefulWidget {
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
String status = "MINIMIZE";
Module? moduleSelected;
late TabController _tabController;

@override
void initState() {
super.initState();
_tabController =
TabController(vsync: this, length: Module.moduleList.length);
}

Widget build(BuildContext context) {
if (moduleSelected == null) {
SOT_WindowsManager.changeSize(const Size(400, 100));
}
late Widget scaffoldChild;
if (status == "MODULES") {
scaffoldChild = _buildModules();
Expand All @@ -90,40 +106,68 @@ class _MyHomePageState extends State<MyHomePage> {
}

Widget _buildModules() {
if (moduleSelected == null) {
SOT_WindowsManager.changeSize(Size(250, 50));
}
return Column(children: [
Row(children: [
InkWell(
child: Icon(Icons.arrow_right),
onTap: () {
setState(() {
status = "MINIMIZE";
});
},
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(Module.moduleList.length, (index) {
return Expanded(child:Row(mainAxisAlignment: MainAxisAlignment.center, children: [ _buildModuleIcon(Module.moduleList[index])]));
})))
]),
moduleSelected != null
? Expanded(
child: Column(children: [
SizedBox(height: 4,),
Container(
margin: EdgeInsets.symmetric(horizontal:10),
height: 2,
width: MediaQuery.of(context).size.width,
color: Colors.white),
SizedBox(height: 4,),
Expanded(child: moduleSelected!.mainPage)
]))
: Container()
]);
return _buildAllModulesColumn();
}

Widget _buildWebView() {
return Expanded(child: Webview(SOT_WebviewManager.currentController));
}

Widget _buildAllModulesColumn() {
return Container(
child: DefaultTabController(
length: 3,
child: Column(children: [
Row(children: [
InkWell(
child: Icon(Icons.arrow_right),
onTap: () {
status = "MINIMIZE";
setState(() {});
},
),
Expanded(
child: TabBar(
onTap: (int index) {
WindowManager.instance
.setSize(Module.moduleList[index].size);
},
controller: _tabController,
tabs: List.generate(Module.moduleList.length, (index) {
return Tab(
child: _buildModuleIcon(
Module.moduleList[index]));
})))
]),
Expanded(
child: TabBarView(
controller: _tabController,
children:
List.generate(Module.moduleList.length, (index) {
return Module.moduleList[index].mainPage;
})))
])));
}

Widget _buildModulePage() {
return moduleSelected != null
? Container(
child: Expanded(
child: Column(children: [
SizedBox(
height: 4,
),
Container(
margin: EdgeInsets.symmetric(horizontal: 10),
height: 2,
width: MediaQuery.of(context).size.width,
color: Colors.white),
SizedBox(
height: 4,
),
Expanded(child: moduleSelected!.mainPage)
])))
: Container();
}

Widget _buildMinimize() {
Expand All @@ -144,8 +188,9 @@ class _MyHomePageState extends State<MyHomePage> {
backgroundColor: Colors.transparent,
backgroundImage: NetworkImage(
"https://static.wikia.nocookie.net/seaofthieves_gamepedia/images/b/b8/Investigator_of_Dark_Intrigue_emblem.png/revision/latest/scale-to-width-down/1000?cb=20220630155533"),
),
),
onTap: () {
_tabController.animateTo(0);
status = "MODULES";
setState(() {});
}),
Expand All @@ -154,16 +199,10 @@ class _MyHomePageState extends State<MyHomePage> {
}

Widget _buildModuleIcon(Module module) {
return InkWell(
child: CircleAvatar(
backgroundColor: Colors.transparent,
backgroundImage: NetworkImage(module.image),
),
onTap: () {
if (moduleSelected == null || moduleSelected!.name != module.name) {
moduleSelected = module;
setState(() {});
}
});
return CircleAvatar(
backgroundColor: Colors.transparent,
backgroundImage: NetworkImage(module.image),
)
;
}
}
4 changes: 2 additions & 2 deletions sot_companion/lib/modules/cook_time/pages/food_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _CookTime_PageState extends State<CookTime_Page> {
}

Widget _buildSelectFood() {
SOT_WindowsManager.changeSize(Size(250, 100));
//SOT_WindowsManager.changeSize(Size(250, 100));
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expand All @@ -57,7 +57,7 @@ class _CookTime_PageState extends State<CookTime_Page> {
}

Widget _buildCooking() {
SOT_WindowsManager.changeSize(Size(250, 100));
//SOT_WindowsManager.changeSize(Size(250, 100));
print(double.maxFinite);
return Container(
padding: EdgeInsets.only(right: 10),
Expand Down
2 changes: 1 addition & 1 deletion sot_companion/lib/modules/discord_rpc/pages/rpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _RPC_PageState extends State<RPC_Page> {
}

Widget _buildMenu() {
SOT_WindowsManager.changeSize(const Size(250, 300));
//SOT_WindowsManager.changeSize(const Size(250, 300));
return Row(children: [
Expanded(
child: Column(
Expand Down
116 changes: 116 additions & 0 deletions sot_companion/lib/modules/maps/pages/map.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sot_companion/helper/WebviewManager.dart';
import 'package:webview_windows/webview_windows.dart';

import '../../../helper/WindowManager.dart';

class Map_Page extends StatefulWidget {
Map_Page({Key? key}) : super(key: key);

@override
State<Map_Page> createState() => _Map_PageState();
}

class _Map_PageState extends State<Map_Page> {
final _controller = WebviewController();
bool ready = false;

@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (mounted) {
initPlatformState();
}
});
}

Future<void> initPlatformState() async {
// Optionally initialize the webview environment using
// a custom user data directory
// and/or a custom browser executable directory
// and/or custom chromium command line flags
//await WebviewController.initializeEnvironment(
// additionalArguments: '--show-fps-counter');

try {
await SOT_WebviewManager.currentController.initialize();

await SOT_WebviewManager.currentController
.setBackgroundColor(Colors.transparent);
await SOT_WebviewManager.currentController
.setPopupWindowPolicy(WebviewPopupWindowPolicy.allow);
await SOT_WebviewManager.currentController
.loadUrl('https://maps.seaofthieves.rarethief.com/');

await SOT_WebviewManager.currentController.executeScript(
"window.addEventListener('load', (event) => {document.body.style.width='100vw';document.body.style.height='100vh';document.body.style.overflow='hidden'});");
//await _controller.stop();
setState(() {
ready = true;
});
} on PlatformException catch (e) {
print(e.toString());
}
}

Future<WebviewPermissionDecision> _onPermissionRequested(
String url, WebviewPermissionKind kind, bool isUserInitiated) async {
final decision = await showDialog<WebviewPermissionDecision>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('WebView permission requested'),
content: Text('WebView has requested permission \'$kind\''),
actions: <Widget>[
TextButton(
onPressed: () =>
Navigator.pop(context, WebviewPermissionDecision.deny),
child: const Text('Deny'),
),
TextButton(
onPressed: () =>
Navigator.pop(context, WebviewPermissionDecision.allow),
child: const Text('Allow'),
),
],
),
);

return decision ?? WebviewPermissionDecision.none;
}

@override
Widget build(BuildContext context) {
//SOT_WindowsManager.changeSize(const Size(400, 600));

return Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(child: Container()),
InkWell(child:
CircleAvatar(backgroundImage: NetworkImage("https://cdn.discordapp.com/attachments/839604520245264404/993969738726260836/rare_thief.png")),
onTap: ()async {
await SOT_WebviewManager.currentController
.loadUrl('https://maps.seaofthieves.rarethief.com/');
},
),
Expanded(child: Container()),
InkWell(child:
CircleAvatar(backgroundImage: NetworkImage("https://cdn.discordapp.com/attachments/839604520245264404/993974389940965468/merfolks_lullaby.png")),
onTap: ()async {
await SOT_WebviewManager.currentController
.loadUrl('https://www.merfolkslullaby.com/map?tab=weather');
},
),
Expanded(child: Container())
]),
ready
? Expanded(
child: Stack(
children: [Webview(SOT_WebviewManager.currentController)],
))
: Container()]);
}
}
Loading

0 comments on commit 46a58fa

Please sign in to comment.