fixing notes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-20 16:49:49 +01:00
parent 77befef8e0
commit 17d6cd28d6
2 changed files with 27 additions and 77 deletions

View File

@ -122,7 +122,7 @@ public class Map:Session
var newNote = new Note { X = selectedNote.X, Y = selectedNote.Y, Text = selectedNote.Text };
if (noteExists)
{
Walls.TryRemove(note.ToString(), out var _);
Notes.TryRemove(note.ToString(), out var _);
}
Notes.TryAdd(newNote.ToString(), newNote);

View File

@ -24,6 +24,7 @@ namespace Sledgemapper
{
private readonly CommunicationManager _communicationManager;
private readonly State _state;
private readonly ArrayPool<Vector2> _vector2Pool;
private readonly GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private CachedContent _cachedContent;
@ -37,6 +38,13 @@ namespace Sledgemapper
private RenderTarget2D rendertarget;
private MainWidget _mainWidget;
private readonly TinyMessengerHub _messenger;
Effect outlineShader;
private Texture2D _transparentRedRectangle;
private Texture2D _whiteRectangle;
private Dictionary<string, Texture2D> _wallsContent;
private SpriteSheet _spriteSheet;
private SpriteSheet _rippleSpriteSheet;
Label _lblOverlayName;
public Sledgemapper()
{
@ -58,7 +66,7 @@ namespace Sledgemapper
_communicationManager.Connection.Reconnecting += OnHubReconnecting;
_communicationManager.Connection.Closed += OnHubDisconnected;
_state = State.Instance;
_vector2Pool = ArrayPool<Vector2>.Create();
_messenger = new TinyMessengerHub();
}
@ -76,6 +84,7 @@ namespace Sledgemapper
_mainWidget.lblConnectionStatus.Text = "Reconnecting";
await Task.Yield();
}
private async Task OnHubReconnected(string arg)
{
// ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Hub reconnected", Type = "SignalR Client Events", Source = _settings.MachineName });
@ -118,7 +127,6 @@ namespace Sledgemapper
}
private void AddItemToToolGrid(Grid grid, EventHandler eventAction, Dictionary<string, Texture2D> tilesFolderContent)
{
var indexX = 0;
@ -165,9 +173,6 @@ namespace Sledgemapper
_lblOverlayName.Visible = false;
}
private SpriteSheet _rippleSpriteSheet;
Label _lblOverlayName;
private void OnTileButtonTouchEntered(object sender, EventArgs e)
{
var mouseState = Mouse.GetState().Position;
@ -188,7 +193,7 @@ namespace Sledgemapper
ResetRenderTarget();
_mainWidget = new MainWidget(_communicationManager, _messenger, Window);
_mainWidget = new MainWidget(_communicationManager, _messenger, Window);
@ -227,29 +232,15 @@ namespace Sledgemapper
CenterOnTile(0, 0);
}
private void OnTxtOverlaySearchChange(object sender, ValueChangedEventArgs<string> e)
{
AddItemToToolGrid(_mainWidget.GridOverlays, OnOverlayButtonClicked, _spriteSheet, e.NewValue);
}
private void EditNote(Note note)
{
_state.SelectedNote = new Note { X = note.X, Y = note.Y, Text = note.Text };
var noteWindow = new NoteWindow();
Window window = new()
{
Title = $" Note on {note.X}:{note.Y}"
};
noteWindow.NoteText.Text = note.Text;
noteWindow.BtnOk.Click += OnButtonNoteOkClick;
noteWindow.BtnCancel.Click += OnButtonNoteCancelClick;
window.Content = noteWindow;
window.ShowModal(_desktop);
noteWindow.NoteText.SetKeyboardFocus();
new NoteWindow(_communicationManager, note).ShowInModalWindow(_desktop, $" Note on {note.X}:{note.Y}");
}
protected override void Update(GameTime gameTime)
@ -262,16 +253,21 @@ namespace Sledgemapper
var screenPosition = new Point(mouseState.Position.X - (int)_state.ViewportCenter.X, mouseState.Position.Y - (int)_state.ViewportCenter.Y);
_state.HoveredTile.X = screenPosition.X / _state.TileSize;
_state.HoveredTile.Y = screenPosition.Y / _state.TileSize;
if (screenPosition.X < 0)
if (!_desktop.ContextMenu?.Visible??true)
{
_state.HoveredTile.X--;
}
_state.HoveredTile.X = screenPosition.X / _state.TileSize;
_state.HoveredTile.Y = screenPosition.Y / _state.TileSize;
if (screenPosition.Y < 0)
{
_state.HoveredTile.Y--;
if (screenPosition.X < 0)
{
_state.HoveredTile.X--;
}
if (screenPosition.Y < 0)
{
_state.HoveredTile.Y--;
}
}
if (_state.InsertMode == InsertMode.Wall)
@ -1462,8 +1458,6 @@ namespace Sledgemapper
}
}
ArrayPool<Vector2> _vector2Pool;
private bool IsOffscreen(Tile position)
{
var boxTL = new Point(200 - _state.TileSize / 2, 75 - _state.TileSize / 2);
@ -1480,8 +1474,6 @@ namespace Sledgemapper
return false;
}
private int _borderWidth => (_state.TileSize / 6) % 2 == 0 ? (_state.TileSize / 6) : (_state.TileSize / 6) + 1;
private void DrawTiles()
{
for (var i = 0; i < _sessionData.Map.Values.Count; i++)
@ -1549,7 +1541,6 @@ namespace Sledgemapper
}
}
private void DrawRoom(Room tile)
{
var posX = tile.Start.X * _state.TileSize;
@ -1620,12 +1611,6 @@ namespace Sledgemapper
}
}
}
Effect outlineShader;
private Texture2D _transparentRedRectangle;
private Texture2D _whiteRectangle;
private Dictionary<string, Texture2D> _wallsContent;
private SpriteSheet _spriteSheet;
private void DrawDelete(Room tile)
{
@ -1725,47 +1710,12 @@ namespace Sledgemapper
}
}
private void OnButtonNoteOkClick(object sender, EventArgs e)
{
var button = ((TextButton)sender);
var localContent = button.GetParentContentInWindow<NoteWindow>();
var note = new Note
{
X = _state.SelectedNote.X,
Y = _state.SelectedNote.Y,
Text = localContent.Content.NoteText.Text
};
_sessionData.NewNote(note);
localContent.Window.Close();
}
private void OnButtonNoteCancelClick(object sender, EventArgs e)
{
var button = ((TextButton)sender);
var content = button.GetParentContentInWindow<Widget>();
content.Window.Close();
}
private void OnContextMenuNewNoteClick(object sender, EventArgs e)
{
_desktop.HideContextMenu();
var noteWindow = new NoteWindow();
Window window = new()
{
Title = $" Note on {_state.SelectedTile.X}:{_state.SelectedTile.Y}"
};
noteWindow.BtnOk.Click += OnButtonNoteOkClick;
noteWindow.BtnCancel.Click += OnButtonNoteCancelClick;
window.Content = noteWindow;
window.ShowModal(_desktop);
noteWindow.NoteText.SetKeyboardFocus();
new NoteWindow(_communicationManager, new Note()).ShowInModalWindow(_desktop, $" Note on {_state.HoveredTile.X}:{_state.HoveredTile.Y}");
}
private void OnContextMenuDeleteNoteClick(object sender, EventArgs e)
{
_desktop.HideContextMenu();