searchable overlays, overlay name on hover

This commit is contained in:
Michele 2021-02-04 11:06:17 +00:00
parent afc94fd698
commit 808c0538be
3 changed files with 172 additions and 42 deletions

View File

@ -12,6 +12,7 @@ using Myra.Graphics2D.TextureAtlases;
using Myra.Graphics2D.UI;
using Myra.Graphics2D.UI.File;
using Myra.Graphics2D.UI.Properties;
using Myra.Utility;
using Newtonsoft.Json;
using Sledgemapper.Shared.Entities;
using Sledgemapper.UI;
@ -147,14 +148,19 @@ namespace Sledgemapper
}
}
private void AddItemToToolGrid(Grid grid, EventHandler eventAction, SpriteSheet spriteSheet)
private void AddItemToToolGrid(Grid grid, EventHandler eventAction, SpriteSheet spriteSheet, string e="")
{
var indexX = 0;
var indexY = 0;
foreach (var item in spriteSheet.index)
//foreach (var item in spriteSheet.index)
grid.Widgets.Clear();
_mainWidget.ScrOverlay.ResetScroll();
foreach (var item in spriteSheet.index.Where(t=>String.IsNullOrWhiteSpace(e) || t.Key.ToLower().Contains(e.ToLower())))
{
var tileButton = new ImageButton { Image = new TextureRegion(spriteSheet.Texture, item.Value), GridColumn = indexY, GridRow = indexX, Id = item.Key, Width = 40, Height = 40 };
tileButton.Click += eventAction;
tileButton.MouseMoved+=OnTileButtonTouchEntered;
tileButton.MouseLeft += OnTileButtonTouchLeft;
grid.Widgets.Add(tileButton);
indexY++;
if (indexY == 4)
@ -165,6 +171,25 @@ namespace Sledgemapper
}
}
private void OnTileButtonTouchLeft(object sender, EventArgs e)
{
_desktop.HideContextMenu();
_lblOverlayName.Visible=false;
}
Label _lblOverlayName;
private void OnTileButtonTouchEntered(object sender, EventArgs e)
{
var mouseState = Mouse.GetState().Position;
mouseState.X+=10;
mouseState.Y+=10;
_lblOverlayName.Visible=true;
_lblOverlayName.Text=((ImageButton)sender).Id;
_desktop.ShowContextMenu(_lblOverlayName, mouseState);
// _lblOverlayName.true;
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
@ -194,10 +219,13 @@ namespace Sledgemapper
_mainWidget.BtnToolbarDelete.Click += OnBtnToolbarDeleteClicked;
_wallsContent = Content.LoadContentFolder<Texture2D>("walls");
_spriteSheet = new SpriteSheet();
_spriteSheet.LoadContent(Content);
_lblOverlayName = new Label();
_lblOverlayName.Background=new SolidBrush(Color.SlateGray);
_lblOverlayName.Padding=new Myra.Graphics2D.Thickness(4);
AddItemToToolGrid(_mainWidget.GridWalls, OnWallButtonClicked, _wallsContent);
AddItemToToolGrid(_mainWidget.GridOverlays, OnOverlayButtonClicked, _spriteSheet);
@ -208,6 +236,8 @@ namespace Sledgemapper
_mainWidget.BtnToolbarLine.Image = new TextureRegion(Content.Load<Texture2D>("icon_line"));
_mainWidget.BtnToolbarRoom.Image = new TextureRegion(Content.Load<Texture2D>("icon_room"));
_mainWidget.BtnToolbarDelete.Image = new TextureRegion(Content.Load<Texture2D>("icon_delete"));
_mainWidget.TxtOverlaySearch.TextChangedByUser += OnTxtOverlaySearchChange;
_desktop.Root = _mainWidget;
_transparentRedRectangle = new Texture2D(GraphicsDevice, 1, 1);
@ -217,38 +247,54 @@ namespace Sledgemapper
_whiteRectangle.SetData(new[] { Color.White });
}
private void OnTxtOverlaySearchChange(object sender, ValueChangedEventArgs<string> e)
{
// var filteredWidget = _mainWidget.GridOverlays.Widgets.Where(m => m.Id.ToLower().Contains(e.NewValue.ToLower())).ToArray();
// foreach (var w in _mainWidget.GridOverlays.Widgets)
// {
// w.
// w.Visible = false;
// }
// foreach (var w in filteredWidget)
// {
// w.Visible = true;
// }
AddItemToToolGrid(_mainWidget.GridOverlays, OnOverlayButtonClicked, _spriteSheet, e.NewValue);
}
private void OnBtnToolbarDeleteClicked(object sender, EventArgs e)
{
_state.InsertMode = InsertMode.NewDelete;
_mainWidget.ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
_mainWidget.ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
}
private void OnBtnToolbarWallClicked(object sender, EventArgs e)
{
_state.InsertMode = InsertMode.NewWall;
_mainWidget.ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
_mainWidget.ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
}
private void OnBtnToolbarTileClicked(object sender, EventArgs e)
{
_state.InsertMode = InsertMode.NewTile;
_mainWidget.ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
_mainWidget.ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
}
private void OnBtnToolbarRoomClicked(object sender, EventArgs e)
{
_state.InsertMode = InsertMode.NewRoom;
_mainWidget.ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
_mainWidget.ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
}
@ -256,8 +302,8 @@ namespace Sledgemapper
private void OnBtnToolbarLinClicked(object sender, EventArgs e)
{
_state.InsertMode = InsertMode.NewLine;
_mainWidget.ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
_mainWidget.ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
}
@ -1025,22 +1071,22 @@ namespace Sledgemapper
private bool IsMapElementOffscreen(BaseMapEntity item)
{
SnapPoint start,end;
SnapPoint start, end;
switch (item)
{
case Line l:
start=l.Start;
end=l.End;
break;
switch (item)
{
case Line l:
start = l.Start;
end = l.End;
break;
case Room room:
start = room.Start;
end=room.End;
break;
default:
return true;
}
case Room room:
start = room.Start;
end = room.End;
break;
default:
return true;
}
var visibleTilesX = GraphicsDevice.Viewport.Width / _state.TileSize + 1;
var visibleTilesY = GraphicsDevice.Viewport.Height / _state.TileSize + 1;
@ -1433,11 +1479,11 @@ namespace Sledgemapper
}
}
}
Effect outlineShader;
Effect outlineShader;
private Texture2D _transparentRedRectangle;
private Texture2D _whiteRectangle;
private Dictionary<string, Texture2D> _wallsContent;
private SpriteSheet _spriteSheet;
private void DrawDelete(Room tile)

