void NewGame() { var e = new YesNoPromptEvent((TextId)Base.SystemText.MainMenu_DoYouReallyWantToStartANewGame); var exchange = Exchange; RaiseAsync(e, response => { Attach(exchange); if (response) { Raise(new NewGameEvent(Base.Map.TorontoBegin, 30, 75)); // TODO: Move this to config? } }); Detach(); }
void NewGame() { var e = new YesNoPromptEvent(SystemTextId.MainMenu_DoYouReallyWantToStartANewGame); var exchange = Exchange; RaiseAsync(e, response => { Attach(exchange); if (response) { Raise(new NewGameEvent(MapDataId.Toronto2DGesamtkarteSpielbeginn, 30, 75)); // TODO: Move this to config? } }); Detach(); }
public void YesNoPromptTest() { AssetMapping.GlobalIsThreadLocal = true; AssetMapping.Global.Clear() .RegisterAssetType(typeof(Base.SystemText), AssetType.Text) ; var systemText = new Dictionary <TextId, string> { { Base.SystemText.MainMenu_DoYouReallyWantToQuit, "Do you really want to quit?" }, { Base.SystemText.MsgBox_Yes, "Yes" }, { Base.SystemText.MsgBox_No, "No" } }; var ex = new EventExchange(new LogExchange()); var dm = new DialogManager(); var lm = new LayoutManager(); var mma = new MockModApplier(GameLanguage.English) .Add(new AssetId(AssetType.MetaFont, (ushort)new MetaFontId(false, FontColor.White)), MockUniformFont.Font) ; foreach (var kvp in systemText) { mma.Add(kvp.Key, kvp.Value); } ex .Attach(mma) .Attach(new AssetManager()) .Attach(new TextFormatter()) .Attach(new TextManager()) .Attach(new SpriteManager()) .Attach(new WindowManager { Window = new MockWindow(1920, 1080) }) .Attach(new MockSettings { Language = GameLanguage.English }) .Attach(dm) .Attach(lm) ; var e = new YesNoPromptEvent((TextId)Base.SystemText.MainMenu_DoYouReallyWantToQuit); bool?result = null; ex.RaiseAsync <bool>(e, null, x => result = x); Assert.Null(result); var layout = lm.GetLayout(); Assert.Equal(1, layout.Children.Count); // Should only be one top-level dialog var yesText = layout.DepthFirstSearch(x => x.Element is TextLine txt && txt.ToString().Contains("\"Yes\"")).First(); var yesButton = (Button)yesText.Ancestors.First(x => x.Element is Button).Element; yesButton.Receive(new HoverEvent(), null); yesButton.Receive(new UiLeftClickEvent(), null); yesButton.Receive(new UiLeftReleaseEvent(), null); Assert.True(result); layout = lm.GetLayout(); Assert.Equal(0, layout.Children.Count); // Dialog should be closed, so no top-level dialogs // Open another yes/no dialog e = new YesNoPromptEvent((TextId)Base.SystemText.MainMenu_DoYouReallyWantToQuit); ex.RaiseAsync <bool>(e, this, x => result = x); layout = lm.GetLayout(); Assert.Equal(1, layout.Children.Count); // Should only be one top-level dialog var noText = layout.DepthFirstSearch(x => x.Element is TextLine txt && txt.ToString().Contains("\"No\"")).First(); var noButton = (Button)noText.Ancestors.First(x => x.Element is Button).Element; noButton.Receive(new HoverEvent(), null); noButton.Receive(new UiLeftClickEvent(), null); noButton.Receive(new UiLeftReleaseEvent(), null); Assert.False(result); }
public void YesNoPromptTest() { var systemText = new Dictionary <int, string> { { (int)SystemTextId.MainMenu_DoYouReallyWantToQuit, "Do you really want to quit?" }, { (int)SystemTextId.MsgBox_Yes, "Yes" }, { (int)SystemTextId.MsgBox_No, "No" } }; var ex = new EventExchange(new LogExchange()); var dm = new DialogManager(); var lm = new LayoutManager(); var alr = new MockAssetLocatorRegistry() .Add(new AssetKey(AssetType.SystemText), systemText) .Add(new AssetKey(AssetType.MetaFont, (ushort)new MetaFontId()), MockUniformFont.Font) ; ex .Attach(alr) .Attach(new AssetManager()) .Attach(new TextFormatter()) .Attach(new TextManager()) .Attach(new SpriteManager()) .Attach(new WindowManager { Window = new MockWindow(1920, 1080) }) .Attach(new MockSettings { Language = GameLanguage.English }) .Attach(dm) .Attach(lm) ; var e = new YesNoPromptEvent(SystemTextId.MainMenu_DoYouReallyWantToQuit); bool?result = null; ex.RaiseAsync <bool>(e, null, x => result = x); Assert.Null(result); var layout = lm.GetLayout(); Assert.Equal(1, layout.Children.Count); // Should only be one top-level dialog var yesText = layout.DepthFirstSearch(x => x.Element is TextLine txt && txt.ToString().Contains("\"Yes\"")).First(); var yesButton = (Button)yesText.Ancestors.First(x => x.Element is Button).Element; yesButton.Receive(new HoverEvent(), null); yesButton.Receive(new UiLeftClickEvent(), null); yesButton.Receive(new UiLeftReleaseEvent(), null); Assert.True(result); layout = lm.GetLayout(); Assert.Equal(0, layout.Children.Count); // Dialog should be closed, so no top-level dialogs // Open another yes/no dialog e = new YesNoPromptEvent(SystemTextId.MainMenu_DoYouReallyWantToQuit); ex.RaiseAsync <bool>(e, this, x => result = x); layout = lm.GetLayout(); Assert.Equal(1, layout.Children.Count); // Should only be one top-level dialog var noText = layout.DepthFirstSearch(x => x.Element is TextLine txt && txt.ToString().Contains("\"No\"")).First(); var noButton = (Button)noText.Ancestors.First(x => x.Element is Button).Element; noButton.Receive(new HoverEvent(), null); noButton.Receive(new UiLeftClickEvent(), null); noButton.Receive(new UiLeftReleaseEvent(), null); Assert.False(result); }