Пример #1
0
        ColorDialogSection(bool showCreateDialog)
        {
            var layout = new DynamicLayout {
                Spacing = new Size(20, 20), DefaultSpacing = new Size(5, 5), Padding = new Padding(10)
            };

            var btnCreateDialog = new Button {
                Text = "Use in Dialog"
            };

            btnCreateDialog.Click += BtnCreateDialog_Click;

            layout.BeginCentered();
            layout.Add(CreateAllowAlphaCheckBox());
            layout.Add(PickColor());
            layout.Add(PickColorWithStartingColor());
            if (showCreateDialog)
            {
                layout.Add(btnCreateDialog);
            }

            layout.EndCentered();
            layout.AddCentered(new ColorPicker());

            layout.AddCentered(new TextBox());

            layout.AddSpace();

            Content = layout;
        }
Пример #2
0
        Control WidthRow()
        {
            var layout = new DynamicLayout();

            layout.Padding = new Padding(20, 10, 20, 0);

            layout.BeginHorizontal();
            layout.AddSpace();
            layout.Add(new Label {
                Text = "Canvas Size", VerticalAlignment = VerticalAlignment.Center
            });
            layout.Add(WidthControl());
            layout.Add(HeightControl());
            layout.AddSpace();

            layout.EndHorizontal();

            return(layout);
        }
Пример #3
0
 Control CreateMenu()
 {
     _menuLayout.BeginVertical();
     _menuLayout.Add(CreateMenuItem("Push To Talk", _homeViewModel.ShowPttView));
     _menuLayout.Add(CreateMenuItem("Browse Groups", _homeViewModel.ShowBrowseGroupsView));
     _menuLayout.Add(CreateMenuItem("About", _homeViewModel.ShowAboutView));
     _menuLayout.AddSpace();
     _menuLayout.EndVertical();
     _menuLayout.BackgroundColor = Color.FromRgb(0x1C282B);
     return(_menuLayout);
 }
Пример #4
0
        public BrowseGroupView(BrowseGroupViewModel browseGroupViewModel, ImageService imageService, INavigator navigator, ColorService colorService)
            : base(imageService, navigator, "Back")
        {
            _browseGroupViewModel = browseGroupViewModel;

            DataContext = _browseGroupViewModel;
            var label = new Label()
            {
                Text = "Browse Group View"
            };

            var image = new ImageView()
            {
                Image = new Bitmap(_browseGroupViewModel.GroupImage)
            };

            if (image.Size.Width > 64)
            {
                image.Size = new Size(64, 64);
            }

            var joinButton = new Button()
            {
                Text = "Join"
            };

            joinButton.BindDataContext(c => c.Visible, (BrowseGroupViewModel m) => m.CanJoin);
            joinButton.Command = _browseGroupViewModel.Join;

            var leaveButton = new Button()
            {
                Text = "Leave"
            };

            leaveButton.BindDataContext(c => c.Visible, (BrowseGroupViewModel m) => m.CanLeave);
            leaveButton.Command = _browseGroupViewModel.Leave;

            var layout = new DynamicLayout();

            layout.BeginVertical();
            layout.Add(image);
            layout.Add(new Label()
            {
                Text = _browseGroupViewModel.Name, TextAlignment = TextAlignment.Center, Font = new Font(FontFamilies.Sans, 24)
            });
            layout.AddCentered(joinButton);
            layout.AddCentered(leaveButton);
            layout.AddSpace();

            ModalContent = layout;
        }
Пример #5
0
        public void TemplateImagesShouldDrawCorrectly(string color)
        {
            ManualForm("Both images should be the same in both light and dark mode",
                       form => {
                Color?backgroundColor = color != null ? Color.Parse(color) : (Color?)null;
                var bmp      = new Bitmap(200, 200, PixelFormat.Format32bppRgba);
                var img      = bmp.ControlObject as NSImage;
                img.Template = true;
                using (var g = new Graphics(bmp))
                {
                    g.PixelOffsetMode = PixelOffsetMode.Half;
                    g.FillRectangle(new Color(Colors.Black, .5f), 39, 39, 120, 120);

                    g.DrawRectangle(Colors.Red, 4.5f, 4.5f, 191, 191);
                    g.FillRectangle(Colors.Red, 49, 49, 100, 100);


                    g.DrawRectangle(Colors.Black, 0.5f, 0.5f, 199, 199);
                    g.FillRectangle(Colors.Black, 59, 59, 80, 80);
                }

                var drawable = new Drawable {
                    Size = bmp.Size
                };
                drawable.Paint += (sender, e) => {
                    if (backgroundColor != null)
                    {
                        e.Graphics.Clear(backgroundColor.Value);
                    }
                    e.Graphics.DrawImage(bmp, 0, 0);
                    // e.Graphics.DrawImage(bmp, 50, 50, 100, 100);
                    // e.Graphics.DrawImage(bmp, new RectangleF(99, 99, 100, 100), new Rectangle(0, 0, 200, 200));
                };

                var imageView   = new ImageView();
                imageView.Image = bmp;
                if (backgroundColor != null)
                {
                    imageView.BackgroundColor = backgroundColor.Value;
                }

                var content = new DynamicLayout();
                content.AddRow(drawable, imageView, null);
                content.AddSpace();
                return(content);
            }
                       );
        }
