-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
742 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using ClientGUI; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using Rampastring.XNAUI; | ||
using Rampastring.XNAUI.XNAControls; | ||
|
||
namespace ClientGUI | ||
{ | ||
public class XNAAdvancedContextMenu : XNAPanel | ||
{ | ||
public XNAAdvancedContextMenu(WindowManager windowManager) : base(windowManager) | ||
{ | ||
} | ||
|
||
// protected override int DrawItem(int index, Point point) | ||
// { | ||
// XNAContextMenuItem xnaContextMenuItem = Items[index]; | ||
// | ||
// switch (xnaContextMenuItem) | ||
// { | ||
// case XNAClientContextMenuDividerItem dividerItem: | ||
// return DrawDivider(dividerItem, point); | ||
// case XNAClientContextSubMenuItem subMenuItem: | ||
// return DrawSubMenuItem(subMenuItem, index, point); | ||
// default: | ||
// return base.DrawItem(index, point); | ||
// ; | ||
// } | ||
// } | ||
|
||
// private int DrawDivider(XNAClientContextMenuDividerItem dividerItem, Point point) | ||
// { | ||
// int lineY = dividerItem.GetLineY(point.Y); | ||
// FillRectangle(new Rectangle(point.X, point.Y, Width - 2, dividerItem.Height ?? ItemHeight), BackColor); | ||
// DrawLine(new Vector2(0, lineY), new Vector2(Width, lineY), BorderColor); | ||
// return dividerItem.Height ?? ItemHeight; | ||
// } | ||
|
||
// private int DrawSubMenuItem(XNAClientContextSubMenuItem subMenuItem, int index, Point point) | ||
// { | ||
// int arrowContainerSize = subMenuItem.Height ?? ItemHeight; | ||
// | ||
// var containerRectangle = new Rectangle(Width - arrowContainerSize, point.Y, arrowContainerSize, arrowContainerSize); | ||
// var topLeftVector = new Vector2(Width - arrowContainerSize + subMenuItem.ArrowGap, point.Y + subMenuItem.ArrowGap); | ||
// var bottomLeftVector = new Vector2(Width - arrowContainerSize + subMenuItem.ArrowGap, point.Y + arrowContainerSize - subMenuItem.ArrowGap); | ||
// var rightVector = new Vector2(Width - subMenuItem.ArrowGap, point.Y + (arrowContainerSize / 2)); | ||
// bool mouseInContainer = containerRectangle.Contains(GetCursorPoint()); | ||
// | ||
// DrawLine(topLeftVector, rightVector, BorderColor, subMenuItem.ArrowThickness); | ||
// DrawLine(bottomLeftVector, rightVector, BorderColor, subMenuItem.ArrowThickness); | ||
// DrawLine(topLeftVector, bottomLeftVector, BorderColor, subMenuItem.ArrowThickness); | ||
// | ||
// if (mouseInContainer) | ||
// FillRectangle(containerRectangle, new Color(BorderColor, 0.1f)); | ||
// else if (HoveredIndex == index) | ||
// FillRectangle(new Rectangle(point.X, point.Y, Width - 2 - arrowContainerSize, arrowContainerSize), FocusColor); | ||
// else | ||
// FillRectangle(new Rectangle(point.X, point.Y, Width - 2 - arrowContainerSize, arrowContainerSize), BackColor); | ||
// | ||
// int x1 = point.X + TextHorizontalPadding; | ||
// if (subMenuItem.Texture != null) | ||
// { | ||
// Renderer.DrawTexture(subMenuItem.Texture, new Rectangle(point.X + 1, point.Y + 1, subMenuItem.Texture.Width, subMenuItem.Texture.Height), Color.White); | ||
// x1 += subMenuItem.Texture.Width + 2; | ||
// } | ||
// | ||
// Color color = subMenuItem.Selectable ? GetItemTextColor(subMenuItem) : DisabledItemColor; | ||
// DrawStringWithShadow(subMenuItem.Text, FontIndex, new Vector2(x1, point.Y + TextVerticalPadding), color); | ||
// if (subMenuItem.HintText != null) | ||
// { | ||
// int x2 = Width - TextHorizontalPadding - (int)Renderer.GetTextDimensions(subMenuItem.HintText, HintFontIndex).X; | ||
// DrawStringWithShadow(subMenuItem.HintText, HintFontIndex, new Vector2(x2, point.Y + TextVerticalPadding), color); | ||
// } | ||
// | ||
// return subMenuItem.Height ?? ItemHeight; | ||
// } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using Rampastring.XNAUI; | ||
using Rampastring.XNAUI.XNAControls; | ||
|
||
namespace ClientGUI | ||
{ | ||
public class XNAAdvancedContextMenuItem : XNAAdvancedContextMenuItem<object> | ||
{ | ||
public XNAAdvancedContextMenuItem(WindowManager windowManager) : base(windowManager) | ||
{ | ||
} | ||
} | ||
|
||
public class XNAAdvancedContextMenuItem<T> : XNAPanel | ||
{ | ||
public T Item { get; set; } | ||
|
||
/// <summary>The text of the context menu item.</summary> | ||
public string Text { get; set; } | ||
|
||
/// <summary> | ||
/// The hint text of the context menu item. | ||
/// Drawn in the end of the item. | ||
/// </summary> | ||
public string HintText { get; set; } | ||
|
||
/// <summary> | ||
/// Determines whether the context menu item is enabled | ||
/// (can be clicked on). | ||
/// </summary> | ||
public bool Selectable { get; set; } = true; | ||
|
||
/// <summary>Determines whether the context menu item is visible.</summary> | ||
public bool Visible { get; set; } = true; | ||
|
||
/// <summary> | ||
/// The height of the context menu item. | ||
/// If null, the common item height is used. | ||
/// </summary> | ||
public int? Height { get; set; } | ||
|
||
/// <summary> | ||
/// The font index of the context menu item. | ||
/// If null, the common font index is used. | ||
/// </summary> | ||
public int? FontIndex { get; set; } | ||
|
||
/// <summary>The texture of the context menu item.</summary> | ||
public Texture2D Texture { get; set; } | ||
|
||
/// <summary> | ||
/// The background color of the context menu item. | ||
/// If null, the common background color is used. | ||
/// </summary> | ||
public Color? BackgroundColor { get; set; } | ||
|
||
/// <summary> | ||
/// The color of the context menu item's text. | ||
/// If null, the common text color is used. | ||
/// </summary> | ||
public Color? TextColor { get; set; } | ||
|
||
/// <summary>The method that is called when the item is selected.</summary> | ||
public Action SelectAction { get; set; } | ||
|
||
/// <summary> | ||
/// When the context menu is shown, this function is called | ||
/// to determine whether this item should be selectable. | ||
/// If null, the value of the Enabled property is not changed. | ||
/// </summary> | ||
public Func<bool> SelectableChecker { get; set; } | ||
|
||
/// <summary> | ||
/// When the context menu is shown, this function is called | ||
/// to determine whether this item should be visible. | ||
/// If null, the value of the Visible property is not changed. | ||
/// </summary> | ||
public Func<bool> VisibilityChecker { get; set; } | ||
|
||
/// <summary>The Y position of the item's text.</summary> | ||
public float TextY { get; set; } | ||
|
||
public XNAAdvancedContextMenuItem(WindowManager windowManager) : base(windowManager) | ||
{ | ||
Height = 22; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using Rampastring.XNAUI; | ||
using Rampastring.XNAUI.XNAControls; | ||
|
||
namespace ClientGUI | ||
{ | ||
public class XNAClientContextMenuDividerItem : XNAPanel | ||
{ | ||
public XNAClientContextMenuDividerItem(WindowManager windowManager) : base(windowManager) | ||
{ | ||
Height = 4; | ||
Text = string.Empty; | ||
} | ||
|
||
public int GetLineY(int relativeY) => relativeY + (int)Math.Ceiling((double)Height / 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Rampastring.XNAUI; | ||
using Rampastring.XNAUI.XNAControls; | ||
|
||
namespace ClientGUI | ||
{ | ||
public class XNAClientContextSubMenuItem<T> : XNAAdvancedContextMenuItem<T> | ||
{ | ||
public XNAAdvancedContextMenu Menu { get; set; } | ||
|
||
public int ArrowGap { get; set; } = 6; | ||
public int ArrowThickness = 2; | ||
|
||
public XNAClientContextSubMenuItem(WindowManager windowManager) : base(windowManager) | ||
{ | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
DXMainClient/DXGUI/Generic/TeamStartMappingPresetMenu.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using clientdx.DXGUI.Generic; | ||
using ClientGUI; | ||
using DTAClient.Domain.Multiplayer; | ||
using Microsoft.Xna.Framework; | ||
using Rampastring.XNAUI; | ||
using Rampastring.XNAUI.XNAControls; | ||
|
||
namespace DTAClient.DXGUI.Generic | ||
{ | ||
public class TeamStartMappingPresetMenu : XNAAdvancedContextMenu | ||
{ | ||
private XNAAdvancedContextMenuItem savePresetItem; | ||
private XNAAdvancedContextMenuItem saveAsPresetItem; | ||
|
||
public TeamStartMappingPresetMenu(WindowManager windowManager) : base(windowManager) | ||
{ | ||
|
||
DrawBorders = true; | ||
BackgroundTexture = AssetLoader.CreateTexture(Color.Black, 1, 1); | ||
PanelBackgroundDrawMode = PanelBackgroundImageDrawMode.TILED; | ||
savePresetItem = new XNAAdvancedContextMenuItem(windowManager) | ||
{ | ||
Text = "Save" | ||
}; | ||
|
||
saveAsPresetItem = new XNAAdvancedContextMenuItem(windowManager) | ||
{ | ||
Text = "Save As" | ||
}; | ||
} | ||
|
||
private void ClearItems() | ||
{ | ||
var children = Children.ToList(); | ||
foreach (XNAControl xnaControl in children) | ||
RemoveChild(xnaControl); | ||
} | ||
|
||
public void ReinitItems() | ||
{ | ||
ClearItems(); | ||
AddChild(savePresetItem); | ||
AddChild(saveAsPresetItem); | ||
} | ||
|
||
public void AddPresetList(List<TeamStartMappingPreset> presets, string headerLabel, Action<TeamStartMappingPreset> selectAction) | ||
{ | ||
if (!presets.Any()) | ||
return; | ||
|
||
AddChild(new XNAClientContextMenuDividerItem(WindowManager)); | ||
AddChild(new XNAAdvancedContextMenuItem(WindowManager) | ||
{ | ||
Text = headerLabel, | ||
Selectable = false | ||
}); | ||
presets.ForEach(preset => AddChild(new TeamStartMappingPresetMenuItem(WindowManager) | ||
{ | ||
Item = preset, | ||
Text = $" {preset.Name}", | ||
SelectAction = selectAction | ||
})); | ||
} | ||
|
||
public List<TeamStartMappingPresetMenuItem> GetPresetItems() => | ||
Children | ||
.OfType<TeamStartMappingPresetMenuItem>() | ||
.ToList(); | ||
|
||
// | ||
public List<TeamStartMappingPreset> GetPresets() => | ||
GetPresetItems() | ||
.Select(i => i.Item) | ||
.ToList(); | ||
|
||
public void Open(Point point, TeamStartMappingPreset currentMappingPreset) | ||
{ | ||
if (Visible) | ||
{ | ||
Attach(); | ||
Disable(); | ||
return; | ||
} | ||
|
||
|
||
Detach(); | ||
|
||
|
||
savePresetItem.Selectable = currentMappingPreset?.CanSave ?? false; | ||
|
||
ClientRectangle = new Rectangle(point.X, point.Y, 100, 100); | ||
Enable(); | ||
} | ||
|
||
public override void Draw(GameTime gameTime) | ||
{ | ||
var children = Children.ToList(); | ||
Height = 0; | ||
children.ForEach(child => Height += child.Height); | ||
|
||
FillRectangle(ClientRectangle, Color.Black); | ||
base.Draw(gameTime); | ||
} | ||
|
||
public override void OnLeftClick() | ||
{ | ||
base.OnLeftClick(); | ||
|
||
Disable(); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
DXMainClient/DXGUI/Generic/TeamStartMappingPresetMenuItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using ClientGUI; | ||
using DTAClient.Domain.Multiplayer; | ||
using Rampastring.XNAUI; | ||
using Rampastring.XNAUI.XNAControls; | ||
|
||
namespace clientdx.DXGUI.Generic | ||
{ | ||
public class TeamStartMappingPresetMenuItem : XNAClientContextSubMenuItem<TeamStartMappingPreset> | ||
{ | ||
public Action<TeamStartMappingPreset> SelectAction; | ||
|
||
public TeamStartMappingPresetMenuItem(WindowManager windowManager) : base(windowManager) | ||
{ | ||
} | ||
|
||
public override void OnLeftClick() | ||
{ | ||
SelectAction?.Invoke(Item); | ||
} | ||
} | ||
} |
Oops, something went wrong.