예제 #1
0
        public static void InitializeComponents(this PageControl pageControl, GameWindow window, AtomicReference <NextController> mainMenuResult, AtomicReference <Func <GameSettings> > gameSettingsProvider)
        {
            var factory = new NavigationButtonsFactory
            {
                ExpectedItems  = 3,
                FontSize       = 24,
                IdleColor      = backgroundColor,
                HighlightColor = highlightColor,
                TextColor      = textColor,
                WindowHeight   = window.Size.Y,
                Width          = navigationPanelLenght
            };

            var settingsFactory = new GameSettingsService
            {
                BackgroundColor = backgroundColor,
                ComponentColor  = componentColor,
                HighlightColor  = highlightColor,
                LeftMargin      = menuOptionsLeftMargin,
                SizeFactor      = frameSizeFactor,
                WindowSize      = window.Size,
                TextColor       = textColor,
                ComponentHeight = 40,
                ComponentMargin = 6,
                Font            = FontExtensions.Font,
                FontSize        = 24,
                TextPosition    = new Vector2f(8, 4)
            };

            var mainView      = new ComponentContainer();
            var newGameView   = new ComponentContainer();
            var optionsView   = new ComponentContainer();
            var settingsFrame = settingsFactory.NewFrame();

            pageControl.Bus.Subscribe(window);

            mainView.Add(factory.New(0, "NEW GAME", (s, e) => pageControl.Set(newGameView)));
            mainView.Add(factory.New(1, "OPTIONS", (s, e) => pageControl.Set(optionsView)));
            mainView.Add(factory.New(2, "EXIT", (s, e) => mainMenuResult.Value = NextController.Exit));

            newGameView.Add(factory.New(0, "START", (s, e) => mainMenuResult.Value = NextController.Game));
            newGameView.Add(factory.New(2, "BACK", (s, e) => pageControl.Set(mainView)));
            newGameView.Add(settingsFrame.InitializeGameSettingsFrame(settingsFactory, gameSettingsProvider));

            optionsView.Add(factory.New(2, "BACK", (s, e) => pageControl.Set(mainView)));

            pageControl.Add(mainView);
            pageControl.Add(newGameView);
            pageControl.Add(optionsView);
            pageControl.Set(mainView);
        }
