Adds verb categories (#766)

* Adds verb categories

* Update Content.Shared/GameObjects/Verbs/Verb.cs

Co-Authored-By: Pieter-Jan Briers <pieterjan.briers@gmail.com>

* Make GetCategory virtual

Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
Víctor Aguilera Puerto
2020-03-06 20:11:24 +01:00
committed by GitHub
parent 5747eb5fac
commit e17ffbd76f
10 changed files with 97 additions and 12 deletions

View File

@@ -121,7 +121,7 @@ namespace Content.Client.GameObjects.EntitySystems
DebugTools.AssertNotNull(_currentPopup); DebugTools.AssertNotNull(_currentPopup);
var buttons = new List<Button>(); var buttons = new Dictionary<string, List<Button>>();
var vBox = _currentPopup.List; var vBox = _currentPopup.List;
vBox.DisposeAllChildren(); vBox.DisposeAllChildren();
@@ -137,7 +137,10 @@ namespace Content.Client.GameObjects.EntitySystems
}; };
} }
buttons.Add(button); if(!buttons.ContainsKey(data.Category))
buttons[data.Category] = new List<Button>();
buttons[data.Category].Add(button);
} }
var user = GetUserEntity(); var user = GetUserEntity();
@@ -148,7 +151,13 @@ namespace Content.Client.GameObjects.EntitySystems
continue; continue;
var disabled = verb.GetVisibility(user, component) != VerbVisibility.Visible; var disabled = verb.GetVisibility(user, component) != VerbVisibility.Visible;
buttons.Add(CreateVerbButton(verb.GetText(user, component), disabled, verb.ToString(), var category = verb.GetCategory(user, component);
if(!buttons.ContainsKey(category))
buttons[category] = new List<Button>();
buttons[category].Add(CreateVerbButton(verb.GetText(user, component), disabled, verb.ToString(),
entity.ToString(), () => verb.Activate(user, component))); entity.ToString(), () => verb.Activate(user, component)));
} }
//Get global verbs. Visible for all entities regardless of their components. //Get global verbs. Visible for all entities regardless of their components.
@@ -158,17 +167,33 @@ namespace Content.Client.GameObjects.EntitySystems
continue; continue;
var disabled = globalVerb.GetVisibility(user, entity) != VerbVisibility.Visible; var disabled = globalVerb.GetVisibility(user, entity) != VerbVisibility.Visible;
buttons.Add(CreateVerbButton(globalVerb.GetText(user, entity), disabled, globalVerb.ToString(), var category = globalVerb.GetCategory(user, entity);
if(!buttons.ContainsKey(category))
buttons[category] = new List<Button>();
buttons[category].Add(CreateVerbButton(globalVerb.GetText(user, entity), disabled, globalVerb.ToString(),
entity.ToString(), () => globalVerb.Activate(user, entity))); entity.ToString(), () => globalVerb.Activate(user, entity)));
} }
if (buttons.Count > 0) if (buttons.Count > 0)
{ {
buttons.Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.Ordinal)); foreach (var (category, verbs) in buttons)
foreach (var button in buttons)
{ {
vBox.AddChild(button); if (string.IsNullOrEmpty(category))
continue;
vBox.AddChild(CreateCategoryButton(category, verbs));
}
if (buttons.ContainsKey(""))
{
buttons[""].Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.Ordinal));
foreach (var verb in buttons[""])
{
vBox.AddChild(verb);
}
} }
} }
else else
@@ -204,6 +229,25 @@ namespace Content.Client.GameObjects.EntitySystems
return button; return button;
} }
private Button CreateCategoryButton(string text, List<Button> verbButtons)
{
verbButtons.Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.Ordinal));
var button = new Button
{
Text = $"{text}...",
};
button.OnPressed += _ =>
{
_currentPopup.List.DisposeAllChildren();
foreach (var verb in verbButtons)
{
_currentPopup.List.AddChild(verb);
}
};
return button;
}
private void CloseContextMenu() private void CloseContextMenu()
{ {
_currentPopup?.Dispose(); _currentPopup?.Dispose();

View File

@@ -13,6 +13,8 @@ namespace Content.Client.GlobalVerbs
class ViewVariablesVerb : GlobalVerb class ViewVariablesVerb : GlobalVerb
{ {
public override string GetText(IEntity user, IEntity target) => "View variables"; public override string GetText(IEntity user, IEntity target) => "View variables";
public override string GetCategory(IEntity user, IEntity target) => "Debug";
public override bool RequireInteractionRange => false; public override bool RequireInteractionRange => false;
public override VerbVisibility GetVisibility(IEntity user, IEntity target) public override VerbVisibility GetVisibility(IEntity user, IEntity target)

View File

@@ -40,6 +40,8 @@ namespace Content.Server.GameObjects.Components
return "Rotate clockwise"; return "Rotate clockwise";
} }
protected override string GetCategory(IEntity user, RotatableComponent component) => "Rotate";
protected override VerbVisibility GetVisibility(IEntity user, RotatableComponent component) protected override VerbVisibility GetVisibility(IEntity user, RotatableComponent component)
{ {
return VerbVisibility.Visible; return VerbVisibility.Visible;
@@ -59,6 +61,8 @@ namespace Content.Server.GameObjects.Components
return "Rotate counter-clockwise"; return "Rotate counter-clockwise";
} }
protected override string GetCategory(IEntity user, RotatableComponent component) => "Rotate";
protected override VerbVisibility GetVisibility(IEntity user, RotatableComponent component) protected override VerbVisibility GetVisibility(IEntity user, RotatableComponent component)
{ {
return VerbVisibility.Visible; return VerbVisibility.Visible;

View File

@@ -108,7 +108,7 @@ namespace Content.Server.GameObjects.EntitySystems
// TODO: These keys being giant strings is inefficient as hell. // TODO: These keys being giant strings is inefficient as hell.
data.Add(new VerbsResponseMessage.VerbData(verb.GetText(userEntity, component), data.Add(new VerbsResponseMessage.VerbData(verb.GetText(userEntity, component),
$"{component.GetType()}:{verb.GetType()}", $"{component.GetType()}:{verb.GetType()}", verb.GetCategory(userEntity, component),
vis == VerbVisibility.Visible)); vis == VerbVisibility.Visible));
} }
@@ -121,7 +121,7 @@ namespace Content.Server.GameObjects.EntitySystems
continue; continue;
data.Add(new VerbsResponseMessage.VerbData(globalVerb.GetText(userEntity, entity), data.Add(new VerbsResponseMessage.VerbData(globalVerb.GetText(userEntity, entity),
globalVerb.GetType().ToString(), vis == VerbVisibility.Visible)); globalVerb.GetType().ToString(), globalVerb.GetCategory(userEntity, entity), vis == VerbVisibility.Visible));
} }
var response = new VerbsResponseMessage(data, req.EntityUid); var response = new VerbsResponseMessage(data, req.EntityUid);

