public BadgeControl(Save save, int index, int offset, int valueOffset) { if (index >= BadgeNames.Length) { throw new Exception($"Badge index was invalid! Got {index} when {BadgeNames.Length - 1} was the maximum possible!"); } _saveFile = save; _index = index; _dataOffset = offset; _valueOffset = valueOffset; Stage = _saveFile.ReadByte(offset); Value = new NewLeafInt32(_saveFile.ReadUInt32(valueOffset), _saveFile.ReadUInt32(valueOffset + 4)); _badgeName = BadgeNames[index]; _badgeNameToolTip = new ToolTip { AutoPopDelay = 5000, InitialDelay = 100, ReshowDelay = 500, ShowAlways = true }; _badgeNameToolTip.SetToolTip(PictureBox, _badgeName + $" - [{BadgeLevels[Stage]}] - " + Value.Value); Size = new Size(28, 28); ImageMaskingType = MaskingType.None; SetImageCrop(); PictureBox.MouseClick += OnClick; Loaded = true; }
private void PriceChanged(int index, int newPrice, bool pm = false) { if (_saveData == null) { return; } Prices[index] = newPrice; // Save price switch (_saveData.SaveGeneration) { case SaveGeneration.N64: case SaveGeneration.GCN: case SaveGeneration.iQue: _saveData.Write(_offset + index * 2, (ushort)newPrice, _saveData.IsBigEndian); break; case SaveGeneration.N3DS: var writeOffset = _offset + index * 0x10 + (pm ? 8 : 0); var encryptedValue = new NewLeafInt32((uint)newPrice); _saveData.Write(writeOffset, encryptedValue.Int1); _saveData.Write(writeOffset + 4, encryptedValue.Int2); break; } }
private void OnClick(object sender, EventArgs e) { if (Loaded && _dataOffset > -1 && _valueOffset > -1 && _index > -1 && _index < BadgeNames.Length) { Stage++; if (Stage > 3) { Stage = 0; } Value = new NewLeafInt32((uint)BadgeValues[_index][Stage]); if (_saveFile != null) { _saveFile.Write(_dataOffset, Stage); _saveFile.Write(_valueOffset, Value.Int1); _saveFile.Write(_valueOffset + 4, Value.Int2); } SetImageCrop(); _badgeNameToolTip.SetToolTip(PictureBox, _badgeName + $" - [{BadgeLevels[Stage]}] - " + Value.Value); } }
public StalkMarketEditor(Save saveData) { AutoSize = true; FlowDirection = FlowDirection.TopDown; _saveData = saveData; Prices = new int[Days]; _priceBoxes = new NumericTextBox[Days]; _panels = new List <FlowLayoutPanel>(); _offset = _trendOffset = -1; switch (_saveData.SaveType) { case SaveType.AnimalCrossing: _offset = saveData.SaveDataStartOffset + 0x20480; _trendOffset = _offset + 0xE; break; case SaveType.NewLeaf: Days = 6; _offset = saveData.SaveDataStartOffset + 0x6535C; break; case SaveType.WelcomeAmiibo: Days = 6; _offset = saveData.SaveDataStartOffset + 0x6AD60; break; } if (_offset < 0) { Dispose(); return; } // Header Label Controls.Add(new Label { AutoSize = true, Text = "Stalk Market" }); // Trend if (_trendOffset > -1) { var trendPanel = new FlowLayoutPanel { AutoSize = true, FlowDirection = FlowDirection.LeftToRight }; var trendLabel = new Label { AutoSize = false, Size = new Size(130, 22), TextAlign = ContentAlignment.MiddleRight, Text = "Trend:" }; trendPanel.Controls.Add(trendLabel); Trend = saveData.ReadUInt16(_trendOffset, saveData.IsBigEndian); _trendComboBox = new ComboBox { AutoSize = false, Size = new Size(60, 20) }; foreach (var trend in Enum.GetNames(typeof(GameCubeStalkMarketTrend))) { _trendComboBox.Items.Add(trend); } _trendComboBox.SelectedIndex = Trend; _trendComboBox.SelectedIndexChanged += (s, e) => TrendChanged(_trendComboBox.SelectedIndex); trendPanel.Controls.Add(_trendComboBox); _panels.Add(trendPanel); Controls.Add(trendPanel); } // Prices var offset = _offset; for (var day = 0; day < Days; day++) { switch (_saveData.SaveGeneration) { case SaveGeneration.N64: case SaveGeneration.GCN: case SaveGeneration.iQue: { Prices[day] = saveData.ReadUInt16(offset, saveData.IsBigEndian); offset += 2; var pricePanel = new FlowLayoutPanel { AutoSize = true, FlowDirection = FlowDirection.LeftToRight }; var priceLabel = new Label { AutoSize = false, Size = new Size(130, 22), TextAlign = ContentAlignment.MiddleRight, Text = $"{DayNames[day]}'s Price:" }; pricePanel.Controls.Add(priceLabel); _priceBoxes[day] = new NumericTextBox { AutoSize = false, Size = new Size(60, 20), Location = new Point(5, day * 24), Text = Prices[day].ToString(), MaxLength = 4 }; var currentDay = day; _priceBoxes[day].TextChanged += (s, e) => PriceChanged(currentDay, int.Parse(_priceBoxes[currentDay].Text)); pricePanel.Controls.Add(_priceBoxes[day]); _panels.Add(pricePanel); Controls.Add(pricePanel); break; } case SaveGeneration.N3DS: { var amPrice = new NewLeafInt32(saveData.ReadUInt32(offset), saveData.ReadUInt32(offset + 4)).Value; var pmPrice = new NewLeafInt32(saveData.ReadUInt32(offset + 8), saveData.ReadUInt32(offset + 0xC)).Value; offset += 0x10; for (var i = 0; i < 2; i++) { var pricePanel = new FlowLayoutPanel { AutoSize = true, FlowDirection = FlowDirection.LeftToRight }; var priceLabel = new Label { AutoSize = false, Size = new Size(130, 22), TextAlign = ContentAlignment.MiddleRight, Text = $"{DayNames[day + 1]}'s Price [{(i == 0 ? "AM" : "PM")}]:" }; pricePanel.Controls.Add(priceLabel); var priceBox = new NumericTextBox { AutoSize = false, Size = new Size(60, 20), Location = new Point(5, day * 24), Text = (i == 0 ? amPrice : pmPrice).ToString(), MaxLength = 9 }; var currentDay = day; priceBox.TextChanged += (s, e) => PriceChanged(currentDay, int.Parse(priceBox.Text)); pricePanel.Controls.Add(priceBox); _panels.Add(pricePanel); Controls.Add(pricePanel); } break; } } } }