From 3d3c80e7de869416c3e12e19019784bc51be8ccf Mon Sep 17 00:00:00 2001 From: Michele Date: Sun, 29 Nov 2020 23:54:48 +0000 Subject: [PATCH 1/2] new note window --- Sledgemapper.Shared/Entities/Note.cs | 11 ++++ Sledgemapper/Sledgemapper.cs | 49 ++++++++++++++++ Sledgemapper/UI/NoteWindow.Generated.cs | 77 +++++++++++++++++++++++++ Sledgemapper/UI/NoteWindow.cs | 11 ++++ Sledgemapper/UI/noteWindow.xml | 19 ++++++ 5 files changed, 167 insertions(+) create mode 100644 Sledgemapper.Shared/Entities/Note.cs create mode 100644 Sledgemapper/UI/NoteWindow.Generated.cs create mode 100644 Sledgemapper/UI/NoteWindow.cs create mode 100644 Sledgemapper/UI/noteWindow.xml diff --git a/Sledgemapper.Shared/Entities/Note.cs b/Sledgemapper.Shared/Entities/Note.cs new file mode 100644 index 0000000..6dac5bb --- /dev/null +++ b/Sledgemapper.Shared/Entities/Note.cs @@ -0,0 +1,11 @@ +namespace Sledgemapper.Shared.Entities +{ + + + public class Note :BaseMapEntity + { + public string Text { get; set; } + } + + +} diff --git a/Sledgemapper/Sledgemapper.cs b/Sledgemapper/Sledgemapper.cs index f5ea365..8aab4a9 100644 --- a/Sledgemapper/Sledgemapper.cs +++ b/Sledgemapper/Sledgemapper.cs @@ -197,6 +197,55 @@ namespace Sledgemapper } } + if (mouseState.RightButton == ButtonState.Released && mouseState.RightButton != oldMouseState.RightButton) + { + var contextMenu = new TextButton { Text = "New Note" }; + contextMenu.Click += (s, e) => + { + _desktop.HideContextMenu(); + var noteWindow = new NoteWindow(); + Window window = new() + { + Title = "Note" + }; + + // var content = new LoginRegisterWindow(); + // content.RdoLogin.IsPressed = true; + // content.RdoLogin.Click += (s, e) => + // { + // content.TxtFirstname.Visible = false; + // content.TxtLastname.Visible = false; + // content.TxtInitials.Visible = false; + // content.LblFirstname.Visible = false; + // content.LblLastname.Visible = false; + // content.LblInitials.Visible = false; + // content.BtnLogin.Visible = true; + // content.BtnRegister.Visible = false; + // window.Title = "Login"; + // }; + + // content.RdoRegister.Click += (s, e) => + // { + // content.TxtFirstname.Visible = true; + // content.TxtLastname.Visible = true; + // content.TxtInitials.Visible = true; + // content.LblFirstname.Visible = true; + // content.LblLastname.Visible = true; + // content.LblInitials.Visible = true; + // content.BtnLogin.Visible = false; + // content.BtnRegister.Visible = true; + // window.Title = "Register"; + // }; + + // content.BtnRegister.Click += OnButtonRegisterClick; + // content.BtnLogin.Click += OnButtonLoginClick; + + window.Content = noteWindow; + window.ShowModal(_desktop); + }; + _desktop.ShowContextMenu(contextMenu, mouseState.Position); + } + if (newState.IsKeyDown(Keys.LeftControl) && mouseState.LeftButton == ButtonState.Pressed && ((mouseState.LeftButton != oldMouseState.LeftButton) || (_state.SelectedTile.X != _state.HoveredTile.X && _state.SelectedTile.Y != _state.HoveredTile.Y))) diff --git a/Sledgemapper/UI/NoteWindow.Generated.cs b/Sledgemapper/UI/NoteWindow.Generated.cs new file mode 100644 index 0000000..4627877 --- /dev/null +++ b/Sledgemapper/UI/NoteWindow.Generated.cs @@ -0,0 +1,77 @@ +/* Generated by MyraPad at 29/11/2020 23:51:26 */ +using Myra.Graphics2D; +using Myra.Graphics2D.TextureAtlases; +using Myra.Graphics2D.UI; +using Myra.Graphics2D.Brushes; + +#if !STRIDE +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +#else +using Stride.Core.Mathematics; +#endif + +namespace Sledgemapper.UI +{ + partial class NoteWindow: Grid + { + private void BuildUI() + { + NoteText = new TextBox(); + NoteText.Multiline = true; + NoteText.Wrap = true; + NoteText.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Stretch; + NoteText.Id = "NoteText"; + + var scrollViewer1 = new ScrollViewer(); + scrollViewer1.Content = NoteText; + + BtnCancel = new TextButton(); + BtnCancel.Text = "Cancel"; + BtnCancel.Width = 70; + BtnCancel.Height = 20; + BtnCancel.Padding = new Thickness(5); + BtnCancel.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; + BtnCancel.Id = "BtnCancel"; + + BtnOk = new TextButton(); + BtnOk.Text = "Ok"; + BtnOk.Width = 70; + BtnOk.Height = 20; + BtnOk.Padding = new Thickness(5); + BtnOk.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; + BtnOk.Id = "BtnOk"; + + var horizontalStackPanel1 = new HorizontalStackPanel(); + horizontalStackPanel1.Spacing = 10; + horizontalStackPanel1.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Right; + horizontalStackPanel1.GridRow = 1; + horizontalStackPanel1.Widgets.Add(BtnCancel); + horizontalStackPanel1.Widgets.Add(BtnOk); + + + RowSpacing = 13; + ColumnsProportions.Add(new Proportion + { + Type = Myra.Graphics2D.UI.ProportionType.Fill, + }); + RowsProportions.Add(new Proportion + { + Type = Myra.Graphics2D.UI.ProportionType.Fill, + }); + RowsProportions.Add(new Proportion + { + Type = Myra.Graphics2D.UI.ProportionType.Auto, + }); + Width = 400; + Height = 300; + Widgets.Add(scrollViewer1); + Widgets.Add(horizontalStackPanel1); + } + + + public TextBox NoteText; + public TextButton BtnCancel; + public TextButton BtnOk; + } +} \ No newline at end of file diff --git a/Sledgemapper/UI/NoteWindow.cs b/Sledgemapper/UI/NoteWindow.cs new file mode 100644 index 0000000..cd5e4bf --- /dev/null +++ b/Sledgemapper/UI/NoteWindow.cs @@ -0,0 +1,11 @@ +/* Generated by MyraPad at 29/11/2020 23:50:42 */ +namespace Sledgemapper.UI +{ + public partial class NoteWindow + { + public NoteWindow() + { + BuildUI(); + } + } +} \ No newline at end of file diff --git a/Sledgemapper/UI/noteWindow.xml b/Sledgemapper/UI/noteWindow.xml new file mode 100644 index 0000000..f31c4d0 --- /dev/null +++ b/Sledgemapper/UI/noteWindow.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 227436c740d3677b4588eaab735af1947dd0c496 Mon Sep 17 00:00:00 2001 From: Michele Date: Mon, 30 Nov 2020 23:17:12 +0000 Subject: [PATCH 2/2] display note on grid --- Sledgemapper.Shared/Entities/Session.cs | 2 ++ Sledgemapper/Sledgemapper.cs | 41 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/Sledgemapper.Shared/Entities/Session.cs b/Sledgemapper.Shared/Entities/Session.cs index 8f5ec5a..692471f 100644 --- a/Sledgemapper.Shared/Entities/Session.cs +++ b/Sledgemapper.Shared/Entities/Session.cs @@ -26,6 +26,7 @@ namespace Sledgemapper.Shared.Entities Map = new ConcurrentDictionary(); Overlays = new ConcurrentDictionary(); Walls = new ConcurrentDictionary(); + Notes = new ConcurrentDictionary(); Players = new List(); Colors = new List(); } @@ -33,6 +34,7 @@ namespace Sledgemapper.Shared.Entities public ConcurrentDictionary Map { get; set; } public ConcurrentDictionary Walls { get; set; } public ConcurrentDictionary Overlays { get; set; } + public ConcurrentDictionary Notes { get; set; } public bool IsValid { get; set; } public List Players { get; set; } public List Colors { get; set; } diff --git a/Sledgemapper/Sledgemapper.cs b/Sledgemapper/Sledgemapper.cs index 8aab4a9..fd301bc 100644 --- a/Sledgemapper/Sledgemapper.cs +++ b/Sledgemapper/Sledgemapper.cs @@ -208,7 +208,17 @@ namespace Sledgemapper { Title = "Note" }; + noteWindow.BtnOk.Click += (s, e) => + { + var note = new Note + { + X = _state.SelectedTile.X, + Y = _state.SelectedTile.Y, + Text = noteWindow.NoteText.Text + }; + _sessionData.Notes.TryAdd(note.ToString(), note); + }; // var content = new LoginRegisterWindow(); // content.RdoLogin.IsPressed = true; // content.RdoLogin.Click += (s, e) => @@ -386,6 +396,8 @@ namespace Sledgemapper DrawWalls(); DrawOverlays(); + DrawNotes(); + if (string.IsNullOrWhiteSpace(_sessionData.SessionName)) { @@ -548,6 +560,35 @@ namespace Sledgemapper } } + private void DrawNotes() + { + foreach (var note in _sessionData.Notes.Values) + { + var ffont = _fonts.FirstOrDefault(m => int.Parse(m.Key.Replace("font", "")) > _state.TileSize / 8).Value ?? _fonts.Last().Value; + var fscale = 1f; + + + var screenPosition = new Point(note.X * _state.TileSize - (int)_viewportCenter.X, note.Y * _state.TileSize - (int)_viewportCenter.Y); + + var x = screenPosition.X / _state.TileSize; + var y = screenPosition.Y / _state.TileSize; + + _spriteBatch.DrawString(ffont, + "N", + new Vector2( + x * _state.TileSize + _state.TileSize - _state.TileSize/3, + y * _state.TileSize + 2 + ), + Color.Black, + 0, + Vector2.Zero, + fscale, + SpriteEffects.None, + 0); + + } + } + private void DrawOverlays() { foreach (var tile in _sessionData.Overlays.Values)