0

I'm trying to create a custom popup in xna that displays some text and adds the choice to select yes or no. Depending on the button selected, a value should be returned. I have everything pretty much set up, but I can't figure out how to do this particular part.

First, I have a PopupDialogHandler class which holds a list of all the Popup_Dialog's and manages their respective click event and also manages updates and drawing.

The class Popup_Dialog is the class that manages creating a new popup object.

Everything is done, I draw the rectangle, draw the text, the button's are being handled, but I don't know what way should I use for a simple, yet effective result management.

Something like winforms' MessageBox.Show that returns. Currently, I create Popup_Dialog object and add it to the list in PopupDialogHandler class, from there I loop through all the items in the list and do the drawing and updating logic

Val
  • 495
  • 1
  • 4
  • 24
  • This is very broad. Can you post some code and maybe focus your question a little better? – djv Feb 24 '15 at 22:31
  • 1
    Back in my XNA days, I had a `Closed` event on my dialog box that triggered when the dialog box was closed (e.g. someone clicked Ok or whatever). The `Closed` event passed along a `DialogClosedEventArgs` object that contained the dialog result, etc. – itsme86 Feb 24 '15 at 22:31
  • @Verdolino, I think more could would just make it more complicated. I just need to know which direction to go. I don't know where to start to accomplish my goal. – Val Feb 24 '15 at 22:32
  • @val would you take some vb.net code? I have a custom messagebox written. – djv Feb 24 '15 at 22:36
  • @Verdolino, sure, anything. – Val Feb 24 '15 at 22:39
  • @val actually, it won't work. I didn't realize xna doesn't work with System.Windows.Forms. I would look at this question http://stackoverflow.com/questions/11815283/messagebox-dialogs-on-xna-c – djv Feb 24 '15 at 22:40

1 Answers1

0

You can do this with Actions. In the PopupDialog class, add private Action<int> Callback; to the properties and this code to the constructor:

public PopupDialog(Action<int> callback /*, rest of constructor parameters if any */)
{
    /* Rest of constructor code, if any */

    if (callback == null)
        throw new ArgumentNullException();
    Callback = callback;
}

In the Click handler, just call Callback() with the value you want to return as the parameter.

In the receiving/waiting class, add this code:

private void CallbackFunction(int theReturnedValue)
{
    // do something with the value here
}

and pass the function like this when creating the new popup:

var RC = new PopupDialog(CallbackFunction);
jan.h
  • 524
  • 5
  • 11