Пример #6
0
        public MainForm()
        {
            // Exit if we're already running the AM2RLauncher
            // Thanks, StackOverflow! https://stackoverflow.com/questions/184084/how-to-force-c-sharp-net-app-to-run-only-one-instance-in-windows
            if (!singleInstance)
            {
                // If on Windows, set the original app to the foreground window to prevent confusion
                if (OS.IsWindows)
                {
                    Process current = Process.GetCurrentProcess();
                    Process process = Process.GetProcessesByName(current.ProcessName).First(p => p.Id == current.Id);
                    if (process != null)
                    {
                        Core.Core.SetForegroundWindow(process.MainWindowHandle);
                    }
                }
                Environment.Exit(0);
            }

            log.Info("Mutex check passed. Entering main thread.");
            log.Info("Current Launcher Version: " + VERSION);
            log.Info("Current Platform-ID is: " + Platform.ID);
            log.Info("Current OS is: " + OS.Name);

            // Set the Current Directory to the path the Launcher is located. Fixes some relative path issues.
            Environment.CurrentDirectory = CrossPlatformOperations.CURRENTPATH;
            log.Info("Set Launcher CWD to " + Environment.CurrentDirectory);

            // But log actual folder location nonetheless
            log.Info("Actual Launcher location: " + Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory));

            // Set the language to what User wanted or choose local language
            string userLanguage = CrossPlatformOperations.ReadFromConfig("Language").ToLower();

            if (!userLanguage.Equals("default"))
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultures(CultureTypes.AllCultures).First(c => c.NativeName.ToLower().Contains(userLanguage));
            }

            log.Info("Language has been set to: " + Thread.CurrentThread.CurrentUICulture.EnglishName);

            #region VARIABLE INITIALIZATION
            log.Info("Beginning UI initialization...");

            Bitmap am2rIcon = new Bitmap(AM2RLauncher.Properties.Resources.AM2RIcon);

            // System tray indicator
            ButtonMenuItem showButton = new ButtonMenuItem {
                Text = Text.TrayButtonShow
            };
            trayIndicator = new TrayIndicator
            {
                Menu    = new ContextMenu(showButton),
                Title   = "AM2RLauncher",
                Visible = false,
                Image   = am2rIcon
            };

            // Create menubar with defaults for mac
            if (OS.IsMac)
            {
                Menu = new MenuBar();
            }

            // Create array from validCount
            profileList = new List <ProfileXML>();

            //TODO: whenever profileDropDown gets rewritten to use a datastore, scrap this
            profileNames = new List <ListItem>();
            foreach (var profile in profileList)
            {
                profileNames.Add(profile.Name);
            }

            // Custom splash texts
            string splash = Splash.GetSplash();
            log.Info("Randomly chosen splash: " + splash);

            Font smallButtonFont = new Font(SystemFont.Default, 10);

            // Create mirror list - eventually this should be platform specific!
            // We do this as a List<Uri> so we can add more dynamically on user input... if necessary.
            mirrorList = CrossPlatformOperations.GenerateMirrorList();

            // Create mirror list
            // We do this as a list<listItem> for 1) make this dynamic and 2) make ETO happy
            mirrorDescriptionList = new List <ListItem>();
            // Add each entry dynamically instead of harcoding it to two. If we have neither a github or gitlab mirror, we use the mirror itself as text
            foreach (var mirror in mirrorList)
            {
                string text = mirror;
                if (text.Contains("github.com"))
                {
                    text = Text.MirrorGithubText;
                }
                else if (text.Contains("gitlab.com"))
                {
                    text = Text.MirrorGitlabText;
                }
                mirrorDescriptionList.Add(new ListItem()
                {
                    Key = mirror, Text = text
                });
            }
            #endregion

            Icon        = new Icon(1f, am2rIcon);
            Title       = "AM2RLauncher " + VERSION + ": " + splash;
            MinimumSize = new Size(500, 400);
            // TODO: for some reason, this sometimes doesn't work on Linux. Was reported at eto, stays here until its fixed
            ClientSize = new Size(Int32.Parse(CrossPlatformOperations.ReadFromConfig("Width")), Int32.Parse(CrossPlatformOperations.ReadFromConfig("Height")));
            if (ClientSize.Width < 500)
            {
                ClientSize = new Size(500, ClientSize.Height);
            }
            if (ClientSize.Height < 400)
            {
                ClientSize = new Size(ClientSize.Width, 400);
            }
            log.Info("Start the launcher with Size: " + ClientSize.Width + ", " + ClientSize.Height);
            if (Boolean.Parse(CrossPlatformOperations.ReadFromConfig("IsMaximized")))
            {
                Maximize();
            }

            drawable = new Drawable {
                BackgroundColor = colBGNoAlpha
            };

            // Drawable paint event
            drawable.Paint += DrawablePaintEvent;
            // Some systems don't call the paintEvent by default and only do so after actual resizing
            if (OS.IsMac)
            {
                LoadComplete += (sender, e) => { Size = new Size(Size.Width + 1, Size.Height); Size = new Size(Size.Width - 1, Size.Height); }
            }
            ;

            #region MAIN WINDOW

            // Center buttons/interface panel
            var centerInterface = new DynamicLayout();

            // PLAY button
            playButton = new ColorButton
            {
                ToolTip = "",
                BackgroundColorHover = colBGHover,
                Height             = 40,
                Width              = 250,
                TextColor          = colGreen,
                TextColorDisabled  = colInactive,
                BackgroundColor    = colBG,
                FrameColor         = colGreen,
                FrameColorDisabled = colInactive
            };

            UpdateStateMachine();

            SetPlayButtonState(updateState);

            centerInterface.AddRow(playButton);

            // 2px spacer between playButton and apkButton (Windows only)
            if (OS.IsWindows)
            {
                centerInterface.AddRow(new Label {
                    BackgroundColor = colBG, Height = 2
                });
            }

            // APK button
            apkButton = new ColorButton
            {
                Text                 = Text.CreateAPK,
                Height               = 40,
                Width                = 250,
                TextColor            = colGreen,
                BackgroundColor      = colBG,
                FrameColor           = colGreen,
                BackgroundColorHover = colBGHover
            };

            centerInterface.AddRow(apkButton);

            progressBar = new ProgressBar
            {
                Visible = false,
                Height  = 15
            };

            // 4px spacer between APK button and progressBar (Windows only)
            if (OS.IsWindows)
            {
                centerInterface.AddRow(new Label {
                    BackgroundColor = colBG, Height = 4
                });
            }

            centerInterface.AddRow(progressBar);

            progressLabel = new Label
            {
                BackgroundColor = colBG,
                Height          = 15,
                Text            = "",
                TextColor       = colGreen,
                Visible         = false
            };

            centerInterface.AddRow(progressLabel);

            // 3px spacer between progressBar and profile label (Windows only)
            if (OS.IsWindows)
            {
                centerInterface.AddRow(new Label {
                    BackgroundColor = colBG, Height = 3
                });
            }

            profileLabel = new Label
            {
                BackgroundColor = colBG,
                Height          = 15,
                Text            = Text.CurrentProfile,
                TextColor       = colGreen
            };

            centerInterface.AddRow(profileLabel);

            // Profiles dropdown

            // Yes, we know this looks horrific on GTK. Sorry.
            // We're not exactly in a position to rewrite the entire DropDown object as a Drawable child, but if you want to, you're more than welcome!
            // Mac gets a default BackgroundColor because it looks waaaaaaay better.
            profileDropDown = new DropDown
            {
                TextColor       = colGreen,
                BackgroundColor = OS.IsWindows ? colBGNoAlpha : new Color()
            };
            // In order to not have conflicting theming, we just always respect the users theme for dropdown on GTK.
            if (OS.IsLinux)
            {
                profileDropDown = new DropDown();
            }

            profileDropDown.Items.AddRange(profileNames);   // It's actually more comfortable if it's outside, because of GTK shenanigans

            centerInterface.AddRow(profileDropDown);

            // Profiles label
            profileAuthorLabel = new Label
            {
                BackgroundColor = colBG,
                Height          = 16,
                Text            = Text.Author + " ",
                TextColor       = colGreen
            };

            centerInterface.AddRow(profileAuthorLabel);

            profileVersionLabel = new Label
            {
                BackgroundColor = colBG,
                Height          = 16,
                Text            = Text.VersionLabel + " ",
                TextColor       = colGreen
            };

            centerInterface.AddRow(profileVersionLabel);

            saveWarningLabel = new Label
            {
                Visible         = false,
                BackgroundColor = colBG,
                Width           = 20,
                Height          = 55,
                Text            = Text.SaveLocationWarning,
                TextColor       = colRed
            };

            centerInterface.AddRow(saveWarningLabel);


            // Social buttons
            Bitmap redditIcon   = new Bitmap(Resources.redditIcon48);
            var    redditButton = new ImageButton {
                ToolTip = Text.RedditToolTip, Image = redditIcon
            };
            redditButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.reddit.com/r/AM2R");

            Bitmap githubIcon   = new Bitmap(Resources.githubIcon48);
            var    githubButton = new ImageButton {
                ToolTip = Text.GithubToolTip, Image = githubIcon
            };
            githubButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.github.com/AM2R-Community-Developers");

            Bitmap youtubeIcon   = new Bitmap(Resources.youtubeIcon48);
            var    youtubeButton = new ImageButton {
                ToolTip = Text.YoutubeToolTip, Image = youtubeIcon
            };
            youtubeButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://www.youtube.com/c/AM2RCommunityUpdates");

            Bitmap discordIcon   = new Bitmap(Resources.discordIcon48);
            var    discordButton = new ImageButton {
                ToolTip = Text.DiscordToolTip, Image = discordIcon
            };
            discordButton.Click += (sender, e) => CrossPlatformOperations.OpenURL("https://discord.gg/nk7UYPbd5u");


            // Social button panel
            var socialPanel = new DynamicLayout();
            socialPanel.BeginVertical();
            socialPanel.AddRow(redditButton);
            socialPanel.AddRow(githubButton);
            socialPanel.AddRow(youtubeButton);
            socialPanel.AddRow(discordButton);
            socialPanel.EndVertical();


            // Version number label
            Label versionLabel = new Label
            {
                Text  = "v" + VERSION + (isThisRunningFromWine ? "-WINE" : ""),
                Width = 48, TextAlignment = TextAlignment.Right, TextColor = colGreen,
                Font  = new Font(SystemFont.Default, 12)
            };

            // Tie everything together
            var mainLayout = new DynamicLayout();

            mainLayout.BeginHorizontal();
            mainLayout.AddColumn(null, socialPanel);

            mainLayout.AddSpace();
            mainLayout.AddColumn(null, centerInterface, null);
            mainLayout.AddSpace();

            // Yes, I'm hardcoding this string. Linux users can english.
            mainLayout.AddColumn(versionLabel, isThisRunningFromWine ? new Label {
                Text = "Unsupported", TextColor = colRed, TextAlignment = TextAlignment.Right
            } : null);

            drawable.Content = mainLayout;

            #endregion

            #region TABS

            #region MAIN PAGE
            // [MAIN PAGE]
            TabPage mainPage = new TabPage
            {
                BackgroundColor = colBGNoAlpha,
                Text            = Text.PlayTab,
                Content         = drawable
            };
            #endregion

            #region CHANGELOG PAGE
            // [CHANGELOG]
            Uri     changelogUri     = new Uri("https://am2r-community-developers.github.io/DistributionCenter/changelog.html");
            WebView changelogWebView = new WebView {
                Url = changelogUri
            };

            if (OS.IsUnix && !isInternetThere)
            {
                changelogWebView = new WebView();
            }

            Label changelogNoConnectionLabel = new Label
            {
                Text      = Text.NoInternetConnection,
                TextColor = colGreen
            };

            TabPage changelogPage = new TabPage
            {
                BackgroundColor = colBGNoAlpha,
                Text            = Text.ChangelogTab,

                Content = new TableLayout
                {
                    Rows =
                    {
                        changelogWebView
                    }
                }
            };

            #endregion

            #region NEWS PAGE

            // [NEWS]
            Uri     newsUri     = new Uri("https://am2r-community-developers.github.io/DistributionCenter/news.html");
            WebView newsWebView = new WebView {
                Url = newsUri
            };

            //TODO: why exactly is this check necessary?
            if (OS.IsUnix && !isInternetThere)
            {
                newsWebView = new WebView();
            }

            Label newsNoConnectionLabel = new Label
            {
                Text      = Text.NoInternetConnection,
                TextColor = colGreen
            };

            TabPage newsPage = new TabPage
            {
                Text            = Text.NewsTab,
                BackgroundColor = colBGNoAlpha,

                Content = new TableLayout
                {
                    Rows =
                    {
                        newsWebView
                    }
                }
            };

            //TODO: this is hack because on linux / mac the other way doesn't work. eto issue?
            if (OS.IsUnix && !isInternetThere)
            {
                changelogPage.Content = new TableLayout
                {
                    Rows =
                    {
                        null,
                        changelogNoConnectionLabel,
                        null
                    }
                };
                newsPage.Content = new TableLayout
                {
                    Rows =
                    {
                        null,
                        newsNoConnectionLabel,
                        null
                    }
                };
            }

            #endregion

            #region SETTINGS PAGE

            // [LAUNCHER SETTINGS]
            DynamicLayout settingsLayout = new DynamicLayout();

            // LanguageLabel
            Label languageLabel = new Label
            {
                Text      = Text.LanguageNotice,
                TextColor = colGreen
            };

            // Language DropDown menu

            List <ListItem> languageList = new List <ListItem>
            {
                Text.SystemLanguage,
                "Deutsch",
                "English",
                "Español",
                "Français",
                "Italiano",
                "Português",
                "Русский",
                "日本語",
                "中文(简体)"
            };

            languageDropDown = new DropDown
            {
                TextColor       = colGreen,
                BackgroundColor = OS.IsWindows ? colBGNoAlpha : new Color()
            };
            if (OS.IsLinux)
            {
                languageDropDown = new DropDown();
            }

            languageDropDown.Items.AddRange(languageList);

            var tmpLanguage = CrossPlatformOperations.ReadFromConfig("Language");
            languageDropDown.SelectedIndex = tmpLanguage == "Default" ? 0 : languageDropDown.Items.IndexOf(languageDropDown.Items.FirstOrDefault(x => x.Text.Equals(tmpLanguage)));

            if (languageDropDown.SelectedIndex == -1)
            {
                log.Info("User has tried to use " + tmpLanguage + " as a Language, but it was not found. Reverting to System Language");
                languageDropDown.SelectedIndex = 0;
            }

            // autoUpdateAM2R checkbox
            autoUpdateAM2RCheck = new CheckBox
            {
                Checked   = Boolean.Parse(CrossPlatformOperations.ReadFromConfig("AutoUpdateAM2R")),
                Text      = Text.AutoUpdateAM2R,
                TextColor = colGreen
            };


            // autoUpdateLauncher checkbox
            autoUpdateLauncherCheck = new CheckBox
            {
                Checked   = Boolean.Parse(CrossPlatformOperations.ReadFromConfig("AutoUpdateLauncher")),
                Text      = Text.AutoUpdateLauncher,
                TextColor = colGreen
            };

            // HQ music, PC
            hqMusicPCCheck = new CheckBox
            {
                Checked   = Boolean.Parse(CrossPlatformOperations.ReadFromConfig("MusicHQPC")),
                Text      = Text.HighQualityPC,
                TextColor = colGreen
            };

            // HQ music, Android
            hqMusicAndroidCheck = new CheckBox
            {
                Checked   = Boolean.Parse(CrossPlatformOperations.ReadFromConfig("MusicHQAndroid")),
                Text      = Text.HighQualityAndroid,
                TextColor = colGreen
            };

            // Create game debug logs
            profileDebugLogCheck = new CheckBox
            {
                Checked   = bool.Parse(CrossPlatformOperations.ReadFromConfig("ProfileDebugLog")),
                Text      = Text.ProfileDebugCheckBox,
                TextColor = colGreen
            };

            // Custom environment variables label
            Label customEnvVarLabel = new Label();
            if (OS.IsLinux)
            {
                customEnvVarLabel = new Label
                {
                    Text      = Text.CustomEnvVarLabel,
                    TextColor = colGreen
                };
            }

            // Custom environment variables textbox
            customEnvVarTextBox = null;
            if (OS.IsLinux)
            {
                customEnvVarTextBox = new TextBox
                {
                    Text            = CrossPlatformOperations.ReadFromConfig("CustomEnvVar"),
                    BackgroundColor = colBGNoAlpha,
                    TextColor       = colGreen
                };
            }

            // Mirror list
            mirrorLabel = new Label
            {
                Text      = Text.DownloadSource,
                TextColor = colGreen
            };

            mirrorDropDown = new DropDown
            {
                TextColor       = colGreen,
                BackgroundColor = OS.IsWindows ? colBGNoAlpha : new Color()
            };
            if (OS.IsLinux)
            {
                mirrorDropDown = new DropDown();
            }

            mirrorDropDown.Items.AddRange(mirrorDescriptionList);   // As above, find a way to get this inside the dropDown definition
            mirrorIndex = (Int32.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex")) < mirrorDropDown.Items.Count) ? Int32.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex"))
                                                                                                                            : 0;
            mirrorDropDown.SelectedIndex = mirrorIndex;

            currentMirror = mirrorList[mirrorDropDown.SelectedIndex];

            // Custom mirror
            customMirrorCheck = new CheckBox
            {
                Checked   = Boolean.Parse(CrossPlatformOperations.ReadFromConfig("CustomMirrorEnabled")),
                Text      = Text.CustomMirrorCheck,
                TextColor = colGreen
            };

            customMirrorTextBox = new TextBox
            {
                Text            = CrossPlatformOperations.ReadFromConfig("CustomMirrorText"),
                BackgroundColor = colBGNoAlpha,
                TextColor       = colGreen
            };

            EnableMirrorControlsAccordingly();

            settingsLayout.BeginHorizontal();
            settingsLayout.AddSpace();
            settingsLayout.AddColumn(null, languageLabel, languageDropDown, autoUpdateAM2RCheck, autoUpdateLauncherCheck, hqMusicPCCheck, hqMusicAndroidCheck, profileDebugLogCheck, customEnvVarLabel, (Control)customEnvVarTextBox ?? new Label(), mirrorLabel, mirrorDropDown, customMirrorCheck, customMirrorTextBox, null);
            settingsLayout.AddSpace();

            TabPage settingsPage = new TabPage
            {
                BackgroundColor = colBGNoAlpha,
                Content         = settingsLayout,
                Text            = Text.LauncherSettingsTab
            };

            #endregion

            #region MODSETTINGS PAGE

            // [MOD SETTINGS]
            DynamicLayout modSettingsLayout = new DynamicLayout();


            addModButton = new ColorButton
            {
                ToolTip              = null,
                Text                 = Text.AddNewMod,
                Font                 = smallButtonFont,
                Height               = 30,
                Width                = 275,
                TextColor            = colGreen,
                BackgroundColor      = colBG,
                FrameColor           = colGreen,
                BackgroundColorHover = colBGHover
            };

            Label modSpacer = new Label
            {
                Height = 14
            };

            settingsProfileLabel = new Label
            {
                Text      = Text.CurrentProfile,
                TextColor = colGreen,
                Width     = 275
            };

            modSettingsProfileDropDown = new DropDown
            {
                TextColor       = colGreen,
                BackgroundColor = OS.IsWindows ? colBGNoAlpha : new Color()
            };

            // In order to not have conflicting theming, we just always respect the users theme for dropdown on GTK.
            if (OS.IsLinux)
            {
                modSettingsProfileDropDown = new DropDown();
            }

            modSettingsProfileDropDown.Items.AddRange(profileNames);   // It's actually more comfortable if it's outside, because of GTK shenanigans

            profileButton = new ColorButton
            {
                ToolTip              = null,
                Text                 = Text.OpenProfileFolder,
                Font                 = smallButtonFont,
                Height               = 30,
                Width                = 275,
                TextColor            = colGreen,
                BackgroundColor      = colBG,
                FrameColor           = colGreen,
                BackgroundColorHover = colBGHover
            };

            saveButton = new ColorButton
            {
                ToolTip              = null,
                Text                 = Text.OpenSaveFolder,
                Font                 = smallButtonFont,
                Height               = 30,
                Width                = 275,
                TextColor            = colGreen,
                BackgroundColor      = colBG,
                FrameColor           = colGreen,
                BackgroundColorHover = colBGHover
            };

            updateModButton = new ColorButton
            {
                ToolTip              = null,
                Text                 = Text.UpdateModButtonText,
                Font                 = smallButtonFont,
                Height               = 30,
                Width                = 275,
                TextColor            = colGreen,
                BackgroundColor      = colBG,
                FrameColor           = colGreen,
                BackgroundColorHover = colBGHover
            };

            deleteModButton = new ColorButton
            {
                ToolTip              = null,
                Text                 = Text.DeleteModButtonText,
                Font                 = smallButtonFont,
                Height               = 30,
                Width                = 275,
                TextColor            = colGreen,
                BackgroundColor      = colBG,
                FrameColor           = colGreen,
                BackgroundColorHover = colBGHover
            };

            profileNotesTextArea = new TextArea
            {
                ReadOnly        = true,
                BackgroundColor = colBGNoAlpha,
                TextColor       = colInactive,
                SpellCheck      = false,
                Width           = 275,
                Height          = 150,
                Text            = Text.ProfileNotes
            };

            modSettingsLayout.BeginHorizontal();
            modSettingsLayout.AddSpace();
            modSettingsLayout.AddColumn(null, addModButton, modSpacer, settingsProfileLabel, modSettingsProfileDropDown, profileButton, saveButton, updateModButton, deleteModButton, profileNotesTextArea, null);
            modSettingsLayout.AddSpace();

            TabPage modSettingsPage = new TabPage
            {
                BackgroundColor = colBGNoAlpha,
                Content         = modSettingsLayout,
                Text            = Text.ModSettingsTab
            };

            #endregion

            #endregion

            Content = new TabControl
            {
                Pages =
                {
                    mainPage,

                    changelogPage,

                    newsPage,

                    settingsPage,

                    modSettingsPage
                }
            };

            #region EVENTS
            log.Info("All UI objects have been initialized, UI has been set up.");
            log.Info("Beginning event linkage...");

            Closing          += MainformClosing;
            showButton.Click += ShowButtonClick;
            profileDropDown.SelectedIndexChanged   += ProfileDropDownSelectedIndexChanged;
            languageDropDown.SelectedIndexChanged  += LanguageDropDownSelectedIndexChanged;
            autoUpdateAM2RCheck.CheckedChanged     += AutoUpdateAM2RCheckChanged;
            autoUpdateLauncherCheck.CheckedChanged += AutoUpdateLauncherCheckChanged;
            hqMusicAndroidCheck.CheckedChanged     += HqMusicAndroidCheckChanged;
            hqMusicPCCheck.CheckedChanged          += HqMusicPCCheckChanged;
            customMirrorCheck.CheckedChanged       += CustomMirrorCheckChanged;
            apkButton.Click                                 += ApkButtonClickEvent;
            apkButton.LoadComplete                          += (sender, e) => UpdateApkState();
            profileDropDown.LoadComplete                    += (sender, e) => UpdateProfileState();
            playButton.Click                                += PlayButtonClickEvent;
            playButton.LoadComplete                         += PlayButtonLoadComplete;
            customMirrorTextBox.LostFocus                   += CustomMirrorTextBoxLostFocus;
            mirrorDropDown.SelectedIndexChanged             += MirrorDropDownSelectedIndexChanged;
            modSettingsLayout.LoadComplete                  += ProfileLayoutLoadComplete;
            addModButton.Click                              += AddModButtonClicked;
            profileButton.Click                             += ProfileDataButtonClickEvent;
            saveButton.Click                                += SaveButtonClickEvent;
            modSettingsProfileDropDown.SelectedIndexChanged += ModSettingsProfileDropDownSelectedIndexChanged;
            deleteModButton.Click                           += DeleteModButtonClicked;
            updateModButton.Click                           += UpdateModButtonClicked;
            profileDebugLogCheck.CheckedChanged             += ProfileDebugLogCheckedChanged;
            if (OS.IsLinux)
            {
                customEnvVarTextBox.LostFocus += CustomEnvVarTextBoxLostFocus;
            }

            //TODO: Retest if these now work on mac
            newsWebView.DocumentLoaded      += (sender, e) => ChangeToEmptyPageOnNoInternet(newsPage, newsNoConnectionLabel);
            changelogWebView.DocumentLoaded += (sender, e) => ChangeToEmptyPageOnNoInternet(changelogPage, changelogNoConnectionLabel);

            log.Info("Events linked successfully.");

            #endregion
        }
