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

Commit

Permalink
Ajout du rich presence Discord
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisL61 committed Jul 3, 2022
1 parent 3d3a6a9 commit ce317d4
Show file tree
Hide file tree
Showing 19 changed files with 817 additions and 172 deletions.
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SOT_Companion

Un simple overlay sur Sea of Thieves
Un simple overlay pour Sea of Thieves

## Fonctionnalités

- Permet de savoir le temps pour cuire un aliment
- 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
22 changes: 22 additions & 0 deletions sot_companion/lib/class/module.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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';

class Module {
String name;
String image;
Widget mainPage;

Module(this.name, this.image, 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",
CookTime_Page()),
Module(
"Discord_rpc",
"https://discord.com/assets/9f6f9cd156ce35e2d94c0e62e3eff462.png",
RPC_Page()),
];
}
3 changes: 2 additions & 1 deletion sot_companion/lib/helper/WindowManager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class SOT_WindowsManager {
SOT_WindowsManager();

static changeSize(Size newSize) async {
if ((await windowManager.getSize()).width != newSize.width) {
Size screenSize = await windowManager.getSize();
if (screenSize.width != newSize.width || screenSize.height != newSize.height) {
await windowManager.setSize(newSize);
await windowManager.setAlignment(Alignment.topRight);
//await windowManager.setBounds(Offset(1,1) & newSize, animate: true);
Expand Down
241 changes: 72 additions & 169 deletions sot_companion/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
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/food.dart';
import 'package:sot_companion/class/module.dart';
import 'package:sot_companion/helper/WindowManager.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
DiscordRPC.initialize();
// Must add this line.
await Window.initialize();
await windowManager.ensureInitialized();

WindowOptions windowOptions = const WindowOptions(
size: Size(250, 50),
minimumSize: Size(10,10),
size: Size(100, 50),
minimumSize: Size(10, 10),
center: true,
skipTaskbar: true,
titleBarStyle: TitleBarStyle.hidden,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.setBounds(Rect.largest);
Size size = await windowManager.getSize();
print(size);
await windowManager.setSize(Size(250, 50));
await windowManager.setPosition(Offset(size.width - 280, 10));
await Window.setEffect(
effect: WindowEffect.aero,
dark: false,
Expand Down Expand Up @@ -79,188 +76,94 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
String status = "SELECT_FOOD";
int cookingStartTime = 0;
Food? foodToCook;
Widget body = Container();
String status = "MINIMIZE";
Module? moduleSelected;

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
switch (status) {
case "SELECT_FOOD":
body = _buildSelectFood();
break;
case "CLOSE":
body = _buildClose();
break;
case "COOKING":
body = _buildCooking();
break;
default:
late Widget scaffoldChild;
if (status == "MODULES") {
scaffoldChild = _buildModules();
} else {
scaffoldChild = _buildMinimize();
}

return Scaffold(backgroundColor: Colors.transparent, body: body);
return Scaffold(backgroundColor: Colors.transparent, body: scaffoldChild);
}

Widget _buildSelectFood() {
SOT_WindowsManager.changeSize(Size(250, 50));
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Widget _buildModules() {
if (moduleSelected == null) {
SOT_WindowsManager.changeSize(Size(250, 50));
}
return Column(children: [
Row(children: [
InkWell(
child: Icon(Icons.arrow_right),
onTap: () {
status = "CLOSE";
setState(() {});
setState(() {
status = "MINIMIZE";
});
},
),
Expanded(
child: Row(
children: List.generate(Food.availableFoods.length,
(index) => _buildFoodToCook(Food.availableFoods[index]))))
],
);
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()
]);
}

Widget _buildClose() {
SOT_WindowsManager.changeSize(Size(50, 50));
return
Row(children: [
Widget _buildMinimize() {
print("BUILD_MINIMZE");
moduleSelected = null;
SOT_WindowsManager.changeSize(Size(100, 50));
return Row(children: [
InkWell(
child: Icon(Icons.close),
onTap: () {
windowManager.close();
},
),
Expanded(child:Row(mainAxisAlignment: MainAxisAlignment.center, children: [

InkWell(
child: CircleAvatar(
backgroundImage: NetworkImage(
"https://static.wikia.nocookie.net/seaofthieves_gamepedia/images/c/c6/Food.png/revision/latest/scale-to-width-down/1000?cb=20200116140939"),
),
onTap: () {
status = "SELECT_FOOD";
setState(() {});
}),
]))]);
}

Widget _buildCooking() {
SOT_WindowsManager.changeSize(Size(250, 50));
print(double.maxFinite);
return Container(
padding: EdgeInsets.only(right: 10),
child: TweenAnimationBuilder<double>(
tween: Tween<double>(
begin: (DateTime.now().millisecondsSinceEpoch / 1000) -
cookingStartTime / 1000,
end: (foodToCook!.timeToBurn).toDouble()),
duration: Duration(
seconds: (foodToCook!.timeToBurn -
((DateTime.now().millisecondsSinceEpoch / 1000) -
cookingStartTime / 1000))
.toInt()),
builder: (BuildContext context, double time, Widget? child) {
return Row(children: [
InkWell(
child: Icon(Icons.arrow_right),
onTap: () {
status = "SELECT_FOOD";
setState(() {});
},
),
SizedBox(
width: 10,
),
CircleAvatar(
backgroundImage: NetworkImage(foodToCook!.image),
),
SizedBox(
width: 10,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
time < foodToCook!.timeToCook
? (foodToCook!.timeToCook - time.floor())
.toString() +
"s"
: (foodToCook!.timeToBurn - time.floor())
.toString() +
"s",
style: TextStyle(
color: time < foodToCook!.timeToBurn
? (time < foodToCook!.timeToCook
? Colors.white
: Colors.green)
: Colors.red,
fontSize: 20)),
Stack(
children: [
Container(
height: 5,
width: double.maxFinite,
color: Colors.white,
),
LayoutBuilder(builder:
(BuildContext context, BoxConstraints constraints) {
return Container(
height: 5,
width: time > foodToCook!.timeToCook
? constraints.maxWidth
: time *
constraints.maxWidth /
foodToCook!.timeToCook,
color: Colors.green,
);
}),
LayoutBuilder(builder:
(BuildContext context, BoxConstraints constraints) {
return Container(
height: 5,
width: time > foodToCook!.timeToCook
? (time > foodToCook!.timeToBurn
? constraints.maxWidth
: (time - foodToCook!.timeToCook) *
constraints.maxWidth /
(foodToCook!.timeToBurn -
foodToCook!.timeToCook))
: 0,
color: Colors.red,
);
}),
//Container(height:5, width:double.maxFinite,color: Colors.red,),
],
)
],
))
]);
}));
Expanded(
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
InkWell(
child: CircleAvatar(
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: () {
status = "MODULES";
setState(() {});
}),
]))
]);
}

Widget _buildFoodToCook(Food food) {
return Expanded(
child: InkWell(
child: CircleAvatar(
radius: 50,
backgroundImage: NetworkImage(food.image),
),
onTap: () {
foodToCook = food;
cookingStartTime = DateTime.now().millisecondsSinceEpoch;
//print(foodToCook!.timeToCook);
status = "COOKING";
setState(() {});
},
));
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(() {});
}
});
}
}
6 changes: 6 additions & 0 deletions sot_companion/lib/modules/cook_time/class/food_intent.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:flutter/widgets.dart';

class FoodIntent extends Intent{
int num;
FoodIntent(this.num);
}
Loading

0 comments on commit ce317d4

Please sign in to comment.