Skip to content

Commit

Permalink
option to enable-disable full app coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
KumoKairo committed Jan 16, 2023
1 parent 8bd4703 commit 4936023
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 38 deletions.
28 changes: 27 additions & 1 deletion lib/dataController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'main.dart';
import 'package:path_provider/path_provider.dart';
import 'package:file_picker/file_picker.dart';
import 'dart:io';
import 'package:shared_preferences/shared_preferences.dart';

class PerkPathToReadableName {
String path;
Expand All @@ -16,7 +17,10 @@ class PerkPathToReadableName {
}

class DataController extends GetxController {
static const String shouldColorEverythingStoreKey = "color_everything";

final beforeCapitalLetterSplit = RegExp(r"(?=[A-Z])");
late SharedPreferences _prefs;

late Function onColorUpdated;
BuildContext? lastContext;
Expand All @@ -25,6 +29,7 @@ class DataController extends GetxController {
// no RxColor unfortunately
Color accentColor = CustomColors.appBackground;
var highlightedPerkPath = "".obs;
var shouldColorEverything = false.obs;
final portraitsScrollController = ScrollController();
final perksGridScrollController = ScrollController();

Expand All @@ -35,7 +40,21 @@ class DataController extends GetxController {
List<PerkPathToReadableName>? allAvailablePerks;

void forceRefresh() {
onColorUpdated();
update();
}

void changeColorSettingsAndSave(bool value) {
shouldColorEverything.value = value;
_prefs.setBool(shouldColorEverythingStoreKey, value);
update();
}

@override
void onReady() async {
_prefs = await SharedPreferences.getInstance();
var storedColorEverything = _prefs.getBool(shouldColorEverythingStoreKey);
shouldColorEverything.value = storedColorEverything ?? false;
super.onReady();
}

Future<void> initializePerksAndKillers({bool force = false}) async {
Expand Down Expand Up @@ -158,6 +177,8 @@ class DataController extends GetxController {
.replaceAll("0x", "");
var intAccentColor = int.parse(accentColor, radix: 16);
this.accentColor = Color(intAccentColor);

update();
}
}

Expand Down Expand Up @@ -204,4 +225,9 @@ class DataController extends GetxController {
highlightedPerkPath.value = "",
});
}

void changeAccentColor(Color color) {
accentColor = color;
update();
}
}
142 changes: 105 additions & 37 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class AllPerksStreakHelper extends StatefulWidget {
class _AllPerksStreakHelperState extends State<AllPerksStreakHelper> {
final data = Get.put(DataController());

bool isChecked = false;

_AllPerksStreakHelperState() {
data.addListener(() => setState(() {}));
}
Expand All @@ -42,8 +44,7 @@ class _AllPerksStreakHelperState extends State<AllPerksStreakHelper> {
final perksKey = GlobalKey<_KillersPerksViewWidgetState>();

void changeColor(Color color) {
data.accentColor = color;
applyChangeColor();
data.changeAccentColor(color);
}

void applyChangeColor() {
Expand Down Expand Up @@ -76,7 +77,9 @@ class _AllPerksStreakHelperState extends State<AllPerksStreakHelper> {
appBar: AppBar(
backgroundColor: data.accentColor,
leading: PopupMenuButton(
color: CustomColors.appBackground,
color: data.shouldColorEverything.value
? data.accentColor
: CustomColors.appBackground,
icon: const Icon(Icons.menu),
itemBuilder: (context) {
return [
Expand Down Expand Up @@ -130,40 +133,22 @@ class _AllPerksStreakHelperState extends State<AllPerksStreakHelper> {
}

Future<void> _dialogBuilder(BuildContext context) {
Color getColor(Set<MaterialState> states) {
const Set<MaterialState> interactiveStates = <MaterialState>{
MaterialState.pressed,
MaterialState.hovered,
MaterialState.focused,
};
if (states.any(interactiveStates.contains)) {
return Colors.blue;
}
return Colors.red;
}

return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
insetPadding: const EdgeInsets.symmetric(
horizontal: 50.0,
vertical: 100.0,
),
backgroundColor: CustomColors.appBackground,
title: const Text(
'Pick a color',
style: TextStyle(color: CustomColors.fontColor),
),
content: SingleChildScrollView(
child: BlockPicker(
pickerColor: data.accentColor,
onColorChanged: changeColor,
availableColors: CustomColors.accentColors,
)),
actions: [
ElevatedButton(
style: const ButtonStyle(
foregroundColor:
MaterialStatePropertyAll<Color>(CustomColors.fontColor),
backgroundColor: MaterialStatePropertyAll<Color>(
CustomColors.buttonsColor)),
child: const Text('Got it'),
onPressed: () {
applyChangeColor();
Navigator.of(context).pop();
},
),
],
);
return CustomDialog();
},
);
}
Expand Down Expand Up @@ -213,7 +198,9 @@ class _KillersPerksViewWidgetState extends State<KillersPerksViewWidget> {
height: 88.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: CustomColors.appBackground,
color: data.shouldColorEverything.value
? data.accentColor
: CustomColors.appBackground,
border: Border.all(
color:
killerPerk == data.highlightedPerkPath.value
Expand Down Expand Up @@ -264,7 +251,9 @@ class _KillersPerksViewWidgetState extends State<KillersPerksViewWidget> {
shape: BoxShape.rectangle,
borderRadius:
const BorderRadius.all(Radius.circular(8.0)),
color: CustomColors.appBackground),
color: data.shouldColorEverything.value
? data.accentColor
: CustomColors.appBackground),
margin:
const EdgeInsets.symmetric(horizontal: 8.0, vertical: 2),
child: Row(children: [
Expand All @@ -281,7 +270,9 @@ class _KillersPerksViewWidgetState extends State<KillersPerksViewWidget> {
height: 88.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: CustomColors.appBackground,
color: data.shouldColorEverything.value
? data.accentColor
: CustomColors.appBackground,
border: Border.all(
color: perk == data.highlightedPerkPath.value
? CustomColors.perkHighlight
Expand Down Expand Up @@ -362,3 +353,80 @@ class _KillersPerksViewWidgetState extends State<KillersPerksViewWidget> {
}));
}
}

class CustomDialog extends StatefulWidget {
@override
_CustomDialogState createState() => _CustomDialogState();
}

class _CustomDialogState extends State<CustomDialog> {
final data = Get.find<DataController>();

bool isChecked = false;

void changeColor(Color color) {
data.changeAccentColor(color);
}

void applyChangeColor() {
setState(() {});
}

@override
Widget build(BuildContext context) {
Color getCheckboxFillColor(Set<MaterialState> states) {
return CustomColors.fontColor;
}

Color getCheckboxOverlayColor(Set<MaterialState> states) {
return Colors.transparent;
}

return AlertDialog(
insetPadding: const EdgeInsets.symmetric(
horizontal: 50.0,
vertical: 100.0,
),
backgroundColor: CustomColors.appBackground,
title: const Text(
'Pick a color',
style: TextStyle(color: CustomColors.fontColor),
),
content: SingleChildScrollView(
child: BlockPicker(
pickerColor: data.accentColor,
onColorChanged: changeColor,
availableColors: CustomColors.accentColors,
)),
actions: [
const Text(
"Color everything",
style: TextStyle(color: CustomColors.fontColor, fontSize: 16),
),
Obx(() => Checkbox(
value: data.shouldColorEverything.value,
checkColor: CustomColors.itemsBorderColor,
activeColor: CustomColors.appBackground,
overlayColor:
MaterialStateProperty.resolveWith(getCheckboxOverlayColor),
fillColor: MaterialStateProperty.resolveWith(getCheckboxFillColor),
onChanged: (value) => setState(() {
data.changeColorSettingsAndSave(value!);
}))),
const Padding(padding: EdgeInsets.fromLTRB(0, 0, 20, 0)),
ElevatedButton(
style: const ButtonStyle(
foregroundColor:
MaterialStatePropertyAll<Color>(CustomColors.fontColor),
backgroundColor:
MaterialStatePropertyAll<Color>(CustomColors.buttonsColor)),
child: const Text('Got it'),
onPressed: () {
applyChangeColor();
Navigator.of(context).pop();
},
),
],
);
}
}
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import FlutterMacOS
import Foundation

import path_provider_macos
import shared_preferences_foundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
}
49 changes: 49 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,55 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.4"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.16"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.14"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
sky_engine:
dependency: transitive
description: flutter
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
file_picker: ^5.2.5
flutter_colorpicker: ^1.0.3
get: ^4.6.5
shared_preferences: ^2.0.16

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 4936023

Please sign in to comment.