Пример #7
0
        public ManualInstallDialog()
        {
            WebView2Loader.CenterDialog(this);
            string Loc(string str) => Application.Instance.Localize(typeof(WebView2Loader), str);

            Title = Loc("Install WebView2 Runtime");

            MinimumSize = new Size(300, 200);

            // controls

            var installButton = new Button {
                Text = Loc("Download && Install Now")
            };

            installButton.Click += OnInstall;

            var downloadButton = new LinkButton {
                Text = Loc("Open the WebView2 download page to install manually")
            };

            downloadButton.Click += OnDownload;

            var cancelButton = new Button {
                Text = Loc("Fallback to IE")
            };

            cancelButton.Click += OnCancel;

            var description = new Label
            {
                TextAlignment = TextAlignment.Center,
                Text          = Loc("This application requires the Microsoft Edge WebView2 Runtime.\nPlease install it to continue.")
            };

            // layout

            var layout = new DynamicLayout {
                Padding = 10, DefaultSpacing = new Size(5, 5)
            };

            layout.AddSpace();
            layout.Add(description);
            layout.AddSpace();

            layout.AddSeparateRow(null, downloadButton);

            Content = layout;

            DefaultButton = installButton;
            PositiveButtons.Add(installButton);
            NegativeButtons.Add(cancelButton);

            Shown += (sender, e) => installButton.Focus();

            timer = new UITimer {
                Interval = 1.0
            };
            timer.Elapsed += timer_Elapsed;
            timer.Start();
        }
