public void onInput(InputHandler input) { bool interacting = ui.onInput(input); if (interacting) { return; } if (input.isKeyPressed(Keys.T)) // title screen image { ui.pushElement(new UiTextInput("BG Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { GameInfo.titleBackground = input.text; titleScreen.updateBackground(); } }), Vector2.Zero); } else if (input.isKeyPressed(Keys.N)) // game name { ui.pushElement(new UiTextInput("Name: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { GameInfo.title = input.text; } }), Vector2.Zero); } else if (input.isKeyPressed(Keys.S)) // game start { ui.pushElement(new UiOptionBox(Content, "Start game where?", "Overworld", "Map").addCallback(element => { UiOptionBox option = (UiOptionBox)element; ui.pushElement(new UiTextInput("Filename: ").addCallback(element2 => { UiTextInput filename = (UiTextInput)element2; if (filename.text != "") { GameInfo.startMap = filename.text; GameInfo.startOverworld = (option.selected == 0); } }), new Vector2(0, 65)); }), Vector2.Zero); } else if (input.isKeyPressed(Keys.F2)) // save { GameInfo.save(); } }
public override void onInput(InputHandler input) { if (input.isAnyKeyPressed(Keys.E, Keys.Enter, Keys.Escape)) { finished = true; } else if (input.isKeyPressed(Keys.T)) { system.pushElement(new UiTilePicker(Content).addCallback(element => { UiTilePicker picker = (UiTilePicker)element; Tile picked = (Tile)picker.selected; this.tile.setTexture(Content, picked.filename); }), Vector2.Zero); } else if (input.isKeyPressed(Keys.W)) { this.tile.collision = !this.tile.collision; } else if (input.isKeyPressed(Keys.N)) { system.pushElement(new UiNpcEditor(Content, npc).addCallback(element => { UiNpcEditor editor = (UiNpcEditor)element; if (editor.delete) { this.npc = null; } else { this.npc = editor.npc; } }), Vector2.Zero); } else if (input.isKeyPressed(Keys.S)) { system.pushElement(new UiTextInput("Script: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { this.script = new LuaScript(input.text); if (!this.script.loaded) { this.script = null; } } }), Vector2.Zero); } }
private static void SpawnInputTextWindow(UiWindow window, UiSpacer spacer, string labelText, string titleText, Func <string, bool> validationAndSuccess, string errorTitle, string errorMessage, Action onClose) { var textInputWindow = new UiWindow(); textInputWindow.Container.SetBackground(Constants.Backgrounds.Dark); textInputWindow.ListenForEscape(true); textInputWindow.OnClose += () => { onClose(); }; var title = new UiTextBlock(); title.SetColor(Color.Orange); title.SetFont(Constants.Fonts.MyFirstCrush36); title.SetString(titleText); textInputWindow.AddChild(title); textInputWindow.AddChild(spacer); var inputRow = new UiRow(); textInputWindow.AddChild(inputRow); textInputWindow.AddChild(spacer); var label = new UiTextBlock(); label.SetString(labelText); inputRow.AddChild(label); inputRow.AddChild(spacer); var input = new UiTextInput(); input.SetBackgroundColor(new Color(237, 207, 154)); input.SetTextColor(Color.Black); input.SetActiveTextColor(Color.Black); input.SetBackground(Constants.Backgrounds.TextInput); inputRow.AddChild(input); input.SetSize(300); input.SetLimit(25); var buttonRow = new UiRow(); textInputWindow.AddChild(buttonRow); var createButton = new UiButton(); buttonRow.AddChild(createButton); buttonRow.AddChild(spacer); var createText = new UiTextBlock(); createText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.create")); createButton.AddChild(createText); createButton.OnClick += () => { if (validationAndSuccess(input.GetValue())) { textInputWindow.Dispose(); } else { var errorWindow = new UiWindow(); errorWindow.Container.SetBackground(Constants.Backgrounds.Dark); var errorTitleText = new UiTextBlock(); errorTitleText.SetColor(Color.Orange); errorTitleText.SetFont(Constants.Fonts.MyFirstCrush36); errorTitleText.SetString(errorTitle); errorWindow.AddChild(errorTitleText); errorWindow.AddChild(spacer); var message = new UiTextBlock(); message.SetString(errorMessage); message.SetColor(Color.Red); errorWindow.AddChild(message); errorWindow.AddChild(spacer); var okButton = new UiButton(); var okText = new UiTextBlock(); okText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.ok")); okButton.AddChild(okText); okButton.OnClick += () => { textInputWindow.StartUpdateCalls(); errorWindow.Dispose(); }; errorWindow.AddChild(okButton); textInputWindow.AddChildWindow(errorWindow); textInputWindow.ListenForEscape(false); textInputWindow.StopUpdateCalls(); errorWindow.ListenForEscape(true); errorWindow.OnClose += () => { textInputWindow.ListenForEscape(true); textInputWindow.StartUpdateCalls(); }; errorWindow.Show(); } }; var cancelButton = new UiButton(); buttonRow.AddChild(cancelButton); var cancelText = new UiTextBlock(); cancelButton.AddChild(cancelText); cancelText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.cancel")); cancelButton.OnClick += () => { textInputWindow.Dispose(); }; window.Hide(); window.ListenForEscape(false); window.AddChildWindow(textInputWindow); window.StopUpdateCalls(); textInputWindow.Show(); }
public ColorPickerWindow(Color?_default = null) { if (_default != null) { _color = _default.Value; } _current = new UiWindow(); _current.ListenForEscape(true); _current.Container.SetBackground(Constants.Backgrounds.Dark); var picker = new UiColorPicker(); var currentColor = new UiTexture2D(context => Helpers.GetTexture(context)); var hoverColor = new UiTexture2D(context => Helpers.GetTexture(context)); var selectedColor = new UiTexture2D(context => Helpers.GetTexture(context)); selectedColor.SetColor(_color); currentColor.SetColor(_color); var row = new UiRow(); row.AddChild(picker); var column = new UiColumn(); var spacer = new UiSpacer(); spacer.SetHeight(20); spacer.SetWidth(20); row.AddChild(spacer); var mouseText = new UiTextBlock(); mouseText.SetColor(Color.White); mouseText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.mouse")); column.AddChild(mouseText); column.AddChild(hoverColor); column.AddChild(spacer); var selectedText = new UiTextBlock(); selectedText.SetColor(Color.White); selectedText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.selected")); column.AddChild(selectedText); column.AddChild(selectedColor); column.AddChild(spacer); var currentText = new UiTextBlock(); currentText.SetColor(Color.White); currentText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.current")); column.AddChild(currentText); column.AddChild(currentColor); row.AddChild(column); _current.AddChild(row); _current.AddChild(spacer); var colorRow = new UiRow(); UiTextInput colorHex = null; var colorR = new UiNumberInput(); colorR.SetItteration(1.0f); colorR.SetMin(0); colorR.SetMax(255); colorR.SetValue(_color.R); colorR.SetBackgroundColors(Color.Red, Color.Pink); colorR.OnChange += value => { if (byte.TryParse(value.ToString(), out var val)) { _color.R = val; colorHex?.ForceSetValue($"{_color.R:X2}{_color.G:X2}{_color.B:X2}"); selectedColor.SetColor(_color); } }; var colorG = new UiNumberInput(); colorG.SetItteration(1.0f); colorG.SetMin(0); colorG.SetMax(255); colorG.SetValue(_color.G); colorG.SetBackgroundColors(Color.Green, Color.LimeGreen); colorG.OnChange += value => { if (byte.TryParse(value.ToString(), out var val)) { _color.G = val; colorHex?.ForceSetValue($"{_color.R:X2}{_color.G:X2}{_color.B:X2}"); selectedColor.SetColor(_color); } }; var colorB = new UiNumberInput(); colorB.SetItteration(1.0f); colorB.SetMin(0); colorB.SetMax(255); colorB.SetValue(_color.B); colorB.SetBackgroundColors(Color.Blue, Color.LightBlue); colorB.SetTextColors(Color.White, Color.Black); colorB.OnChange += value => { if (byte.TryParse(value.ToString(), out var val)) { _color.B = val; colorHex?.ForceSetValue($"{_color.R:X2}{_color.G:X2}{_color.B:X2}"); selectedColor.SetColor(_color); } }; var colorHexRow = new UiRow(); var hex = new UiTextBlock(); hex.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.hex")); colorHex = new UiTextInput(); colorHex.ForceSetValue($"{_color.R:X2}{_color.G:X2}{_color.B:X2}"); colorHex.SetBackgroundColor(new Color(237, 207, 154)); colorHex.SetTextColor(Color.Black); colorHex.SetActiveTextColor(Color.Black); colorHex.SetBackground(Constants.Backgrounds.TextInput); colorHex.SetLimit(6); colorHex.InputCheck += key => { switch (key.ToString().ToUpper()) { default: return(false); case "A": case "B": case "C": case "D": case "E": case "F": case "0": case "1": case "2": case "3": case "4": case "5": case "6": case "7": case "8": case "9": return(true); } }; colorHex.OnChange += text => { if (text.IsNullOrEmpty()) { _color = Color.Black; } else { _color = ColorMath.ParseString(text); } selectedColor.SetColor(_color); colorR.ForceSetValue(_color.R); colorG.ForceSetValue(_color.G); colorB.ForceSetValue(_color.B); }; picker.ColorClick += color => { selectedColor.SetColor(color); _color = color; colorR.ForceSetValue(_color.R); colorG.ForceSetValue(_color.G); colorB.ForceSetValue(_color.B); colorHex.ForceSetValue($"{_color.R:X2}{_color.G:X2}{_color.B:X2}"); }; colorRow.AddChild(colorR); colorRow.AddChild(spacer); colorRow.AddChild(colorG); colorRow.AddChild(spacer); colorRow.AddChild(colorB); _current.AddChild(colorRow); _current.AddChild(spacer); colorHexRow.AddChild(hex); colorHexRow.AddChild(colorHex); _current.AddChild(colorHexRow); _current.AddChild(spacer); var confirmButton = new UiButton(); confirmButton.SetBackground(Constants.Backgrounds.Button); var confirmText = new UiTextBlock(); confirmText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.setColor")); confirmButton.AddChild(confirmText); confirmButton.OnClick += () => { OnColorSet?.Invoke(_color); if (_colorHistory.Contains(_color)) { _colorHistory.Remove(_color); } _colorHistory.Add(_color); _current.Dispose(); }; var cancelButton = new UiButton(); cancelButton.SetBackground(Constants.Backgrounds.Button); var cancelText = new UiTextBlock(); cancelText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.cancel")); cancelButton.AddChild(cancelText); cancelButton.OnClick += () => { _current.Dispose(); }; var buttonRow = new UiRow(); buttonRow.AddChild(confirmButton); buttonRow.AddChild(spacer); buttonRow.AddChild(cancelButton); buttonRow.AddChild(spacer); var favButton = new UiButton(); favButton.SetBackground(Constants.Backgrounds.Button); var favPic = FoxUIHook.Instance.GetPicture("nimbusfox.ui.images.favorites"); favButton.AddChild(favPic); buttonRow.AddChild(favButton); buttonRow.AddChild(spacer); favButton.OnClick += () => { SpawnFavoriteFolderMenu(_current, spacer, color => { colorHex.ForceSetValue($"{color.R:X2}{color.G:X2}{color.B:X2}", true); }); }; var historyButton = new UiButton(); historyButton.SetBackground(Constants.Backgrounds.Button); var historyPic = FoxUIHook.Instance.GetPicture("nimbusfox.ui.images.history"); historyButton.AddChild(historyPic); buttonRow.AddChild(historyButton); historyButton.OnClick += () => { SpawnHistoryWindow(_current, spacer, color => { colorHex.ForceSetValue($"{color.R:X2}{color.G:X2}{color.B:X2}", true); }); }; _current.AddChild(buttonRow); picker.ColorHover += color => { hoverColor.SetColor(color); }; _current.OnClose += () => { OnClose?.Invoke(); }; }
public void onInput(InputHandler input) { bool interacting = ui.onInput(input); if (interacting) { return; } cursor.onInput(input); if (input.isKeyPressed(Keys.F2)) // Save { UiElement filename = new UiTextInput("Save Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { string json = JsonSerializer.Serialize <OverworldMeta>(map.meta, SerializableMap.OPTIONS); File.WriteAllText("Content/map/" + input.text, json); } }); ui.pushElement(filename, Vector2.One); } else if (input.isKeyPressed(Keys.F3)) // Load { UiElement filename = new UiTextInput("Load Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { map.loadMap("Content/map/" + input.text); map.setPlayerLocation(); } }); ui.pushElement(filename, Vector2.One); } else if (input.isKeyPressed(Keys.E)) // Create new map location { ui.pushElement(new UiTextInput("Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { map.addLocation(input.text, cursor.getLocation()); map.setPlayerLocation(); } }), Vector2.Zero); } else if (input.isKeyPressed(Keys.R)) // Delete map location { for (int i = 0; i < map.meta.locations.Count; i++) { if (Vector2.Distance(map.meta.locations[i].center, cursor.center) < 10) { map.meta.locations.Remove(map.meta.locations[i]); map.setPlayerLocation(); break; } } } else if (input.isKeyPressed(Keys.L)) // Layer editor { ui.pushElement(new UiLayerEditor(Content, map), new Vector2(10, 30)); } }
public UiLayerEditor(ContentManager Content, Overworld o) { this.o = o; this.layers = o.meta.layers; layerList = new UiList(Content, layers.ToArray()); commandList = new UiList(Content, new string[4] { "Add", "Delete", "Set Base", "Exit" }); commandList.addCallback(element => { commandList.finished = false; switch (commandList.selected) { case 0: mode = Mode.Adding; genLayerStrings(); layerList.selected = 0; break; case 1: mode = Mode.Deleting; genLayerStrings(); layerList.selected = 0; break; case 2: mode = Mode.SetBase; genLayerStrings(); layerList.selected = o.meta.baseLayer; break; case 3: finished = true; break; } }); layerList.addCallback(element => { layerList.finished = false; if (layerList.selected != -1) { if (mode == Mode.Adding) { system.pushElement(new UiTextInput("Filename: ").addCallback(input => { UiTextInput textInput = (UiTextInput)input; if (textInput.text != null) { layers.Insert(layerList.selected, textInput.text); if (layerList.selected >= o.meta.baseLayer) { o.meta.baseLayer++; } layerList.setStrings(layers.ToArray()); o.reloadLayers(); } }), Vector2.Zero); } else if (mode == Mode.Deleting) { layers.RemoveAt(layerList.selected); if (layerList.selected <= o.meta.baseLayer) { o.meta.baseLayer--; } layerList.setStrings(layers.ToArray()); o.reloadLayers(); } else if (mode == Mode.SetBase) { o.meta.baseLayer = layerList.selected; o.reloadLayers(); } mode = Mode.Inactive; } }); }
public void onInput(InputHandler input) { bool interactingWithUi = ui.onInput(input); if (interactingWithUi) { return; } cursor.onInput(input); if (input.isKeyPressed(Keys.F2)) // Save { UiElement filename = new UiTextInput("Save Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { SerializableMap.Save(Content, map, input.text); } }); ui.pushElement(filename, Vector2.One); } else if (input.isKeyPressed(Keys.F3)) // Load { UiElement filename = new UiTextInput("Load Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { TileMap newMap = SerializableMap.Load(Content, input.text); if (newMap != null) { this.world.setMap(newMap); cursor.setLocation(Vector2.Zero); } } }); ui.pushElement(filename, Vector2.One); } else if (input.isKeyPressed(Keys.E)) // Edit tile properties { Tile selected = map.getTile(cursor.getTileLocation()); NPC npc = map.getNPC(cursor.getTileLocation()); LuaScript script = map.getScript(cursor.getTileLocation()); if (selected != null) { ui.pushElement(new UiTileEditor(Content, selected, npc, script).addCallback(element => { UiTileEditor editor = (UiTileEditor)element; map.setTile(cursor.getTileLocation(), editor.tile); map.setNPC(cursor.getTileLocation(), editor.npc); map.setScript(cursor.getTileLocation(), editor.script); lastEditedTile = editor.tile; lastEditedScript = editor.script; }), new Vector2(160, 0)); } } else if (input.isKeyHeld(Keys.P)) // Tile painter { if (lastEditedTile != null) { map.setTile(cursor.getTileLocation(), new Tile(lastEditedTile)); if (lastEditedScript != null) { map.setScript(cursor.getTileLocation(), new LuaScript(lastEditedScript.filename)); } } } else if (input.isKeyPressed(Keys.M)) // Edit map meta info { ui.pushElement(new UiMapMetaEditor(Content, map), new Vector2(160, 0)); } }
public override void onInput(InputHandler input) { if (input.isAnyKeyPressed(Keys.M, Keys.Enter, Keys.Escape)) { finished = true; } else if (input.isKeyPressed(Keys.R)) // resize map { system.pushElement(new UiTextInput("Width: ").addCallback((element) => { UiTextInput widthInput = (UiTextInput)element; int newWidth = map.width; if (widthInput.text != "") { newWidth = int.Parse(widthInput.text); } system.pushElement(new UiTextInput("Height: ").addCallback((element2) => { UiTextInput heightInput = (UiTextInput)element2; int newHeight = map.height; if (heightInput.text != "") { newHeight = int.Parse(heightInput.text); } map.resize(Content, newWidth, newHeight); }), new Vector2(0, 20)); }), Vector2.Zero); } else if (input.isKeyPressed(Keys.B)) { // push elements in reverse order system.pushElement(new UiTextInput("B: ").addCallback((element) => { UiTextInput input = (UiTextInput)element; if (input.text != "") { map.color.B = Convert.ToByte(input.text); } }), new Vector2(0, 40)); system.pushElement(new UiTextInput("G: ").addCallback((element) => { UiTextInput input = (UiTextInput)element; if (input.text != "") { map.color.G = Convert.ToByte(input.text); } }), new Vector2(0, 20)); system.pushElement(new UiTextInput("R: ").addCallback((element) => { UiTextInput input = (UiTextInput)element; if (input.text != "") { map.color.R = Convert.ToByte(input.text); } }), Vector2.Zero); } else if (input.isKeyPressed(Keys.S)) { system.pushElement(new UiTextInput("X: ").addCallback((element) => { UiTextInput xi = (UiTextInput)element; int x = (int)map.playerStart.X; if (xi.text != "") { x = int.Parse(xi.text); } system.pushElement(new UiTextInput("Y: ").addCallback((element2) => { UiTextInput yi = (UiTextInput)element2; int y = (int)map.playerStart.Y; if (yi.text != "") { y = int.Parse(yi.text); } map.playerStart = new Vector2(x, y); }), new Vector2(0, 20)); }), Vector2.Zero); } }
public override void onInput(InputHandler input) { if (input.isAnyKeyPressed(Keys.Enter, Keys.Escape)) { finished = true; } else if (input.isKeyPressed(Keys.T)) { system.pushElement(new UiEntityPicker(Content).addCallback(element => { UiEntityPicker picker = (UiEntityPicker)element; NPC n = (NPC)picker.selected; if (this.npc == null) { this.npc = new NPC(Content, n.filename, "", false, picker.GetHashCode() + ""); } else { this.npc.setTexture(Content, n.filename); } }), new Vector2(160, 0)); } else if (input.isKeyPressed(Keys.N) && this.npc != null) { system.pushElement(new UiTextInput("Name: ").addCallback(element => { UiTextInput input = (UiTextInput)element; string proposed = input.text; if (proposed != "") { this.npc.setName(input.text); } }), Vector2.Zero); } else if (input.isKeyPressed(Keys.S) && this.npc != null) { system.pushElement(new UiTextInput("Script: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { this.npc.setScript(input.text); } }), Vector2.Zero); } else if (input.isKeyPressed(Keys.L) && this.npc != null) { this.npc.locked = !this.npc.locked; } else if (input.isKeyPressed(Keys.D) && this.npc != null) { system.pushElement(new UiTextInput("Sure? (Y/N): ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text.ToLower() == "y") { this.delete = true; finished = true; } }), Vector2.Zero); } }