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:
committed by
GitHub
parent
5747eb5fac
commit
e17ffbd76f
@@ -121,7 +121,7 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
|
||||
DebugTools.AssertNotNull(_currentPopup);
|
||||
|
||||
var buttons = new List<Button>();
|
||||
var buttons = new Dictionary<string, List<Button>>();
|
||||
|
||||
var vBox = _currentPopup.List;
|
||||
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();
|
||||
@@ -148,7 +151,13 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
continue;
|
||||
|
||||
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)));
|
||||
}
|
||||
//Get global verbs. Visible for all entities regardless of their components.
|
||||
@@ -158,17 +167,33 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
continue;
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
if (buttons.Count > 0)
|
||||
{
|
||||
buttons.Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.Ordinal));
|
||||
|
||||
foreach (var button in buttons)
|
||||
foreach (var (category, verbs) 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
|
||||
@@ -204,6 +229,25 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
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()
|
||||
{
|
||||
_currentPopup?.Dispose();
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace Content.Client.GlobalVerbs
|
||||
class ViewVariablesVerb : GlobalVerb
|
||||
{
|
||||
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 VerbVisibility GetVisibility(IEntity user, IEntity target)
|
||||
|
||||
@@ -40,6 +40,8 @@ namespace Content.Server.GameObjects.Components
|
||||
return "Rotate clockwise";
|
||||
}
|
||||
|
||||
protected override string GetCategory(IEntity user, RotatableComponent component) => "Rotate";
|
||||
|
||||
protected override VerbVisibility GetVisibility(IEntity user, RotatableComponent component)
|
||||
{
|
||||
return VerbVisibility.Visible;
|
||||
@@ -59,6 +61,8 @@ namespace Content.Server.GameObjects.Components
|
||||
return "Rotate counter-clockwise";
|
||||
}
|
||||
|
||||
protected override string GetCategory(IEntity user, RotatableComponent component) => "Rotate";
|
||||
|
||||
protected override VerbVisibility GetVisibility(IEntity user, RotatableComponent component)
|
||||
{
|
||||
return VerbVisibility.Visible;
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
|
||||
// TODO: These keys being giant strings is inefficient as hell.
|
||||
data.Add(new VerbsResponseMessage.VerbData(verb.GetText(userEntity, component),
|
||||
$"{component.GetType()}:{verb.GetType()}",
|
||||
$"{component.GetType()}:{verb.GetType()}", verb.GetCategory(userEntity, component),
|
||||
vis == VerbVisibility.Visible));
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
continue;
|
||||
|
||||
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);
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace Content.Server.GlobalVerbs
|
||||
public class ControlMobVerb : GlobalVerb
|
||||
{
|
||||
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 VerbVisibility GetVisibility(IEntity user, IEntity target)
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace Content.Server.GlobalVerbs
|
||||
class RejuvenateVerb : GlobalVerb
|
||||
{
|
||||
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 VerbVisibility GetVisibility(IEntity user, IEntity target)
|
||||
|
||||
@@ -35,12 +35,14 @@ namespace Content.Shared.GameObjects.EntitySystemMessages
|
||||
{
|
||||
public readonly string Text;
|
||||
public readonly string Key;
|
||||
public readonly string Category;
|
||||
public readonly bool Available;
|
||||
|
||||
public VerbData(string text, string key, bool available)
|
||||
public VerbData(string text, string key, string category, bool available)
|
||||
{
|
||||
Text = text;
|
||||
Key = key;
|
||||
Category = category;
|
||||
Available = available;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,13 @@ namespace Content.Shared.GameObjects
|
||||
/// <returns>The text string that is shown in the right click menu for this verb.</returns>
|
||||
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>
|
||||
/// Gets the visibility level of this verb in the right click menu.
|
||||
/// </summary>
|
||||
|
||||
@@ -31,6 +31,14 @@ namespace Content.Shared.GameObjects
|
||||
/// <returns>The text string that is shown in the right click menu for this verb.</returns>
|
||||
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>
|
||||
/// Gets the visibility level of this verb in the right click menu.
|
||||
/// </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>
|
||||
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>
|
||||
/// Gets the visibility level of this verb in the right click menu.
|
||||
/// </summary>
|
||||
@@ -84,6 +100,12 @@ namespace Content.Shared.GameObjects
|
||||
return GetText(user, (T) component);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public sealed override string GetCategory(IEntity user, IComponent component)
|
||||
{
|
||||
return GetCategory(user, (T) component);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public sealed override VerbVisibility GetVisibility(IEntity user, IComponent component)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user