Пример #8
0
        public SignupPage(SignupViewModel signupViewModel, ImageService imageService)
        {
            _signupViewModel = signupViewModel;
            _imageService    = imageService;
            DataContext      = _signupViewModel;

            var emailBox = new TextBox();

            emailBox.TextBinding.BindDataContext <SignupViewModel>(m => m.Email);

            var nameBox = new TextBox();

            nameBox.TextBinding.BindDataContext <SignupViewModel>(m => m.Name);

            var passwordBox = new PasswordBox();

            passwordBox.TextBinding.BindDataContext <SignupViewModel>(m => m.Password);

            var retypePassordBox = new PasswordBox();

            retypePassordBox.TextBinding.BindDataContext <SignupViewModel>(m => m.RetypePassword);

            var signupButton = new Button()
            {
                Text = "Sign up"
            };

            signupButton.Command = _signupViewModel.Signup;

            var errorLabel = new Label()
            {
                TextColor = Color.FromArgb(0xFF, 0, 0, 0xFF)
            };

            errorLabel.TextBinding.BindDataContext <SignupViewModel>(m => m.FailureMessage);

            //cancel;
            var backImageView = new ImageView()
            {
                Image = _imageService.Back
            };

            backImageView.MouseDown += (sender, args) =>
            {
                args.Handled = true;
            };
            backImageView.MouseUp += (sender, args) => _signupViewModel.Cancel.Execute(null);
            var cancelLabel = new Label()
            {
                Text = "Cancel"
            };

            cancelLabel.MouseDown += (sender, args) => args.Handled = true;
            cancelLabel.MouseUp   += (sender, args) => _signupViewModel.Cancel.Execute(null);


            var cancelLayout = new StackLayout();

            cancelLayout.Padding     = 10;
            cancelLayout.Orientation = Orientation.Horizontal;
            cancelLayout.Spacing     = 5;
            cancelLayout.Items.Add(backImageView);
            cancelLayout.Items.Add(cancelLabel);

            // cancelLayout.MouseDown += (sender, args) => args.Handled = true;
            // cancelLayout.MouseUp += (sender, args) => _signupViewModel.Cancel.Execute(null);

            //sign in stuff
            var signinLayout = new DynamicLayout();

            signinLayout.BeginHorizontal();
            signinLayout.AddSpace();
            signinLayout.BeginVertical();
            signinLayout.AddSpace();
            signinLayout.Add(errorLabel);
            signinLayout.AddSpace();
            signinLayout.Add(new Label()
            {
                Text = "Email"
            });
            signinLayout.Add(emailBox);
            signinLayout.Add(new Label()
            {
                Text = "Name"
            });
            signinLayout.Add(nameBox);
            signinLayout.Add(new Label()
            {
                Text = "Password"
            });
            signinLayout.Add(passwordBox);
            signinLayout.Add(new Label()
            {
                Text = "Retype Password"
            });
            signinLayout.Add(retypePassordBox);
            signinLayout.AddSpace();
            signinLayout.Add(signupButton);
            signinLayout.AddSpace();
            signinLayout.AddSpace();
            signinLayout.EndVertical();
            signinLayout.AddSpace();
            signinLayout.EndHorizontal();


            var pageLayout = new DynamicLayout();

            pageLayout.BeginVertical();
            pageLayout.Add(cancelLayout);
            pageLayout.Add(signinLayout, false, true);
            pageLayout.BeginVertical();

            Content = pageLayout;
        }
