Skip to content

Commit

Permalink
Merge pull request #316 from tzachshabtay/dialog_font
Browse files Browse the repository at this point in the history
Dialogs- use default text font as default for dialog option labels
  • Loading branch information
tzachshabtay committed May 5, 2019
2 parents 649342f + 017d151 commit 49feb71
Show file tree
Hide file tree
Showing 28 changed files with 382 additions and 199 deletions.
29 changes: 29 additions & 0 deletions Source/AGS.API/Game/Settings/IDefaultFonts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AGS.API
{
/// <summary>
/// Allows to set the default fonts to be used in the game.
/// </summary>
public interface IDefaultFonts
{
/// <summary>
/// Gets or sets the default speech font (for text displayed when characters are speaking if no other font was given).
/// </summary>
/// <value>The speech font.</value>
IFont Speech { get; set; }

/// <summary>
/// Gets or sets the default text font (for any non-speech related text shown on screen if no other font was given).
/// </summary>
/// <value>The text font.</value>
IFont Text { get; set; }

/// <summary>
/// Gets or sets the default dialog font (for rendering the dialog options). Leave as null to use the default text font as the default dialog font.
/// </summary>
IFont Dialogs { get; set; }
}
}
18 changes: 8 additions & 10 deletions Source/AGS.API/Game/Settings/IDefaultsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@
public interface IDefaultsSettings
{
/// <summary>
/// Gets or sets the default speech font (for text displayed when characters are speaking if no other font was given).
/// Gets or sets the default fonts to be used in the game.
/// </summary>
/// <value>The speech font.</value>
IFont SpeechFont { get; set; }

/// <summary>
/// Gets or sets the default text font (for any non-speech related text shown on screen if no other font was given).
/// </summary>
/// <value>The text font.</value>
IFont TextFont { get; set; }
IDefaultFonts Fonts { get; set; }

/// <summary>
/// Gets or sets the default skin (which applies a consistent look to GUIs).
Expand All @@ -28,5 +21,10 @@ public interface IDefaultsSettings
/// </summary>
/// <value>The message box.</value>
IMessageBoxSettings MessageBox { get; set; }

/// <summary>
/// Gets or sets default settings to control how dialogs look and behave.
/// </summary>
IDialogSettings Dialog { get; set; }
}
}
}
28 changes: 28 additions & 0 deletions Source/AGS.API/Game/Settings/IDialogSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace AGS.API
{
/// <summary>
/// Allows to set default settings to control how dialogs look and behave.
/// </summary>
public interface IDialogSettings
{
/// <summary>
/// The default <see cref="IRenderLayer"/> used to display the dialogs (by default, this will be AGSLayers.Dialog).
/// </summary>
IRenderLayer RenderLayer { get; set; }

/// <summary>
/// The default text configurations for showing dialog options when they're in their "normal" state.
/// </summary>
ITextConfig Idle { get; set; }

/// <summary>
/// The default text configurations for showing dialog options when they're hovered on via the mouse.
/// </summary>
ITextConfig Hovered { get; set; }

/// <summary>
/// The default text configurations for showing dialog options after they have already been used before.
/// </summary>
ITextConfig Chosen { get; set; }
}
}
277 changes: 139 additions & 138 deletions Source/Demo/DemoQuest/Dialogs/BemanDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,155 +7,156 @@

