Make faded notes pop in on hover (#19101)
This commit is contained in:
@@ -87,12 +87,64 @@ public sealed partial class AdminNotesControl : Control
|
|||||||
};
|
};
|
||||||
|
|
||||||
_popup.OnDeletePressed += (noteId, noteType) => NoteDeleted?.Invoke(noteId, noteType);
|
_popup.OnDeletePressed += (noteId, noteType) => NoteDeleted?.Invoke(noteId, noteType);
|
||||||
|
_popup.OnPopupHide += OnPopupHide;
|
||||||
|
|
||||||
var box = UIBox2.FromDimensions(UserInterfaceManager.MousePositionScaled.Position, Vector2.One);
|
var box = UIBox2.FromDimensions(UserInterfaceManager.MousePositionScaled.Position, Vector2.One);
|
||||||
_popup.Open(box);
|
_popup.Open(box);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPopupHide()
|
||||||
|
{
|
||||||
|
if (_popup == null ||
|
||||||
|
!Inputs.TryGetValue((_popup.NoteId, _popup.NoteType), out var input))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateNoteLineAlpha(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NoteMouseEntered(GUIMouseHoverEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.SourceControl is not AdminNotesLine line)
|
||||||
|
return;
|
||||||
|
|
||||||
|
line.Modulate = line.Modulate.WithAlpha(1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NoteMouseExited(GUIMouseHoverEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.SourceControl is not AdminNotesLine line)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_popup?.NoteId == line.Note.Id && _popup.Visible)
|
||||||
|
return;
|
||||||
|
|
||||||
|
UpdateNoteLineAlpha(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateNoteLineAlpha(AdminNotesLine input)
|
||||||
|
{
|
||||||
|
var timeDiff = DateTime.UtcNow - input.Note.CreatedAt;
|
||||||
|
float alpha;
|
||||||
|
if (_noteFreshDays == 0 || timeDiff.TotalDays <= _noteFreshDays)
|
||||||
|
{
|
||||||
|
alpha = 1f;
|
||||||
|
}
|
||||||
|
else if (_noteStaleDays == 0 || timeDiff.TotalDays > _noteStaleDays)
|
||||||
|
{
|
||||||
|
alpha = 0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
alpha = (float) (1 - Math.Clamp((timeDiff.TotalDays - _noteFreshDays) / (_noteStaleDays - _noteFreshDays), 0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
input.Modulate = input.Modulate.WithAlpha(alpha);
|
||||||
|
}
|
||||||
|
|
||||||
public void SetNotes(Dictionary<(int, NoteType), SharedAdminNote> notes)
|
public void SetNotes(Dictionary<(int, NoteType), SharedAdminNote> notes)
|
||||||
{
|
{
|
||||||
foreach (var (key, input) in Inputs)
|
foreach (var (key, input) in Inputs)
|
||||||
@@ -119,25 +171,17 @@ public sealed partial class AdminNotesControl : Control
|
|||||||
|
|
||||||
input = new AdminNotesLine(_sprites, note);
|
input = new AdminNotesLine(_sprites, note);
|
||||||
input.OnClicked += NoteClicked;
|
input.OnClicked += NoteClicked;
|
||||||
|
input.OnMouseEntered += NoteMouseEntered;
|
||||||
|
input.OnMouseExited += NoteMouseExited;
|
||||||
|
|
||||||
var timeDiff = DateTime.UtcNow - note.CreatedAt;
|
UpdateNoteLineAlpha(input);
|
||||||
float alpha;
|
|
||||||
if (_noteFreshDays == 0 || timeDiff.TotalDays <= _noteFreshDays)
|
if (input.Modulate.A == 0)
|
||||||
{
|
{
|
||||||
alpha = 1f;
|
|
||||||
}
|
|
||||||
else if (_noteStaleDays == 0 || timeDiff.TotalDays > _noteStaleDays)
|
|
||||||
{
|
|
||||||
alpha = 0f;
|
|
||||||
input.Visible = false;
|
input.Visible = false;
|
||||||
showMoreButtonVisible = true;
|
showMoreButtonVisible = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
alpha = (float) (1 - Math.Clamp((timeDiff.TotalDays - _noteFreshDays) / (_noteStaleDays - _noteFreshDays), 0, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
input.Modulate = input.Modulate.WithAlpha(alpha);
|
|
||||||
Notes.AddChild(input);
|
Notes.AddChild(input);
|
||||||
Inputs[(note.Id, note.NoteType)] = input;
|
Inputs[(note.Id, note.NoteType)] = input;
|
||||||
ShowMoreButton.Visible = showMoreButtonVisible;
|
ShowMoreButton.Visible = showMoreButtonVisible;
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ public sealed partial class AdminNotesLinePopup : Popup
|
|||||||
DeleteButton.OnPressed += DeletePressed;
|
DeleteButton.OnPressed += DeletePressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int NoteId { get; }
|
public int NoteId { get; }
|
||||||
private NoteType NoteType { get; }
|
public NoteType NoteType { get; }
|
||||||
private TimeSpan? DeleteResetOn { get; set; }
|
private TimeSpan? DeleteResetOn { get; set; }
|
||||||
|
|
||||||
private void EditPressed(ButtonEventArgs args)
|
private void EditPressed(ButtonEventArgs args)
|
||||||
|
|||||||
Reference in New Issue
Block a user