private void InitUI() { const int ButtonSize = 28; ui = new UI.UI(); ui.Input = SceneManager.Input; Button exitButton = new Button(20, 20, 40, 40) { Shortcut = Key.Escape }; exitButton.OnLeftClick += (sender) => SceneManager.LoadScene(new Transition(new MainMenu(), 10)); UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black); exitImage.SetConstraints(new UIConstraints(10, 10, 20, 20)); exitButton.AddChild(exitImage); ui.Add(exitButton); Frame buttonFrame = new Frame { Color = Color.Transparent, Constraints = new UIConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint(ButtonSize * width), new PixelConstraint(ButtonSize * height)) }; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Button button = new Button(x * ButtonSize, y * ButtonSize, ButtonSize, ButtonSize) { Style = 1 }; int copyX = x; int copyY = y; button.OnLeftClick += (sender) => { if (firstClick) { InitTiles(copyX, copyY); firstClick = false; } RevealTile(copyX, copyY); }; button.OnRightClick += (sender) => MarkTile(copyX, copyY); tiles[x, y].Button = button; buttonFrame.AddChild(button); } } ui.Add(buttonFrame); }
private void InitUI() { ui = new UI.UI { Input = SceneManager.Input }; Button exitButton = new Button(40, 40, 40, 40) { Shortcut = Key.Escape }; exitButton.OnLeftClick += (sender) => { SceneManager.LoadScene(new Transition(new MainMenu(), 10)); }; UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black); exitImage.SetConstraints(new UIConstraints(10, 10, 20, 20)); exitButton.AddChild(exitImage); ui.Add(exitButton); Button weeklyButton = new Button(200, 40, 40, 40); weeklyButton.OnLeftClick += (sender) => { if (!weekly.HasValue) { Notification.Show("Wöchentliche Welt ist nicht verfügbar"); return; } Game game = new Game(weekly.Value); game.OnExit += () => { SceneManager.LoadScene(new Transition(this, 10)); }; SceneManager.LoadScene(new Transition(game, 10)); }; ui.Add(weeklyButton); worldFrame = new Frame { Color = Color.Transparent, Constraints = new UIConstraints(new CenterConstraint(), new PixelConstraint(100), new RelativeConstraint(0.8f, RelativeTo.Window), new PixelConstraint(200)) }; ui.Add(worldFrame); }
private void InitUI() { ui = new UI.UI { Input = new Input(SceneManager.Window) }; void AddText(string s, string value, int y) { TextBlock text1 = new TextBlock(s, 3, 0, y) { Color = Color.White }; text1.Constraints.x = new CenterConstraint(-text1.TextWidth / 2f); ui.Add(text1); TextBlock text2 = new TextBlock(value, 3, 0, y) { Color = Color.White }; text2.Constraints.x = new CenterConstraint(text2.TextWidth / 2f); ui.Add(text2); } TextBlock title = new TextBlock("Statistik", 4, 0, 50) { Color = Color.White }; title.Constraints.x = new CenterConstraint(); ui.Add(title); Button button = new Button(40, 40, 40, 40) { Shortcut = OpenTK.Input.Key.Escape }; button.OnLeftClick += (sender) => { SceneManager.LoadScene(new Transition(new MainMenu(), 10)); }; UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black); exitImage.SetConstraints(new UIConstraints(10, 10, 20, 20)); button.AddChild(exitImage); ui.Add(button); int y = 100; AddText("Züge: ", Stats.Current.TotalMoves.ToString(), y += 30); AddText("Level geschafft: ", Stats.Current.LevelsCompleted.ToString(), y += 30); AddText("Level perfekt geschafft: ", Stats.Current.LevelsCompletedPerfect.ToString(), y += 30); AddText("Erstes Spiel: ", Stats.Current.FirstStart.ToString("dd.MM.yy"), y += 30); AddText("Spielzeit: ", $"{(int)Stats.Current.TimePlaying.TotalHours}:{Stats.Current.TimePlaying.Minutes:00}:{Stats.Current.TimePlaying.Seconds:00}", y += 30); AddText("Tode: ", Stats.Current.Fails.ToString(), y += 30); if (Stats.Current.TetrisHighScore > 0) { AddText("Tetris höchste Punktzahl: ", Stats.Current.TetrisHighScore.ToString(), y += 30); AddText("Tetris meiste Linien: ", Stats.Current.TetrisMostLines.ToString(), y += 30); AddText("Tetris höchstes Level: ", Stats.Current.TetrisHighLevel.ToString(), y += 30); } if (Stats.Current.MinesweeperWon > 0 || Stats.Current.MinesweeperLost > 0) { AddText("Minesweeper geschafft: ", Stats.Current.MinesweeperWon.ToString(), y += 30); AddText("Minesweeper gescheitert: ", Stats.Current.MinesweeperLost.ToString(), y += 30); } }
private void InitUI() { ui = new UI.UI(); ui.Input = SceneManager.Input; TextBlock title = new TextBlock("Einstellungen", 4); title.Color = Color.White; title.SetConstraints(new CenterConstraint(), new PixelConstraint(50), new PixelConstraint((int)title.TextWidth), new PixelConstraint((int)title.TextHeight)); ui.Add(title); { Button button = new Button(40, 40, 40, 40); button.Shortcut = OpenTK.Input.Key.Escape; button.OnLeftClick += (sender) => { SceneManager.LoadScene(new Transition(new MainMenu(), 10)); }; UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black); exitImage.SetConstraints(new UIConstraints(10, 10, 20, 20)); button.AddChild(exitImage); ui.Add(button); } void AddCheckBox(string s, int y, bool state, CheckEvent clickEvent) { Frame frame = new Frame(); frame.Color = Color.Transparent; CheckBox box = new CheckBox(0, 0, 36, 36); box.Checked = state; box.OnChecked += clickEvent; frame.AddChild(box); TextBlock text = new TextBlock(s, 3, 45, 0); text.Constraints.y = new CenterConstraint(); text.Color = Color.White; frame.AddChild(text); frame.SetConstraints(new CenterConstraint(), new PixelConstraint(y), new PixelConstraint(45 + (int)text.TextWidth), new PixelConstraint(36)); ui.Add(frame); } void AddText(string s, int y) { TextBlock text = new TextBlock(s, 3); text.Color = Color.White; text.SetConstraints(new CenterConstraint(), new PixelConstraint(y), new PixelConstraint((int)text.TextWidth), new PixelConstraint((int)text.TextHeight)); ui.Add(text); } AddCheckBox("Vollbild", 100, Settings.Current.Fullscreen, (b) => { Settings.Current.Fullscreen = b; SceneManager.Window.WindowState = b ? WindowState.Fullscreen : WindowState.Normal; }); AddCheckBox("Züge anzeigen", 150, Settings.Current.ShowMoves, (b) => { Settings.Current.ShowMoves = b; }); AddCheckBox("FPS/UPS anzeigen", 200, Settings.Current.ShowFps, (b) => { Settings.Current.ShowFps = b; }); AddCheckBox("Animationen anzeigen", 250, Settings.Current.ShowAnimations, (b) => { Settings.Current.ShowAnimations = b; }); TextBox textBox = new TextBox { Constraints = new UIConstraints(new CenterConstraint(), new PixelConstraint(310), new PixelConstraint(180), new PixelConstraint(34)), Enabled = !Settings.Current.LoggedIn, TextColor = Color.Black, MaxTextSize = 15, Text = Settings.Current.UserName ?? "" }; ui.Add(textBox); Button sendButton = new Button(); sendButton.SetConstraints(new CenterConstraint(), new PixelConstraint(350), new PixelConstraint(120), new PixelConstraint(34)); sendButton.Enabled = !Settings.Current.LoggedIn; sendButton.OnLeftClick += (sender) => SignUp(textBox); TextBlock sendText = new TextBlock("Anmelden", 2, 10, 10); sendButton.AddChild(sendText); ui.Add(sendButton); AddText($"ID: {Settings.Current.UserID.ToID()}", 400); AddText($"LoginInfo: {Settings.Current.LoginInfo.ToID()}", 440); }
private void InitWorlds() { const int ButtonSize = 60; const int StarsPerWorld = 2; const int WorldsPerRow = 5; List <World> worlds = new List <World>(); int worldcount = 0; while (File.Exists($"{World.BasePath}{worldcount:000}.wld")) { World item = World.LoadFromFile($"{worldcount:000}"); worlds.Add(item); worldcount++; } // Get stars bool[,] stars = new bool[worldcount, StarsPerWorld]; int totalStars = 0; bool[] showWorld = new bool[worldcount]; for (int i = 0; i < worldcount; i++) { stars[i, 0] = worlds[i].AllCompleted; totalStars += worlds[i].AllCompleted ? 1 : 0; stars[i, 1] = worlds[i].AllPerfect; totalStars += worlds[i].AllPerfect ? 1 : 0; } // Decide if world is shown for (int i = 0; i < worldcount; i++) { if (i > 1) { for (int j = 0; j < 3; j++) { for (int k = 0; k < StarsPerWorld; k++) { if (stars[i - j, k]) { showWorld[i] = true; break; } } } } else { showWorld[i] = true; } } Frame worldFrame = new Frame { Color = Color.Transparent, Constraints = new UIConstraints( new CenterConstraint(), new PixelConstraint(180), new PixelConstraint((showWorld.Count(x => x) / WorldsPerRow < 1 ? showWorld.Count(x => x) % WorldsPerRow : WorldsPerRow) * (ButtonSize + 20) + 20), new PixelConstraint((ButtonSize + 20) * (showWorld.Count(x => x) / WorldsPerRow + 1) + 20)) }; // Make buttons int count = 0; for (int i = 0; i < worldcount; i++) { if (showWorld[i]) { Button button = new Button((ButtonSize + 20) * (count % WorldsPerRow) + 20, (ButtonSize + 20) * (count / WorldsPerRow) + 20, ButtonSize, ButtonSize); for (int j = 0; j < StarsPerWorld; j++) { UI.Image image = new UI.Image(Textures.Get("Icons"), new RectangleF(stars[i, j] ? 10 : 0, 0, 10, 10)); image.SetConstraints(new UIConstraints( ButtonSize * (j + 1) / (StarsPerWorld + 1) - 10, ButtonSize - 15, 20, 20)); button.AddChild(image); } if (i < 10) { button.Shortcut = (Key)(110 + i); } if (i > 0) { button.Enabled = worlds[i - 1].AllCompleted || worlds[i - 1].AllPerfect; } int world = i; button.OnLeftClick += (sender) => { NewGame(world); }; TextBlock text = new TextBlock((i + 1).ToRoman().ToLower(), 3); text.Constraints = new UIConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)text.TextWidth), new PixelConstraint((int)text.TextHeight)); button.AddChild(text); worldFrame.AddChild(button); count++; } } ui.Add(worldFrame); }
private void InitLevels() { const int ButtonSize = 60; const int StarsPerLevel = 2; int lvlCount = world.Levels.Count; // Read stars bool[,] stars = new bool[lvlCount, StarsPerLevel]; int totalStars = 0; for (int i = 0; i < lvlCount; i++) { stars[i, 0] = world.Levels[i].Completed; totalStars += world.Levels[i].Completed ? 1 : 0; stars[i, 1] = world.Levels[i].Perfect; totalStars += world.Levels[i].Perfect ? 1 : 0; } Frame levelFrame = new Frame() { Color = Color.Transparent, Constraints = new UIConstraints( new CenterConstraint(), new PixelConstraint(180), new PixelConstraint(lvlCount * (ButtonSize + 20) + 20), new PixelConstraint(ButtonSize + 40)) }; List <Tuple <int, int> > connections = new List <Tuple <int, int> >(); for (int i = 0; i < lvlCount; i++) { for (int j = 0; j < world.LevelConnections[i].Count; j++) { connections.Add(new Tuple <int, int>(i, world.LevelConnections[i][j])); } } Vector2[] positions = new Vector2[lvlCount]; void CalcPosition(int level, int index, int prev = 0, int count = 0) { int next = world.LevelConnections[level][index]; if (world.LevelConnections[next].Count > 0) { for (int i = 0; i < world.LevelConnections[next].Count; i++) { CalcPosition(next, i, level, count + 1); } } else { positions[next] = new Vector2(count + 1, index); } positions[level] = new Vector2(count, index); } CalcPosition(0, 0); // Create buttons int count = 0; for (int i = 0; i < lvlCount; i++) { Button button = new Button((ButtonSize + 20) * (int)positions[i].X + 20, (ButtonSize + 20) * (int)positions[i].Y + 20, ButtonSize, ButtonSize); // Create stars for (int j = 0; j < StarsPerLevel; j++) { UI.Image image = new UI.Image(Textures.Get("Icons"), new RectangleF(stars[i, j] ? 10 : 0, 0, 10, 10)); image.SetConstraints(new UIConstraints( ButtonSize * (j + 1) / (StarsPerLevel + 1) - 10, ButtonSize - 15, 20, 20)); button.AddChild(image); } if (i < 10) { button.Shortcut = (Key)(110 + i); } if (i > 0) { button.Enabled = false; for (int j = 0; j < world.LevelConnections.Length; j++) { if (world.Levels[j].Completed && world.LevelConnections[j].Contains(i)) { button.Enabled = true; break; } } } int level = i; button.OnLeftClick += (sender) => NewGame(level); TextBlock text = new TextBlock((i + 1).ToString(), 3); text.SetConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)text.TextWidth), new PixelConstraint((int)text.TextHeight)); button.AddChild(text); levelFrame.AddChild(button); count++; } ui.Add(levelFrame); }