Пример #9
0
        public DragDropSection()
        {
            // drag data object

            showDragOverEvents = new CheckBox {
                Text = "Show DragOver Events"
            };
            var includeImageCheck = new CheckBox {
                Text = "Include Image"
            };

            descriptionTextBox = new TextBox {
                PlaceholderText = "Format", ToolTip = "Add {0} to insert inner text into the description, e.g. 'Move to {0}'"
            };
            innerTextBox = new TextBox {
                PlaceholderText = "Inner", ToolTip = "Highlighted text to insert into description"
            };
            var textBox = new TextBox {
                Text = "Some text"
            };

            allowedEffectDropDown = new EnumDropDown <DragEffects> {
                SelectedValue = DragEffects.All
            };
            dragEnterEffect = new EnumDropDown <DragEffects?> {
                SelectedValue = DragEffects.Copy
            };
            dragOverEffect = new EnumDropDown <DragEffects?> {
                SelectedValue = null
            };
            writeDataCheckBox = new CheckBox {
                Text = "Write data to log"
            };
            useDragImage = new CheckBox {
                Text = "Use custom drag image"
            };
            imageOffset = new PointEntry {
                Value = new Point(80, 80)
            };
            imageOffset.Bind(c => c.Enabled, useDragImage, c => c.Checked);

            var htmlTextArea = new TextArea {
                Height = 24
            };
            var selectFilesButton = new Button {
                Text = "Select Files"
            };

            Uri[] fileUris = null;
            selectFilesButton.Click += (sender, e) =>
            {
                var ofd = new OpenFileDialog();
                ofd.MultiSelect = true;
                ofd.ShowDialog(this);
                fileUris = ofd.Filenames.Select(r => new Uri(r)).ToArray();
                if (fileUris.Length == 0)
                {
                    fileUris = null;
                }
            };

            var urlTextBox = new TextBox();

            DataObject CreateDataObject()
            {
                var data = new DataObject();

                if (!string.IsNullOrEmpty(textBox.Text))
                {
                    data.Text = textBox.Text;
                }
                var uris = new List <Uri>();

                if (fileUris != null)
                {
                    uris.AddRange(fileUris);
                }
                if (Uri.TryCreate(urlTextBox.Text, UriKind.Absolute, out var uri))
                {
                    uris.Add(uri);
                }
                if (uris.Count > 0)
                {
                    data.Uris = uris.ToArray();
                }
                if (!string.IsNullOrEmpty(htmlTextArea.Text))
                {
                    data.Html = htmlTextArea.Text;
                }
                if (includeImageCheck.Checked == true)
                {
                    data.Image = TestIcons.Logo;
                }

                return(data);
            }

            // sources

            var buttonSource = new Button {
                Text = "Source"
            };

            buttonSource.MouseDown += (sender, e) =>
            {
                if (e.Buttons != MouseButtons.None)
                {
                    DoDragDrop(buttonSource, CreateDataObject());
                    e.Handled = true;
                }
            };

            var panelSource = new Panel {
                BackgroundColor = Colors.Red, Size = new Size(50, 50)
            };

            panelSource.MouseMove += (sender, e) =>
            {
                if (e.Buttons != MouseButtons.None)
                {
                    DoDragDrop(panelSource, CreateDataObject());
                    e.Handled = true;
                }
            };

            var treeSource = new TreeGridView {
                Size = new Size(200, 200)
            };

            treeSource.SelectedItemsChanged += (sender, e) => Log.Write(treeSource, $"TreeGridView.SelectedItemsChanged (source) Rows: {string.Join(", ", treeSource.SelectedRows.Select(r => r.ToString()))}");
            treeSource.DataStore             = CreateTreeData();
            SetupTreeColumns(treeSource);
            treeSource.MouseMove += (sender, e) =>
            {
                if (e.Buttons == MouseButtons.Primary && !treeSource.IsEditing)
                {
                    var cell = treeSource.GetCellAt(e.Location);
                    if (cell.Item == null || cell.ColumnIndex == -1)
                    {
                        return;
                    }
                    var data     = CreateDataObject();
                    var selected = treeSource.SelectedItems.OfType <TreeGridItem>().Select(r => (string)r.Values[0]);
                    data.SetString(string.Join(";", selected), "my.tree.data");

                    DoDragDrop(treeSource, data);
                    e.Handled = true;
                }
            };

            var gridSource = new GridView {
            };

            gridSource.SelectedRowsChanged += (sender, e) => Log.Write(gridSource, $"GridView.SelectedItemsChanged (source): {string.Join(", ", gridSource.SelectedRows.Select(r => r.ToString()))}");
            SetupGridColumns(gridSource);
            gridSource.DataStore  = CreateGridData();
            gridSource.MouseMove += (sender, e) =>
            {
                if (e.Buttons == MouseButtons.Primary && !gridSource.IsEditing)
                {
                    var cell = gridSource.GetCellAt(e.Location);
                    if (cell.RowIndex == -1 || cell.ColumnIndex == -1)
                    {
                        return;
                    }
                    var data     = CreateDataObject();
                    var selected = gridSource.SelectedItems.OfType <GridItem>().Select(r => (string)r.Values[0]);
                    data.SetString(string.Join(";", selected), "my.grid.data");

                    DoDragDrop(gridSource, data);
                    e.Handled = true;
                }
            };


            // destinations

            var buttonDestination = new Button {
                Text = "Drop here!", AllowDrop = true
            };

            buttonDestination.DragEnter += (sender, e) => buttonDestination.Text = "Now, drop it!";
            buttonDestination.DragLeave += (sender, e) => buttonDestination.Text = "Drop here!";
            LogEvents(buttonDestination);

            var drawableDest = new Drawable {
                BackgroundColor = Colors.Blue, AllowDrop = true, Size = new Size(50, 50)
            };

            LogEvents(drawableDest);
            drawableDest.DragEnter += (sender, e) =>
            {
                if (e.Effects != DragEffects.None)
                {
                    drawableDest.BackgroundColor = Colors.Green;
                }
            };
            drawableDest.DragLeave += (sender, e) =>
            {
                if (e.Effects != DragEffects.None)
                {
                    drawableDest.BackgroundColor = Colors.Blue;
                }
            };
            drawableDest.DragDrop += (sender, e) =>
            {
                if (e.Effects != DragEffects.None)
                {
                    drawableDest.BackgroundColor = Colors.Blue;
                }
            };

            var dragMode = new RadioButtonList
            {
                Orientation = Orientation.Vertical,
                Items       =
                {
                    new ListItem {
                        Text = "No Restriction", Key = ""
                    },
                    new ListItem {
                        Text = "RestrictToOver", Key = "over"
                    },
                    new ListItem {
                        Text = "RestrictToInsert", Key = "insert"
                    },
                    new ListItem {
                        Text = "RestrictToNode", Key = "node"
                    },
                    new ListItem {
                        Text = "No Node", Key = "none"
                    }
                },
                SelectedIndex = 0
            };
            var treeDest = new TreeGridView {
                AllowDrop = true, Size = new Size(200, 200)
            };
            var treeDestData = CreateTreeData();

            treeDest.DataStore = treeDestData;
            treeDest.DragOver += (sender, e) =>
            {
                var info = treeDest.GetDragInfo(e);
                if (info == null)
                {
                    return;                     // not supported
                }
                switch (dragMode.SelectedKey)
                {
                case "over":
                    info.RestrictToOver();
                    break;

                case "insert":
                    info.RestrictToInsert();
                    break;

                case "node":
                    info.RestrictToNode(treeDestData[2]);
                    break;

                case "none":
                    info.Item = info.Parent = null;
                    break;
                }
            };
            SetupTreeColumns(treeDest);
            LogEvents(treeDest);

            var gridDest = new GridView {
                AllowDrop = true
            };
            var gridDestData = CreateGridData();

            gridDest.DataStore = gridDestData;
            gridDest.DragOver += (sender, e) =>
            {
                var info = gridDest.GetDragInfo(e);
                if (info == null)
                {
                    return;                     // not supported
                }
                switch (dragMode.SelectedKey)
                {
                case "over":
                    info.RestrictToOver();
                    break;

                case "insert":
                    info.RestrictToInsert();
                    break;

                case "node":
                    info.Index    = 2;
                    info.Position = GridDragPosition.Over;
                    break;

                case "none":
                    info.Index = -1;
                    break;
                }
            };
            SetupGridColumns(gridDest);
            LogEvents(gridDest);



            // layout

            var layout = new DynamicLayout {
                Padding = 10, DefaultSpacing = new Size(4, 4)
            };

            layout.BeginHorizontal();

            layout.BeginScrollable(BorderType.None);
            layout.BeginCentered();

            layout.AddSeparateRow(showDragOverEvents);
            layout.AddSeparateRow("AllowedEffect", allowedEffectDropDown, null);
            layout.BeginVertical();
            layout.AddRow("DropDescription", descriptionTextBox);
            layout.AddRow(new Panel(), innerTextBox);
            layout.EndVertical();
            layout.AddSeparateRow("DragEnter Effect", dragEnterEffect, null);
            layout.AddSeparateRow("DragOver Effect", dragOverEffect, null);
            layout.AddSeparateRow(useDragImage);
            layout.AddSeparateRow("Image offset:", imageOffset);
            layout.AddSeparateRow(writeDataCheckBox);

            layout.BeginGroup("DataObject", 10);
            layout.AddRow("Text", textBox);
            layout.AddRow("Html", htmlTextArea);
            layout.AddRow("Url", urlTextBox);
            layout.BeginHorizontal();
            layout.AddSpace();
            layout.BeginVertical();
            layout.AddCentered(includeImageCheck);
            layout.AddCentered(selectFilesButton);
            layout.EndVertical();
            layout.EndGroup();
            layout.Add(dragMode);
            layout.AddSpace();

            layout.EndCentered();
            layout.EndScrollable();

            layout.BeginVertical(xscale: true);
            layout.AddRange("Drag sources:", buttonSource, panelSource);
            layout.Add(treeSource, yscale: true);
            layout.Add(gridSource, yscale: true);
            layout.EndVertical();

            layout.BeginVertical(xscale: true);
            layout.AddRange("Drag destinations:", buttonDestination, drawableDest);
            layout.Add(treeDest, yscale: true);
            layout.Add(gridDest, yscale: true);
            layout.EndVertical();

            layout.EndHorizontal();

            Content = layout;
        }
