sledgemapper/Sledgemapper/UI/NoteList.Custom.cs
Michele Scandura f15f1c8857
All checks were successful
continuous-integration/drone/push Build is passing
cleanup, refactoring, usual stuff
2021-09-16 11:11:07 +01:00

54 lines
No EOL
2 KiB
C#

/* Generated by MyraPad at 01/12/2020 11:46:54 */
using System.Linq;
using Myra.Graphics2D.TextureAtlases;
using Myra.Graphics2D.UI;
using Sledgemapper.Messages;
using Sledgemapper.Shared.Entities;
using TinyMessenger;
namespace Sledgemapper.UI
{
public partial class NoteList
{
private readonly CommunicationManager CommunicationManager;
private readonly Window Window;
private readonly TinyMessengerHub Messenger;
public NoteList(CommunicationManager communicationManager, TinyMessengerHub messenger, Window window)
{
BuildUI();
CommunicationManager = communicationManager;
Messenger = messenger;
Window = window;
for (var i = 0; i < CommunicationManager.SessionData.Notes.Values.Count; i++)
{
var note = CommunicationManager.SessionData.Notes.Values.ElementAt(i);
var item = new NoteListItem();
item.LblNoteText.Text = $"{note.ToString()} - {note.Text}";
item.BtnNoteCenter.Image = new TextureRegion(CachedContent.Instance.Location);
item.BtnNoteView.Image = new TextureRegion(CachedContent.Instance.Eye);
item.BtnNoteCenter.Click += (s, e) =>
{
Messenger.Publish(new CenterOnTileMessage(this) { X = note.X, Y = note.Y });
};
item.BtnNoteView.Click += (s, e) => { EditNote(note); window.Close(); };
StackNotesList.AddChild(item);
}
}
private void EditNote(Note note)
{
State.Instance.SelectedNote = new Note { X = note.X, Y = note.Y, Text = note.Text };
Window window = new()
{
Title = $" Note on {note.X}:{note.Y}"
};
var noteWindow = new NoteWindow(CommunicationManager, window, note);
window.Content = noteWindow;
window.ShowModal(Window.Desktop);
}
}
}