mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-21 17:48:28 -05:00
All subform ViewModels now use transactional cancel semantics matching WinForms: edits happen on a clone, Cancel discards them, Save copies the clone back to the origin via CopyChangesFrom. Gen 1-2: SAVEventReset1, SAVHallOfFame1, SAVMisc2, SAVRTC2 Gen 3: SAVRoamer3, SAVSecretBase3, SAVHallOfFame3, SAVRTC3, SAVMisc3, PokeBlock3CaseEditor, SimplePokedex Gen 4: PokeGear4, Trainer4BR, BattlePass4, Gear4, Apricorn4, HoneyTree4, Underground4, Geonet4, PoffinCase4, Pokedex4 Gen 5: Pokedex5, UnityTower5, DLC5 Gen 6: SAVPokepuff6 Gen 7: SAVHallOfFame7 Gen 8 BDSP: Poffin8b, SealStickers8b, Underground8b Cross-gen: EventFlags, EventFlags2, EventWork, Inventory, MailBox, Wondercard, BoxLayout, TrainerStat
103 lines
2.6 KiB
C#
103 lines
2.6 KiB
C#
using System;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using PKHeX.Core;
|
|
|
|
namespace PKHeX.Avalonia.ViewModels.Subforms;
|
|
|
|
/// <summary>
|
|
/// ViewModel for the Gen 3 Real-Time Clock editor.
|
|
/// Edits initial and elapsed clock values for RSE saves.
|
|
/// </summary>
|
|
public partial class SAVRTC3ViewModel : SaveEditorViewModelBase
|
|
{
|
|
private readonly SaveFile _origin;
|
|
private readonly SAV3 _sav;
|
|
private readonly ISaveBlock3SmallHoenn _small;
|
|
private readonly RTC3 _clockInitial;
|
|
private readonly RTC3 _clockElapsed;
|
|
|
|
// Initial clock
|
|
[ObservableProperty]
|
|
private int _initialDay;
|
|
|
|
[ObservableProperty]
|
|
private int _initialHour;
|
|
|
|
[ObservableProperty]
|
|
private int _initialMinute;
|
|
|
|
[ObservableProperty]
|
|
private int _initialSecond;
|
|
|
|
// Elapsed clock
|
|
[ObservableProperty]
|
|
private int _elapsedDay;
|
|
|
|
[ObservableProperty]
|
|
private int _elapsedHour;
|
|
|
|
[ObservableProperty]
|
|
private int _elapsedMinute;
|
|
|
|
[ObservableProperty]
|
|
private int _elapsedSecond;
|
|
|
|
public SAVRTC3ViewModel(SAV3 sav) : base(sav)
|
|
{
|
|
_origin = sav;
|
|
_sav = (SAV3)sav.Clone();
|
|
_small = (ISaveBlock3SmallHoenn)_sav.SmallBlock;
|
|
_clockInitial = _small.ClockInitial;
|
|
_clockElapsed = _small.ClockElapsed;
|
|
|
|
LoadData();
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
InitialDay = _clockInitial.Day;
|
|
InitialHour = Math.Min(23, _clockInitial.Hour);
|
|
InitialMinute = Math.Min(59, _clockInitial.Minute);
|
|
InitialSecond = Math.Min(59, _clockInitial.Second);
|
|
|
|
ElapsedDay = _clockElapsed.Day;
|
|
ElapsedHour = Math.Min(23, _clockElapsed.Hour);
|
|
ElapsedMinute = Math.Min(59, _clockElapsed.Minute);
|
|
ElapsedSecond = Math.Min(59, _clockElapsed.Second);
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void Reset()
|
|
{
|
|
InitialDay = InitialHour = InitialMinute = InitialSecond = 0;
|
|
ElapsedDay = ElapsedHour = ElapsedMinute = ElapsedSecond = 0;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void BerryFix()
|
|
{
|
|
ElapsedDay = Math.Max((2 * 366) + 2, ElapsedDay);
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void Save()
|
|
{
|
|
_clockInitial.Day = InitialDay;
|
|
_clockInitial.Hour = InitialHour;
|
|
_clockInitial.Minute = InitialMinute;
|
|
_clockInitial.Second = InitialSecond;
|
|
|
|
_clockElapsed.Day = ElapsedDay;
|
|
_clockElapsed.Hour = ElapsedHour;
|
|
_clockElapsed.Minute = ElapsedMinute;
|
|
_clockElapsed.Second = ElapsedSecond;
|
|
|
|
_small.ClockInitial = _clockInitial;
|
|
_small.ClockElapsed = _clockElapsed;
|
|
|
|
_origin.CopyChangesFrom(_sav);
|
|
Modified = true;
|
|
}
|
|
}
|