Skip to content

Commit

Permalink
Add: Remember beatmap collumns between runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Jul 31, 2024
1 parent 1f5b5f8 commit 6b1f9ec
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
26 changes: 21 additions & 5 deletions App/Presenters/Controls/BeatmapListingPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using App.Interfaces;
using App.Misc;
using GuiComponents.Interfaces;
using CollectionManagerApp.Properties;
using Newtonsoft.Json;

namespace App.Presenters.Controls
{
public class BeatmapListingPresenter: IBeatmapListingPresenter
public class BeatmapListingPresenter : IBeatmapListingPresenter
{
readonly IBeatmapListingView _view;
readonly IBeatmapListingModel _model;
Expand All @@ -28,21 +30,35 @@ public Beatmaps Beatmaps
public BeatmapListingPresenter(IBeatmapListingView view, IBeatmapListingModel model)
{
_view = view;
_view.SearchTextChanged+=ViewOnSearchTextChanged;
_view.SearchTextChanged += ViewOnSearchTextChanged;
_view.SelectedBeatmapChanged += (s, a) => _model.SelectedBeatmap = _view.SelectedBeatmap;
_view.SelectedBeatmapsChanged += (s, a) => _model.SelectedBeatmaps = _view.SelectedBeatmaps;

_view.BeatmapsDropped += (s, a) => _model.EmitBeatmapsDropped(s, a);
_view.BeatmapOperation += (s, a) => _model.EmitBeatmapOperation(a);
_view.ColumnsToggled += (s, a) => OnColumnsToggled(a);

_model = model;
_model.BeatmapsChanged += _model_BeatmapsChanged;
_model.FilteringStarted+=ModelOnFilteringStarted;
_model.FilteringStarted += ModelOnFilteringStarted;
_model.FilteringFinished += _model_FilteringFinished;
_view.SetFilter(_model.GetFilter());

var visibleColumns = JsonConvert.DeserializeObject<string[]>(Settings.Default.BeatmapColumns);

if (visibleColumns.Length > 0)
{
_view.SetVisibleColumns(visibleColumns);
}

Beatmaps = _model.GetBeatmaps();
}


private void OnColumnsToggled(string[] visibleColumnAspectNames)
{
Settings.Default.BeatmapColumns = JsonConvert.SerializeObject(visibleColumnAspectNames);
}

private void _model_FilteringFinished(object sender, EventArgs e)
{
if (_model.GetFilter() is BeatmapListFilter filter)
Expand Down
1 change: 1 addition & 0 deletions Common/GuiHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public static class GuiHelpers
public delegate void LoadFileArgs(object sender, string[] filePaths);
public delegate void StartupCollectionEventArgs(object sender, StartupCollectionAction args);
public delegate void StartupDatabaseEventArgs(object sender, StartupDatabaseAction args);
public delegate void ColumnsToggledEventArgs(object sender, string[] visibleCollumnAspectNames);
}
}
2 changes: 2 additions & 0 deletions Common/Interfaces/Controls/IBeatmapListingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public interface IBeatmapListingView
event EventHandler SelectedBeatmapsChanged;
event GuiHelpers.BeatmapListingActionArgs BeatmapOperation;
event GuiHelpers.BeatmapsEventArgs BeatmapsDropped;
event GuiHelpers.ColumnsToggledEventArgs ColumnsToggled;

void SetCurrentPlayMode(PlayMode playMode);
void SetCurrentMods(Mods mods);
void SetBeatmaps(IEnumerable beatmaps);
void SetVisibleColumns(string[] visibleColumnsAspectNames);
void SetFilter(IModelFilter filter);
void FilteringStarted();
void FilteringFinished();
Expand Down
30 changes: 28 additions & 2 deletions GuiComponents/Controls/BeatmapListingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Common;
using GuiComponents.Interfaces;
using Gui.Misc;
using System.Linq;

namespace GuiComponents.Controls
{
Expand All @@ -22,6 +23,7 @@ public partial class BeatmapListingView : UserControl, IBeatmapListingView

public event GuiHelpers.BeatmapListingActionArgs BeatmapOperation;
public event GuiHelpers.BeatmapsEventArgs BeatmapsDropped;
public event GuiHelpers.ColumnsToggledEventArgs ColumnsToggled;

public string SearchText => textBox_beatmapSearch.Text;
public string ResultText { get; set; }
Expand Down Expand Up @@ -54,6 +56,16 @@ public void SetBeatmaps(IEnumerable beatmaps)
UpdateResultsCount();
}

public void SetVisibleColumns(string[] visibleColumnsAspectNames)
{
foreach (var column in ListViewBeatmaps.AllColumns)
{
column.IsVisible = visibleColumnsAspectNames.Contains(column.AspectName);
}

ListViewBeatmaps.RebuildColumns();
}

public Beatmap SelectedBeatmap
{
get => (Beatmap)ListViewBeatmaps.SelectedObject;
Expand Down Expand Up @@ -99,7 +111,18 @@ private void Bind()
{
args.MenuStrip = BeatmapsContextMenuStrip;
};
ListViewBeatmaps.ColumnWidthChanged += OnColumnReordered;
}

private void OnColumnReordered(object sender, ColumnWidthChangedEventArgs e)
{
var visibleColumnAspectNames = ListViewBeatmaps.AllColumns
.Where(column => column.IsVisible)
.Select(column => column.AspectName);

ColumnsToggled?.Invoke(this, visibleColumnAspectNames.ToArray());
}

private void UpdateResultsCount()
{
int count = 0;
Expand Down Expand Up @@ -174,7 +197,8 @@ private void InitListView()
};
LastPlayed.AspectToStringConverter = delegate (object cellValue)
{
if (cellValue == null) return string.Empty;
if (cellValue == null)
return string.Empty;
var val = (DateTimeOffset)cellValue;
return val > d ? $"{val}" : "Never";
};
Expand All @@ -188,7 +212,8 @@ private void InitListView()
};
column_bpm.AspectToStringConverter = delegate (object cellValue)
{
if (cellValue == null) return string.Empty;
if (cellValue == null)
return string.Empty;
return $"{cellValue:0.##}";
};

Expand Down Expand Up @@ -312,6 +337,7 @@ private void ListViewBeatmaps_KeyUp(object sender, KeyEventArgs e)
MenuStripClick(DeleteMapMenuStrip, e);
}
}

}


Expand Down

0 comments on commit 6b1f9ec

Please sign in to comment.