private void Modify(ToolStripItem sender, Func <int, int, int, int, int> action) { bool wholeMap = (ModifierKeys & Keys.Shift) != 0; string q = string.Format(MessageStrings.MsgFieldItemModifyAsk, sender.Text); var question = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, q); if (question != DialogResult.Yes) { return; } int count = View.ModifyFieldItems(action, wholeMap); if (count == 0) { WinFormsUtil.Alert(MessageStrings.MsgFieldItemModifyNone); return; } LoadItemGridAcre(); WinFormsUtil.Alert(string.Format(MessageStrings.MsgFieldItemModifyCount, count)); }
private void Menu_SavePNG_Click(object sender, EventArgs e) { var pb = WinFormsUtil.GetUnderlyingControl <PictureBox>(sender); if (pb?.Image == null) { WinFormsUtil.Alert("No picture loaded."); return; } string name; if (pb == PB_Player) { name = SAV.Players[PlayerIndex].Personal.PlayerName; } else if (pb == PB_Villager) { name = L_ExternalName.Text; } else { name = "photo"; } var bmp = pb.Image; using var sfd = new SaveFileDialog { Filter = "png file (*.png)|*.png|All files (*.*)|*.*", FileName = $"{name}.png", }; if (sfd.ShowDialog() != DialogResult.OK) { return; } bmp.Save(sfd.FileName, ImageFormat.Png); }
private void ReplaceTile(Item tile, int x, int y) { var l = Map.CurrentLayer; var pgt = new Item(); ItemEdit.SetItem(pgt); if (pgt.IsFieldItem && CHK_FieldItemSnap.Checked) { // coordinates must be even (not odd-half) x &= 0xFFFE; y &= 0xFFFE; tile = l.GetTile(x, y); } var permission = l.IsOccupied(pgt, x, y); switch (permission) { case PlacedItemPermission.OutOfBounds: System.Media.SystemSounds.Asterisk.Play(); return; } bool wholeMap = (ModifierKeys & Keys.Shift) != 0; var copy = new Item(tile.RawValue); var count = View.ReplaceFieldItems(copy, pgt, wholeMap); if (count == 0) { WinFormsUtil.Alert(MessageStrings.MsgFieldItemModifyNone); return; } LoadItemGridAcre(); WinFormsUtil.Alert(string.Format(MessageStrings.MsgFieldItemModifyCount, count)); }
private void WriteUSB_Click(object sender, EventArgs e) { if (!BotUSB.Connect()) { return; } var offset = StringUtil.GetHexValue(RamOffsetUSB.Text); if (offset == 0) { WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue); return; } InjectorUSB.SetWriteOffset(offset); Bot.SetOffset(offset); try { var result = InjectorUSB.Write(true); if (result == InjectionResult.Success) { return; } WinFormsUtil.Alert(result.ToString()); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) #pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error(ex.Message); } BotUSB.Disconnect(); }
private void Remove(Control sender, Func <int, int, int, int, int> removal) { bool wholeMap = ModifierKeys == Keys.Shift; string q = string.Format(MessageStrings.MsgFieldItemRemoveAsk, sender.Text); var question = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, q); if (question != DialogResult.Yes) { return; } var count = wholeMap ? removal(0, 0, Layer.MapWidth, Layer.MapHeight) : removal(X, Y, Layer.GridWidth, Layer.GridHeight); if (count == 0) { WinFormsUtil.Alert(MessageStrings.MsgFieldItemRemoveNone); return; } LoadGrid(X, Y); WinFormsUtil.Alert(string.Format(MessageStrings.MsgFieldItemRemoveCount, count)); }
private void Remove(Control sender, Func <int, int, int, int, int> removal) { bool wholeMap = ModifierKeys == Keys.Shift; string q = $"Are you sure you want to remove {sender.Text}?"; var question = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, q); if (question != DialogResult.Yes) { return; } var count = wholeMap ? removal(0, 0, Layer.MapWidth, Layer.MapHeight) : removal(X, Y, Layer.GridWidth, Layer.GridHeight); if (count == 0) { WinFormsUtil.Alert("Nothing removed (none found)."); return; } LoadGrid(X, Y); WinFormsUtil.Alert($"Removed {count} from the map."); }
private void Menu_SavePNG_Click(object sender, EventArgs e) { var pb = WinFormsUtil.GetUnderlyingControl<PictureBox>(sender); if (pb?.Image == null) { WinFormsUtil.Alert(MessageStrings.MsgNoPictureLoaded); return; } CM_Picture.Close(ToolStripDropDownCloseReason.CloseCalled); const string name = "map"; using var sfd = new SaveFileDialog { Filter = "png file (*.png)|*.png|All files (*.*)|*.*", FileName = $"{name}.png", }; if (sfd.ShowDialog() != DialogResult.OK) return; if (!Menu_SavePNGTerrain.Checked) { PB_Map.Image.Save(sfd.FileName, ImageFormat.Png); } else if (!Menu_SavePNGItems.Checked) { PB_Map.BackgroundImage.Save(sfd.FileName, ImageFormat.Png); } else { var img = (Bitmap)PB_Map.BackgroundImage.Clone(); using var gfx = Graphics.FromImage(img); gfx.DrawImage(PB_Map.Image, new Point(0, 0)); img.Save(sfd.FileName, ImageFormat.Png); } }
private void B_Apply_Click(object sender, EventArgs e) { var type = (SpawnType)CB_SpawnType.SelectedIndex; var arrange = (SpawnArrangement)CB_SpawnArrange.SelectedIndex; var x = (int)NUD_SpawnX.Value; var y = (int)NUD_SpawnY.Value; var count = (int)NUD_SpawnCount.Value; IReadOnlyList <Item> items; int sizeX; int sizeY; if (type == SpawnType.SequentialDIY) { var min = (ushort)NUD_DIYStart.Value; var max = (ushort)NUD_DIYStop.Value; var diy = RecipeList.Recipes .Where(z => min <= z.Key && z.Key <= max) .Select(z => z.Key) .Select(z => new Item(Item.DIYRecipe) { FreeParam = z }); items = Enumerable.Repeat(diy, count).SelectMany(z => z).ToArray(); sizeX = sizeY = 2; } else if (type == SpawnType.ItemsFromNHI) { if (string.IsNullOrEmpty(NHIFilePath) || !File.Exists(NHIFilePath)) { WinFormsUtil.Alert(MessageStrings.MsgFieldItemNoNHI); return; } // read non-empty slots into item array var data = File.ReadAllBytes(this.NHIFilePath); var array = data.GetArray <Item>(Item.SIZE).Where(item => !item.IsNone); items = Enumerable.Repeat(array, count).SelectMany(z => z).ToArray(); // set flag0 = 0x20 for each item to ensure it gets dropped // this also forces a 2x2 item size foreach (Item item in items) { item.SystemParam = 0x20; } sizeX = sizeY = 2; } else { var item = Editor.ItemProvider.SetItem(new Item()); items = Enumerable.Repeat(item, count).ToArray(); var size = ItemInfo.GetItemSize(item); sizeX = size.GetWidth(); sizeY = size.GetHeight(); } if (sizeX % 2 == 1) { sizeX++; } if (sizeY % 2 == 1) { sizeY++; } var ctr = SpawnItems(Editor.SpawnLayer, items, x, y, arrange, sizeX, sizeY, true); if (ctr == 0) { WinFormsUtil.Alert(MessageStrings.MsgFieldItemModifyNone); return; } Editor.ReloadItems(); WinFormsUtil.Alert(string.Format(MessageStrings.MsgFieldItemModifyCount, count)); }
private void Menu_Open_Click(object sender, EventArgs e) { WinFormsUtil.Alert("I don't do anything yet!"); }
private void Menu_Save_Click(object sender, EventArgs e) { SaveAll(); SAV.Save((uint)DateTime.Now.Ticks); WinFormsUtil.Alert("Saved all save data!"); }