Пример #10
0
        public LoginView(LoginViewModel loginViewModel, ImageService imageService)
        {
            _loginViewModel = loginViewModel;
            DataContext     = loginViewModel;

            var addressBox = new TextBox();

            addressBox.TextBinding.BindDataContext <LoginViewModel>(m => m.ServerAddress);

            var emailBox = new TextBox();

            emailBox.TextBinding.BindDataContext <LoginViewModel>(m => m.Email);

            var passwordBox = new PasswordBox();

            passwordBox.TextBinding.BindDataContext <LoginViewModel>(m => m.Password);

            var loginButton = new Button()
            {
                Text = "Login"
            };

            loginButton.Command = loginViewModel.Login;

            var signupButton = new LinkButton()
            {
                Text = "Sign up"
            };

            signupButton.Command = loginViewModel.Signup;

            var errorLabel = new Label()
            {
            };

            errorLabel.TextBinding.BindDataContext <LoginViewModel>(m => m.FailureMessage);

            var layout = new DynamicLayout();

            layout.BeginHorizontal();
            layout.AddSpace();
            layout.BeginVertical();
            layout.AddSpace();
            layout.Add(imageService.Ropu);
            layout.Add(errorLabel);
            layout.Add(new Label()
            {
                Text = "Server"
            });
            layout.Add(addressBox);
            layout.Add(new Label()
            {
                Text = "Email"
            });
            layout.Add(emailBox);
            layout.Add(new Label()
            {
                Text = "Password"
            });
            layout.Add(passwordBox);
            layout.AddSpace();
            layout.Add(loginButton);
            layout.AddSpace();
            layout.Add(signupButton);
            layout.AddSpace();
            layout.EndVertical();
            layout.AddSpace();
            layout.EndHorizontal();
            Content = layout;

            this.Shown += async(sender, args) =>
            {
                await _loginViewModel.Initialize();
            };
        }
