Skip to content

Commit

Permalink
Merge pull request #565 from RafaelBarbosatec/develop
Browse files Browse the repository at this point in the history
Version 3.12.0
  • Loading branch information
RafaelBarbosatec authored Nov 14, 2024
2 parents f75d6ed + a0a3f33 commit 7485938
Show file tree
Hide file tree
Showing 27 changed files with 886 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 3.12.0
- Adds `UseShader` mixin.

# 3.11.0
- Adds `MapNavigator`. Structure to facilitate map navigations.
- Update `MultiScenario` example to use `MapNavigator`.
Expand Down
Binary file added example/assets/images/noise/gradiente_noise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/noise/value_noise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
184 changes: 184 additions & 0 deletions example/assets/images/solaria/map.tmj

Large diffs are not rendered by default.

Binary file added example/assets/images/solaria/solaria_tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions example/assets/images/solaria/solaria_tiles.tsj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ "columns":56,
"image":"solaria_tiles.png",
"imageheight":240,
"imagewidth":448,
"margin":0,
"name":"solaria_tiles",
"spacing":0,
"tilecount":1680,
"tiledversion":"1.10.2",
"tileheight":8,
"tilewidth":8,
"type":"tileset",
"version":"1.10"
}
12 changes: 12 additions & 0 deletions example/lib/pages/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:example/pages/path_finding/path_finding_page.dart';
import 'package:example/pages/player/platform/platform_player_page.dart';
import 'package:example/pages/player/rotation/rotation_player_page.dart';
import 'package:example/pages/player/simple/simple_player_page.dart';
import 'package:example/pages/shader/shader_page.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

Expand Down Expand Up @@ -255,6 +256,16 @@ class _HomePageState extends State<HomePage> {
),
],
),
SectionDrawer(
itens: [
ItemDrawer(
name: 'Shader',
builder: (_) => const ShaderPage(),
codeUrl:
'https://github.com/RafaelBarbosatec/bonfire/blob/develop/example/lib/pages/shader',
),
],
),
SectionDrawer(
name: 'Parallax',
itens: [
Expand All @@ -272,6 +283,7 @@ class _HomePageState extends State<HomePage> {
),
],
),