예제 #2
0
        public static void InitializeComponents(this PageControl pageControl, GameWindow window, ResourceManager resources, TurnCycle turnCycle)
        {
            var tileset       = resources.Get <GameTilesets>().Gui;
            var mainContainer = new ComponentContainer();
            var topFrame      = new Frame
            {
                Shape = new RectangleShape
                {
                    FillColor = Color.White,
                    Size      = new Vector2f(window.Size.X, 100)
                },
                Position = new Vector2f()
            };

            mainContainer.Add(topFrame);
            pageControl.Add(mainContainer);
            pageControl.Set(mainContainer);

            var resourcesPicturesStartPosition = new Vector2f(300, 25);

            topFrame.Components.AddResourcePicture(ResourceType.Food, tileset.Food, turnCycle, resourcesPicturesStartPosition, 0);
            topFrame.Components.AddResourcePicture(ResourceType.Wood, tileset.Wood, turnCycle, resourcesPicturesStartPosition, 1);
            topFrame.Components.AddResourcePicture(ResourceType.Iron, tileset.Iron, turnCycle, resourcesPicturesStartPosition, 2);
            topFrame.Components.AddResourcePicture(ResourceType.Gems, tileset.Gems, turnCycle, resourcesPicturesStartPosition, 3);

            var bottomFrameSize     = new Vector2f(400, 40);
            var bottomFramePosition = new Vector2f(window.Size.X - bottomFrameSize.X, window.Size.Y - bottomFrameSize.Y);
            var bottomFrame         = new Frame
            {
                Shape = new RectangleShape
                {
                    FillColor = Color.White,
                    Size      = bottomFrameSize
                },
                Position = bottomFramePosition
            };

            mainContainer.Add(bottomFrame);

            var activePlayerLabel = new ActivePlayerLabel(new Vector2f(6, 0), turnCycle);
            var currentRoundLabel = new CurrentRoundLabel(new Vector2f(bottomFrameSize.X - 64, 6), turnCycle);

            bottomFrame.Components.Add(activePlayerLabel);
            bottomFrame.Components.Add(currentRoundLabel);
        }
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            _aboutButton         = new Button();
            _taskCreatorButton   = new Button();
            _settingsButton      = new Button();
            _additionalsButton   = new Button();
            _downloadControl     = new DownloadControl(this);
            _logRichTextBox      = new LoggerRichTextBox();
            _queueRequestListBox = new AdvancedListBox();
            _helpToolTip         = new HelpToolTip();
            _pageControl         = new PageControl <Control>();
            SuspendLayout();

            _pageControl.Size = new Size(LayoutGUI.DownloadControlSizeWidth,
                                         LayoutGUI.MainFormSizeHeight - LayoutGUI.ButtonSizeHeight - LayoutGUI.DistanceBetweenControls);
            _pageControl.Location  = new Point(0, LayoutGUI.ButtonSizeHeight + 1);
            _pageControl.Font      = new Font(Font.Name, Font.Size + 2);
            _pageControl.Position  = TabAlignment.Bottom;
            _pageControl.Alignment = ContentAlignment.BottomCenter;
            _pageControl.NextPageButton.Enabled     = false;
            _pageControl.PreviousPageButton.Enabled = false;
            _pageControl.PageValueLabel.Enabled     = false;
            _pageControl.NextPageButton.Visible     = false;
            _pageControl.PreviousPageButton.Visible = false;
            _pageControl.PageValueLabel.Visible     = false;
            _pageControl.Add(_downloadControl);
            //
            //DownloadControl
            //
            _downloadControl.Location        = new Point(0, 0);
            _downloadControl.Size            = new Size(_pageControl.Size.Width, _pageControl.Size.Height - _pageControl.ButtonHeight);
            _downloadControl.VisibleChanged += (sender, args) => UpdateText();
            //
            // taskCreatorButton
            //
            _taskCreatorButton.Location = new Point(0, 0);
            _taskCreatorButton.Size     = new Size(LayoutGUI.ButtonSizeWidth, LayoutGUI.ButtonSizeHeight);
            _taskCreatorButton.Image    = new Bitmap(Images.Lineal.Plus, new Size(LayoutGUI.ButtonSizeWidth / 2, LayoutGUI.ButtonSizeHeight / 2));
            _taskCreatorButton.UseVisualStyleBackColor = true;
            _taskCreatorButton.Enabled = Globals.APIKey.IsValid;
            _taskCreatorButton.Click  += (sender, args) =>
            {
                if (_downloadControl.CurrentTasks < DownloadControl.MaximumTasks &&
                    (ModifierKeys == Keys.Control || ModifierKeys == (Keys.Shift | Keys.Control)))
                {
                    _downloadControl.AddDownloadTaskControl();
                    return;
                }

                OpenTaskCreatorForm(ModifierKeys.HasFlag(Keys.Shift));
            };
            Globals.APIKey.Changed += () => { _taskCreatorButton.Enabled = Globals.APIKey.IsValid; };
            Globals.APIKey.Changed += () =>
            {
                if (Globals.APIKey.IsValid && _downloadControl.CurrentTasks <= 0)
                {
                    _downloadControl.AddDownloadTaskControl();
                }
            };
            //
            // settingsButton
            //
            _settingsButton.Size     = new Size(LayoutGUI.ButtonSizeWidth, LayoutGUI.ButtonSizeHeight);
            _settingsButton.Location = new Point(LayoutGUI.MainFormSizeWidth - _settingsButton.Size.Width, 0);
            _settingsButton.Image    = new Bitmap(Images.Line.Settings, new Size(LayoutGUI.ButtonSizeWidth / 2, LayoutGUI.ButtonSizeHeight / 2));
            _settingsButton.UseVisualStyleBackColor = true;
            _settingsButton.Click += (sender, args) => { _settingsForm.ShowDialog(); };
            //
            // additionalsButton
            //
            _additionalsButton.Size     = new Size(LayoutGUI.ButtonSizeWidth, LayoutGUI.ButtonSizeHeight);
            _additionalsButton.Location = new Point(LayoutGUI.MainFormSizeWidth - _settingsButton.Size.Width - _additionalsButton.Size.Width, 0);
            _additionalsButton.Image    = new Bitmap(Images.Line.Tech, new Size(LayoutGUI.ButtonSizeWidth / 2, LayoutGUI.ButtonSizeHeight / 2));
            _additionalsButton.UseVisualStyleBackColor = true;
            _additionalsButton.Click += (sender, args) => { _additionalsForm.ShowDialog(); };
            //
            // aboutButton
            //
            _aboutButton.Size     = new Size(LayoutGUI.ButtonSizeWidth, LayoutGUI.ButtonSizeHeight);
            _aboutButton.Location =
                new Point(LayoutGUI.MainFormSizeWidth - _settingsButton.Size.Width - _additionalsButton.Size.Width - _aboutButton.Size.Width, 0);
            _aboutButton.UseVisualStyleBackColor = true;
            _aboutButton.Image  = new Bitmap(Images.Basic.Question, new Size(LayoutGUI.ButtonSizeWidth / 2, LayoutGUI.ButtonSizeHeight / 2));
            _aboutButton.Click += (sender, args) =>
            {
                new MessageForm(ModifierKeys == Keys.Shift ? Globals.Localization.FirstKnowText : Globals.Localization.AboutProgramText,
                                Globals.Localization.AboutProgramTitle, Images.Basic.Information, Resource.icon.ToBitmap(), MessageBoxButtons.OK,
                                new[] { Globals.Localization.Close }).ShowDialog();
            };

            _logRichTextBox.Size     = new Size(LayoutGUI.MainFormLoggerRichTextBoxSizeWidth - 2, LayoutGUI.MainFormLoggerRichTextBoxSizeHeight);
            _logRichTextBox.Location = new Point(LayoutGUI.MainFormSizeWidth - _logRichTextBox.Size.Width - LayoutGUI.QueueRequestListBoxWidth,
                                                 LayoutGUI.MainFormSizeHeight - _logRichTextBox.Size.Height - _pageControl.ButtonHeight - LayoutGUI.DistanceBetweenControls + 1);
            _logRichTextBox.BorderStyle = BorderStyle.None;
            _logRichTextBox.ScrollBars  = RichTextBoxScrollBars.None;
            _logRichTextBox.Reversed    = false;
            _logRichTextBox.BorderStyle = BorderStyle.Fixed3D;
            Globals.Logger.Logged      += _logRichTextBox.Log;

            _queueRequestListBox.Size             = new Size(LayoutGUI.QueueRequestListBoxWidth, _logRichTextBox.Size.Height);
            _queueRequestListBox.Location         = new Point(_logRichTextBox.Location.X + _logRichTextBox.Size.Width, _logRichTextBox.Location.Y);
            _queueRequestListBox.AddButton.Click += (sender, args) =>
            {
                OpenTaskCreatorForm(ModifierKeys.HasFlag(Keys.Shift));
            };
            _queueRequestListBox.ListBox.ItemAdded += (index, obj) =>
            {
                if (obj is DownloadRequest request)
                {
                    AddedRequest?.Invoke(request);
                }
            };

            //
            // MainForm
            //
            AutoScaleDimensions = new SizeF(7F, 15F);
            AutoScaleMode       = AutoScaleMode.Font;
            ClientSize          = new Size(LayoutGUI.MainFormSizeWidth, LayoutGUI.MainFormSizeHeight);
            FormBorderStyle     = FormBorderStyle.FixedSingle;
            MaximizeBox         = false;
            Controls.Add(_logRichTextBox);
            Controls.Add(_queueRequestListBox);
            Controls.Add(_aboutButton);
            Controls.Add(_additionalsButton);
            Controls.Add(_taskCreatorButton);
            Controls.Add(_settingsButton);
            Controls.Add(_pageControl);
            Icon   = Resource.icon;
            Shown += OnForm_Shown;
            Globals.APIKey.Changed += OnAPIKeyChanged;
            OnAPIKeyChanged();
            JsonAPI.OnExceptionResponce += code =>
            {
                switch (code)
                {
                case HttpStatusCode.Forbidden:
                case HttpStatusCode.Unauthorized:
                    new MessageForm(Globals.Localization.CurrentAPIKeyInvalid, Globals.Localization.APIKeyInvalid, Images.Basic.Error, Images.Basic.Error)
                    .ShowDialog();
                    _settingsForm.ResetAPI();
                    _settingsForm.ShowDialog();
                    break;

                default:
                    new MessageForm($"{Globals.Localization.UnknownError}: {code}", Globals.Localization.UnknownError, Images.Basic.Error,
                                    Images.Basic.Error).ShowDialog();
                    break;
                }
            };
            ResumeLayout();
        }