-
-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a setter for TextBoxComponent.boxConfig and add a convenien…
…ce method to skip per-char buildup (#3490) This PR addresses the concerns in #3488 For convenience, here is the relevant text. > It is a fairly common feature for a game to "type out" dialogue within a TextBoxComponent (as the behavior would be if timePerChar > 0, but also allow the user to skip that type-out effect, and display the dialogue in its entirety (as the behavior would be if timePerChar == 0). This PR implements a setter for TextBoxComponent.boxConfig, allowing for the TextBoxConfig to be changed after TextBoxComponent is instantiated. The `_boxConfig` has been made non-final to allow this field to be modifiable. Additionally, a `skip` method is implemented which more explicitly provides the intended skipping behavior. --------- Co-authored-by: Lukas Klingsbo <[email protected]>
- Loading branch information
Showing
4 changed files
with
142 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
examples/lib/stories/components/skip_text_box_component_example.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flame/components.dart'; | ||
import 'package:flame/game.dart'; | ||
import 'package:flame/input.dart'; | ||
|
||
class SkipTextBoxComponentExample extends FlameGame { | ||
static const String description = ''' | ||
On this example, click on the "Skip" button to display all the text at once. | ||
'''; | ||
|
||
@override | ||
FutureOr<void> onLoad() { | ||
final textBoxComponent = TextBoxComponent( | ||
text: samplePassage, | ||
position: Vector2(48, 48 * 2), | ||
boxConfig: const TextBoxConfig( | ||
maxWidth: 480, | ||
timePerChar: 0.01, | ||
), | ||
); | ||
addAll([ | ||
ButtonComponent( | ||
position: Vector2(48, 48), | ||
button: TextComponent(text: 'Skip'), | ||
onReleased: textBoxComponent.skip, | ||
), | ||
textBoxComponent, | ||
]); | ||
} | ||
|
||
static const String samplePassage = ''' | ||
Look again at that dot. That's here. That's home. That's us. On it everyone you love, everyone you know, everyone you ever heard of, every human being who ever was, lived out their lives. The aggregate of our joy and suffering, thousands of confident religions, ideologies, and economic doctrines, every hunter and forager, every hero and coward, every creator and destroyer of civilization, every king and peasant, every young couple in love, every mother and father, hopeful child, inventor and explorer, every teacher of morals, every corrupt politician, every "superstar," every "supreme leader," every saint and sinner in the history of our species lived there--on a mote of dust suspended in a sunbeam. | ||
The Earth is a very small stage in a vast cosmic arena. Think of the rivers of blood spilled by all those generals and emperors so that, in glory and triumph, they could become the momentary masters of a fraction of a dot. Think of the endless cruelties visited by the inhabitants of one corner of this pixel on the scarcely distinguishable inhabitants of some other corner, how frequent their misunderstandings, how eager they are to kill one another, how fervent their hatreds. | ||
Our posturings, our imagined self-importance, the delusion that we have some privileged position in the Universe, are challenged by this point of pale light. Our planet is a lonely speck in the great enveloping cosmic dark. In our obscurity, in all this vastness, there is no hint that help will come from elsewhere to save us from ourselves. | ||
The Earth is the only world known so far to harbor life. There is nowhere else, at least in the near future, to which our species could migrate. Visit, yes. Settle, not yet. Like it or not, for the moment the Earth is where we make our stand. | ||
It has been said that astronomy is a humbling and character-building experience. There is perhaps no better demonstration of the folly of human conceits than this distant image of our tiny world. To me, it underscores our responsibility to deal more kindly with one another, and to preserve and cherish the pale blue dot, the only home we've ever known. | ||
— Carl Sagan, Pale Blue Dot, 1994 | ||
'''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters