Confirmedusers, Bureaucrats, editor, Administrators
1,779
edits
(→TBD) |
|||
Line 56: | Line 56: | ||
* <code>CairoFont.WhiteDetailText()</code>: Create a new font configuration based on a often used size and color, in this case white with font size 14 | * <code>CairoFont.WhiteDetailText()</code>: Create a new font configuration based on a often used size and color, in this case white with font size 14 | ||
* <code>SingleComposer</code>: This property is defined in the <code>GuiDialog</code> class. Its a getter/setter to the <code>Composers</code> dictionary. It contains all the "windows" of this dialog which are then rendered / handled by this GuiDialog instance | * <code>SingleComposer</code>: This property is defined in the <code>GuiDialog</code> class. Its a getter/setter to the <code>Composers</code> dictionary. It contains all the "windows" of this dialog which are then rendered / handled by this GuiDialog instance | ||
== Examples == | |||
A simple standard dialog, triggered by the keyboard key 'U' | |||
<syntaxhighlight lang="c#"> | |||
public class GuiDialogAnnoyingText : GuiDialog | |||
{ | |||
public override string ToggleKeyCombinationCode => "annoyingtextgui"; | |||
public GuiDialogAnnoyingText(ICoreClientAPI capi) : base(capi) | |||
{ | |||
SetupDialog(); | |||
} | |||
private void SetupDialog() | |||
{ | |||
// Auto-sized dialog at the center of the screen | |||
ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle); | |||
// Just a simple 300x300 pixel box | |||
ElementBounds textBounds = ElementBounds.Fixed(0, 40, 300, 100); | |||
// Background boundaries. Again, just make it fit it's child elements, then add the text as a child element | |||
ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); | |||
bgBounds.BothSizing = ElementSizing.FitToChildren; | |||
bgBounds.WithChildren(textBounds); | |||
// Lastly, create the dialog | |||
SingleComposer = capi.Gui.CreateCompo("myAwesomeDialog", dialogBounds) | |||
.AddShadedDialogBG(bgBounds) | |||
.AddDialogTitleBar("Heck yeah!", OnTitleBarCloseClicked) | |||
.AddStaticText("This is a piece of text at the center of your screen - Enjoy!", CairoFont.WhiteDetailText(), textBounds) | |||
.Compose() | |||
; | |||
} | |||
private void OnTitleBarCloseClicked() | |||
{ | |||
TryClose(); | |||
} | |||
} | |||
public class AnnoyingTextSystem : ModSystem | |||
{ | |||
ICoreClientAPI capi; | |||
GuiDialog dialog; | |||
public override bool ShouldLoad(EnumAppSide forSide) | |||
{ | |||
return forSide == EnumAppSide.Client; | |||
} | |||
public override void StartClientSide(ICoreClientAPI api) | |||
{ | |||
base.StartClientSide(api); | |||
dialog = new GuiDialogAnnoyingText(api); | |||
capi = api; | |||
capi.Input.RegisterHotKey("annoyingtextgui", "Annoys you with annoyingly centered text", GlKeys.U, HotkeyType.GUIOrOtherControls); | |||
capi.Input.SetHotKeyHandler("annoyingtextgui", ToggleGui); | |||
} | |||
private bool ToggleGui(KeyCombination comb) | |||
{ | |||
if (dialog.IsOpened()) dialog.TryClose(); | |||
else dialog.TryOpen(); | |||
return true; | |||
} | |||
} | |||
</syntaxhighlight> | |||
=== TBD === | === TBD === | ||
More to come here in the future. | More to come here in the future. |