示例#1
0
        public LuaArgs getRobotCount(LuaArgs args)
        {
            var campaign = GetCampaign();

            if (campaign != null)
            {
                int total;
                int rescued = ProgressUtils.CountRobotsRescued(campaign, GetMod(), m_state.Game.User, out total, GetIgnoreLevel());
                return(new LuaArgs(total, rescued));
            }
            return(new LuaArgs(0, 0));
        }
示例#2
0
        public void Refresh()
        {
            // Unhighlight
            int oldHighlight = m_highlight;
            int oldCount     = m_count;

            if (Screen != null)
            {
                SetHighlight(-1);
            }

            // Dispose old elements
            for (int i = 0; i < m_campaignThumbnails.Count; ++i)
            {
                var thumbnail = m_campaignThumbnails[i];
                thumbnail.Dispose();
            }
            m_campaignThumbnails.Clear();

            // Get campaign list
            var campaigns = AllCampaigns();

            m_count = campaigns.Count;

            // Add new elements
            var yPos = 0.0f;

            for (int i = m_offset; i < Math.Min(campaigns.Count, m_offset + ENTRIES_PER_PAGE); ++i)
            {
                var campaign  = campaigns[i].Campaign;
                var mod       = campaigns[i].Mod;
                var thumbnail = new CampaignThumbnail(m_width, 16.0f + 2.0f * UIFonts.Default.Height);
                thumbnail.Anchor        = Anchor;
                thumbnail.LocalPosition = LocalPosition + new Vector2(0.0f, yPos);

                // Set icon
                if (mod != null)
                {
                    var icon = mod.LoadIcon(true);
                    if (icon != null)
                    {
                        thumbnail.Icon        = icon;
                        thumbnail.DisposeIcon = true;
                    }
                    else
                    {
                        thumbnail.Icon = Texture.Get("gui/blue_icon.png", true);
                    }
                }
                else
                {
                    thumbnail.Icon = Texture.Get("gui/red_icon.png", true);
                }

                // Set title, info and action
                int  robotsRescued, totalRobots;
                bool allLevelsCompleted = ProgressUtils.IsCampaignCompleted(campaign, mod, m_game.User);
                robotsRescued = ProgressUtils.CountRobotsRescued(campaign, mod, m_game.User, out totalRobots);

                thumbnail.Title = campaign.Title;
                if (m_editor)
                {
                    thumbnail.Info   = "[gui/red_robot.png] " + totalRobots;
                    thumbnail.Action = CampaignThumbnailAction.Delete;
                }
                else
                {
                    if (allLevelsCompleted)
                    {
                        thumbnail.Info = "[gui/red_robot.png] " + robotsRescued + " [gui/completed.png]";
                    }
                    else
                    {
                        thumbnail.Info = "[gui/red_robot.png] " + robotsRescued;
                    }
                    if (mod != null && mod.Source == ModSource.Editor)
                    {
                        thumbnail.Action = CampaignThumbnailAction.Edit;
                    }
                    else if (mod != null && mod.Source == ModSource.Workshop)
                    {
                        thumbnail.Action = CampaignThumbnailAction.ShowInWorkshop;
                    }
                }

                thumbnail.OnClicked += delegate(object sender, EventArgs e)
                {
                    FireOnSelection(campaign, mod);
                };
                thumbnail.OnActionClicked += delegate(object sender, EventArgs e)
                {
                    FireOnAction(campaign, mod, thumbnail.Action);
                };

                m_campaignThumbnails.Add(thumbnail);
                yPos += thumbnail.Height + MARGIN_HEIGHT;
            }
            m_actionButton.Anchor        = Anchor;
            m_actionButton.LocalPosition = LocalPosition + new Vector2(0.0f, yPos);

            if (Screen != null)
            {
                // Init new elements
                for (int i = 0; i < m_campaignThumbnails.Count; ++i)
                {
                    var thumbnail = m_campaignThumbnails[i];
                    thumbnail.Init(Screen);
                }

                // Set highlight
                if (oldHighlight == oldCount)
                {
                    SetHighlight(m_count);
                }
                else if (oldHighlight >= 0 && oldHighlight < m_count)
                {
                    SetHighlight(oldHighlight);
                }
                else
                {
                    SetHighlight(-1);
                }
            }

            m_upButton.Visible   = m_offset > 0;
            m_downButton.Visible = (m_offset + ENTRIES_PER_PAGE) < m_count;
        }