backend note implementation.

This commit is contained in:
Michele Scandura 2020-12-03 19:38:03 +00:00
parent 651aeb407b
commit fe3c0ed2cf
11 changed files with 185 additions and 75 deletions

View file

@ -57,7 +57,7 @@ namespace Sledgemapper
_communicationManager.Connection.Reconnecting += OnHubReconnecting;
_communicationManager.Connection.Closed += OnHubDisconnected;
_state = new State();
_settings= new Settings();
_settings = new Settings();
}
private async Task OnHubDisconnected(Exception arg)
@ -137,17 +137,17 @@ namespace Sledgemapper
private void OneMenuFileSettingsSelected(object sender, EventArgs e)
{
var propertyGrid = new PropertyGrid
{
Object = _settings,
Width = 350
};
var propertyGrid = new PropertyGrid
{
Object = _settings,
Width = 350
};
var _windowEditor = new Window
{
Title = "Object Editor",
Content = propertyGrid
};
var _windowEditor = new Window
{
Title = "Object Editor",
Content = propertyGrid
};
_windowEditor.ShowModal(_desktop);
}
@ -269,9 +269,29 @@ namespace Sledgemapper
_state.SelectedNote.X = _state.HoveredTile.X;
_state.SelectedNote.Y = _state.HoveredTile.Y;
var contextMenu = new TextButton { Text = "New Note" };
contextMenu.Click += OnContextMenuNewNoteClick;
_desktop.ShowContextMenu(contextMenu, mouseState.Position);
var popup = new VerticalStackPanel { Padding = new Myra.Graphics2D.Thickness(1), Spacing = 2, Background = new SolidBrush(Color.DarkGray) };
if (!_sessionData.Notes.ContainsKey(_state.SelectedNote.ToString()))
{
var newNoteButton = new TextButton { Text = "New Note", Width = 80, Height = 20, Padding = new Myra.Graphics2D.Thickness(2), HorizontalAlignment = HorizontalAlignment.Left };
newNoteButton.Click += OnContextMenuNewNoteClick;
popup.AddChild(newNoteButton);
}
else
{
_sessionData.Notes.TryGetValue(_state.SelectedNote.ToString(), out var n);
_state.SelectedNote = n;
var viewNoteButton = new TextButton { Text = "View Note", Width = 80, Height = 20, Padding = new Myra.Graphics2D.Thickness(2), HorizontalAlignment = HorizontalAlignment.Left };
var deleteNoteButton = new TextButton { Text = "Delete Note", Width = 80, Height = 20, Padding = new Myra.Graphics2D.Thickness(2), HorizontalAlignment = HorizontalAlignment.Left };
viewNoteButton.Click += OnContextMenuViewNoteClick;
deleteNoteButton.Click += OnContextMenuDeleteNoteClick;
popup.AddChild(viewNoteButton);
popup.AddChild(deleteNoteButton);
}
_desktop.ShowContextMenu(popup, mouseState.Position);
}
if (newState.IsKeyDown(Keys.LeftControl)
@ -590,8 +610,8 @@ namespace Sledgemapper
_spriteBatch.Draw(
_comment,
new Rectangle(
note.X * _state.TileSize + _state.TileSize - (int)(_state.TileSize / 2) + _state.TileSize / 20,
note.Y * _state.TileSize + _state.TileSize / 8 + _state.TileSize / 20,
note.X * _state.TileSize + _state.TileSize - (int)(_state.TileSize / 2) + _state.TileSize / 25,
note.Y * _state.TileSize + _state.TileSize / 8 + _state.TileSize / 25,
(int)(_state.TileSize / 2.5), (int)(_state.TileSize / 2.5 / 1.136)
), Color.Black * .2f
);
@ -916,63 +936,14 @@ namespace Sledgemapper
var localWindow = (Window)container;
var localContent = localWindow.Content as NoteWindow;
if (!button.Enabled)
var note = new Note
{
return;
}
var isValid = true;
isValid &= ValidateTextbox(localContent.NoteText);
if (!isValid)
{
return;
}
var successful = false;
try
{
var note = new Note
{
X = _state.SelectedNote.X,
Y = _state.SelectedNote.Y,
Text = localContent.NoteText.Text
};
_sessionData.Notes.AddOrUpdate(note.ToString(), note, (key, oldValue) => note);
button.Text = "Wait...";
// localContent.LblLoginError.Text = "";
// localContent.LblLoginError.Visible = false;
// _authResponse = await _communicationManager.Login(new AuthenticateModel
// {
// Username = localContent.TxtEmail.Text,
// Password = localContent.TxtPassword.Text
// });
// successful = _authResponse != null;
successful = true;
}
catch (Refit.ApiException refitException)
{
// localContent.LblLoginError.Text = refitException.Content;
// localContent.LblLoginError.Visible = true;
}
catch (Exception ex)
{
// localContent.LblLoginError.Text = "Can't connect to the server";
// localContent.LblLoginError.Visible = true;
}
finally
{
button.Enabled = true;
button.Text = "OK";
}
if (successful)
{
localWindow.Close();
}
X = _state.SelectedNote.X,
Y = _state.SelectedNote.Y,
Text = localContent.NoteText.Text
};
_sessionData.NewNote(note);
localWindow.Close();
}
private async void OnButtonNoteCancelClick(object sender, EventArgs e)
@ -1162,6 +1133,18 @@ namespace Sledgemapper
window.ShowModal(_desktop);
}
private void OnContextMenuDeleteNoteClick(object sender, EventArgs e)
{
_desktop.HideContextMenu();
_sessionData.DeleteNote(_state.SelectedNote);
}
private void OnContextMenuViewNoteClick(object sender, EventArgs e)
{
_desktop.HideContextMenu();
EditNote(_state.SelectedNote);
}
private void OnOverlayButtonClicked(object sender, EventArgs e)
{
_state.CurrentOverlayId = ((ImageButton)sender).Id;