示例#1
0
        public HudsTFWidget(string title, string creator, string imgUrl, string hudstfUrl, string download, string website)
        {
            var downloadLower = download.ToLower();

            AddChild(ImageView = new ImageView() { WidthRequest = ImageSize.Width, HeightRequest = ImageSize.Height }, new Rectangle(1, 1, ImageSize.Width, ImageSize.Height));
            AddChild(titleLabel = new Label(title + " by " + creator) { TextColor = Colors.White }, new Rectangle(4, 0, ImageSize.Width, 40));

            titleLabel.Font = titleLabel.Font.WithScaledSize(1.5);
            titleLabel.WidthRequest = ImageSize.Width;
            titleLabel.HeightRequest = 40;
            titleLabel.QueueForReallocate();

            WidthRequest = ImageSize.Width + 2;
            HeightRequest = ImageSize.Height + 39;

            if (hudstfUrl != null)
            {
                hudstfButton = new ImageButton(57, 16, HudsTfLogo);
                hudstfButton.Click += (s, e) => { Desktop.OpenUrl(hudstfUrl); };

                AddChild(hudstfButton, ImageSize.Width - 64, ImageSize.Height + 11);
                //AddChild(hudstfButton, ImageSize.Width - 61, 24);
            }

            if (website != null)
            {
                websiteButton = new ImageButton(16, 16, QuadImageLinkButton.DefaultImage);
                websiteButton.Click += (s, e) => { Desktop.OpenUrl(website); };

                AddChild(websiteButton, ImageSize.Width - 84, ImageSize.Height + 11);
                //AddChild(websiteButton, ImageSize.Width - 81, 24);
            }

            bool hasDirectDownload = true;
            string zipLink = null;

            //string zipLink = download.Contains("github.com") || download.Contains("gitgud.net");
            if (downloadLower.Contains("github.com"))
                zipLink = download.TrimEnd('/') + "/archive/master.zip";
            else if (downloadLower.Contains("gitgud.net"))
                zipLink = download.TrimEnd('/') + "/repository/archive.zip";
            else
                hasDirectDownload = false;

            if (hasDirectDownload)
            {
                githubButton = new ImageButton(16, 16, GithubLogo);
                githubButton.Click += (s, e) => { Desktop.OpenUrl(download); };

                AddChild(githubButton, ImageSize.Width - 104, ImageSize.Height + 11);
            }

            dlButton = new Button();
            dlButton.Label = hasDirectDownload ? "Install" : "Get";
            dlButton.WidthRequest = 120;
            dlButton.HeightRequest = 24;
            //dlButton.Sensitive = downloadIsGithub;
            //https://gitgud.net/JediThug/jedihud/repository/archive.zip

            dlButton.Clicked += (s, e) =>
            {
                if (hasDirectDownload)
                {
                    DownloadHudWidget dl = new DownloadHudWidget("Fetching " + zipLink);

                    dl.DownloadFinished += (s2, e2) =>
                    {
                        try
                        {
                            if (!App.InstallZip(new MemoryStream(e2.Result), title))
                                MessageDialog.ShowError("Installing the Hud failed", "You can try to install it yourself.");
                        }
                        catch { }
                        Application.Invoke(() => { App.MainWindow.RemovePlugin(dl); });//App.MainWindow.Layout.RemoveChild(this));
                        Dispose();
                    };

                    dl.Download(zipLink);

                    App.MainWindow.Present();
                    System.Threading.Thread.Sleep(50);
                    App.MainWindow.Layout.AddChild(dl);
                }
                else
                {
                    Desktop.OpenUrl(download);
                }
            };

            AddChild(dlButton, 7, ImageSize.Height + 7);
            //AddChild(dlButton, 4, 20);

            Margin = new WidgetSpacing(4,4,4,4);

            //OnMouseExited(null);
        }
示例#2
0
        public PluginWidget(string path)
        {
            Path = path;
            Name = path.GetFileName();

            this.PluginType = GetPluginType();

            //---- image
            pluginImage = new PluginImageButton();
            pluginImage.Click += (s, e) =>
                {
                    if (!InstallOrUninstall())
                        errorSound();
                };
            pluginImage.PluginType = PluginType;
            AddChild(pluginImage, 33, 3);

            //---- buttons
            openFolderBtn = new ImageButton();
            openFolderBtn.Image = imgOpenFolder;
            openFolderBtn.Click += (s, e) => { Desktop.OpenFolder(Path); };

            moreActionsBtn = new ImageButton();
            moreActionsBtn.Image = imgMoreActions;
            moreActionsBtn.ButtonReleased += (s, e) =>
                {
                    if (e.Button == PointerButton.Left)
                    {
                        lastClicked = this;
                        menu.Popup(this, e.X, e.Y);
                    }
                };

            AddChild(openFolderBtn, 6, 6);
            AddChild(moreActionsBtn, 6, 25);

            AddChild(new VerticalLine(), new Rectangle(28, 6, 1, 34));

            //---- lbl
            lblName = new Label(Name + new string(' ', 30));
            lblAuthor = new Label(new string(' ', 30));
            lblVersion = new Label(new string(' ', 30));

            AddChild(lblName, new Rectangle(117, 1, 132, 18));
            AddChild(lblAuthor, new Rectangle(117, 14, 132, 18));
            AddChild(lblVersion, new Rectangle(117, 27, 132, 18));

            lblName.ButtonPressed += (s, e) =>
            {
                if (e.MultiplePress == 2)
                {
                    StartRename();
                    e.Handled = true;
                }
            };

            lblAuthor.Opacity = lblVersion.Opacity = .5;
            lblAuthor.Text = lblVersion.Text = "";

            //---- rename
            txtNameRename = new TextEntry();
            txtNameRename.KeyPressed += (s, e) =>
            {
                if (e.Key == Key.Return)
                {
                    if (Rename(txtNameRename.Text))
                    {
                        EndRename();
                        // disabled if there's no move animation
                        if (App.MoveWidget != null)
                            App.MainWindow.Layout.Sort(true);
                    }
                    else
                        errorSound();
                }
                else if (e.Key == Key.Escape)
                {
                    EndRename();
                }
            };

            AddChild(txtNameRename, new Rectangle(117, 2, 132, 22));
            txtNameRename.Visible = false;

            AddChild(new VerticalLine(), new Rectangle(250, 6, 1, 34));

            //---- little icons
            AddChild(btnChangelog = new ImageButton(12, 12, imgChangeLog) { Visible = false }, 208, 32);
            AddChild(btnReadme = new ImageButton(12, 12, imgReadme) { Visible = false }, 222, 32);
            AddChild(btnFaq = new ImageButton(12, 12, imgHelp) { Visible = false }, 236, 32);

            btnChangelog.Click += (s, e) => { if (changelogPath != null) new TextViewerWindow(changelogPath).Show(); };
            btnReadme.Click += (s, e) => { if (readmePath != null) new TextViewerWindow(readmePath).Show(); };
            btnFaq.Click += (s, e) => { if (faqPath != null) new TextViewerWindow(faqPath).Show(); };

            //---- update btn
            buttonUpdate = new ImageButton(16, 16, imgUpdate);
            buttonUpdate.Visible = false;
            AddChild(buttonUpdate, 232, 8);

            //---- settings button
            settingsBtn = new Button();
            //settingsBtn.Image = imgSettings;
            settingsBtn.ImagePosition = ContentPosition.Center;
            settingsBtn.WidthRequest = 25;
            settingsBtn.HeightRequest = 22;
            settingsBtn.Sensitive = false;
            settingsBtn.Clicked += (s, e) => { ShowSettings(); };
            AddChild(settingsBtn, 256, 11);

            AddChild(new VerticalLine(), new Rectangle(285, 6, 1, 34));

            //---- links
            linksQuad = new QuadImageLinkButton();
            AddChild(linksQuad, 284, 0);
            //AddChild(linksQuad, 252, 0);

            Load();
        }