notes
This commit is contained in:
parent
b2567b2a01
commit
1e244795fc
49 changed files with 2767 additions and 78 deletions
|
@ -30,6 +30,9 @@ namespace Sledgemapper
|
|||
private Vector3 _viewportCenter = new(0, 0, 0);
|
||||
private bool _isDraggin;
|
||||
private Dictionary<string, SpriteFont> _fonts;
|
||||
private Texture2D _eye;
|
||||
private Texture2D _location;
|
||||
private Texture2D _comment;
|
||||
private readonly Session _sessionData;
|
||||
private AuthenticateResponse _authResponse;
|
||||
private MainWidget _mainWidget;
|
||||
|
@ -111,6 +114,7 @@ namespace Sledgemapper
|
|||
_mainWidget.MenuConnectUpload.Selected += OnMenuConnectUploadSelected;
|
||||
_mainWidget.MenuViewCenterOnSelection.Selected += OnMenuViewCenterOnSelectionSelected;
|
||||
_mainWidget.MenuViewShowCellNUmbers.Selected += OnMenuViewShowCellNUmbersSelected;
|
||||
_mainWidget.MenuViewShowNotes.Selected += OnMenuViewNotesSelected;
|
||||
_mainWidget.MenuConnectNew.Enabled = false;
|
||||
_mainWidget.MenuConnectJoin.Enabled = false;
|
||||
_mainWidget.MenuConnectSync.Enabled = false;
|
||||
|
@ -121,7 +125,9 @@ namespace Sledgemapper
|
|||
AddItemToToolGrid(_mainWidget.GridOverlays, OnOverlayButtonClicked, "overlays");
|
||||
|
||||
_fonts = Content.LoadContentFolder<SpriteFont>("fonts");
|
||||
|
||||
_eye = Content.Load<Texture2D>("eye");
|
||||
_location = Content.Load<Texture2D>("location");
|
||||
_comment = Content.Load<Texture2D>("comment");
|
||||
_desktop.Root = _mainWidget;
|
||||
}
|
||||
|
||||
|
@ -135,6 +141,28 @@ namespace Sledgemapper
|
|||
CenterOnSelectedTile();
|
||||
}
|
||||
|
||||
private void OnMenuViewNotesSelected(object sender, EventArgs e)
|
||||
{
|
||||
Window window = new()
|
||||
{
|
||||
Title = "Notes"
|
||||
};
|
||||
|
||||
var content = new NoteList();
|
||||
|
||||
foreach (var note in _sessionData.Notes.Values)
|
||||
{
|
||||
var item = new NoteListItem();
|
||||
item.LblNoteText.Text = $"{note.ToString()} - {note.Text}";
|
||||
item.BtnNoteCenter.Image = new TextureRegion(_location);
|
||||
item.BtnNoteView.Image = new TextureRegion(_eye);
|
||||
content.StackNotesList.AddChild(item);
|
||||
}
|
||||
|
||||
window.Content = content;
|
||||
window.ShowModal(_desktop);
|
||||
}
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
KeyboardState newState = Keyboard.GetState();
|
||||
|
@ -199,60 +227,11 @@ namespace Sledgemapper
|
|||
|
||||
if (mouseState.RightButton == ButtonState.Released && mouseState.RightButton != oldMouseState.RightButton)
|
||||
{
|
||||
_state.SelectedTile.X = _state.HoveredTile.X;
|
||||
_state.SelectedTile.Y = _state.HoveredTile.Y;
|
||||
|
||||
var contextMenu = new TextButton { Text = "New Note" };
|
||||
contextMenu.Click += (s, e) =>
|
||||
{
|
||||
_desktop.HideContextMenu();
|
||||
var noteWindow = new NoteWindow();
|
||||
Window window = new()
|
||||
{
|
||||
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) =>
|
||||
// {
|
||||
// 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);
|
||||
};
|
||||
contextMenu.Click += OnContextMenuNewNoteClick;
|
||||
_desktop.ShowContextMenu(contextMenu, mouseState.Position);
|
||||
}
|
||||
|
||||
|
@ -531,7 +510,7 @@ namespace Sledgemapper
|
|||
|
||||
if (_showCellNumbers && _state.TileSize >= 30)
|
||||
{
|
||||
var ffont = _fonts.FirstOrDefault(m => int.Parse(m.Key.Replace("font", "")) > _state.TileSize / 8).Value ?? _fonts.Last().Value;
|
||||
var ffont = _fonts.Where(m => m.Key.Contains("awesome")).FirstOrDefault(m => int.Parse(m.Key.Replace("font", "")) > _state.TileSize / 8).Value ?? _fonts.Last().Value;
|
||||
var fscale = 1f;
|
||||
|
||||
for (var i = -1; i < visibleTilesX + 2; i++)
|
||||
|
@ -562,30 +541,46 @@ namespace Sledgemapper
|
|||
|
||||
private void DrawNotes()
|
||||
{
|
||||
if (_state.TileSize < 30)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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 ffont = _fonts.Where(m=>m.Key.Contains("awesome")).FirstOrDefault(m => int.Parse(m.Key.Replace("awesome", "")) > _state.TileSize / 8).Value ?? _fonts.Last().Value;
|
||||
// var fscale = 1f;
|
||||
|
||||
// _spriteBatch.DrawString(ffont,
|
||||
// "0xf06e",
|
||||
// new Vector2(
|
||||
// note.X * _state.TileSize + _state.TileSize - _state.TileSize / 3,
|
||||
// note.Y * _state.TileSize + _state.TileSize / 4
|
||||
// ),
|
||||
// Color.Black,
|
||||
// 0,
|
||||
// Vector2.Zero,
|
||||
// fscale,
|
||||
// SpriteEffects.None,
|
||||
// 0);
|
||||
|
||||
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);
|
||||
_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,
|
||||
(int)(_state.TileSize / 2.5), (int)(_state.TileSize / 2.5 / 1.136)
|
||||
), Color.Black * .2f
|
||||
);
|
||||
|
||||
_spriteBatch.Draw(
|
||||
_comment,
|
||||
new Rectangle(
|
||||
note.X * _state.TileSize + _state.TileSize - (int)(_state.TileSize / 2),
|
||||
note.Y * _state.TileSize + _state.TileSize / 8,
|
||||
(int)(_state.TileSize / 2.5), (int)(_state.TileSize / 2.5 / 1.136)
|
||||
), Color.DarkRed
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -621,7 +616,7 @@ namespace Sledgemapper
|
|||
var color = player.Color.ToColor();
|
||||
_spriteBatch.DrawRectangle(new Rectangle(player.Position.X * _state.TileSize - 4, player.Position.Y * _state.TileSize - 4, _state.TileSize + 7, _state.TileSize + 7), color, 2);
|
||||
|
||||
var ffont = _fonts.FirstOrDefault(m => int.Parse(m.Key.Replace("font", "")) > _state.TileSize).Value ?? _fonts.Last().Value;
|
||||
var ffont = _fonts.Where(m => m.Key.Contains("awesome")).FirstOrDefault(m => int.Parse(m.Key.Replace("font", "")) > _state.TileSize).Value ?? _fonts.Last().Value;
|
||||
|
||||
var fscale = _state.TileSize / ((float)ffont.LineSpacing * 2);
|
||||
_spriteBatch.DrawString(ffont,
|
||||
|
@ -887,6 +882,89 @@ namespace Sledgemapper
|
|||
}
|
||||
}
|
||||
|
||||
private async void OnButtonNoteOkClick(object sender, EventArgs e)
|
||||
{
|
||||
var button = ((TextButton)sender);
|
||||
Container container = button.Parent;
|
||||
while (!(container is Window))
|
||||
{
|
||||
container = container.Parent;
|
||||
}
|
||||
|
||||
var localWindow = (Window)container;
|
||||
var localContent = localWindow.Content as NoteWindow;
|
||||
|
||||
if (!button.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var isValid = true;
|
||||
isValid &= ValidateTextbox(localContent.NoteText);
|
||||
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var successful = false;
|
||||
try
|
||||
{
|
||||
var note = new Note
|
||||
{
|
||||
X = _state.SelectedTile.X,
|
||||
Y = _state.SelectedTile.Y,
|
||||
Text = localContent.NoteText.Text
|
||||
};
|
||||
_sessionData.Notes.TryAdd(note.ToString(), 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();
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnButtonNoteCancelClick(object sender, EventArgs e)
|
||||
{
|
||||
var button = ((TextButton)sender);
|
||||
Container container = button.Parent;
|
||||
while (!(container is Window))
|
||||
{
|
||||
container = container.Parent;
|
||||
}
|
||||
|
||||
var localWindow = (Window)container;
|
||||
|
||||
localWindow.Close();
|
||||
}
|
||||
private async void OnButtonLoginClick(object sender, EventArgs e)
|
||||
{
|
||||
var button = ((TextButton)sender);
|
||||
|
@ -1045,6 +1123,22 @@ namespace Sledgemapper
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void OnOverlayButtonClicked(object sender, EventArgs e)
|
||||
{
|
||||
_state.CurrentOverlayId = ((ImageButton)sender).Id;
|
||||
|
@ -1087,6 +1181,7 @@ namespace Sledgemapper
|
|||
var content = new SessionWindow();
|
||||
content.BtnLogin.Text = "Join";
|
||||
content.BtnLogin.Click += OnButtonJoinSessionClicked;
|
||||
|
||||
window.Content = content;
|
||||
|
||||
window.ShowModal(_desktop);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue