1
votes

I'm working on porting a game engine from Java to Windows Phone 7 XNA. One thing I'm struggling with is how to create modal dialogs. The dialog is rendered in XNA using SpriteBatch just like everything else, but what I basically want is something like this:

result = Dialog.Ask("Some Question?", DialogButtons.YesNo);

Where Dialog.Ask doesn't return until the user clicks one of the buttons. The only thing I've done to come close is a method to continuously call RunOneFrame() on the game:

private int runLoopCount;
public void BeginRunLoop() {
  int runIndex = ++runLoopCount;
  while (runLoopCount == runIndex) {
    RunOneFrame();
    Thread.Sleep(1);
  }
}

public void EndRunLoop() {
  --runLoopCount;
}

There are a few problems with this:

  1. RunOneFrame is only supposedly for debugging purposes.
  2. Input doesn't work! Calling TouchPanel.GetState() or GamePad.GetState(PlayerIndex.One) doesn't return new values.

Is there any way to initiate a run loop without throwing away the Game class and all it does for initialization? And I don't really know how to do without the Game class anyway, as there is no Main() method in Windows Phone 7 XNA applications. It just goes right into the Game constructor.

1
This is hard to do in XNA. Have you tried this? msdn.microsoft.com/en-us/library/ff827868.aspxLukasz Madon
I am aware of the method, and I know how to go about implementing asynchronous displays of custom dialog boxes using sprites, but I'm really looking for a way to do it synchronously. I'm already so close with the (admittedly unsupported) RunOneFrame, I'm just missing input.Ed Marty
I've been looking in to detecting touches and keyboard state using other methods, but no luck so far. The only available methods seem to be specific to XNA (which doesn't work) and Silverlight (which I'm not using).Ed Marty

1 Answers

0
votes

What you want to do is to add another 'state', you just have to show dialog until user do not select something... and _modalDialogIsUp bool..

    protected override void Update(GameTime gameTime)
    {
        if (_modalDialogIsUp)
        {
            // handle only secesary mouse and button clicks
        }
        else
        {
            // normal mouse and button clicks
        }
    }

    protected override void Draw(GameTime gameTime)
    {
        if (_modalDialogIsUp)
        {
            // draw only modal dialog
        }
        else
        {
            // draw game
        }
    }

I just can't undestang why you so desparatly want exactly modal behavior... is it some kind of new "sync" sect? :)