Пример #1
0
 internal static FloatMenuOption SubscribeOption(string name, string identifier)
 {
     return(new FloatMenuOption(I18n.Subscribe(name), () => Workshop.Subscribe(identifier)));
 }
        private static void DrawCrossPromotions(ref Rect canvas, IEnumerable <CrossPromotion> promotions)
        {
            var backgroundRect = new Rect(
                canvas.xMin,
                canvas.yMin,
                canvas.width,
                PromotionsHeight);
            var outRect = backgroundRect.ContractedBy(SmallMargin / 2);
            var height  = (int)outRect.height;
            var width   = promotions.Sum(p => p.NormalizedWidth(height)) + (promotions.Count() - 1) * SmallMargin;

            if (width > outRect.width)
            {
                height -= 16;
                // recalculate total width
                width = promotions.Sum(p => p.NormalizedWidth(height)) + (promotions.Count() - 1) * SmallMargin;
            }
            var viewRect = new Rect(
                canvas.xMin,
                canvas.yMin,
                width,
                height);
            var pos = viewRect.min;

            canvas.yMin += PromotionsHeight + SmallMargin;

            Widgets.DrawBoxSolid(backgroundRect, SlightlyDarkBackground);
            if (Mouse.IsOver(outRect) && Event.current.type == EventType.ScrollWheel)
            {
                _scrollPosition.x += Event.current.delta.y * Constants.ScrollSpeed;
            }
            Widgets.BeginScrollView(outRect, ref _scrollPosition, viewRect);
            foreach (var promotion in promotions)
            {
                var normalizedWidth = promotion.NormalizedWidth(height);
                var rect            = new Rect(pos.x, pos.y, normalizedWidth, height);
                if (Widgets.ButtonImage(rect, promotion.Preview, new Color(.9f, .9f, .9f), Color.white))
                {
                    if (!promotion.Installed)
                    {
                        var options = Utilities.NewOptionsList;
                        options.Add(new FloatMenuOption(I18n.Subscribe(promotion.Name),
                                                        () => Workshop.Subscribe(promotion.FileId)));
                        options.Add(new FloatMenuOption(I18n.WorkshopPage(promotion.Name),
                                                        () => SteamUtility.OpenWorkshopPage(promotion.FileId)));
                        Utilities.FloatMenu(options);
                    }
                    else
                    {
                        var button = ModButtonManager.AllButtons.FirstOrDefault(b => b.Name == promotion.Name);
                        if (button != null)
                        {
                            Page_BetterModConfig.Instance.Selected = button;
                        }
                    }
                }
                TooltipHandler.TipRegion(rect, promotion.Name + "\n\n" + promotion.Description);
                pos.x += normalizedWidth + SmallMargin;
            }
            Widgets.EndScrollView();
        }