namespace DemoGame
{
public class BemanDialogs
{
private IGame _game;
public class BemanDialogs
{
private IGame _game;

public IDialog StartDialog { get; private set; }
public IDialog StartDialog { get; private set; }

public void Load(IGame game)
{
_game = game;
public void Load(IGame game)
{
_game = game;
_game.Events.OnSavedGameLoad.Subscribe(onSavedGameLoaded);
initDialogs();
}

private void onSavedGameLoaded()
{
clearDialogs();
initDialogs();
}

private void initDialogs()
{
IGameFactory factory = _game.Factory;
StartDialog = factory.Dialog.GetDialog("Dialog: Beman- Start");
createStartDialog(factory, createQuestionsDialog(factory), createShadersDialog(factory));
}

private void clearDialogs()
{
HashSet<string> ids = new HashSet<string> ();
getDialogGraphics(StartDialog, ids);
_game.State.UI.RemoveAll(o => ids.Contains(o.ID));
}

private void getDialogGraphics(IDialog dialog, HashSet<string> ids)
{
if (dialog == null) return;
if (!ids.Add(dialog.Graphics.ID)) return;
foreach (var option in dialog.Options)
{
option.Dispose();
ids.Add(option.Label.ID);
getDialogGraphics(option.ChangeDialogWhenFinished, ids);
}
}

private void createStartDialog(IGameFactory factory, IDialog questionsDialog, IDialog shadersDialog)
{
StartDialog.StartupActions.AddPlayerText("Hello there!");
StartDialog.StartupActions.AddText(Characters.Beman, "Hello yourself!");
StartDialog.StartupActions.AddConditionalActions(() => Repeat.OnceOnly("BemanStartDialog"));
StartDialog.StartupActions.AddText(Characters.Beman, "God, that's a relief.", "It's good to see I'm not alone in this place.");

IDialogOption option1 = factory.Dialog.GetDialogOption("Who are you?", showOnce: true);
option1.AddText(Characters.Beman, "I am Beman, and you are?");
option1.AddPlayerText("I am Cris.");

IDialogOption option2 = factory.Dialog.GetDialogOption("What is this place?");
option2.AddText(Characters.Beman, "I have no idea. I just woke up here.");
option2.AddPlayerText("Wow, seems like we share a similar story.");

IDialogOption option3 = factory.Dialog.GetDialogOption("Tell me a little bit about yourself.", speakOption: false);
option3.AddText(Characters.Beman, "What do you want to know?");
option3.ChangeDialogWhenFinished = questionsDialog;

IDialogOption option4 = factory.Dialog.GetDialogOption("Can I set a shader?");
option4.AddText(Characters.Beman, "Sure, choose a shader...");
option4.ChangeDialogWhenFinished = shadersDialog;

IDialogOption option5 = factory.Dialog.GetDialogOption("I'll be going now.");
option5.AddText(Characters.Beman, "Ok, see you around.");
option5.ExitDialogWhenFinished = true;

StartDialog.AddOptions(option1, option2, option3, option4, option5);
}

private IDialog createQuestionsDialog(IGameFactory factory)
{
IDialogOption option1 = factory.Dialog.GetDialogOption("Where are you from?");
option1.AddText(Characters.Beman, "I'm from Sweden.");

IDialogOption option2 = factory.Dialog.GetDialogOption("What do you do?");
option2.AddText(Characters.Beman, "I'm a hobbyist game developer.");

IDialogOption option3 = factory.Dialog.GetDialogOption("Can I start a scene?");
option3.ExitDialogWhenFinished = true;
option3.AddText(Characters.Beman, "Go for it, though remember that the user can skip the scene by pressing any key on the keyboard");
initDialogs();
}

private void onSavedGameLoaded()
{
clearDialogs();
initDialogs();
}

private void initDialogs()
{
IGameFactory factory = _game.Factory;
StartDialog = factory.Dialog.GetDialog("Dialog: Beman- Start");
createStartDialog(factory, createQuestionsDialog(factory), createShadersDialog(factory));
}

private void clearDialogs()
{
HashSet<string> ids = new HashSet<string>();
getDialogGraphics(StartDialog, ids);
_game.State.UI.RemoveAll(o => ids.Contains(o.ID));
}

private void getDialogGraphics(IDialog dialog, HashSet<string> ids)
{
if (dialog == null)
return;
if (!ids.Add(dialog.Graphics.ID))
return;
foreach (var option in dialog.Options)
{
option.Dispose();
ids.Add(option.Label.ID);
getDialogGraphics(option.ChangeDialogWhenFinished, ids);
}
}

private void createStartDialog(IGameFactory factory, IDialog questionsDialog, IDialog shadersDialog)
{
StartDialog.StartupActions.AddPlayerText("Hello there!");
StartDialog.StartupActions.AddText(Characters.Beman, "Hello yourself!");
StartDialog.StartupActions.AddConditionalActions(() => Repeat.OnceOnly("BemanStartDialog"));
StartDialog.StartupActions.AddText(Characters.Beman, "God, that's a relief.", "It's good to see I'm not alone in this place.");

IDialogOption option1 = factory.Dialog.GetDialogOption("Who are you?", showOnce: true);
option1.AddText(Characters.Beman, "I am Beman, and you are?");
option1.AddPlayerText("I am Cris.");

IDialogOption option2 = factory.Dialog.GetDialogOption("What is this place?");
option2.AddText(Characters.Beman, "I have no idea. I just woke up here.");
option2.AddPlayerText("Wow, seems like we share a similar story.");

IDialogOption option3 = factory.Dialog.GetDialogOption("Tell me a little bit about yourself.", speakOption: false);
option3.AddText(Characters.Beman, "What do you want to know?");
option3.ChangeDialogWhenFinished = questionsDialog;

IDialogOption option4 = factory.Dialog.GetDialogOption("Can I set a shader?");
option4.AddText(Characters.Beman, "Sure, choose a shader...");
option4.ChangeDialogWhenFinished = shadersDialog;

IDialogOption option5 = factory.Dialog.GetDialogOption("I'll be going now.");
option5.AddText(Characters.Beman, "Ok, see you around.");
option5.ExitDialogWhenFinished = true;

StartDialog.AddOptions(option1, option2, option3, option4, option5);
}

private IDialog createQuestionsDialog(IGameFactory factory)
{
IDialogOption option1 = factory.Dialog.GetDialogOption("Where are you from?");
option1.AddText(Characters.Beman, "I'm from Sweden.");

IDialogOption option2 = factory.Dialog.GetDialogOption("What do you do?");
option2.AddText(Characters.Beman, "I'm a hobbyist game developer.");

IDialogOption option3 = factory.Dialog.GetDialogOption("Can I start a scene?");
option3.ExitDialogWhenFinished = true;
option3.AddText(Characters.Beman, "Go for it, though remember that the user can skip the scene by pressing any key on the keyboard");
option3.AddAsyncConditionalActions(startAScene);

IDialogOption option4 = factory.Dialog.GetDialogOption("That's all I have...");
option4.ChangeDialogWhenFinished = StartDialog;

IDialog dialog = factory.Dialog.GetDialog("Dialog: Beman- Questions");
dialog.AddOptions(option1, option2, option3, option4);

return dialog;
}

private IDialog createShadersDialog(IGameFactory factory)
{
IDialogOption option1 = factory.Dialog.GetDialogOption("Normal");
IDialogOption option2 = factory.Dialog.GetDialogOption("Grayscale");
IDialogOption option3 = factory.Dialog.GetDialogOption("Sepia");
IDialogOption option4 = factory.Dialog.GetDialogOption("Soft Sepia");
IDialogOption option5 = factory.Dialog.GetDialogOption("Vignette");
IDialogOption option6 = factory.Dialog.GetDialogOption("Blur me!");
IDialogOption option7 = factory.Dialog.GetDialogOption("Shake the screen!");
IDialogOption option8 = factory.Dialog.GetDialogOption("Actually, I don't want a shader!");

setShaderOption(option1, () => Shaders.SetStandardShader());
setShaderOption(option2, () => Shaders.SetGrayscaleShader());
setShaderOption(option3, () => Shaders.SetSepiaShader());
setShaderOption(option4, () => Shaders.SetSoftSepiaShader());
setShaderOption(option5, () => Shaders.SetVignetteShader());
setShaderOption(option6, () => Shaders.SetBlurShader());
setShaderOption(option7, () => Shaders.SetShakeShader());
setShaderOption(option8, () => Shaders.TurnOffShader());

IDialog dialog = factory.Dialog.GetDialog("Dialog: Beman- Shaders");
dialog.AddOptions(option1, option2, option3, option4, option5, option6, option7, option8);

return dialog;
}

private void setShaderOption(IDialogOption option, Action setShader)
{
option.AddText(Characters.Beman, "Your wish is my command.");
option.AddActions(setShader);
option.ExitDialogWhenFinished = true;
}

private async Task<bool> startAScene()
{
ICharacter player = _game.State.Player;
_game.State.Cutscene.Start();
IDialogOption option4 = factory.Dialog.GetDialogOption("That's all I have...");
option4.ChangeDialogWhenFinished = StartDialog;

IDialog dialog = factory.Dialog.GetDialog("Dialog: Beman- Questions");
dialog.AddOptions(option1, option2, option3, option4);

return dialog;
}

private IDialog createShadersDialog(IGameFactory factory)
{
IDialogOption option1 = factory.Dialog.GetDialogOption("Normal");
IDialogOption option2 = factory.Dialog.GetDialogOption("Grayscale");
IDialogOption option3 = factory.Dialog.GetDialogOption("Sepia");
IDialogOption option4 = factory.Dialog.GetDialogOption("Soft Sepia");
IDialogOption option5 = factory.Dialog.GetDialogOption("Vignette");
IDialogOption option6 = factory.Dialog.GetDialogOption("Blur me!");
IDialogOption option7 = factory.Dialog.GetDialogOption("Shake the screen!");
IDialogOption option8 = factory.Dialog.GetDialogOption("Actually, I don't want a shader!");

setShaderOption(option1, () => Shaders.SetStandardShader());
setShaderOption(option2, () => Shaders.SetGrayscaleShader());
setShaderOption(option3, () => Shaders.SetSepiaShader());
setShaderOption(option4, () => Shaders.SetSoftSepiaShader());
setShaderOption(option5, () => Shaders.SetVignetteShader());
setShaderOption(option6, () => Shaders.SetBlurShader());
setShaderOption(option7, () => Shaders.SetShakeShader());
setShaderOption(option8, () => Shaders.TurnOffShader());

IDialog dialog = factory.Dialog.GetDialog("Dialog: Beman- Shaders");
dialog.AddOptions(option1, option2, option3, option4, option5, option6, option7, option8);

return dialog;
}

private void setShaderOption(IDialogOption option, Action setShader)
{
option.AddText(Characters.Beman, "Your wish is my command.");
option.AddActions(setShader);
option.ExitDialogWhenFinished = true;
}

private async Task<bool> startAScene()
{
ICharacter player = _game.State.Player;
_game.State.Cutscene.Start();

await player.SayAsync("Scene is now in session.");
var leftEdge = player.Room.Edges.Left;
leftEdge.Enabled = false;
await player.WalkAsync((0f, player.Y));
await player.WalkAsync((0f, player.Y));
leftEdge.Enabled = true;
await player.ChangeRoomAsync(Rooms.EmptyStreet.Result, 400f);
await player.ChangeRoomAsync(Rooms.EmptyStreet.Result, 400f);
await player.SayAsync("This scene involves switching rooms!");
await player.WalkAsync((70f, player.Y));
await player.WalkAsync((70f, player.Y));

_game.State.Cutscene.End();
_game.State.Cutscene.End();

await player.SayAsync("End scene.");
return true;
}
}
await player.SayAsync("End scene.");
return true;
}
}
}

0 comments on commit 49feb71

Please sign in to comment.