Skip to content

Commit

Permalink
Dialog box now supports styling and automatic pages
Browse files Browse the repository at this point in the history
Added example dialog box to project.
  • Loading branch information
vchelaru committed Feb 17, 2024
1 parent 382257f commit bc56371
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,24 @@ private void ShowInternal(string text, bool forceImmediatePrint)
textComponent.SetProperty("Text", text);


var tags = BbCodeParser.Parse(text, CustomSetPropertyOnRenderable.Tags);
var strippedLength = BbCodeParser.RemoveTags(text, tags).Length;

var shouldPrintCharacterByCharacter = LettersPerSecond > 0 && !forceImmediatePrint;
if(shouldPrintCharacterByCharacter)
{
coreTextObject.MaxLettersToShow = 0;
var allTextShownState = new global::Gum.DataTypes.Variables.StateSave();


allTextShownState.Variables.Add(new global::Gum.DataTypes.Variables.VariableSave
{
Name = "TextInstance.MaxLettersToShow",
Value = text.Length,
Value = strippedLength,
SetsValue = true
});

var duration = text.Length / (float)LettersPerSecond;
var duration = strippedLength / (float)LettersPerSecond;

showLetterTweener = this.Visual.InterpolateTo(NoTextShownState, allTextShownState, duration, InterpolationType.Linear, Easing.Out);

Expand All @@ -360,7 +365,7 @@ private void ShowInternal(string text, bool forceImmediatePrint)
}
else
{
coreTextObject.MaxLettersToShow = text.Length;
coreTextObject.MaxLettersToShow = strippedLength;

if (TakingInput && continueIndicatorInstance != null)
{
Expand All @@ -378,6 +383,7 @@ private void ShowInternal(string text, bool forceImmediatePrint)

private string[] ConvertToPages(string text)
{

var limitsLines =
this.coreTextObject.MaxNumberOfLines != null ||
this.textComponent.HeightUnits != global::Gum.DataTypes.DimensionUnitType.RelativeToChildren;
Expand All @@ -390,14 +396,18 @@ private string[] ConvertToPages(string text)
}
else
{
var foundTags = BbCodeParser.Parse(text, CustomSetPropertyOnRenderable.Tags);

var withRemovedTags = BbCodeParser.RemoveTags(text, foundTags);

var unlimitedLines = new List<string>();
var oldVerticalMode = this.coreTextObject.TextOverflowVerticalMode;
this.coreTextObject.TextOverflowVerticalMode = RenderingLibrary.Graphics.TextOverflowVerticalMode.SpillOver;
coreTextObject.RawText = text;
coreTextObject.RawText = withRemovedTags;
coreTextObject.UpdateLines(unlimitedLines);

this.coreTextObject.TextOverflowVerticalMode = oldVerticalMode;
this.textComponent.SetProperty("Text", text);
this.textComponent.SetProperty("Text", withRemovedTags);

var limitedLines = coreTextObject.WrappedText;

Expand All @@ -416,13 +426,21 @@ private string[] ConvertToPages(string text)
currentPage.Clear();

StringBuilder stringBuilder = new StringBuilder();
int strippedTextCount = 0;
while(absoluteLineNumber < unlimitedLines.Count)
{
stringBuilder.Clear();

for(int i = 0; i < limitedLines.Count && absoluteLineNumber < unlimitedLines.Count; i++)
{
stringBuilder.Append(unlimitedLines[absoluteLineNumber]);
var toAppend = unlimitedLines[absoluteLineNumber];
var sizeBeforeTags = toAppend.Length;
if(foundTags.Count > 0)
{
toAppend = BbCodeParser.AddTags(toAppend, foundTags, strippedTextCount);
}
strippedTextCount += sizeBeforeTags;
stringBuilder.Append(toAppend);
absoluteLineNumber++;
}
pages.Add(stringBuilder.ToString());
Expand Down Expand Up @@ -472,7 +490,10 @@ private void ReactToInputForAdvancing(bool forceImmediatePrint)
return;
}
//////////////////End Early Out///////////////////
var hasMoreToType = coreTextObject.MaxLettersToShow < currentPageText?.Length;
//var hasMoreToType = coreTextObject.MaxLettersToShow < currentPageText?.Length;

// Use the raw text since that has stripped out the tags
var hasMoreToType = coreTextObject.MaxLettersToShow < coreTextObject.RawText.Length;
if (hasMoreToType)
{
showLetterTweener?.Stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"AspectRatioWidth": 16.0,
"AspectRatioHeight": 9.0,
"SupportLandscape": true,
"AllowWindowResizing": true,
"Scale": 100,
"ScaleGum": 100,
"DominantInternalCoordinates": 1,
Expand Down
24 changes: 16 additions & 8 deletions Samples/FormsSampleProject/FormsSampleProject/Screens/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,28 @@ void CustomInitialize()
private async void HandleShowDialogButtonClicked(object sender, EventArgs e)
{
var dialog = new DialogBox();
//dialog.LettersPerSecond = 24;
dialog.LettersPerSecond = null;
dialog.LettersPerSecond = 47;
dialog.IsFocused = true;
var dialogVisual = dialog.Visual;
dialogVisual.XUnits = Gum.Converters.GeneralUnitType.PixelsFromMiddle;
dialogVisual.XOrigin = RenderingLibrary.Graphics.HorizontalAlignment.Center;
dialogVisual.Y = 20;
dialogVisual.Y = -20;
dialogVisual.YUnits = Gum.Converters.GeneralUnitType.PixelsFromLarge;
dialogVisual.YOrigin = RenderingLibrary.Graphics.VerticalAlignment.Bottom;

await dialog.ShowAsync("This is a DialogBox in [Color=Red]FlatRedBall.Forms[/Color]. It supports " +
"lots of features including typing out the text [Color=Yellow]letter-by-letter[/Color], multiple pages, " +
"and even [Color=Green]styling[/Color] using BBCode. Wow, how handy! You can create mulitple " +
"pages by explicitly giving it a string array, or you can give it a long string and let the " +
"dialog box [Color=Pink]automatically[/Color] handle the multiple pages.");

await dialog.ShowAsync("This is some really long text. We want to show long text so that it " +
"line wraps and so that it has enough text to fill an entire page. The DialogBox control " +
"should automatically detect if the text is too long for a single page and it should break " +
"it up into multiple pages. You can advance this dialog by clicking on it with the mouse or " +
"by pressing the space bar on the keyboard");


//await dialog.ShowAsync("This is [Color=Orange]some really[/Color] long [Color=Pink]text[/Color]. [Color=Purple]We[/Color] want to show long text so that it " +
// "line wraps [Color=Cyan]and[/Color] so that it has [Color=Green]enough[/Color] text to fill an [Color=Yellow]entire page[/Color]. The DialogBox control " +
// "should automatically detect if the text is too long for a single page and it should break " +
// "it up into multiple pages. You can advance this dialog by clicking on it with the [Color=Blue]mouse[/Color] or " +
// "by pressing the [Color=Gold]space bar[/Color] on the keyboard.");

dialog.Visual.RemoveFromManagers();
}
Expand Down

0 comments on commit bc56371

Please sign in to comment.