View File

@@ -16,6 +16,8 @@ namespace Content.Server.GlobalVerbs
public class ControlMobVerb : GlobalVerb public class ControlMobVerb : GlobalVerb
{ {
public override string GetText(IEntity user, IEntity target) => "Control Mob"; public override string GetText(IEntity user, IEntity target) => "Control Mob";
public override string GetCategory(IEntity user, IEntity target) => "Debug";
public override bool RequireInteractionRange => false; public override bool RequireInteractionRange => false;
public override VerbVisibility GetVisibility(IEntity user, IEntity target) public override VerbVisibility GetVisibility(IEntity user, IEntity target)

View File

@@ -15,6 +15,8 @@ namespace Content.Server.GlobalVerbs
class RejuvenateVerb : GlobalVerb class RejuvenateVerb : GlobalVerb
{ {
public override string GetText(IEntity user, IEntity target) => "Rejuvenate"; public override string GetText(IEntity user, IEntity target) => "Rejuvenate";
public override string GetCategory(IEntity user, IEntity target) => "Debug";
public override bool RequireInteractionRange => false; public override bool RequireInteractionRange => false;
public override VerbVisibility GetVisibility(IEntity user, IEntity target) public override VerbVisibility GetVisibility(IEntity user, IEntity target)

View File

@@ -35,12 +35,14 @@ namespace Content.Shared.GameObjects.EntitySystemMessages
{ {
public readonly string Text; public readonly string Text;
public readonly string Key; public readonly string Key;
public readonly string Category;
public readonly bool Available; public readonly bool Available;
public VerbData(string text, string key, bool available) public VerbData(string text, string key, string category, bool available)
{ {
Text = text; Text = text;
Key = key; Key = key;
Category = category;
Available = available; Available = available;
} }
} }

View File

@@ -27,6 +27,13 @@ namespace Content.Shared.GameObjects
/// <returns>The text string that is shown in the right click menu for this verb.</returns> /// <returns>The text string that is shown in the right click menu for this verb.</returns>
public abstract string GetText(IEntity user, IEntity target); public abstract string GetText(IEntity user, IEntity target);
/// <summary>
/// Gets the category of this verb.
/// </summary>
/// <param name="user">The entity of the user opening this menu.</param>
/// <returns>The category of this verb.</returns>
public virtual string GetCategory(IEntity user, IEntity target) => "";
/// <summary> /// <summary>
/// Gets the visibility level of this verb in the right click menu. /// Gets the visibility level of this verb in the right click menu.
/// </summary> /// </summary>

View File

@@ -31,6 +31,14 @@ namespace Content.Shared.GameObjects
/// <returns>The text string that is shown in the right click menu for this verb.</returns> /// <returns>The text string that is shown in the right click menu for this verb.</returns>
public abstract string GetText(IEntity user, IComponent component); public abstract string GetText(IEntity user, IComponent component);
/// <summary>
/// Gets the category of this verb.
/// </summary>
/// <param name="user">The entity of the user opening this menu.</param>
/// <param name="component">The component instance for which this verb is being loaded.</param>
/// <returns>The category of this verb.</returns>
public virtual string GetCategory(IEntity user, IComponent component) => "";
/// <summary> /// <summary>
/// Gets the visibility level of this verb in the right click menu. /// Gets the visibility level of this verb in the right click menu.
/// </summary> /// </summary>
@@ -63,6 +71,14 @@ namespace Content.Shared.GameObjects
/// <returns>The text string that is shown in the right click menu for this verb.</returns> /// <returns>The text string that is shown in the right click menu for this verb.</returns>
protected abstract string GetText(IEntity user, T component); protected abstract string GetText(IEntity user, T component);
/// <summary>
/// Gets the category of this verb.
/// </summary>
/// <param name="user">The entity of the user opening this menu.</param>
/// <param name="component">The component instance for which this verb is being loaded.</param>
/// <returns>The category of this verb.</returns>
protected virtual string GetCategory(IEntity user, T component) => "";
/// <summary> /// <summary>
/// Gets the visibility level of this verb in the right click menu. /// Gets the visibility level of this verb in the right click menu.
/// </summary> /// </summary>
@@ -84,6 +100,12 @@ namespace Content.Shared.GameObjects
return GetText(user, (T) component); return GetText(user, (T) component);
} }
/// <inheritdoc />
public sealed override string GetCategory(IEntity user, IComponent component)
{
return GetCategory(user, (T) component);
}
/// <inheritdoc /> /// <inheritdoc />
public sealed override VerbVisibility GetVisibility(IEntity user, IComponent component) public sealed override VerbVisibility GetVisibility(IEntity user, IComponent component)
{ {