View File

@ -1,4 +1,4 @@
/* Generated by MyraPad at 04/02/2021 10:02:37 */
/* Generated by MyraPad at 04/02/2021 10:36:48 */
using Myra;
using Myra.Graphics2D;
using Myra.Graphics2D.TextureAtlases;
@ -191,11 +191,6 @@ namespace Sledgemapper.UI
});
verticalStackPanel1.Widgets.Add(scrollViewer1);
TxtOverlaySearch = new TextBox();
TxtOverlaySearch.MinHeight = 40;
TxtOverlaySearch.Margin = new Thickness(0, 4);
TxtOverlaySearch.Id = "TxtOverlaySearch";
GridOverlays = new Grid();
GridOverlays.ColumnSpacing = 8;
GridOverlays.RowSpacing = 8;
@ -211,16 +206,22 @@ namespace Sledgemapper.UI
};
GridOverlays.Id = "GridOverlays";
var scrollViewer2 = new ScrollViewer();
scrollViewer2.Content = GridOverlays;
ScrOverlay = new ScrollViewer();
ScrOverlay.Id = "ScrOverlay";
ScrOverlay.Content = GridOverlays;
TxtOverlaySearch = new TextBox();
TxtOverlaySearch.Height = 40;
TxtOverlaySearch.Margin = new Thickness(0, 4);
TxtOverlaySearch.Id = "TxtOverlaySearch";
var verticalStackPanel2 = new VerticalStackPanel();
verticalStackPanel2.Proportions.Add(new Proportion
{
Type = Myra.Graphics2D.UI.ProportionType.Fill,
});
verticalStackPanel2.Widgets.Add(ScrOverlay);
verticalStackPanel2.Widgets.Add(TxtOverlaySearch);
verticalStackPanel2.Widgets.Add(scrollViewer2);
var verticalSplitPane1 = new VerticalSplitPane();
verticalSplitPane1.Width = 200;
@ -313,8 +314,9 @@ namespace Sledgemapper.UI
public ImageTextButton BtnToolbarDelete;
public HorizontalStackPanel Toolbar;
public Grid GridWalls;
public TextBox TxtOverlaySearch;
public Grid GridOverlays;
public ScrollViewer ScrOverlay;
public TextBox TxtOverlaySearch;
public Label lblConnectionStatus;
public Label lblUsername;
public Label lblSessionName;

View File

