Skip to content

Commit cf8e1cd

Browse files
committed
Option to hide header items with no children in the overlay
1 parent c74b621 commit cf8e1cd

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

ReleaseNotes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11

22
# Release Notes
33

4+
## Version 2.3.0
5+
6+
* Configuration changes now refresh the overlay list when the
7+
configuration is saved rather than being delayed until the next
8+
list refresh.
9+
* Added a overlay configuration option to hide items marked as
10+
"header" if they have no children (i.e., if the next visible
11+
item is also a header).
12+
413
## Version 2.2.1
514

615
* Added Polish translation from github user marcix99942

ToDew/ModEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public ModEntry() {
4848
// this really shouldn't happen
4949
api = new ToDoApiImpl(this, ModManifest);
5050
}
51-
ToDoListOverlayDataSource source = new(() => api.RefreshOverlay());
51+
ToDoListOverlayDataSource source = new(this, () => api.RefreshOverlay());
5252
api.AddOverlayDataSource(source);
5353
return source;
5454
});

ToDew/ToDoListOverlayDataSource.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// Copyright 2023 Jamie Taylor
22
using System;
33
using System.Collections.Generic;
4+
using System.Linq;
45

56
namespace ToDew {
67
public class ToDoListOverlayDataSource : IToDewOverlayDataSource {
8+
private readonly ModEntry theMod;
79
private ToDoList? _theList;
10+
private OverlayConfig config { get => theMod.config.overlay; }
811
public ToDoList? theList {
912
get => _theList;
1013
set {
@@ -18,7 +21,8 @@ public ToDoList? theList {
1821
}
1922
}
2023
private readonly Action refreshOverlay;
21-
public ToDoListOverlayDataSource(Action refreshOverlay) {
24+
public ToDoListOverlayDataSource(ModEntry theMod, Action refreshOverlay) {
25+
this.theMod = theMod;
2226
this.refreshOverlay = refreshOverlay;
2327
}
2428

@@ -29,11 +33,23 @@ public string GetSectionTitle() {
2933
public List<(string text, bool isBold, Action? onDone)> GetItems(int limit) {
3034
List<(string text, bool isBold, Action? onDone)> result = new();
3135
if (theList is null) return result;
36+
bool lastIsHeader = false;
3237
foreach (var item in theList.Items) {
3338
if (item.IsDone || item.HideInOverlay || !item.IsVisibleToday) continue;
34-
string itemText = item.IsHeader ? item.Text : (" " + item.Text);
35-
result.Add((itemText, item.IsBold, item.IsHeader ? null : () => theList.SetItemDone(item, true)));
36-
if (result.Count == limit) break;
39+
if (item.IsHeader) {
40+
if (lastIsHeader && config.hideHeaderWithNoChildren) {
41+
result.RemoveAt(result.Count - 1);
42+
}
43+
lastIsHeader = true;
44+
result.Add((" " + item.Text, item.IsBold, null));
45+
} else {
46+
lastIsHeader = false;
47+
result.Add((item.Text, item.IsBold, () => theList.SetItemDone(item, true)));
48+
if (result.Count >= limit) break;
49+
}
50+
}
51+
if (config.hideHeaderWithNoChildren && lastIsHeader) {
52+
result.RemoveAt(result.Count - 1);
3753
}
3854
return result;
3955
}

ToDew/ToDoOverlay.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace ToDew {
1616
public class OverlayConfig {
1717
public bool enabled = true;
1818
public bool clickToMarkDone = true;
19+
public bool hideHeaderWithNoChildren = false;
1920
public SButton hotkey = SButton.None;
2021
public KeybindList hotkeyList = new KeybindList();
2122
public bool hideAtFestivals = false;
@@ -40,6 +41,12 @@ public static void RegisterConfigMenuOptions(Func<OverlayConfig> getThis, Generi
4041
tooltip: I18n.Config_Overlay_ClickToMarkDone_Desc,
4142
getValue: () => getThis().clickToMarkDone,
4243
setValue: (bool val) => getThis().clickToMarkDone = val);
44+
api.AddBoolOption(
45+
mod: modManifest,
46+
name: I18n.Config_Overlay_HideHeaderWithNoChildren,
47+
tooltip: I18n.Config_Overlay_HideHeaderWithNoChildren_Desc,
48+
getValue: () => getThis().hideHeaderWithNoChildren,
49+
setValue: (bool val) => getThis().hideHeaderWithNoChildren = val);
4350
api.AddKeybind(
4451
mod: modManifest,
4552
name: I18n.Config_Overlay_Hotkey,

ToDew/i18n/default.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"config.overlay.enabled.desc": "Is the overlay enabled?",
1919
"config.overlay.click-to-mark-done": "Click items to mark done",
2020
"config.overlay.click-to-mark-done.desc": "Enable clicking in the overlay to mark items done",
21+
"config.overlay.hide-header-with-no-children": "Hide headers with no children",
22+
"config.overlay.hide-header-with-no-children.desc": "Do not show a header item if the next visible item is also a header",
2123
"config.overlay.hotkey": "Hotkey",
2224
"config.overlay.hotkey.desc": "Hotkey to show or hide",
2325
"config.overlay.hide-at-festivals": "Hide at festivals",

0 commit comments

Comments
 (0)