public void Update() { MouseItem.Update(); Inventory.Update(); if (MouseInput.MouseClickedLeft()) { if (MouseItem.Item != null && GridCraft.AddItem(MouseInput.MouseRealPosMenu(), _items, MouseItem.Item.Rotation) == true) { if (Game1.PlayerInstance.Items.Any(i => i.Type == MouseItem.Item.Type) == true) { Game1.PlayerInstance.Items.Single(i => i.Type == MouseItem.Item.Type).Amount--; } if (Game1.PlayerInstance.Items.Single(i => i.Type == MouseItem.Item.Type).Amount <= 0) { Game1.PlayerInstance.Items.Remove(Game1.PlayerInstance.Items.Single(i => i.Type == MouseItem.Item.Type)); } MouseItem.Item = null; Inventory.ResetChoosed(); CalculateAll(); } } if (MouseInput.MouseClickedRight()) { GridItem item = GridCraft.RemoveItem(MouseInput.MouseRealPosMenu(), _items); if (item != null) { if (Game1.PlayerInstance.Items.Any(i => i.Type == item.Type) == true) { Game1.PlayerInstance.Items.Single(i => i.Type == item.Type).Amount++; } else { Game1.PlayerInstance.Items.Add(new PlayersItem(item.Type, 1)); } } UIShop.Instance.Sync(); CalculateAll(); } UIShop.Instance.Sync(); Inventory.Set(); }
public static void Update() { if (Game1.EditorMenuOpen == true) { EditorMenu.Update(); } else { if (MouseInput.MouseStateOld.LeftButton == ButtonState.Pressed) { if (UIDrawing.Instance.Tiles.SelectedIndex != null || UIDrawing.Instance.TilesPhysics.SelectedIndex != null) { DrawOnBackground(SelectedEditTile); } } if (MouseInput.MouseStateNew.MiddleButton == ButtonState.Pressed) { Camera2DEditor.MoveBy(MouseInput.MouseStateNew.Position.ToVector2() - MouseInput.MouseStateOld.Position.ToVector2()); } if (MouseInput.MouseStateOld.RightButton == ButtonState.Pressed) { DrawOnBackground("_blank_"); } if (MouseInput.MouseClickedLeft() == true) { if (UIEntities.Instance.Entities.SelectedIndex != null) { if (UIEntities.Instance.Entities.SelectedIndex == 0) { AddPlayer(new Vector2(MouseInput.MousePositionRealGrid().X, MouseInput.MousePositionRealGrid().Y - (62 * 2))); } if (UIEntities.Instance.Entities.SelectedIndex == 1) { AddEntity(new Vector2(MouseInput.MousePositionRealGrid().X, MouseInput.MousePositionRealGrid().Y - (194))); } } } } if (KeyboardInput.KeyboardStateNew.IsKeyUp(Keys.Tab) && KeyboardInput.KeyboardStateOld.IsKeyDown(Keys.Tab)) { Game1.EditorMenuOpen = !Game1.EditorMenuOpen; } }
public bool Update() { _textOld = Text; if (MouseInput.MouseClickedLeft() == true) { if (CompareF.RectangleVsVector2(_boundary, MouseInput.MouseRealPosMenu()) == true) { IsActive = true; _cursor = (int)Math.Round(MouseInput.MouseRealPosMenu().X - _boundary.Position.X) / 16; if (_cursor > Text.Length) { _cursor = Text.Length; } if (_cursor < 0) { _cursor = 0; } MakeVisible(); } else { IsActive = false; MakeVisible(); } } if (IsActive == true) { keys = KeyboardInput.GetPressedKeys(); _backSpace.Update(); _left.Update(); _right.Update(); _blink.Update(); if (_blink.Ready == true) { _cursorVisible = !_cursorVisible; _blink.Reset(); } foreach (Keys key in keys) { int number = (int)key; if (_type == textBoxType.text || _type == textBoxType.fileName) { if (number >= 65 && number <= 90) { if (_cursor <= Text.Length) { Text = Text.Insert(_cursor + _offset, key.ToString()); CursorAdd(); MakeVisible(); } } if (key == Keys.Space) { if (_cursor <= Text.Length) { Text = Text.Insert(_cursor + _offset, " "); CursorAdd(); MakeVisible(); } } } if (number >= 96 && number <= 105) { if (_cursor <= Text.Length) { Text = Text.Insert(_cursor + _offset, (number - 96).ToString()); CursorAdd(); MakeVisible(); } } if (number >= 48 && number <= 57) { if (_cursor <= Text.Length) { Text = Text.Insert(_cursor + _offset, (number - 48).ToString()); CursorAdd(); MakeVisible(); } } if (key == Keys.OemMinus || key == Keys.Subtract) { if (_cursor <= Text.Length) { Text = Text.Insert(_cursor + _offset, "-"); CursorAdd(); MakeVisible(); } } } if (KeyboardInput.KeyboardStateNew.IsKeyDown(Keys.Back) == true && KeyboardInput.KeyboardStateOld.IsKeyDown(Keys.Back) == true) { if (_backSpace.Ready == true) { if (_cursor > 0 || _offset > 0) { Text = Text.Remove(_cursor - 1 + _offset, 1); MakeVisible(); _backSpace.Reset(); } if (_offset > 0) { _offset--; } else if (_cursor > 0) { _cursor--; } } } if (KeyboardInput.KeyboardStateNew.IsKeyDown(Keys.Left) == true && KeyboardInput.KeyboardStateOld.IsKeyDown(Keys.Left) == true) { if (_left.Ready == true) { if (_cursor > 0) { _cursor--; } else if (_offset > 0) { _offset--; } MakeVisible(); _left.Reset(); } } if (KeyboardInput.KeyboardStateNew.IsKeyDown(Keys.Right) == true && KeyboardInput.KeyboardStateOld.IsKeyDown(Keys.Right) == true) { if (_right.Ready == true) { if (_cursor < Text.Length) { if (_cursor < (int)((_boundary.Size.X - 16) / 16)) { _cursor++; } else if (_offset < Text.Length - (int)((_boundary.Size.X - 16) / 16)) { _offset++; } } MakeVisible(); _right.Reset(); } } } int i = 0; Parsed = int.TryParse(Text, out i); Valid = true; if ((Text.IndexOfAny(Path.GetInvalidFileNameChars()) != -1 && _type == textBoxType.fileName) || Text == "") { Valid = false; } if (_type == textBoxType.number && Parsed == true && (i < _min || i > _max)) { Valid = false; } if (Parsed == false && _type == textBoxType.number) { Valid = false; } if (_changeMehod != null) { _changeMehod?.Invoke(); return(true); } else { return(false); } }