Code/ChitChat/UI/DefaultDialoguePanel.razor
@using Sandbox;
@using Sandbox.UI;
@using System.Collections.Generic;
@namespace ChitChat
@inherits DialoguePanelBase
<root>
<div class="screen-container">
<div class="dialogue-container">
@if (PicturePosition == PicturePosition.Left && !IsChoice)
{
<div style="margin: 10px; background-color: #333333; border-radius: 10px; overflow: hidden;">
<img src="@TexturePath" style="height: 300px; width: 300px;" />
</div>
}
<div style="display: flex; flex-direction: column; flex: 1;">
@if (IsChoice)
{
<div style="margin: 5px; display: flex; flex-direction: column;">
@for (int i = 0; i < Choices.Count; i++)
{
int index = i;
<div onclick="@(() => OnChoiceClicked(index))" class="choice-button">
<p style="margin:auto; font-size: 28px;">@Choices[i].Text</p>
</div>
}
</div>
}
else
{
@if (!string.IsNullOrEmpty(CharacterName))
{
<div style="margin: 10px; background-color: #333333; border-radius: 10px;">
<h1 style="font-size: 40px; font-weight: bold; margin: 10px;">@CharacterName</h1>
</div>
}
<div style="margin: 10px; background-color: #333333; border-radius: 10px; overflow: hidden;">
<p style="margin: 10px; font-size: 28px; min-height: 188px;">@DialogueText</p>
<IconPanel style="margin-left: auto; margin-top:auto; padding: 10px;">arrow_drop_down_circle</IconPanel>
</div>
}
</div>
@if (PicturePosition == PicturePosition.Right && !IsChoice)
{
<div style="margin: 10px; background-color: #333333; border-radius: 10px;">
<img src="@TexturePath" style="height: 300px; width: 300px;" />
</div>
}
</div>
</div>
</root>
@code
{
public string DialogueText { get; set; } = "Placeholder text";
public string CharacterName { get; set; } = "Placeholder name";
public string TexturePath { get; set; } = "";
public PicturePosition PicturePosition { get; set; } = PicturePosition.Left;
public List<Choice> Choices { get; set; }
public bool IsChoice { get; set; } = false;
public override void OnText(string text)
{
DialogueText = text;
IsChoice = false;
}
public override void OnCharacterName(string name)
{
CharacterName = name;
}
public override void OnCharacterPicture(Texture tex, PicturePosition position)
{
Log.Info(tex);
if(tex != null)
TexturePath = tex.ResourcePath;
PicturePosition = position;
}
public override void OnChoices(List<Choice> choices)
{
Choices = choices;
IsChoice = true;
}
public void OnChoiceClicked(int index)
{
onChoiceClicked?.Invoke(Choices[index].Data);
}
/// <summary>
/// The hash determines if the system should be rebuilt. If it changes, it will be rebuilt
/// </summary>
protected override int BuildHash() => System.HashCode.Combine(DialogueText, CharacterName, TexturePath, PicturePosition, Choices);
}