Last active
August 29, 2015 14:06
-
-
Save phrohdoh/a2faa6d51f45bc2a9a64 to your computer and use it in GitHub Desktop.
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
public DebugGridToolsLogic(Widget widget, World world) | |
{ | |
var gridTrait = world.WorldActor.Trait<CellGridDebugOverlay>(); | |
var btnToggleVisibility = widget.GetOrNull<ButtonWidget>("TOGGLE_GRID"); | |
if (btnToggleVisibility != null) | |
btnToggleVisibility.OnClick = () => gridTrait.Visible ^= true; | |
var btnCycleRenderOrder = widget.GetOrNull<ButtonWidget>("TOGGLE_RENDER_ORDER"); | |
if (btnCycleRenderOrder != null) | |
{ | |
btnCycleRenderOrder.Text = GetRenderOrderText(gridTrait); | |
btnCycleRenderOrder.OnClick = () => | |
{ | |
gridTrait.SwapRenderOrder(); | |
btnCycleRenderOrder.Text = GetRenderOrderText(gridTrait); | |
}; | |
} | |
var colorFullDropDown = widget.GetOrNull<DropDownButtonWidget>("COLOR_FULL"); | |
if (colorFullDropDown != null) | |
{ | |
colorFullDropDown.Text = "Full Cell Color"; | |
colorFullDropDown.OnMouseDown = SetupColorDropdown(colorFullDropDown, gridTrait); | |
} | |
} | |
Action<MouseInput> SetupColorDropdown(DropDownButtonWidget dropdown, CellGridDebugOverlay grid) | |
{ | |
var allColors = Enum.GetValues(typeof(KnownColor)).Cast<KnownColor>(); | |
var options = new List<DropDownOption>(); | |
foreach (var color in allColors) | |
{ | |
var newOption = new DropDownOption() | |
{ | |
Title = color.ToString(), | |
IsSelected = () => false, | |
OnClick = () => grid.FullCellColor = Color.FromName(color.ToString()) | |
}; | |
options.Add(newOption); | |
} | |
Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => | |
{ | |
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); | |
item.Get<LabelWidget>("LABEL").GetText = () => option.Title; | |
return item; | |
}; | |
dropdown.OnClick = () => dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 175, options, setupItem); | |
return mi => SetupColorDropdown(dropdown, grid); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment