Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dalet committed Sep 6, 2016
2 parents c74502a + 60d3a1a commit 2b4e7f1
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 37 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#editorconfig.org
root = true

[*.cs]
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

[*.xml]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
Binary file modified Components/LiveSplit.Skyrim.dll
Binary file not shown.
8 changes: 8 additions & 0 deletions Components/update.LiveSplit.Skyrim.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<updates>
<update version="3.2">
<files>
<file path="Components/LiveSplit.Skyrim.dll" status="changed"/>
</files>
<changelog>
<change>Added a way to generate segments from autosplit names. (accessible via the "Other" button)</change>
</changelog>
</update>
<update version="3.1">
<files>
<file path="Components/LiveSplit.Skyrim.dll" status="changed"/>
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.1.0.0")]
[assembly: AssemblyFileVersion("3.1.0.0")]
[assembly: AssemblyVersion("3.2.0.0")]
[assembly: AssemblyFileVersion("3.2.0.0")]

[assembly: ComponentFactory(typeof(SkyrimFactory))]
32 changes: 16 additions & 16 deletions SkyrimSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 108 additions & 12 deletions SkyrimSettings.FormLogic.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LiveSplit.AutoSplitting;
using LiveSplit.AutoSplitting.Editors;
using LiveSplit.Model;
using System;
using System.IO;
using System.Linq;
Expand All @@ -9,6 +10,9 @@ namespace LiveSplit.Skyrim
{
partial class SkyrimSettings
{
ContextMenuStrip _cmsOtherBtn;
bool _autoCloseRunEditor = false;

void InitializeFormLogic()
{
chkAutoStart.DataBindings.Add("Checked", this, "AutoStart", false, DataSourceUpdateMode.OnPropertyChanged);
Expand Down Expand Up @@ -38,6 +42,10 @@ void InitializeFormLogic()
cbPreset.DisplayMember = "Name";
cbPreset.SelectedItem = Presets.FirstOrDefault(p => p.Name == Preset) ?? CustomAutosplits;
cbPreset.SelectionChangeCommitted += CbPreset_SelectionChangeCommitted;

_cmsOtherBtn = new ContextMenuStrip();
_cmsOtherBtn.Items.Add("Update presets list", null, (s,e) => UpdatePresets());
_cmsOtherBtn.Items.Add("Generate segments from preset", null, cmsOtherBtn_GenerateSegments);
}

void Settings_OnLoad(object sender, EventArgs e)
Expand All @@ -50,7 +58,8 @@ void Settings_OnLoad(object sender, EventArgs e)

if (BearCartPB.RealTime != null && BearCartPB.RealTime != new TimeSpan(0))
{
lBearCartPB.Text = string.Format("Personal Best:\n Game Time: {0}, Real Time: {1}", BearCartPB.GameTime.Value.ToString(@"mm\:ss\.fff"), BearCartPB.RealTime.Value.ToString(@"mm\:ss\.fff"));
lBearCartPB.Text = string.Format("Personal Best:\n Game Time: {0}, Real Time: {1}",
BearCartPB.GameTime.Value.ToString(@"mm\:ss\.fff"), BearCartPB.RealTime.Value.ToString(@"mm\:ss\.fff"));
lBearCartPB.Visible = true;
}
else
Expand All @@ -70,12 +79,15 @@ void RefreshSplitsListControl()

chklbSplits.Items.Clear();

disableNbrSplitCheck = true;
for (int i = 0; i < AutoSplitList.Count; i++)
{
var split = AutoSplitList[i];
chklbSplits.Items.Add(split);
chklbSplits.SetItemChecked(i, split.Enabled);
}
disableNbrSplitCheck = false;
CheckNbrAutoSplits();
}

void CbPreset_SelectionChangeCommitted(object sender, EventArgs e)
Expand All @@ -94,22 +106,106 @@ void btnCustomize_Click(object sender, EventArgs e)
RefreshSplitsListControl();
}

void btnUpdatePresets_Click(object sender, EventArgs e)
void btnOther_Click(object sender, EventArgs e)
{
if (!CheckForComponentUpdate())
_cmsOtherBtn.Show(Cursor.Position);
}

void cmsOtherBtn_GenerateSegments(object sender, EventArgs e)
{
if (_state.CurrentPhase == TimerPhase.Running)
{
btnUpdatePresets.Enabled = false;
MessageBox.Show(this, "This cannot be done while the timer is running.",
"Generate segments", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}

if (DownloadPresetsFile(false) && LoadPresets(false))
MessageBox.Show("Presets successfully updated.", "Presets updated",
MessageBoxButtons.OK, MessageBoxIcon.Information);
UsePreset(Presets.FirstOrDefault(l => l.Name == Preset) ?? CustomAutosplits);
var autosplitNames = Presets.First(p => p.Name == Preset)
.Select(split => split.Name)
.ToList();

btnUpdatePresets.Enabled = true;
if (autosplitNames.Count == 0)
{
MessageBox.Show(this, "Your autosplit list is empty.", "Generate segments",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}

int i = -1;

if (_state.Run.Count == autosplitNames.Count)
{
// find the first index that doesn't match
i = 0;
while (i < _state.Run.Count)
{
if (_state.Run[i].Name != autosplitNames[i])
break;
i++;
}
}

if (i == _state.Run.Count)
{
MessageBox.Show(this, "Your segments already match your autosplits.",
"Generate segments", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (i == _state.Run.Count - 1) // everything matched except the last one
{
_state.Run[i].Name = autosplitNames[i];
}
else
MessageBox.Show("An update is available for the autosplitter.\nPresets can only be updated with the latest autosplitter version available.",
"Presets update cancelled", MessageBoxButtons.OK, MessageBoxIcon.Warning);
{
var result = MessageBox.Show(this, "All your existing segments except the last one will be deleted.\n\nContinue?",
"Generate segments", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
return;

// remove everything except last split
while (_state.Run.Count > 1)
_state.Run.RemoveAt(0);

_state.Run[0].Name = autosplitNames[autosplitNames.Count - 1];

for (int j = 0; j < autosplitNames.Count - 1; j++)
{
var newSegment = new Segment(autosplitNames[j]);

_state.Run.ImportBestSegment(j);
var maxIndex = _state.Run.AttemptHistory.Select(x => x.Index).DefaultIfEmpty(0).Max();
for (var x = _state.Run.GetMinSegmentHistoryIndex(); x <= maxIndex; x++)
newSegment.SegmentHistory.Add(x, default(Time));

_state.Run.Insert(j, newSegment);
}

_state.Run.FixSplits();
}

_state.Run.HasChanged = true;
_state.Form.Invalidate();
CheckNbrAutoSplits();

// force close the splits editor because editing the segments messes it up
var editor = _state.Form.OwnedForms.FirstOrDefault(f => f.Text == "Splits Editor");
if (!_autoCloseRunEditor && editor != null)
{
ParentForm.FormClosed += (s, ea) =>
{
if (ParentForm.DialogResult == DialogResult.OK)
editor.AcceptButton.PerformClick();
else
editor.Close();

_autoCloseRunEditor = false;
};

_autoCloseRunEditor = true;
}

MessageBox.Show(this, "Your segments have been updated.\nYou might want to reset the Best Segment time of your last split.",
"Generate segments", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

void llCheckAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Expand All @@ -136,7 +232,7 @@ void CheckNbrAutoSplits()
var enabledSplitsCount = AutoSplitList.Count(s => s.Enabled);
if (enabledSplitsCount != 0 && enabledSplitsCount != _state.Run.Count)
{
lWarningNbrAutoSplit.Text = string.Format("Enabled autosplit count: {0} Segment count: {1}", enabledSplitsCount, _state.Run.Count);
lWarningNbrAutoSplit.Text = $"Segment count: {_state.Run.Count} Enabled autosplit count: {enabledSplitsCount}";
lWarningNbrAutoSplit.Visible = true;
}
else
Expand Down
27 changes: 20 additions & 7 deletions SkyrimSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public partial class SkyrimSettings : UserControl
const bool DEFAULT_PLAYBEARCARTSOUNDONLYONPB = false;
const string BEAR_CART_CFG_FILE = "LiveSplit.Skyrim.cfg";
const string PRESETS_FILE_NAME = "LiveSplit.Skyrim.Presets.xml";
readonly string DefaultPreset;
const string DEFAULT_PRESET_NAME = "Custom";
readonly string PRESETS_FILE_PATH;

SkyrimComponent _component;
Expand All @@ -67,8 +67,7 @@ public SkyrimSettings(SkyrimComponent component, LiveSplitState state)
AutoReset = DEFAULT_AUTORESET;
AutoUpdatePresets = DEFAULT_AUTOUPDATEPRESETS;

CustomAutosplits = new AutoSplitList("Custom");
DefaultPreset = CustomAutosplits.Name;
CustomAutosplits = new AutoSplitList(DEFAULT_PRESET_NAME);
AutoSplitList = new AutoSplitList();
Presets = new BindingList<AutoSplitList>() { CustomAutosplits };

Expand All @@ -92,7 +91,7 @@ public SkyrimSettings(SkyrimComponent component, LiveSplitState state)
if (File.Exists(PRESETS_FILE_PATH))
LoadPresets();

Preset = DefaultPreset;
Preset = DEFAULT_PRESET_NAME;

BearCartPBNotification = DEFAULT_BEARCARTPBNOTIFICATION;
PlayBearCartSound = DEFAULT_PLAYBEARCARTSOUND;
Expand Down Expand Up @@ -171,7 +170,7 @@ public void SetSettings(XmlNode settings)
CustomAutosplits.AddRange(customList);
}

Preset = SettingsHelper.ParseString(settings["Preset"], DefaultPreset);
Preset = SettingsHelper.ParseString(settings["Preset"], DEFAULT_PRESET_NAME);
if (!updatedPresets)
{
if ((AutoUpdatePresets || !File.Exists(PRESETS_FILE_PATH)) && !CheckForComponentUpdate())
Expand Down Expand Up @@ -203,7 +202,7 @@ void ConvertOldSettings(XmlNode settings)

if (version < new Version(3, 0) && version >= new Version(2, 0))
{
var preset = DefaultPreset;
var preset = DEFAULT_PRESET_NAME;
switch (settings["AnyPercentTemplate"]?.InnerText)
{
case "MrWalrus":
Expand Down Expand Up @@ -322,6 +321,20 @@ bool DownloadPresetsFile(bool silentErrors = true)
return true;
}

void UpdatePresets()
{
if (!CheckForComponentUpdate())
{
if (DownloadPresetsFile(false) && LoadPresets(false))
MessageBox.Show("Presets successfully updated.", "Presets updated",
MessageBoxButtons.OK, MessageBoxIcon.Information);
UsePreset(Presets.FirstOrDefault(l => l.Name == Preset) ?? CustomAutosplits);
}
else
MessageBox.Show("An update is available for the autosplitter.\nPresets can only be updated with the latest autosplitter version available.",
"Presets update cancelled", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

bool CheckForComponentUpdate()
{
var updateAvailable = false;
Expand Down Expand Up @@ -351,7 +364,7 @@ bool CheckForComponentUpdate()
}

if (updateAvailable)
btnUpdatePresets.Enabled = false;
btnOther.Enabled = false;

return updateAvailable;
}
Expand Down

0 comments on commit 2b4e7f1

Please sign in to comment.