public override bool InheritInteractionsFrom(Gizmo other) { Command_Toggle command_Toggle = other as Command_Toggle; if (command_Toggle != null) { return(command_Toggle.isActive() == isActive()); } return(false); }
public override bool InheritInteractionsFrom(Gizmo other) { Command_Toggle command_Toggle = other as Command_Toggle; return(command_Toggle != null && command_Toggle.isActive() == this.isActive()); }
public static void DrawGizmoGrid(IEnumerable <Gizmo> gizmos, float startX, out Gizmo mouseoverGizmo) { tmpAllGizmos.Clear(); tmpAllGizmos.AddRange(gizmos); tmpAllGizmos.SortStable(SortByOrder); gizmoGroups.Clear(); for (int i = 0; i < tmpAllGizmos.Count; i++) { Gizmo gizmo = tmpAllGizmos[i]; bool flag = false; for (int j = 0; j < gizmoGroups.Count; j++) { if (gizmoGroups[j][0].GroupsWith(gizmo)) { flag = true; gizmoGroups[j].Add(gizmo); gizmoGroups[j][0].MergeWith(gizmo); break; } } if (!flag) { List <Gizmo> list = SimplePool <List <Gizmo> > .Get(); list.Add(gizmo); gizmoGroups.Add(list); } } firstGizmos.Clear(); for (int k = 0; k < gizmoGroups.Count; k++) { List <Gizmo> list2 = gizmoGroups[k]; Gizmo gizmo2 = null; for (int l = 0; l < list2.Count; l++) { if (!list2[l].disabled) { gizmo2 = list2[l]; break; } } if (gizmo2 == null) { gizmo2 = list2.FirstOrDefault(); } else { Command_Toggle command_Toggle = gizmo2 as Command_Toggle; if (command_Toggle != null) { if (!command_Toggle.activateIfAmbiguous && !command_Toggle.isActive()) { for (int m = 0; m < list2.Count; m++) { Command_Toggle command_Toggle2 = list2[m] as Command_Toggle; if (command_Toggle2 != null && !command_Toggle2.disabled && command_Toggle2.isActive()) { gizmo2 = list2[m]; break; } } } if (command_Toggle.activateIfAmbiguous && command_Toggle.isActive()) { for (int n = 0; n < list2.Count; n++) { Command_Toggle command_Toggle3 = list2[n] as Command_Toggle; if (command_Toggle3 != null && !command_Toggle3.disabled && !command_Toggle3.isActive()) { gizmo2 = list2[n]; break; } } } } } if (gizmo2 != null) { firstGizmos.Add(gizmo2); } } drawnHotKeys.Clear(); float num = UI.screenWidth - 147; float maxWidth = num - startX; Text.Font = GameFont.Tiny; Vector2 topLeft = new Vector2(startX, (float)(UI.screenHeight - 35) - GizmoSpacing.y - 75f); mouseoverGizmo = null; Gizmo gizmo3 = null; Event ev = null; Gizmo gizmo4 = null; for (int num2 = 0; num2 < firstGizmos.Count; num2++) { Gizmo gizmo5 = firstGizmos[num2]; if (gizmo5.Visible) { if (topLeft.x + gizmo5.GetWidth(maxWidth) > num) { topLeft.x = startX; topLeft.y -= 75f + GizmoSpacing.x; } heightDrawnFrame = Time.frameCount; heightDrawn = (float)UI.screenHeight - topLeft.y; GizmoResult gizmoResult = gizmo5.GizmoOnGUI(topLeft, maxWidth); if (gizmoResult.State == GizmoState.Interacted || (gizmoResult.State == GizmoState.OpenedFloatMenu && gizmo5.RightClickFloatMenuOptions.FirstOrDefault() == null)) { ev = gizmoResult.InteractEvent; gizmo3 = gizmo5; } else if (gizmoResult.State == GizmoState.OpenedFloatMenu) { gizmo4 = gizmo5; } if ((int)gizmoResult.State >= 1) { mouseoverGizmo = gizmo5; } GenUI.AbsorbClicksInRect(new Rect(topLeft.x, topLeft.y, gizmo5.GetWidth(maxWidth), 75f + GizmoSpacing.y).ContractedBy(-12f)); topLeft.x += gizmo5.GetWidth(maxWidth) + GizmoSpacing.x; } } if (gizmo3 != null) { List <Gizmo> list3 = FindMatchingGroup(gizmo3); for (int num3 = 0; num3 < list3.Count; num3++) { Gizmo gizmo6 = list3[num3]; if (gizmo6 != gizmo3 && !gizmo6.disabled && gizmo3.InheritInteractionsFrom(gizmo6)) { gizmo6.ProcessInput(ev); } } gizmo3.ProcessInput(ev); Event.current.Use(); } else if (gizmo4 != null) { List <FloatMenuOption> list4 = new List <FloatMenuOption>(); foreach (FloatMenuOption rightClickFloatMenuOption in gizmo4.RightClickFloatMenuOptions) { list4.Add(rightClickFloatMenuOption); } List <Gizmo> list5 = FindMatchingGroup(gizmo4); Action prevAction; Action localOptionAction; for (int num4 = 0; num4 < list5.Count; num4++) { Gizmo gizmo7 = list5[num4]; if (gizmo7 != gizmo4 && !gizmo7.disabled && gizmo4.InheritFloatMenuInteractionsFrom(gizmo7)) { foreach (FloatMenuOption rightClickFloatMenuOption2 in gizmo7.RightClickFloatMenuOptions) { FloatMenuOption floatMenuOption = null; for (int num5 = 0; num5 < list4.Count; num5++) { if (list4[num5].Label == rightClickFloatMenuOption2.Label) { floatMenuOption = list4[num5]; break; } } if (floatMenuOption == null) { list4.Add(rightClickFloatMenuOption2); } else if (!rightClickFloatMenuOption2.Disabled) { if (!floatMenuOption.Disabled) { prevAction = floatMenuOption.action; localOptionAction = rightClickFloatMenuOption2.action; floatMenuOption.action = delegate { prevAction(); localOptionAction(); }; } else if (floatMenuOption.Disabled) { list4[list4.IndexOf(floatMenuOption)] = rightClickFloatMenuOption2; } } } } } Event.current.Use(); if (list4.Any()) { Find.WindowStack.Add(new FloatMenu(list4)); } } for (int num6 = 0; num6 < gizmoGroups.Count; num6++) { gizmoGroups[num6].Clear(); SimplePool <List <Gizmo> > .Return(gizmoGroups[num6]); } gizmoGroups.Clear(); firstGizmos.Clear(); tmpAllGizmos.Clear(); List <Gizmo> FindMatchingGroup(Gizmo toMatch) { for (int num7 = 0; num7 < gizmoGroups.Count; num7++) { if (gizmoGroups[num7].Contains(toMatch)) { return(gizmoGroups[num7]); } } return(null); } }
public static void DrawGizmoGrid(IEnumerable <Gizmo> gizmos, float startX, out Gizmo mouseoverGizmo) { if (Event.current.type == EventType.Layout) { mouseoverGizmo = null; return; } tmpAllGizmos.Clear(); tmpAllGizmos.AddRange(gizmos); tmpAllGizmos.SortStable(SortByOrder); gizmoGroups.Clear(); for (int i = 0; i < tmpAllGizmos.Count; i++) { Gizmo gizmo = tmpAllGizmos[i]; bool flag = false; for (int j = 0; j < gizmoGroups.Count; j++) { if (gizmoGroups[j][0].GroupsWith(gizmo)) { flag = true; gizmoGroups[j].Add(gizmo); gizmoGroups[j][0].MergeWith(gizmo); break; } } if (!flag) { List <Gizmo> list = SimplePool <List <Gizmo> > .Get(); list.Add(gizmo); gizmoGroups.Add(list); } } firstGizmos.Clear(); shrinkableCommands.Clear(); float num = UI.screenWidth - 147; Vector2 vector = new Vector2(startX, (float)(UI.screenHeight - 35) - GizmoSpacing.y - 75f); float maxWidth = num - startX; int num2 = 0; for (int k = 0; k < gizmoGroups.Count; k++) { List <Gizmo> list2 = gizmoGroups[k]; Gizmo gizmo2 = null; for (int l = 0; l < list2.Count; l++) { if (!list2[l].disabled) { gizmo2 = list2[l]; break; } } if (gizmo2 == null) { gizmo2 = list2.FirstOrDefault(); } else { Command_Toggle command_Toggle = gizmo2 as Command_Toggle; if (command_Toggle != null) { if (!command_Toggle.activateIfAmbiguous && !command_Toggle.isActive()) { for (int m = 0; m < list2.Count; m++) { Command_Toggle command_Toggle2 = list2[m] as Command_Toggle; if (command_Toggle2 != null && !command_Toggle2.disabled && command_Toggle2.isActive()) { gizmo2 = list2[m]; break; } } } if (command_Toggle.activateIfAmbiguous && command_Toggle.isActive()) { for (int n = 0; n < list2.Count; n++) { Command_Toggle command_Toggle3 = list2[n] as Command_Toggle; if (command_Toggle3 != null && !command_Toggle3.disabled && !command_Toggle3.isActive()) { gizmo2 = list2[n]; break; } } } } } if (gizmo2 != null) { Command command; if ((command = gizmo2 as Command) != null && command.shrinkable && command.Visible) { shrinkableCommands.Add(command); } if (vector.x + gizmo2.GetWidth(maxWidth) > num) { vector.x = startX; vector.y -= 75f + GizmoSpacing.x; num2++; } vector.x += gizmo2.GetWidth(maxWidth) + GizmoSpacing.x; firstGizmos.Add(gizmo2); } } if (num2 > 1 && shrinkableCommands.Count > 1) { for (int num3 = 0; num3 < shrinkableCommands.Count; num3++) { firstGizmos.Remove(shrinkableCommands[num3]); } } else { shrinkableCommands.Clear(); } drawnHotKeys.Clear(); Text.Font = GameFont.Tiny; Vector2 vector2 = new Vector2(startX, (float)(UI.screenHeight - 35) - GizmoSpacing.y - 75f); mouseoverGizmo = null; Gizmo interactedGiz = null; Event interactedEvent = null; Gizmo floatMenuGiz = null; for (int num4 = 0; num4 < firstGizmos.Count; num4++) { Gizmo gizmo3 = firstGizmos[num4]; if (gizmo3.Visible) { if (vector2.x + gizmo3.GetWidth(maxWidth) > num) { vector2.x = startX; vector2.y -= 75f + GizmoSpacing.x; } heightDrawnFrame = Time.frameCount; heightDrawn = (float)UI.screenHeight - vector2.y; GizmoResult result2 = gizmo3.GizmoOnGUI(vector2, maxWidth); ProcessGizmoState(gizmo3, result2, ref mouseoverGizmo); GenUI.AbsorbClicksInRect(new Rect(vector2.x, vector2.y, gizmo3.GetWidth(maxWidth), 75f + GizmoSpacing.y).ContractedBy(-12f)); vector2.x += gizmo3.GetWidth(maxWidth) + GizmoSpacing.x; } } float x = vector2.x; int num5 = 0; for (int num6 = 0; num6 < shrinkableCommands.Count; num6++) { Command command2 = shrinkableCommands[num6]; float getShrunkSize = command2.GetShrunkSize; if (vector2.x + getShrunkSize > num) { num5++; if (num5 > 1) { x = startX; } vector2.x = x; vector2.y -= getShrunkSize + 3f; } Vector2 topLeft = vector2; topLeft.y += getShrunkSize + 3f; heightDrawnFrame = Time.frameCount; heightDrawn = Mathf.Min(heightDrawn, (float)UI.screenHeight - topLeft.y); GizmoResult result3 = command2.GizmoOnGUIShrunk(topLeft, getShrunkSize); ProcessGizmoState(command2, result3, ref mouseoverGizmo); GenUI.AbsorbClicksInRect(new Rect(topLeft.x, topLeft.y, getShrunkSize, getShrunkSize + 3f).ExpandedBy(3f)); vector2.x += getShrunkSize + 3f; } if (interactedGiz != null) { List <Gizmo> list3 = FindMatchingGroup(interactedGiz); for (int num7 = 0; num7 < list3.Count; num7++) { Gizmo gizmo4 = list3[num7]; if (gizmo4 != interactedGiz && !gizmo4.disabled && interactedGiz.InheritInteractionsFrom(gizmo4)) { gizmo4.ProcessInput(interactedEvent); } } interactedGiz.ProcessInput(interactedEvent); Event.current.Use(); } else if (floatMenuGiz != null) { List <FloatMenuOption> list4 = new List <FloatMenuOption>(); foreach (FloatMenuOption rightClickFloatMenuOption in floatMenuGiz.RightClickFloatMenuOptions) { list4.Add(rightClickFloatMenuOption); } List <Gizmo> list5 = FindMatchingGroup(floatMenuGiz); for (int num8 = 0; num8 < list5.Count; num8++) { Gizmo gizmo5 = list5[num8]; if (gizmo5 == floatMenuGiz || gizmo5.disabled || !floatMenuGiz.InheritFloatMenuInteractionsFrom(gizmo5)) { continue; } foreach (FloatMenuOption rightClickFloatMenuOption2 in gizmo5.RightClickFloatMenuOptions) { FloatMenuOption floatMenuOption = null; for (int num9 = 0; num9 < list4.Count; num9++) { if (list4[num9].Label == rightClickFloatMenuOption2.Label) { floatMenuOption = list4[num9]; break; } } if (floatMenuOption == null) { list4.Add(rightClickFloatMenuOption2); } else { if (rightClickFloatMenuOption2.Disabled) { continue; } if (!floatMenuOption.Disabled) { Action prevAction = floatMenuOption.action; Action localOptionAction = rightClickFloatMenuOption2.action; floatMenuOption.action = delegate { prevAction(); localOptionAction(); }; } else if (floatMenuOption.Disabled) { list4[list4.IndexOf(floatMenuOption)] = rightClickFloatMenuOption2; } } } } Event.current.Use(); if (list4.Any()) { Find.WindowStack.Add(new FloatMenu(list4)); } } for (int num10 = 0; num10 < gizmoGroups.Count; num10++) { gizmoGroups[num10].Clear(); SimplePool <List <Gizmo> > .Return(gizmoGroups[num10]); } gizmoGroups.Clear(); firstGizmos.Clear(); tmpAllGizmos.Clear();