private static FloatMenu MakeInfoMenuFromDefs(IEnumerable <Def> defs) { List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (var def in defs) { Texture2D icon = def.IconTexture(); Dialog_InfoCard.Hyperlink hyperlink = new Dialog_InfoCard.Hyperlink(def); options.Add(new FloatMenuOption(def.label, () => hyperlink.OpenDialog(), icon, def.IconColor())); } return(new FloatMenu(options)); }
private void IconActions(bool draw) { // handle only right click if (!draw && !(Event.current.type == EventType.MouseDown && Event.current.button == 1)) { return; } var unlocks = Unlocks(); for (var i = 0; i < unlocks.Count; ++i) { var iconRect = new Rect( IconsRect.xMax - (i + 1) * (IconSize.x + 4f), IconsRect.yMin + (IconsRect.height - IconSize.y) / 2f, IconSize.x, IconSize.y); if (iconRect.xMin - IconSize.x < IconsRect.xMin && i + 1 < unlocks.Count) { // stop the loop if we're about to overflow and have 2 or more unlocks yet to print. iconRect.x = IconsRect.x + 4f; if (draw) { GUI.DrawTexture(iconRect, Assets.MoreIcon, ScaleMode.ScaleToFit); if (!PainterIs(Painter.Drag)) { var tip = string.Join( "\n", unlocks.GetRange(i, unlocks.Count - i).Select(p => p.Second).ToArray()); TooltipHandler.TipRegion(iconRect, tip); } } else if (!draw && Mouse.IsOver(iconRect) && Find.WindowStack.FloatMenu == null) { var floatMenu = MakeInfoMenuFromDefs(unlocks.Skip(i).Select(p => p.First)); Find.WindowStack.Add(floatMenu); Event.current.Use(); } break; } var def = unlocks[i].First; if (draw) { def.DrawColouredIcon(iconRect); if (!PainterIs(Painter.Drag)) { TooltipHandler.TipRegion(iconRect, unlocks[i].Second); } } else if (Mouse.IsOver(iconRect)) { Dialog_InfoCard.Hyperlink link = new Dialog_InfoCard.Hyperlink(def); link.OpenDialog(); Event.current.Use(); break; } } }