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:
parent
36f0e4b364
commit
0ae4a388f5
14 changed files with 1062 additions and 226 deletions
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue