Exemplo n.º 1
0
        public static async Task <DialogButton> ShowDialog(SmartSpriteBatch spriteBatch, string title, string body, List <DialogButton> buttons)
        {
            TaskCompletionSource <DialogButton> completionSource = new TaskCompletionSource <DialogButton>();
            XuiDialog    dialog = new XuiDialog();
            DialogScreen screen = new DialogScreen
            {
                Buttons = new List <StaticButtonAsset>()
            };

            float margin = 0.005f;

            List <StaticButtonAsset> buttonStack = ButtonHelpers.CreateButtonHorizontalStack(new FloatRectangle(0.15f, 0.75f - margin - margin, 0.75f, 0.1f),
                                                                                             0.1f, margin,
                                                                                             buttons.Select(t => new ButtonBasics(t.Text, (args) =>
            {
                dialog.HandleClick(t, completionSource, screen);
            })).ToList());

            screen.Buttons.AddRange(buttonStack);
            screen.Title = title;
            screen.Body  = body;
            await screen.Initialise();

            Solids.Instance.ScreenManager.Add(screen);
            Solids.Instance.ScreenManager.BringToFront(screen);

            return(await completionSource.Task);
        }
Exemplo n.º 2
0
        public static async Task <int> ShowDialog(SmartSpriteBatch spriteBatch, string title, string body,
                                                  List <string> buttons)
        {
            TaskCompletionSource <int> completionSource = new TaskCompletionSource <int>();
            XuiDialog    dialog = new XuiDialog();
            DialogScreen screen = new DialogScreen
            {
                Buttons = new List <StaticButtonAsset>()
            };

            List <StaticButtonAsset> buttonStack = ButtonHelpers.CreateButtonHorizontalStack(new Vector2(0.2f, 0.65f), 0.3f,
                                                                                             0.1f, 0.025f,
                                                                                             buttons.Select(t => new ButtonBasics(t, (args) =>
            {
                dialog.HandleClick(t, buttons.IndexOf(t), completionSource, screen);
            })).ToList());

            screen.Buttons.AddRange(buttonStack);
            screen.Title = title;
            screen.Body  = body;
            await screen.Initialise();

            Solids.Instance.ScreenManager.Add(screen);

            return(await completionSource.Task);
        }
Exemplo n.º 3
0
 public void HandleClick(DialogButton button, TaskCompletionSource <DialogButton> completionSource, DialogScreen screen)
 {
     Solids.Instance.ScreenManager.Remove(screen);
     completionSource.SetResult(button);
     button.Action?.Invoke();
 }
Exemplo n.º 4
0
 public void HandleClick(string clickText, int indexOf, TaskCompletionSource <int> completionSource, DialogScreen screen)
 {
     Solids.Instance.ScreenManager.Remove(screen);
     completionSource.SetResult(indexOf);
 }