public override void Update() { Color currentValue = (Color)m_DebugItem.GetValue(); UI.Image image = m_ColorRect.GetComponent <UI.Image>(); image.color = currentValue; }
private void InitUI() { ui = new UI.UI { Input = new Input(SceneManager.Window) }; TextBlock title = new TextBlock("Welten", 4, 0, 50) { Color = Color.White }; title.Constraints.x = new CenterConstraint(); ui.Add(title); 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) { Constraints = new UIConstraints(10, 10, 20, 20) }; exitButton.AddChild(exitImage); ui.Add(exitButton); InitWorlds(); }
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 = new Input(SceneManager.Window) }; TextBlock title = new TextBlock("Level", 4, 0, 50) { Color = Color.White }; title.Constraints.x = new CenterConstraint(); ui.Add(title); Button exitButton = new Button(20, 20, 40, 40) { Shortcut = Key.Escape }; exitButton.OnLeftClick += (sender) => SceneManager.LoadScene(new Transition(new WorldMenu(), 10)); UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black) { Constraints = new UIConstraints(10, 10, 20, 20) }; exitButton.AddChild(exitImage); ui.Add(exitButton); Button modeButton = new Button(); modeButton.Shortcut = Key.Tab; modeButton.Color = Color.FromArgb(100, 255, 100); modeButton.SetConstraints(new PixelConstraint(40, RelativeTo.Window, Direction.Left), new PixelConstraint(40, RelativeTo.Window, Direction.Bottom), new PixelConstraint(300), new PixelConstraint(60)); TextBlock modeText = new TextBlock("Normal", 3); modeText.SetConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)modeText.TextWidth), new PixelConstraint((int)modeText.TextHeight)); modeButton.AddChild(modeText); modeButton.OnLeftClick += (sender) => { normalMode = !normalMode; modeText.Text = normalMode ? "Normal" : "Perfekt"; modeButton.Color = normalMode ? Color.FromArgb(100, 255, 100) : Color.FromArgb(255, 100, 100); modeText.SetConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)modeText.TextWidth), new PixelConstraint((int)modeText.TextHeight)); }; ui.Add(modeButton); }
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 MarkTile(int x, int y) { if (tiles[x, y].Revealed) { return; } if (!allowAction) { return; } tiles[x, y].Marked = !tiles[x, y].Marked; if (tiles[x, y].Marked) { UI.Image icon = new UI.Image(Textures.Get("Icons"), new RectangleF(20, 0, 10, 10)); icon.Constraints = new UIConstraints(4, 4, 20, 20); tiles[x, y].Button.AddChild(icon); } else { tiles[x, y].Button.ClearChildren(); } }
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 InitUI() { ui = new UI.UI { Input = SceneManager.Input }; Button exitButton = new Button(20, 20, 40, 40) { Shortcut = Key.Escape }; exitButton.OnLeftClick += (sender) => OnExit?.Invoke(); UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black) { Constraints = new UIConstraints(10, 10, 20, 20) }; exitButton.AddChild(exitImage); ui.Add(exitButton); void AddNumber(string desc, int value, int y, ValueEvent e, byte min = byte.MinValue, byte max = byte.MaxValue) { TextBlock text = new TextBlock(desc, 2, 20, y) { Color = Color.White }; NumberInput input = new NumberInput(20 + (int)text.TextWidth, y - 3, value) { MinValue = min, MaxValue = max, }; input.ValueChanged += e; input.AddTo(ui); ui.Add(text); } void AddCheckBox(string desc, int y, bool check, CheckEvent e) { TextBlock text = new TextBlock(desc, 2, 20, y + 2) { Color = Color.White }; CheckBox checkBox = new CheckBox(20 + (int)text.TextWidth, y, 24, 24) { Checked = check }; checkBox.OnChecked += e; ui.Add(text); ui.Add(checkBox); } AddNumber("Id: ", Data.ID, 100, a => Data.ID = (byte)a); AddNumber("Textur: ", Data.Texture, 120, a => Data.Texture = (byte)a); AddNumber("Anim.länge: ", Data.AnimationLength, 140, a => Data.AnimationLength = (byte)a); AddNumber("Anim.phase: ", Data.AnimationPhase, 160, a => Data.AnimationPhase = (byte)a); AddNumber("Anim.geschw.: ", Data.AnimationSpeed, 180, a => Data.AnimationSpeed = (byte)a); AddCheckBox("Solide: ", 200, Data.HexFlags.HasFlag(HexFlags.Solid), a => { if (a) { Data.HexFlags |= HexFlags.Solid; } else { Data.HexFlags &= ~HexFlags.Solid; } }); AddCheckBox("Tödlich: ", 224, Data.HexFlags.HasFlag(HexFlags.Deadly), a => { if (a) { Data.HexFlags |= HexFlags.Deadly; } else { Data.HexFlags &= ~HexFlags.Deadly; } }); AddCheckBox("Ziel: ", 248, Data.HexFlags.HasFlag(HexFlags.Goal), a => { if (a) { Data.HexFlags |= HexFlags.Goal; } else { Data.HexFlags &= ~HexFlags.Goal; } }); AddCheckBox("Animiert: ", 272, Data.RenderFlags.HasFlag(RenderFlags.Animated), a => { if (a) { Data.RenderFlags |= RenderFlags.Animated; } else { Data.RenderFlags &= ~RenderFlags.Animated; } }); AddCheckBox("Verbunden: ", 296, Data.RenderFlags.HasFlag(RenderFlags.Connected), a => { if (a) { Data.RenderFlags |= RenderFlags.Connected; } else { Data.RenderFlags &= ~RenderFlags.Connected; } }); }
private void InitUI() { ui = new UI.UI { Input = SceneManager.Input }; TextBlock title = new TextBlock("KREATIVER NAME", 5, 0, 50); title.Constraints.x = new CenterConstraint(); title.Color = Color.White; ui.Add(title); TextBlock splash = new TextBlock(File.ReadAllLines(@"Resources\Splash.txt").Random(), 2, 0, 90); splash.Constraints.x = new CenterConstraint(); splash.Color = Color.White; ui.Add(splash); TextBlock version = new TextBlock($"Version {MainWindow.version}", 2, 5, 0); version.Constraints.y = new PixelConstraint(5, RelativeTo.Window, Direction.Bottom); version.Color = Color.White; ui.Add(version); Frame mainFrame = new Frame { Constraints = new UIConstraints(new CenterConstraint(), new CenterConstraint(-50), new PixelConstraint(300), new PixelConstraint(200)), Color = Color.Transparent }; // Add start button Button startButton = new Button { Color = Color.FromArgb(100, 255, 100), Shortcut = OpenTK.Input.Key.S, Constraints = new UIConstraints(new CenterConstraint(), new PixelConstraint(0), new PixelConstraint(300), new PixelConstraint(60)) }; startButton.OnLeftClick += (sender) => { SceneManager.LoadScene(new Transition(new WorldMenu(), 10)); }; TextBlock startText = new TextBlock("Spiel starten", 3); startText.SetConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)startText.TextWidth), new PixelConstraint((int)startText.TextHeight)); startButton.AddChild(startText); mainFrame.AddChild(startButton); // Add middle frame Frame frame = new Frame { Color = Color.Transparent, Constraints = new UIConstraints(new CenterConstraint(), new PixelConstraint(100), new PixelConstraint(300), new PixelConstraint(60)) }; void AddButton(int x, int icon, ClickEvent click) { Button button = new Button(x, 0, 60, 60); button.OnLeftClick += click; UI.Image image = new UI.Image(Textures.Get("Icons"), new RectangleF(icon * 10, 10, 10, 10)) { Color = Color.Black, Constraints = new UIConstraints(10, 10, 40, 40) }; button.AddChild(image); frame.AddChild(button); } AddButton(0, 1, (sender) => { SceneManager.LoadScene(new Transition(new StatisticsScene(), 10)); }); AddButton(80, 2, (sender) => { SceneManager.LoadScene(new Transition(new SettingsScene(), 10)); }); AddButton(160, 3, NewEditor); AddButton(240, 4, (sender) => { SceneManager.LoadScene(new Transition(new OnlineScene(), 10)); }); mainFrame.AddChild(frame); // Add exit button Button exitButton = new Button { Color = Color.FromArgb(255, 100, 100), Constraints = new UIConstraints(new CenterConstraint(), new PixelConstraint(200), new PixelConstraint(300), new PixelConstraint(60)) }; exitButton.OnLeftClick += (sender) => { SceneManager.CloseWindow(); }; TextBlock exitText = new TextBlock("Schliessen", 3); exitText.Constraints = new UIConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)exitText.TextWidth), new PixelConstraint((int)exitText.TextHeight)); exitButton.AddChild(exitText); mainFrame.AddChild(exitButton); ui.Add(mainFrame); }
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); }