Improved Context Menus

Context menus now support dropdown options
Context menus can now be created for UI elements with new dedicated cancellation click catcher
Game manager creates context menus based on the object being clicked, no need for duplicate code in every context that object appears
This commit is contained in:
hyperion51 2020-05-22 00:01:07 +01:00
commit 0ae4a388f5
14 changed files with 1062 additions and 226 deletions

View file

@ -266,7 +266,6 @@ public class StrategyGameManager : MonoBehaviour
ClickRaycaster.OnClickMiss += () =>
{
ContextMenu.gameObject.SetActive(false);
if (_currentTab == GalaxyTabButton) PopulateGalaxyProperties();
else if (_currentTab == ZoneTabButton) PopulateZoneProperties(_populatedZone);
else if (_currentTab == TechTabButton) PopulateTechProperties();
@ -345,6 +344,25 @@ public class StrategyGameManager : MonoBehaviour
}
}
void ShowContextMenu(object clickTarget)
{
ContextMenu.gameObject.SetActive(true);
ContextMenu.Clear();
if (clickTarget is PlanetData planet)
{
ContextMenu.AddOption("Test Option 1", () => Debug.Log("Test Option 1 Selected"));
ContextMenu.AddOption("Test Option 2", () => Debug.Log("Test Option 2 Selected"));
ContextMenu.AddDropdown("Test Dropdown", new []
{
("Dropdown Option 1", (Action) (() => Debug.Log("Dropdown Option 1 Selected"))),
("Dropdown Option 2", (Action) (() => Debug.Log("Dropdown Option 2 Selected"))),
("Dropdown Option 3", (Action) (() => Debug.Log("Dropdown Option 3 Selected")))
});
ContextMenu.AddOption("Test Option 3", () => Debug.Log("Test Option 3 Selected"));
}
ContextMenu.Show();
}
void PopulateGalaxy()
{
_galaxyPopulated = true;
@ -507,11 +525,7 @@ public class StrategyGameManager : MonoBehaviour
}
else if (data.button == PointerEventData.InputButton.Right)
{
ContextMenu.gameObject.SetActive(true);
ContextMenu.SetOptions(new []
{
("Test Option", (Action) (() => Debug.Log("Test Option Selected")))
});
ShowContextMenu(planetData);
}
};
}
@ -537,7 +551,7 @@ public class StrategyGameManager : MonoBehaviour
}
else if (data.button == PointerEventData.InputButton.Right)
{
ShowContextMenu(planetData);
}
};
}