Пример #11
0
        public void WidthOfContentShouldAffectScrollableRegionWhenLabelsWrap()
        {
            void CreateAndAddEmptySpace(DynamicLayout container)
            {
                container.AddRow(new TableRow(new Label {
                    Text = "", Height = 10
                }));
            }

            Label CreateAndAddLabelRow(DynamicLayout container, string text)
            {
                var label = new Label {
                    Text = text, Font = SystemFonts.Bold(null, FontDecoration.None), Wrap = WrapMode.Word
                };

                container.AddRow(new TableRow(label));
                CreateAndAddEmptySpace(container);
                return(label);
            }

            void CreateAndAddDescriptionRow(DynamicLayout container, string text)
            {
                container.AddRow(new TableRow(new Label {
                    Text = text, Wrap = WrapMode.Word, Font = SystemFonts.Label(SystemFonts.Default().Size - 2.0f)
                }));
                CreateAndAddEmptySpace(container);
            }

            DropDown CreateAndAddDropDownRow(DynamicLayout container, string text, List <string> options, int position, Action <DropDown, EventArgs> command)
            {
                var txt = new Label {
                    Text = text, VerticalAlignment = VerticalAlignment.Center
                };
                var drop = new DropDown {
                    Width = 200
                };

                foreach (var item in options)
                {
                    drop.Items.Add(item);
                }

                drop.SelectedIndex = position;

                if (command != null)
                {
                    drop.SelectedIndexChanged += (sender, e) => command.Invoke((DropDown)sender, e);
                }

                var tr = new TableRow(txt, null, drop);

                container.AddRow(tr);
                CreateAndAddEmptySpace(container);

                return(drop);
            }

            ManualForm(
                "You should be able to scroll down to the 'BOTTOM' label, and long paragraphs should be wrapped.",
                form =>
            {
                var container = new DynamicLayout();

                container.BeginVertical();

                container.Padding = 0;

                CreateAndAddLabelRow(container, "Header 1");

                CreateAndAddDescriptionRow(container, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras suscipit malesuada ex, ut iaculis nisl. Donec eros est, rutrum ac molestie vitae, euismod mollis enim. Integer eget turpis sit amet nulla laoreet dapibus. Curabitur sit amet nulla sed erat rutrum gravida. Donec vel erat ex. Aenean sit amet massa at ante suscipit fringilla. Sed bibendum tempor sem et congue. Maecenas diam neque, dictum id ligula eget, vulputate ornare massa. Integer lobortis dolor risus, a eleifend ante feugiat ac. Aenean egestas bibendum fermentum. In ac elit vitae augue convallis blandit eu eget ligula.");

                CreateAndAddDropDownRow(container, "Some Drop Down", new List <string>()
                {
                    "item1", "item2"
                }, 0, (sender, e) => { });

                CreateAndAddLabelRow(container, "Header 2");

                CreateAndAddLabelRow(container, "Header 3");

                CreateAndAddDescriptionRow(container, "Vestibulum dignissim in ipsum sed condimentum. Etiam vitae ullamcorper dui. Pellentesque non imperdiet lacus. Maecenas ullamcorper sapien enim, sit amet commodo mauris scelerisque non. Nullam facilisis ipsum laoreet, gravida eros in, egestas odio. Morbi id ex vitae dui viverra ornare et vel metus. Phasellus lobortis finibus ex. Nulla tristique malesuada eros eget maximus. Donec a nisi facilisis sapien porta mattis. Curabitur sodales, magna sit amet aliquet commodo, eros quam congue felis, sit amet dictum orci neque nec risus. Aenean id auctor tellus. Etiam ac imperdiet nunc. Aliquam suscipit quam nec velit sollicitudin, posuere tempor ante vehicula. Suspendisse vitae massa tempus, maximus urna vitae, bibendum arcu.");

                CreateAndAddDropDownRow(container, "Other Drop Down", new List <string>(), -1, (sender, e) => { });

                container.AddRow(new Label {
                    Text = "BOTTOM", Font = SystemFonts.Bold()
                });

                container.AddSpace();

                container.EndVertical();

                container.Width = 300;                        // - container.Padding.Value.Left * 2 - container.Padding.Value.Right * 2;

                var tabs = new List <TabPage>
                {
                    new TabPage(new Scrollable {
                        Content = container, Border = BorderType.None
                    })
                    {
                        Text = "Tab 1"
                    },
                    new TabPage(new Panel())
                    {
                        Text = "Tab 2"
                    }
                };

                var tabctrl = new TabControl();
                foreach (var tab in tabs)
                {
                    tabctrl.Pages.Add(tab);
                }

                form.ClientSize = new Size(500, 300);

                return(tabctrl);
            });
        }
Пример #12
0
        public DragDropSection()
        {
            // drag data object

            showDragOverEvents = new CheckBox {
                Text = "Show DragOver Events"
            };
            var includeImageCheck = new CheckBox {
                Text = "Include Image"
            };
            var textBox = new TextBox {
                Text = "Some text"
            };
            var allowedEffectDropDown = new EnumDropDown <DragEffects> {
                SelectedValue = DragEffects.All
            };

            dragOverEffect = new EnumDropDown <DragEffects> {
                SelectedValue = DragEffects.Copy
            };

            var htmlTextArea      = new TextArea();
            var selectFilesButton = new Button {
                Text = "Select Files"
            };

            Uri[] uris = null;
            selectFilesButton.Click += (sender, e) =>
            {
                var ofd = new OpenFileDialog();
                ofd.MultiSelect = true;
                ofd.ShowDialog(this);
                uris = ofd.Filenames.Select(r => new Uri(r)).ToArray();
                if (uris.Length == 0)
                {
                    uris = null;
                }
            };

            Func <DataObject> createDataObject = () =>
            {
                var data = new DataObject();
                if (!string.IsNullOrEmpty(textBox.Text))
                {
                    data.Text = textBox.Text;
                }
                if (uris != null)
                {
                    data.Uris = uris;
                }
                if (!string.IsNullOrEmpty(htmlTextArea.Text))
                {
                    data.Html = htmlTextArea.Text;
                }
                if (includeImageCheck.Checked == true)
                {
                    data.Image = TestIcons.Logo;
                }
                return(data);
            };

            // sources

            var buttonSource = new Button {
                Text = "Source"
            };

            buttonSource.MouseDown += (sender, e) =>
            {
                buttonSource.DoDragDrop(createDataObject(), allowedEffectDropDown.SelectedValue);
                e.Handled = true;
            };

            var panelSource = new Panel {
                BackgroundColor = Colors.Red, Size = new Size(50, 50)
            };

            panelSource.MouseDown += (sender, e) =>
            {
                panelSource.DoDragDrop(createDataObject(), allowedEffectDropDown.SelectedValue);
                e.Handled = true;
            };

            var treeSource = new TreeGridView {
                Size = new Size(200, 200)
            };

            treeSource.DataStore = CreateTreeData();
            SetupTreeColumns(treeSource);
            treeSource.MouseMove += (sender, e) =>
            {
                if (e.Buttons == MouseButtons.Primary)
                {
                    var cell = treeSource.GetCellAt(e.Location);
                    if (cell.Item == null || cell.ColumnIndex == -1)
                    {
                        return;
                    }
                    var data     = createDataObject();
                    var selected = treeSource.SelectedItems.OfType <TreeGridItem>().Select(r => (string)r.Values[0]);
                    data.SetString(string.Join(";", selected), "my-tree-data");

                    treeSource.DoDragDrop(data, allowedEffectDropDown.SelectedValue);
                    e.Handled = true;
                }
            };

            var gridSource = new GridView {
            };

            SetupGridColumns(gridSource);
            gridSource.DataStore  = CreateGridData();
            gridSource.MouseMove += (sender, e) =>
            {
                if (e.Buttons == MouseButtons.Primary)
                {
                    var data     = createDataObject();
                    var selected = gridSource.SelectedItems.OfType <GridItem>().Select(r => (string)r.Values[0]);
                    data.SetString(string.Join(";", selected), "my-grid-data");

                    gridSource.DoDragDrop(data, allowedEffectDropDown.SelectedValue);
                    e.Handled = true;
                }
            };


            // destinations

            var buttonDestination = new Button {
                Text = "Drop here!", AllowDrop = true
            };

            buttonDestination.DragEnter += (sender, e) => buttonDestination.Text = "Now, drop it!";
            buttonDestination.DragLeave += (sender, e) => buttonDestination.Text = "Drop here!";
            LogEvents(buttonDestination);

            var drawableDest = new Drawable {
                BackgroundColor = Colors.Blue, AllowDrop = true, Size = new Size(50, 50)
            };

            LogEvents(drawableDest);
            drawableDest.DragEnter += (sender, e) =>
            {
                if (e.Effects != DragEffects.None)
                {
                    drawableDest.BackgroundColor = Colors.Green;
                }
            };
            drawableDest.DragLeave += (sender, e) =>
            {
                if (e.Effects != DragEffects.None)
                {
                    drawableDest.BackgroundColor = Colors.Blue;
                }
            };
            drawableDest.DragDrop += (sender, e) =>
            {
                if (e.Effects != DragEffects.None)
                {
                    drawableDest.BackgroundColor = Colors.Blue;
                }
            };

            var dragMode = new RadioButtonList
            {
                Orientation = Orientation.Vertical,
                Items       =
                {
                    new ListItem {
                        Text = "No Restriction", Key = ""
                    },
                    new ListItem {
                        Text = "RestrictToOver", Key = "over"
                    },
                    new ListItem {
                        Text = "RestrictToInsert", Key = "insert"
                    },
                    new ListItem {
                        Text = "RestrictToNode", Key = "node"
                    },
                    new ListItem {
                        Text = "No Node", Key = "none"
                    }
                },
                SelectedIndex = 0
            };
            var treeDest = new TreeGridView {
                AllowDrop = true, Size = new Size(200, 200)
            };
            var treeDestData = CreateTreeData();

            treeDest.DataStore = treeDestData;
            treeDest.DragOver += (sender, e) =>
            {
                var info = treeDest.GetDragInfo(e);
                if (info == null)
                {
                    return;                     // not supported
                }
                switch (dragMode.SelectedKey)
                {
                case "over":
                    info.RestrictToOver();
                    break;

                case "insert":
                    info.RestrictToInsert();
                    break;

                case "node":
                    info.RestrictToNode(treeDestData[2]);
                    break;

                case "none":
                    info.Item = info.Parent = null;
                    break;
                }
            };
            SetupTreeColumns(treeDest);
            LogEvents(treeDest);

            var gridDest = new GridView {
                AllowDrop = true
            };
            var gridDestData = CreateGridData();

            gridDest.DataStore = gridDestData;
            gridDest.DragOver += (sender, e) =>
            {
                var info = gridDest.GetDragInfo(e);
                if (info == null)
                {
                    return;                     // not supported
                }
                switch (dragMode.SelectedKey)
                {
                case "over":
                    info.RestrictToOver();
                    break;

                case "insert":
                    info.RestrictToInsert();
                    break;

                case "node":
                    info.Index    = 2;
                    info.Position = GridDragPosition.Over;
                    break;

                case "none":
                    info.Index = -1;
                    break;
                }
            };
            SetupGridColumns(gridDest);
            LogEvents(gridDest);



            // layout

            var layout = new DynamicLayout {
                Padding = 10, DefaultSpacing = new Size(4, 4)
            };

            layout.BeginHorizontal();

            layout.BeginCentered();

            layout.AddSeparateRow(showDragOverEvents);
            layout.AddSeparateRow("AllowedEffect", allowedEffectDropDown, null);
            layout.AddSeparateRow("DragOver Effect", dragOverEffect, null);

            layout.BeginGroup("DataObject", 10);
            layout.AddRow("Text", textBox);
            layout.AddRow("Html", htmlTextArea);
            layout.BeginHorizontal();
            layout.AddSpace();
            layout.BeginVertical();
            layout.AddCentered(includeImageCheck);
            layout.AddCentered(selectFilesButton);
            layout.EndVertical();
            layout.EndGroup();
            layout.Add(dragMode);
            layout.AddSpace();

            layout.EndCentered();

            layout.BeginVertical(xscale: true);
            layout.AddRange("Drag sources:", buttonSource, panelSource);
            layout.Add(treeSource, yscale: true);
            layout.Add(gridSource, yscale: true);
            layout.EndVertical();

            layout.BeginVertical(xscale: true);
            layout.AddRange("Drag destinations:", buttonDestination, drawableDest);
            layout.Add(treeDest, yscale: true);
            layout.Add(gridDest, yscale: true);
            layout.EndVertical();

            layout.EndHorizontal();

            Content = layout;
        }
        public LevelPropertiesWindow(IEditor <CampaignFile> editor, CampaignLevel level)
        {
            this.editor = editor;

            Data = level.CloneObject()
                   ?? new CampaignLevel()
            {
                Guid = Guid.NewGuid().ToString()
            };

            Title   = $"{(Equals(level, null) ? "Add" : "Edit")} level";
            Size    = MinimumSize = new Size(600, 400);
            Padding = new Padding(8);

            Resizable = true;

            Content = new StackLayout()
            {
                Style   = "vertical",
                Spacing = 8,

                Items =
                {
                    new StackLayoutItem(tabs = new ExtendedTabControl(),           true),
                    new StackLayoutItem(new StackLayout()
                    {
                        Style   = "horizontal",
                        Spacing =                                  8,
                        Padding = new Padding(0,                          8,0, 0),

                        Items                =
                        {
                            null,
                            (DefaultButton   = new Button(OnConfirm)
                            {
                                Text         = "OK",
                                Image        = Resources.GetIcon("CheckGreen.ico",     16)
                            }),
                            (AbortButton     = new Button(OnCancel)
                            {
                                Text         = "Cancel",
                                Image        = Resources.GetIcon("CloseRed.ico", 16)
                            })
                        }
                    }, false)
                }
            };

            #region General Tab
            tabs.AddPage("General", generalProperties = new DynamicLayout());

            generalProperties.BeginScrollable(BorderType.None);
            generalProperties.BeginVertical();

            generalProperties.AddRow("Unique ID", propLevelGuid  = new GuidLabel());
            generalProperties.AddRow("Level file", propLevelFile = new ResourceSelector(editor, ResourceType.Level));
            generalProperties.AddRow("Level name", propLevelName = new TextBox());

            generalProperties.EndVertical();
            generalProperties.AddSpace();
            generalProperties.EndScrollable();
            #endregion

            //tabs.AddPage("Gameplay", gameplayProperties = new DynamicLayout());

            #region Loading Screen Tab
            tabs.AddPage("Loading screen", loadingScreenProperties = new DynamicLayout());

            loadingScreenProperties.BeginScrollable(BorderType.None);
            loadingScreenProperties.BeginVertical();

            loadingScreenProperties.AddRow("Background image", propLoadingBackground = new ResourceSelector(editor, ResourceType.Texture));

            loadingScreenProperties.AddRow(string.Empty, new StackLayout()
            {
                Style = "no-padding horizontal",

                Items =
                {
                    (propLoadingBackgroundPreview = new StretchedImageBox()
                    {
                        Width                     =160,
                        Height                    = 90
                    }),
                    null
                }
            });

            loadingScreenProperties.AddRow("Overwrite loading text", propLoadingOverwriteText = new BooleanSelector());
            loadingScreenProperties.AddRow("Loading text", propLoadingText = new TextBox());
            loadingScreenProperties.AddRow("Progress indicator icon", propLoadingBackgroundIcon = new ResourceSelector(editor, ResourceType.Texture));
            loadingScreenProperties.AddRow(string.Empty, new StackLayout()
            {
                Style = "no-padding horizontal",

                Items =
                {
                    (propLoadingBackgroundIconPreview = new StretchedImageBox()
                    {
                        Width                         =64,
                        Height                        = 64
                    }),
                    null
                }
            });

            loadingScreenProperties.EndVertical();
            loadingScreenProperties.AddSpace();
            loadingScreenProperties.EndScrollable();
            #endregion

            #region Intro Sequence Tab
            tabs.AddPage("Intro sequence", introSequenceProperties = new DynamicLayout());

            introSequenceProperties.BeginScrollable(BorderType.None);
            introSequenceProperties.BeginVertical();

            // Set whether or not to show the intro, the intro style and text values

            introSequenceProperties.AddRow("Intro type", propIntroType   = new EnumDropDown <LevelTransitionType>());
            introSequenceProperties.AddRow("First line", propIntroLine1  = new TextBox());
            introSequenceProperties.AddRow("Second line", propIntroLine2 = new TextBox());

            introSequenceProperties.EndVertical();
            introSequenceProperties.AddSpace();
            introSequenceProperties.EndScrollable();
            #endregion

            #region Event Subscribing
            propLoadingOverwriteText.ValueChanged      += OnOverwriteLoadingTextChanged;
            propIntroType.SelectedValueChanged         += OnTransitionTypeChanged;
            propLoadingBackground.ResourceSelected     += OnBackgroundSelected;
            propLoadingBackgroundIcon.ResourceSelected += OnLoadingIconSelected;
            #endregion

            LoadData(Data);
        }