more refactoring
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-09 10:58:05 +01:00
parent 34863a9984
commit 09c32c605e
2 changed files with 39 additions and 123 deletions

View File

@ -2,7 +2,6 @@ using Exceptionless;
using Exceptionless.Models;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGame.Extended;
@ -1734,46 +1733,10 @@ namespace Sledgemapper
}
}
private void UpdateConnectionState(HubConnection connection)
{
switch (connection.State)
{
case HubConnectionState.Connected:
_mainWidget.lblConnectionStatus.Text = "Connected";
break;
case HubConnectionState.Connecting:
_mainWidget.lblConnectionStatus.Text = "Connecting";
break;
case HubConnectionState.Disconnected:
_mainWidget.lblConnectionStatus.Text = "Disconnected";
break;
case HubConnectionState.Reconnecting:
_mainWidget.lblConnectionStatus.Text = "Reconnecting";
break;
}
}
private (Window Window, C Content) GetParentContentInWindow<C>(Widget widget) where C : Widget
{
Container container = widget.Parent;
while (!(container is Window))
{
container = container.Parent;
}
var localWindow = (Window)container;
var localContent = localWindow.Content as C;
return (localWindow, localContent);
}
private void OnButtonNoteOkClick(object sender, EventArgs e)
{
var button = ((TextButton)sender);
var localContent = GetParentContentInWindow<NoteWindow>(button);
var localContent = button.GetParentContentInWindow<NoteWindow>();
var note = new Note
{
X = _state.SelectedNote.X,
@ -1787,7 +1750,7 @@ namespace Sledgemapper
private void OnButtonNoteCancelClick(object sender, EventArgs e)
{
var button = ((TextButton)sender);
var content = GetParentContentInWindow<Widget>(button);
var content = button.GetParentContentInWindow<Widget>();
content.Window.Close();
}
@ -1840,89 +1803,5 @@ namespace Sledgemapper
((ImageButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
_state.InsertMode = InsertMode.Wall;
}
private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled)
{
return;
}
var serverMap = await _communicationManager.Api.Session(_sessionData.SessionName);
_sessionData.Overlays = serverMap.Overlays;
_sessionData.Map = serverMap.Map;
_sessionData.Walls = serverMap.Walls;
_sessionData.Notes = serverMap.Notes;
_sessionData.Lines = serverMap.Lines;
_sessionData.Rooms = serverMap.Rooms;
}
private async void OnMenuConnectUploadSelected(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled)
{
return;
}
await _communicationManager.Api.SaveSnapshot(_sessionData, _sessionData.SessionName);
}
private void OnMapEntityAdded(object sender, MapEntityAddedEventArgs e)
{
_communicationManager.Enqueue(e.MapEntity, TileAction.Add);
}
private void OnMapEntityDeleted(object sender, MapEntityDeletedEventArgs e)
{
_communicationManager.Enqueue(e.MapEntity, TileAction.Delete);
}
private bool ValidateTextbox(TextBox textBox)
{
var valid = !string.IsNullOrWhiteSpace(textBox.Text);
if (!valid)
{
textBox.Background = new SolidBrush(Color.Red);
}
else
{
textBox.Background = new SolidBrush(new Color(51, 51, 51)); ;
}
return valid;
}
}
internal class SpriteSheet
{
internal Texture2D Texture;
internal Dictionary<String, Rectangle> index;
public void LoadContent(ContentManager content, string spriteIndex, string texture)
{
index = content.Load<Dictionary<String, Rectangle>>(spriteIndex);
Texture = content.Load<Texture2D>(texture);
}
internal Rectangle? SourceRectangle(string spriteName)
{
Rectangle r;
bool hasValue = index.TryGetValue(spriteName, out r);
if (hasValue)
{
return r;
}
else
{
throw new Exception("value doesn't exist");
}
}
}
}

View File

@ -0,0 +1,37 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
namespace Sledgemapper
{
internal class SpriteSheet
{
internal Texture2D Texture;
internal Dictionary<String, Rectangle> index;
public void LoadContent(ContentManager content, string spriteIndex, string texture)
{
index = content.Load<Dictionary<String, Rectangle>>(spriteIndex);
Texture = content.Load<Texture2D>(texture);
}
internal Rectangle? SourceRectangle(string spriteName)
{
Rectangle r;
bool hasValue = index.TryGetValue(spriteName, out r);
if (hasValue)
{
return r;
}
else
{
throw new Exception("value doesn't exist");
}
}
}
}