@ -0,0 +1,82 @@
<Project>
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="MainWidget" OutputPath="C:\dev\Map\Sledgemapper\UI" />
<VerticalStackPanel>
<VerticalStackPanel.Proportions>
<Proportion Type="Auto" />
<Proportion Type="Auto" />
<Proportion Type="Fill" />
</VerticalStackPanel.Proportions>
<HorizontalMenu Id="_mainMenu">
<MenuItem Text="&amp;File" Id="MenuFile">
<MenuItem Text="&amp;Load" ShortcutText="Ctrl+L" Id="MenuFileLoad" />
<MenuItem Text="&amp;Save" ShortcutText="Ctrl+S" Id="MenuFileSave" />
<MenuSeparator />
<MenuItem Text="S&amp;ettings" ShortcutText="Ctrl+E" Id="MenuFileSettings" />
<MenuSeparator />
<MenuItem Text="&amp;Quit" ShortcutText="Ctrl+Q" Id="MenuFileQuit" />
</MenuItem>
<MenuItem Text="&amp;Connect">
<MenuItem Text="L&amp;ogin" ShortcutText="Ctrl+O" Id="MenuConnectLogin" />
<MenuSeparator />
<MenuItem Text="&amp;New" ShortcutText="Ctrl+N" Id="MenuConnectNew" />
<MenuItem Text="&amp;Join" ShortcutText="Ctrl+J" Id="MenuConnectJoin" />
<MenuItem Text="S&amp;ync" ShortcutText="Ctrl+Y" Id="MenuConnectSync" />
<MenuItem Text="&amp;Upload" ShortcutText="Ctrl+U" Id="MenuConnectUpload" />
</MenuItem>
<MenuItem Text="&amp;View">
<MenuItem Text="N&amp;otes" ShortcutText="Ctrl+O" Id="MenuViewShowNotes" />
<MenuItem Text="S&amp;how cell numbers" ShortcutText="Ctrl+H" Id="MenuViewShowCellNUmbers" />
<MenuItem Text="C&amp;enter on selection" ShortcutText="Ctrl+E" Id="MenuViewCenterOnSelection" />
</MenuItem>
<MenuItem Text="&amp;Help">
<MenuItem Text="&amp;About" Id="MenuHelpAbout" />
</MenuItem>
</HorizontalMenu>
<HorizontalStackPanel Spacing="12" VerticalAlignment="Center" Height="51" Padding="4, 0, 0, 0" Background="#404040FF" Id="Toolbar">
<HorizontalStackPanel.Proportions>
<Proportion Type="Auto" />
</HorizontalStackPanel.Proportions>
<ImageTextButton Text=" C" Width="40" Height="40" BorderThickness="2" VerticalAlignment="Center" Id="BtnToolbarLine" />
<ImageTextButton Text=" R" Width="40" Height="40" BorderThickness="2" VerticalAlignment="Center" Id="BtnToolbarRoom" />
<ImageTextButton Text=" D" Width="40" Height="40" BorderThickness="2" VerticalAlignment="Center" Id="BtnToolbarDelete" />
</HorizontalStackPanel>
<VerticalSplitPane Width="200" Background="#A1A1A1FF">
<VerticalStackPanel>
<VerticalStackPanel.Proportions>
<Proportion Type="Fill" />
</VerticalStackPanel.Proportions>
<ScrollViewer>
<Grid ColumnSpacing="8" RowSpacing="8" Id="GridWalls">
<Grid.DefaultColumnProportion Type="Pixels" Value="40" />
<Grid.DefaultRowProportion Type="Pixels" Value="40" />
</Grid>
</ScrollViewer>
</VerticalStackPanel>
<VerticalStackPanel>
<VerticalStackPanel.Proportions>
<Proportion Type="Fill" />
</VerticalStackPanel.Proportions>
<ScrollViewer Id="ScrOverlay">
<Grid ColumnSpacing="8" RowSpacing="8" Id="GridOverlays">
<Grid.DefaultColumnProportion Type="Pixels" Value="40" />
<Grid.DefaultRowProportion Type="Pixels" Value="40" />
</Grid>
</ScrollViewer>
<TextBox Height="40" Margin="0, 4" Id="TxtOverlaySearch" />
</VerticalStackPanel>
</VerticalSplitPane>
<HorizontalStackPanel Spacing="10" Height="25" Background="#333333FF">
<HorizontalStackPanel.Proportions>
<Proportion Type="Auto" />
</HorizontalStackPanel.Proportions>
<Label Text="Connection status:" />
<Label Text="Disconnected" MinWidth="100" Id="lblConnectionStatus" />
<VerticalSeparator />
<Label Text="Username:" />
<Label Text="n/a" MinWidth="100" Id="lblUsername" />
<VerticalSeparator />
<Label Text="Session name:" />
<Label Text="n/a" MinWidth="100" Id="lblSessionName" />
</HorizontalStackPanel>
</VerticalStackPanel>
</Project>