/// <summary>
 /// Gets the author view model.
 /// </summary>
 /// <param name="obj">The object.</param>
 /// <param name="currentNewsItem">The current news item.</param>
 /// <returns>Author View Moddel</returns>
 public static AuthorViewModel GetAuthorViewModel(DynamicContent obj)
 {
     return(new AuthorViewModel(obj)
     {
         Name = obj.GetString("Name"),
         JobTitle = obj.GetString("JobTitle"),
         Bio = obj.GetString("Bio"),
         Avatar = WidgetExtensions.GetRelatedMediaUrl(obj, "Avatar")
     });
 }
예제 #2
0
        private static void DrawDynamicLeader(Rect rect, out Rect leaderRect, PersistentColony colony, PersistentWorld world,
                                              float widthMultiplier)
        {
            var portraitSize = new Vector2(rect.width / 2, rect.height);

            leaderRect = new Rect(rect.x + rect.width * widthMultiplier, rect.y, portraitSize.x, portraitSize.y);;

            if (colony.ColonyData.Leader != null && colony.ColonyData.Leader.Set &&
                (object)colony.ColonyData.Leader.Texture != null ||
                colony.ColonyData.Leader?.Reference != null)
            {
                if (colony.ColonyData.Leader.Reference != null)
                {
                    colony.ColonyData.Leader.Texture =
                        PortraitsCache.Get(colony.ColonyData.Leader.Reference, portraitSize, new Vector3(), 1f, true, true);
                }

                var leaderPortrait = colony.ColonyData.Leader.Texture;

                var canChangeLeader = CanChangeLeader(colony, world);

                if (canChangeLeader)
                {
                    if (WidgetExtensions.ButtonImage(leaderRect, leaderPortrait, Color.white, GenUI.MouseoverColor))
                    {
                        Find.WindowStack.Add(new Dialog_PersistentWorlds_LeaderPawnSelection(colony));
                    }
                }
                else
                {
                    GUI.DrawTexture(leaderRect, leaderPortrait);
                }

                TooltipHandler.TipRegion(leaderRect,
                                         canChangeLeader
                        ? "FilUnderscore.PersistentRimWorlds.Colony.ChangeLeader".Translate()
                        : "FilUnderscore.PersistentRimWorlds.Colony.ColonyLeader".Translate(colony.ColonyData.Leader
                                                                                            .Name.ToStringFull));
            }
            else
            {
                Text.Font = GameFont.Tiny;

                Widgets.Label(leaderRect, "FilUnderscore.PersistentRimWorlds.Colony.NoLeader".Translate());

                Text.Font = GameFont.Small;
            }
        }
예제 #3
0
        private static void DrawLabel(Rect rect, string label, UIEntry item)
        {
            if (!ScrollPositions.ContainsKey(item))
            {
                ScrollPositions.Add(item, new Vector2());
            }

            var itemScrollPosition = ScrollPositions[item];

            Text.Font = GameFont.Small;

            WidgetExtensions.LabelScrollable(rect, label, ref itemScrollPosition, false, true, false);

            Text.Font = GameFont.Small;

            ScrollPositions[item] = _scrollPosition;
        }
예제 #4
0
        private static void DrawNameLabel(Rect rect, PersistentColony colony, Faction faction)
        {
            if (!ScrollPositions.ContainsKey(colony))
            {
                ScrollPositions.Add(colony, new Vector2());
            }

            var labelScrollPosition = ScrollPositions[colony];

            Text.Font = GameFont.Tiny;

            WidgetExtensions.LabelScrollable(rect, faction.Name, ref labelScrollPosition, false,
                                             true, false);

            Text.Font = GameFont.Small;

            ScrollPositions[colony] = labelScrollPosition;
        }
예제 #5
0
        static void Postfix()
        {
            drawing = false;

            Vector2 size = new Vector2(WorldIcon.width / 16f, WorldIcon.height / 16f);

            Rect rect = new Rect((Verse.UI.screenWidth - size.x) * 0.99675f, (Verse.UI.screenHeight - size.y) * 0.99f, size.x, size.y);

            GUI.BeginGroup(rect);
            Rect rect1 = new Rect(0, 0, size.x, size.y);

            if (WidgetExtensions.ButtonImageOn(rect1, WorldIcon))
            {
                Find.WindowStack.Add(new Page_PersistentWorlds_LoadWorld_FileList());
            }

            TooltipHandler.TipRegion(rect1, "FilUnderscore.PersistentRimWorlds".Translate());

            GUI.EndGroup();
        }