SectionDrawer(
name: 'Mini games',
itens: [
Expand Down
4 changes: 3 additions & 1 deletion example/lib/pages/player/simple/human.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:async';

import 'package:bonfire/bonfire.dart';
import 'package:example/shared/util/person_sprite_sheet.dart';

class HumanPlayer extends SimplePlayer with BlockMovementCollision {
class HumanPlayer extends SimplePlayer with BlockMovementCollision, UseShader {
HumanPlayer({
required Vector2 position,
}) : super(
Expand Down
49 changes: 49 additions & 0 deletions example/lib/pages/shader/shader_config_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:bonfire/bonfire.dart';
import 'package:flutter/widgets.dart';

class ShaderConfig {
final double distortionStrength;
final Color toneColor;
final Color lightColor;
final double speed;
final double opacity;
final Vector2 lightRange;

ShaderConfig({
this.distortionStrength = 0.05,
this.toneColor = const Color(0xFF5ca4ec),
this.lightColor = const Color(0xFFffffff),
this.speed = 0.04,
this.opacity = 0.7,
Vector2? lightRange,
}) : lightRange = lightRange ?? Vector2(0.4, 0.5);

ShaderConfig copyWith({
double? distortionStrength,
Color? toneColor,
Color? lightColor,
double? speed,
double? opacity,
Vector2? lightRange,
}) {
return ShaderConfig(
distortionStrength: distortionStrength ?? this.distortionStrength,
toneColor: toneColor ?? this.toneColor,
lightColor: lightColor ?? this.lightColor,
speed: speed ?? this.speed,
opacity: opacity ?? this.opacity,
lightRange: lightRange ?? this.lightRange,
);
}
}

class ShaderConfigController extends ChangeNotifier {
ShaderConfig _config = ShaderConfig();
ShaderConfig get config => _config;

void update(ShaderConfig config) {
_config = config;
notifyListeners();
}
}
218 changes: 218 additions & 0 deletions example/lib/pages/shader/shader_config_panel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
import 'package:bonfire/bonfire.dart';
import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';

import 'shader_config_controller.dart';

class ShaderConfigPanel extends StatefulWidget {
final ShaderConfigController controller;
const ShaderConfigPanel({super.key, required this.controller});

@override
State<ShaderConfigPanel> createState() => _ShaderConfigPanelState();
}

class _ShaderConfigPanelState extends State<ShaderConfigPanel> {
late double speed;
late double distortionStrength;
late double opacity;
late Color toneColor;
late Color lightColor;
late Vector2 lightRange;

@override
void initState() {
speed = widget.controller.config.speed;
distortionStrength = widget.controller.config.distortionStrength;
toneColor = widget.controller.config.toneColor;
lightColor = widget.controller.config.lightColor;
opacity = widget.controller.config.opacity;
lightRange = widget.controller.config.lightRange;
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Speed: ${speed.toStringAsFixed(3)}'),
Slider(
value: speed,
min: 0,
max: 0.5,
onChanged: (value) {
setState(() {
speed = value;
});
widget.controller.update(
widget.controller.config.copyWith(
speed: speed,
),
);
},
),
Text(
'Distortion Strength: ${distortionStrength.toStringAsFixed(3)}'),
Slider(
value: distortionStrength,
min: 0,
max: 0.5,
onChanged: (value) {
setState(() {
distortionStrength = value;
});
widget.controller.update(
widget.controller.config.copyWith(
distortionStrength: distortionStrength,
),
);
},
),
Text('Opacity: ${opacity.toStringAsFixed(3)}'),
Slider(
value: opacity,
min: 0,
max: 1,
onChanged: (value) {
setState(() {
opacity = value;
});
widget.controller.update(
widget.controller.config.copyWith(
opacity: opacity,
),
);
},
),
Text(
'Light range: min${lightRange.x.toStringAsFixed(3)} | max${lightRange.y.toStringAsFixed(3)}'),
RangeSlider(
values: RangeValues(lightRange.x, lightRange.y),
min: 0,
max: 1,
onChanged: (value) {
setState(() {
lightRange = Vector2(value.start, value.end);
});
widget.controller.update(
widget.controller.config.copyWith(
lightRange: lightRange,
),
);
},
),
const SizedBox(
height: 16,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
const Text('Tone color'),
const SizedBox(
width: 16,
),
InkWell(
onTap: () {
showColorPicker(
toneColor,
(value) {
setState(() {
toneColor = value;
});
widget.controller.update(
widget.controller.config.copyWith(
toneColor: toneColor,
),
);
},
);
},
child: Container(
decoration: BoxDecoration(
color: toneColor,
shape: BoxShape.circle,
),
width: 30,
height: 30,
),
),
],
),
),
const SizedBox(
height: 16,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
const Text('Light color'),
const SizedBox(
width: 16,
),
InkWell(
onTap: () {
showColorPicker(
lightColor,
(value) {
setState(() {
lightColor = value;
});
widget.controller.update(
widget.controller.config.copyWith(
lightColor: lightColor,
),
);
},
);
},
child: Container(
decoration: BoxDecoration(
color: lightColor,
shape: BoxShape.circle,
),
width: 30,
height: 30,
),
),
],
),
)
],
),
),
),
);
}

void showColorPicker(Color color, ValueChanged<Color> onChange) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Pick a color!'),
content: SingleChildScrollView(
child: ColorPicker(
pickerColor: color,
onColorChanged: onChange,
),
),
actions: <Widget>[
ElevatedButton(
child: const Text('Got it'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}
Loading

0 comments on commit 7485938

Please sign in to comment.