Hello everyone^^ Im pretty new to programming and monogame in particular and i bet theres some obvious solution to my problem that i just havent been able to track down trough google yet. Anyway the situation:
Ive made a game with a registration, login and main menu screens. Since taking input trough monogame apparently is quiet a hassle ive tried to make winforms for my login and menu screens, which works fine, but i cant get them to communicate with my game1 monogame class.
What i need to do is change my enum GameState in Game1 to GameState.MainMenu when a button called “main menu” on the login form is clicked. Ive tried all the ways i usuallky send data between classes without luck. Anyone have experience with ssending data between form and Game1? Or have other advice? Im even willing to try take input in other ways, though it seemed very difficult to do it via monogame/xna from the guides i found.
Cheers
Kasper
Also heres my login form code:
class LoginForm
{
public static string ShowDialog()
{
Form input = new Form()
{
Width = 800,
Height = 600,
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None,
StartPosition = FormStartPosition.Manual,
Location = new System.Drawing.Point(100, 100),
BackgroundImage = Image.FromFile(@"Content/loginBg.jpg")
};
bool wishedNameIsFree = true;
TextBox textBox1 = new TextBox() { Left = 350, Top = 150, Width = 200 };
TextBox textBox2 = new TextBox() { Left = 350, Top = 180, Width = 200 };
Label label1 = new Label();
label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
label1.Location = new System.Drawing.Point(210, 150);
label1.Size = new System.Drawing.Size(120, 18);
label1.Text = ("Wished Name: ");
label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
Label label2 = new Label();
label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
label2.Location = new System.Drawing.Point(210, 180);
label2.Size = new System.Drawing.Size(120, 18);
label2.Text = ("Wished Password: ");
label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
input.Controls.Add(textBox1);
input.Controls.Add(textBox2);
Button okCheck = new Button() { Text = "Check if OK", Left = 400, Width = 100, Top = 300, DialogResult = DialogResult.OK };
input.Controls.Add(okCheck);
input.Controls.Add(label1);
input.Controls.Add(label2);
//input.AcceptButton = okCheck;
okCheck.Click += (sender, e) =>
{
// Kald databasen og tjek om det ønskede navn er i brug og -->
if (wishedNameIsFree)
{
MessageBox.Show("Wished name was free, proceding to main menu!");
input.Close();
game1.CurrentGameState = GameState.Playing;
// CurrentGamestate == gamestate.mainmenu
}
else
{
MessageBox.Show("Wished name is not free, try another!");
}
};
string checkingWishedName = textBox1.Text;
string checkingWishedPassword = textBox2.Text;
return input.ShowDialog() == DialogResult.OK ? textBox1.Text : "";
//return input.ShowDialog() == DialogResult.OK ? textBox2.Text : "";
}
And my GameState enum in Game1:
enum GameState
{
Login, // Login, Password, OK, Register
Register, // Hvis register er valgt : Wished login, Wished password, Ok, --> Gem database --> Send til MainMenu
MainMenu, // Start Game, About the game, Credits, Exit Game
About, // Om spillet, controls, historie etc
Credits, // Om os udviklerne af spillet
Playing, // Spillogik her
Closing, // Gemmer alt data til databaserne så progression ikke mistes.
}
GameState CurrentGameState = GameState.Login;