예제 #6
0
        /// <summary>
        /// Adds a menu item button to a menu button.
        /// </summary>
        /// <param name="parentButtonText">Text on the parent button.</param>
        /// <param name="text">Text on the button.</param>
        /// <param name="image">Image on the button.</param>
        /// <param name="handler">Handler to call when button is clicked.</param>
        public void AddButtonToMenu(string parentButtonText, string text, Image image, EventHandler handler)
        {
            if (!ButtonsAreToolbar)
            {
                throw new NotImplementedException();
            }

            // Find the top-level menu button (the button which, when clicked, causes the menu to appear).
            MenuToolButton toplevel = btnToolbar.AllChildren.OfType <MenuToolButton>().FirstOrDefault(b => (b.LabelWidget as Label).Text == parentButtonText);

            if (toplevel.Menu as Menu == null)
            {
                toplevel.Menu = new Menu();
            }
            Menu     menu     = toplevel.Menu as Menu;
            MenuItem menuItem = WidgetExtensions.CreateImageMenuItem(text, image);

            menuItem.Activated += handler;
            menu.Append(menuItem);
            menuItem.ShowAll();
        }
예제 #7
0
 public void PopulateContextMenu(List <MenuDescriptionArgs> menuDescriptions)
 {
     ClearPopup();
     foreach (MenuDescriptionArgs description in menuDescriptions)
     {
         MenuItem item;
         if (description.ShowCheckbox)
         {
             CheckMenuItem checkItem = new CheckMenuItem(description.Name);
             checkItem.Active = description.Checked;
             item             = checkItem;
         }
         else if (!String.IsNullOrEmpty(description.ResourceNameForImage) && MasterView.HasResource(description.ResourceNameForImage))
         {
             item = WidgetExtensions.CreateImageMenuItem(description.Name, new Image(null, description.ResourceNameForImage));
         }
         else
         {
             item = new MenuItem(description.Name);
         }
         if (!String.IsNullOrEmpty(description.ShortcutKey))
         {
             string           keyName  = String.Empty;
             Gdk.ModifierType modifier = Gdk.ModifierType.None;
             string[]         keyNames = description.ShortcutKey.Split(new Char[] { '+' });
             foreach (string name in keyNames)
             {
                 if (name == "Ctrl")
                 {
                     modifier |= Gdk.ModifierType.ControlMask;
                 }
                 else if (name == "Shift")
                 {
                     modifier |= Gdk.ModifierType.ShiftMask;
                 }
                 else if (name == "Alt")
                 {
                     modifier |= Gdk.ModifierType.Mod1Mask;
                 }
                 else if (name == "Del")
                 {
                     keyName = "Delete";
                 }
                 else
                 {
                     keyName = name;
                 }
             }
             try
             {
                 Gdk.Key accelKey = (Gdk.Key)Enum.Parse(typeof(Gdk.Key), keyName, false);
                 item.AddAccelerator("activate", accel, (uint)accelKey, modifier, AccelFlags.Visible);
             }
             catch
             {
             }
         }
         item.Activated += description.OnClick;
         popup.Append(item);
     }
     if (popup.AttachWidget == null)
     {
         popup.AttachToWidget(Listview, null);
     }
     popup.ShowAll();
 }
예제 #8
0
        /// <summary>Populate the main menu tool strip.</summary>
        /// <param name="menuDescriptions">Descriptions for each item.</param>
        public void Populate(List <MenuDescriptionArgs> menuDescriptions)
        {
            menu.Clear();
            foreach (MenuDescriptionArgs description in menuDescriptions)
            {
                MenuItem item;
                if (description.ShowCheckbox)
                {
                    CheckMenuItem checkItem = new CheckMenuItem(description.Name);
                    checkItem.Active = description.Checked;
                    item             = checkItem;
                }
                else
                {
                    ManifestResourceInfo info = Assembly.GetExecutingAssembly().GetManifestResourceInfo(description.ResourceNameForImage);
                    if (info != null)
                    {
                        MenuItem imageItem = WidgetExtensions.CreateImageMenuItem(description.Name, new Gtk.Image(null, description.ResourceNameForImage));
                        item = imageItem;
                    }
                    else
                    {
                        item = new MenuItem(description.Name);
                    }
                }

                if (!String.IsNullOrEmpty(description.ShortcutKey))
                {
                    string           keyName  = String.Empty;
                    Gdk.ModifierType modifier = Gdk.ModifierType.None;
                    string[]         keyNames = description.ShortcutKey.Split(new Char[] { '+' });
                    foreach (string name in keyNames)
                    {
                        if (name == "Ctrl")
                        {
                            modifier |= Gdk.ModifierType.ControlMask;
                        }
                        else if (name == "Shift")
                        {
                            modifier |= Gdk.ModifierType.ShiftMask;
                        }
                        else if (name == "Alt")
                        {
                            modifier |= Gdk.ModifierType.Mod1Mask;
                        }
                        else if (name == "Del")
                        {
                            keyName = "Delete";
                        }
                        else
                        {
                            keyName = name;
                        }
                    }
                    try
                    {
                        Gdk.Key accelKey = (Gdk.Key)Enum.Parse(typeof(Gdk.Key), keyName, false);
                        item.AddAccelerator("activate", Accelerators, (uint)accelKey, modifier, AccelFlags.Visible);
                    }
                    catch
                    {
                    }
                }
                item.Activated += description.OnClick;
                if (description.FollowsSeparator && (menu.Children.Length > 0))
                {
                    menu.Append(new SeparatorMenuItem());
                }
                menu.Append(item);
            }
            menu.ShowAll();
        }