diff --git a/README.md b/README.md index 975be16..b784147 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ However of course feel free to use it for your own runs that you do not want to 1. Download the dlls from the latest release on the [releases page](https://github.com/Shotnex4/LiveSplit.TimeAttackPause/releases) and put them in your LiveSplit/Components folder. 2. Add the component to your layout. (Right click → Edit Layout → Timer → TimeAttackPause) 3. Start your run and pause your timer at any time. -4. Click on the "Export" button in the component to save your splits to a json file. +4. Use Control → `Export current run` to save your splits to a json file. 5. Now you can close LiveSplit. Shut down your PC. Go to sleep. Whatever you want. -6. When you are ready to continue your run, open LiveSplit again and load your splits by clicking on the "Import" button in the component. +6. When you are ready to continue your run, open LiveSplit again and load your splits by using Control → `Import run`. ![example.png](doc/example.png) \ No newline at end of file diff --git a/UI/Components/TimeAttackPauseComponent.cs b/UI/Components/TimeAttackPauseComponent.cs index dc6bc49..d518012 100644 --- a/UI/Components/TimeAttackPauseComponent.cs +++ b/UI/Components/TimeAttackPauseComponent.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Xml; @@ -10,10 +11,6 @@ namespace LiveSplit.UI.Components { public class TimeAttackPauseComponent : ControlComponent { - private readonly Button _exportButton; - private readonly Button _importButton; - - private TimeAttackPauseSettings Settings { get; set; } private ITimerModel Model { get; set; } @@ -23,60 +20,29 @@ public class TimeAttackPauseComponent : ControlComponent public override string ComponentName => "TimeAttackPause"; - public override float HorizontalWidth => 50; - public override float MinimumWidth => 160; - public override float VerticalHeight => 40; - public override float MinimumHeight => 40; + public override float HorizontalWidth => 0; + public override float MinimumWidth => 0; + public override float VerticalHeight => 0; + public override float MinimumHeight => 0; // This function is called when LiveSplit creates your component. This happens when the // component is added to the layout, or when LiveSplit opens a layout with this component // already added. - public TimeAttackPauseComponent(LiveSplitState state) : this(state, CreateFormControl(state)) + public TimeAttackPauseComponent(LiveSplitState state) : this(state, CreateFormControl()) { + ContextMenuControls = new Dictionary(); + ContextMenuControls.Add("Export current run", ExportCurrentRun); + ContextMenuControls.Add("Import run", ImportRun); } - private static Control CreateFormControl(LiveSplitState state) + private static Control CreateFormControl() { - // create a basic button to export the current run state - var exportButton = new Button - { - Name = "ExportButton", - Text = "Export", - Location = new Point(0, 0), - BackColor = Color.LightBlue, - Dock = DockStyle.Fill, - }; - - // create a new button that will be used to import a run state - var importButton = new Button - { - Name = "ImportButton", - Text = "Import", - Location = new Point(0, 0), - BackColor = Color.LightBlue, - Dock = DockStyle.Fill, - }; - - var tableLayoutContainer = new TableLayoutPanel + // not used anymore + return new FlowLayoutPanel { - Name = "Container", - Size = new Size(100, 32), - ColumnCount = 2, - RowCount = 1, - AutoSize = false, + Size = new Size(0, 0), Location = new Point(0, 0), - ColumnStyles = - { - new ColumnStyle(SizeType.Percent, 50F), - new ColumnStyle(SizeType.Percent, 50F), - } }; - - // add the buttons to the container - tableLayoutContainer.Controls.Add(exportButton); - tableLayoutContainer.Controls.Add(importButton); - - return tableLayoutContainer; } private TimeAttackPauseComponent(LiveSplitState state, Control formControl) : base(state, formControl, @@ -85,21 +51,10 @@ private TimeAttackPauseComponent(LiveSplitState state, Control formControl) : ba Settings = new TimeAttackPauseSettings(); Model = new TimerModel() { CurrentState = state }; - _exportButton = formControl.Controls["ExportButton"] as Button; - _importButton = formControl.Controls["importButton"] as Button; - - if (_exportButton == null || _importButton == null) - { - throw new Exception("Could not find the buttons in the form control."); - } - - _exportButton.Click += OnExportButtonClick; - _importButton.Click += OnImportButtonClick; - CurrentState = state; } - private void OnExportButtonClick(object sender, EventArgs e) + private void ExportCurrentRun() { if (CurrentState.CurrentPhase == TimerPhase.Running) { @@ -117,7 +72,7 @@ private void OnExportButtonClick(object sender, EventArgs e) SplitsStateWriter.SaveSplitsState(CurrentState, saveFileDialog.FileName); } - private void OnImportButtonClick(object sender, EventArgs e) + private void ImportRun() { // Displays a OpenFileDialog so the user can save the Run as json file OpenFileDialog openFileDialog = new OpenFileDialog(); @@ -142,27 +97,6 @@ static void ErrorCallback(Form form, Exception ex) MessageBoxButtons.OK, MessageBoxIcon.Error); } - private void DisposeIfError() - { - if (ErrorWithControl) - { - Dispose(); - } - } - - public override void DrawHorizontal(Graphics g, LiveSplitState state, float height, Region clipRegion) - { - base.DrawHorizontal(g, state, height, clipRegion); - DisposeIfError(); - } - - // We will be adding the ability to display the component across two rows in our settings menu. - public override void DrawVertical(Graphics g, LiveSplitState state, float width, Region clipRegion) - { - base.DrawVertical(g, state, width, clipRegion); - DisposeIfError(); - } - public override Control GetSettingsControl(LayoutMode mode) { Settings.Mode = mode; @@ -188,16 +122,6 @@ public override void Update(IInvalidator invalidator, LiveSplitState state, floa CurrentState = state; } - // This function is called when the component is removed from the layout, or when LiveSplit - // closes a layout with this component in it. - public override void Dispose() - { - base.Dispose(); - - _exportButton.Click -= OnExportButtonClick; - _importButton.Click -= OnImportButtonClick; - } - // I do not know what this is for. public int GetSettingsHashCode() => Settings.GetSettingsHashCode(); } diff --git a/UI/Components/TimeAttackPauseFactory.cs b/UI/Components/TimeAttackPauseFactory.cs index 81a1f81..a1c2c31 100644 --- a/UI/Components/TimeAttackPauseFactory.cs +++ b/UI/Components/TimeAttackPauseFactory.cs @@ -1,19 +1,16 @@ -using LiveSplit.Model; +using System; +using LiveSplit.Model; using LiveSplit.UI.Components; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LiveSplit.TimeAttackPause.UI.Components { - internal class TimeAttackPauseFactory: IComponentFactory + internal class TimeAttackPauseFactory : IComponentFactory { // The displayed name of the component in the Layout Editor. public string ComponentName => "Time Attack Pause"; - public string Description => "Adds the possibility to save your progress mid run to a file and then continue from this point on. Only use this for TA runs or unofficial runs that you do not submit to the leaderboards."; + public string Description => + "Adds the possibility to save your progress mid run to a file and then continue from this point on. Only use this for TA runs or unofficial runs that you do not submit to the leaderboards."; // The sub-menu this component will appear under when adding the component to the layout. public ComponentCategory Category => ComponentCategory.Timer; @@ -34,4 +31,4 @@ internal class TimeAttackPauseFactory: IComponentFactory public Version Version => Version.Parse("1.0.0"); } -} +} \ No newline at end of file diff --git a/doc/example.png b/doc/example.png index 3c40ad0..6647686 100644 Binary files a/doc/example.png and b/doc/example.png differ