Example #1
0
        public LoadingScreen (Application application, MessageProvider messageProvider, string backgroundPath,
            string name,
            IEnumerable<Tuple<string, GameStateTransition>> from = null,
            IEnumerable<Tuple<string, GameStateTransition>> to = null)
        {
            if (application.Game.AddGameState(name, Content.Environment.Default, from, to))
                LoadingState = application.Game.GetGameState(name);
            else
            {
                Logger.Log.AddLogEntry(LogLevel.Error, "LoadingScreen", "Could not add loading screen game state!");
                return;
            }

            this.application = application;

            ValidMessages = new[] { (int) MessageId.WindowResize };
            messageProvider += this;

            image = new ImagePanel(application.RendererContext.Canvas);
            image.ImageName = backgroundPath;
            updateImage();
            image.BringToFront();

            progressBar = new ProgressBar (image);
            progressBar.IsHorizontal = true;
            progressBar.AutoLabel = false;
            progressBar.Y = application.RendererContext.Canvas.Height - 70;
            progressBar.X = 40 + (image.Width - application.RendererContext.Canvas.Width) / 2;
            progressBar.Height = 30;
            progressBar.Width = application.RendererContext.Canvas.Width - 80;
        }
Example #2
0
        public Screen_TechTree(Base parent)
            : base(parent)
        {
            Gwen.Control.Button buttonOK = new Gwen.Control.Button(this);
            buttonOK.Text = "Back";
            buttonOK.Font = Program.fontButtonLabels;
            buttonOK.SetBounds(500, 500, 50, 50);
            buttonOK.Clicked += onButtonOKClick;

            Tech.Inint();
            SetSize(parent.Width, parent.Height);

            label      = new Gwen.Control.Label(this);
            label.Text = "Tech_Tree Probe";
            label.SetPosition(Program.percentW(85), Program.percentH(85));
            label.TextColor = Color.FromArgb(200, 80, 0, 250);
            label.Font      = Program.fontLogo;

            img = new Gwen.Control.ImagePanel(this);


            updateDrawing();

            img.SetPosition(Program.percentW(0), Program.percentH(0));
            img.SetSize(Program.percentW(80), Program.percentH(80));
            //img.Clicked += new GwenEventHandler<ClickedEventArgs>(img_Clicked);
            img.MouseMoved += new GwenEventHandler <MovedEventArgs>(img_MouseMoved);
            img.MouseDown  += new GwenEventHandler <ClickedEventArgs>(img_MouseDown);
            img.MouseUp    += new GwenEventHandler <ClickedEventArgs>(img_MouseUp);
        }
Example #3
0
        /// <summary>
        /// Sets the button's image.
        /// </summary>
        /// <param name="textureName">Texture name. Null to remove.</param>
        /// <param name="center">Determines whether the image should be centered.</param>
        public virtual void SetImage(string textureName, bool center = false)
        {
            if (String.IsNullOrEmpty(textureName))
            {
                if (image != null)
                {
                    image.Dispose();
                }
                image = null;
                return;
            }

            if (image == null)
            {
                image = new ImagePanel(this);
            }

            image.ImageName = textureName;
            image.SizeToContents( );
            image.SetPosition(Math.Max(Padding.Left, 2), 2);
            image.KeyboardInputEnabled = false;
            image.MouseInputEnabled    = false;
            centerImage = center;

            TextPadding = new Padding(image.Right + 2, TextPadding.Top, TextPadding.Right, TextPadding.Bottom);
        }
        public Screen_GameScreen(Base parent)
            : base(parent)
        {
            SetSize(parent.Width, parent.Height);

            label      = new Gwen.Control.Label(this);
            label.Text = "GAME!!!";
            label.SetPosition(Program.percentW(5), Program.percentH(5));
            label.TextColor = Color.FromArgb(200, 80, 0, 250);
            label.Font      = Program.fontLogo;

            img = new Gwen.Control.ImagePanel(this);


            galaxyImage = new Bitmap(Program.percentW(100), Program.percentH(80), PixelFormat.Format32bppArgb);
            DrawControl = new DrawController(galaxyImage);

            updateDrawing();

            img.SetPosition(Program.percentW(0), Program.percentH(20));
            img.SetSize(Program.percentW(100), Program.percentH(80));
            //img.Clicked += new GwenEventHandler<ClickedEventArgs>(img_Clicked);
            img.MouseMoved += new GwenEventHandler <MovedEventArgs>(img_MouseMoved);
            img.MouseDown  += new GwenEventHandler <ClickedEventArgs>(img_MouseDown);
            img.MouseUp    += new GwenEventHandler <ClickedEventArgs>(img_MouseUp);

            Gwen.Control.Button buttonTech = new Gwen.Control.Button(this);
            buttonTech.Text = "Tech Tree";
            buttonTech.Font = Program.fontButtonLabels;
            buttonTech.SetBounds(Program.percentW(80), Program.percentH(84), Program.percentW(20), Program.percentH(8));
            buttonTech.Clicked += onButtonTechClick;

            Gwen.Control.Button buttonMenu = new Gwen.Control.Button(this);
            buttonMenu.Text = "Menu";
            buttonMenu.Font = Program.fontButtonLabels;
            buttonMenu.SetBounds(Program.percentW(0), Program.percentH(0), Program.percentW(13), Program.percentH(8));
            buttonMenu.Clicked += onButtonMenuClick;

            Gwen.Control.Button buttonSolarSystem = new Gwen.Control.Button(this);
            buttonSolarSystem.Text = "Solar System";
            buttonSolarSystem.Font = Program.fontButtonLabels;
            buttonSolarSystem.SetBounds(Program.percentW(0), Program.percentH(92), Program.percentW(19), Program.percentH(8));
            buttonSolarSystem.Clicked += onSolarSystemClick;

            Gwen.Control.Button buttonStep = new Gwen.Control.Button(this);
            buttonStep.Text = "Step";
            buttonStep.Font = Program.fontButtonLabels;
            buttonStep.SetBounds(Program.percentW(90), Program.percentH(92), Program.percentW(10), Program.percentH(8));
            buttonStep.Clicked += onSolarSystemClick;

            buttonCombat      = new Gwen.Control.Button(this);
            buttonCombat.Text = "Combat";
            buttonCombat.Font = Program.fontButtonLabels;
            buttonCombat.SetBounds(Program.percentW(19), Program.percentH(92), Program.percentW(18), Program.percentH(8));
            buttonCombat.Clicked += onCombatClick;
        }
Example #5
0
        public Screen_Combat(Base parent)
            : base(parent)
        {
            SetSize(parent.Width, parent.Height);

            imgCombatMap = new Gwen.Control.ImagePanel(this);

            tacticState.New(ref seed);
            ShipsCounter.ShipsCount(ref seed);
            pictureMap.Width  = Program.percentW(100);
            pictureMap.Height = Program.percentH(82);
            tacticDraw.New(pictureMap, seed, tacticState);

            UpdateDrawing();

            imgCombatMap.SetPosition(Program.percentW(0), Program.percentH(0));
            imgCombatMap.SetSize(pictureMap.Width, pictureMap.Height);
            imgCombatMap.MouseDown += new GwenEventHandler <ClickedEventArgs>(imgCombatMap_MouseDown);

            buttonStep      = new Gwen.Control.Button(this);
            buttonStep.Text = "Step";
            buttonStep.Font = Program.fontButtonLabels;
            buttonStep.SetBounds(Program.percentW(82), Program.percentH(82), Program.percentW(18), Program.percentH(6));
            buttonStep.Clicked += onStepClick;

            buttonConcede      = new Gwen.Control.Button(this);
            buttonConcede.Text = "Concede";
            buttonConcede.Font = Program.fontButtonLabels;
            buttonConcede.SetBounds(Program.percentW(82), Program.percentH(88), Program.percentW(18), Program.percentH(6));
            buttonConcede.Clicked += onConcedeClick;

            buttonAutoBattle      = new Gwen.Control.Button(this);
            buttonAutoBattle.Text = "Auto Battle";
            buttonAutoBattle.Font = Program.fontButtonLabels;
            buttonAutoBattle.SetBounds(Program.percentW(82), Program.percentH(94), Program.percentW(18), Program.percentH(6));
            buttonAutoBattle.Clicked += onAutoBattleClick;

            labelStep           = new Gwen.Control.Label(this);
            labelStep.Text      = "Ходит 1-й игрок";
            labelStep.Font      = Program.fontText;
            labelStep.TextColor = Color.GreenYellow;
            labelStep.SetBounds(Program.percentW(65), Program.percentH(90), Program.percentW(20), Program.percentH(8));

            labelDescription           = new Gwen.Control.Label(this);
            labelDescription.Text      = "";
            labelDescription.Font      = Program.fontText;
            labelDescription.TextColor = Color.GreenYellow;
            labelDescription.SetBounds(Program.percentW(0), Program.percentH(82), Program.percentW(50), Program.percentH(18));
        }
Example #6
0
		/// <summary>
		/// Sets the button's image.
		/// </summary>
		/// <param name="textureName">Texture name. Null to remove.</param>
		/// <param name="imageAlign">Determines how the image should be aligned.</param>
		public virtual void SetImage(string textureName, ImageAlign imageAlign = ImageAlign.LeftSide)
        {
            if (String.IsNullOrEmpty(textureName))
            {
                if (m_Image != null)
                    m_Image.Dispose();
                m_Image = null;
                return;
            }

            if (m_Image == null)
            {
                m_Image = new ImagePanel(this);
            }

            m_Image.ImageName = textureName;
			m_Image.MouseInputEnabled = false;
			m_ImageAlign = imageAlign;
			m_Image.SendToBack();

			Invalidate();
		}
        public Screen_NewGame(Base parent)
            : base(parent)
        {
            SetSize(parent.Width, parent.Height);


            label      = new Gwen.Control.Label(this);
            label.Text = "New game";
            label.SetPosition(Program.percentW(5), Program.percentH(5));
            label.TextColor = Color.FromArgb(200, 80, 0, 250);
            label.Font      = Program.fontLogo;

            Gwen.Control.Button buttonBack = new Gwen.Control.Button(this);
            buttonBack.Text = "Back";
            buttonBack.Font = Program.fontButtonLabels;
            buttonBack.SetBounds(Program.percentW(5), Program.percentH(87), Program.percentW(18), Program.percentH(8));
            buttonBack.Clicked += onButtonBackClick;

            Gwen.Control.Button buttonNewGame = new Gwen.Control.Button(this);
            buttonNewGame.Text = "New game";
            buttonNewGame.Font = Program.fontButtonLabels;
            buttonNewGame.SetBounds(Program.percentW(77), Program.percentH(87), Program.percentW(18), Program.percentH(8));
            buttonNewGame.Clicked += onButtonNewGameClick;

            imageGalaxyType       = new Gwen.Control.ImagePanel(this);
            imageGalaxyType.Image = Properties.Resources.icon_newgame_spiral;
            imageGalaxyType.SetBounds(Program.percentW(20), Program.percentH(20), Program.percentW(25), Program.percentH(25));

            Gwen.Control.Button buttonGalaxyTypeLeft = new Gwen.Control.Button(this);
            buttonGalaxyTypeLeft.Text = "<";
            buttonGalaxyTypeLeft.SetBounds(Program.percentW(20), Program.percentH(40), Program.percentW(5), Program.percentH(5));
            buttonGalaxyTypeLeft.Clicked += onButtonGalaxyTypeLeftClick;

            Gwen.Control.Button buttonGalaxyTypeRight = new Gwen.Control.Button(this);
            buttonGalaxyTypeRight.Text = ">";
            buttonGalaxyTypeRight.SetBounds(Program.percentW(40), Program.percentH(40), Program.percentW(5), Program.percentH(5));
            buttonGalaxyTypeRight.Clicked += onButtonGalaxyTypeRightClick;
        }
Example #8
0
        /// <summary>
        /// Sets the button's image.
        /// </summary>
        /// <param name="textureName">Texture name. Null to remove.</param>
        /// <param name="center">Determines whether the image should be centered.</param>
        public virtual void SetImage(String textureName, bool center = false)
        {
            if (String.IsNullOrEmpty(textureName))
            {
                if (m_Image != null)
                {
                    m_Image.Dispose();
                }
                m_Image = null;
                return;
            }

            if (m_Image == null)
            {
                m_Image = new ImagePanel(this);
            }

            m_Image.ImageName = textureName;
            m_Image.SizeToContents( );
            m_Image.SetPosition(Math.Max(Padding.Left, 2), 2);
            m_CenterImage = center;

            TextPadding = new Padding(m_Image.Right + 2, TextPadding.Top, TextPadding.Right, TextPadding.Bottom);
        }
Example #9
0
        /// <summary>
        /// Sets the button's image.
        /// </summary>
        /// <param name="textureName">Texture name. Null to remove.</param>
        /// <param name="center">Determines whether the image should be centered.</param>
        public virtual void SetImage(string textureName, bool center = false)
        {
            if (String.IsNullOrEmpty(textureName))
            {
                if (m_Image != null)
                    m_Image.Dispose();
                m_Image = null;
                return;
            }

            if (m_Image == null)
            {
                m_Image = new ImagePanel(this);
            }

            m_Image.ImageName = textureName;
            m_Image.SizeToContents();
            m_Image.SetPosition(Math.Max(Padding.Left, 2), 2);
            m_CenterImage = center;

            TextPadding = new Padding(m_Image.Right + 2, TextPadding.Top, TextPadding.Right, TextPadding.Bottom);
        }
Example #10
0
        public void Init(Base parent, Inventory inventory)
        {
            this.inventory = inventory;

            Item_Text = new Gwen.ControlInternal.Text (parent);
            Item_Text.Font = new Gwen.Font (application.RendererContext.GwenRenderer);
            Item_Text.Y = 5;
            Item_Text.Font.Size = 15;

            spaces = new InventorySpace[inventory.Size.X, inventory.Size.Y];
            barItems = new List<InventoryBarButton>();

            canvasFrame = new InventoryBackground(parent, inventory, this);
            canvasFrame.Width = parent.Width;
            canvasFrame.Height = parent.Height;

            window = new WindowControl (canvasFrame, Localizer.Instance.GetValueForName("inventory"));
            window.DisableResizing ();
            window.IsMoveable = false;
            window.OnClose += (sender, arguments) => application.Window.CaptureMouse ();

            itemGridFrame = new Base (window);
            itemGridFrame.SetSize ((BoxSize + 1) * inventory.Size.X, (BoxSize + 1) * inventory.Size.Y);


            bla_unfug_crosshair = new ImagePanel (canvasFrame);
            bla_unfug_crosshair.SetSize (16, 16);
            bla_unfug_crosshair.ImageName = "Content/crosshair.png";
            bla_unfug_crosshair.SetPosition ((canvasFrame.Width / 2.0f) - (bla_unfug_crosshair.Width / 2.0f), 
                (canvasFrame.Height / 2.0f) - (bla_unfug_crosshair.Width / 2.0f));
            bla_unfug_crosshair.BringToFront ();

            itemInfoFrame = new Base (window);
            itemInfoFrame.SetSize (infoFrameSize, itemGridFrame.Height);
            itemGridFrame.X += itemInfoFrame.Width + 4;

            toolbarFrame = new Base(window);
            toolbarFrame.Width = itemGridFrame.Width + itemInfoFrame.Width;
            toolbarFrame.Height = toolbarFrameSize;
            toolbarFrame.Y = itemGridFrame.Height - 4;

            dropBtn = new Button(toolbarFrame);
            dropBtn.AutoSizeToContents = true;
            dropBtn.Padding = btnPadding;
            dropBtn.Text = Localizer.Instance.GetValueForName("drop");
            dropBtn.X = toolbarFrame.Width - dropBtn.Width;
            dropBtn.Y = (toolbarFrameSize - dropBtn.Height) / 2;
            dropBtn.IsDisabled = true;
            dropBtn.Clicked += (sender, arguments) => {
                if (dropBtn.IsDisabled)
                    return;

                if (toggledBtn != null)
                {
                    dropItem(toggledBtn, toggledBtn.Item, inventory);
                }
            };

            useBtn = new Button(toolbarFrame);
            useBtn.AutoSizeToContents = true;
            useBtn.Padding = btnPadding;
            useBtn.Text = Localizer.Instance.GetValueForName("use");
            useBtn.X = dropBtn.X - useBtn.Width - 8;
            useBtn.Y = (toolbarFrameSize - useBtn.Height) / 2;
            useBtn.IsDisabled = true;
            useBtn.Clicked += (sender, arguments) => {
                if (useBtn.IsDisabled)
                    return;

                if (toggledBtn != null)
                {
                    if (MessageCreated != null)
                        MessageCreated(new ItemUseMessage(player, GameState.Scene, toggledBtn.Item, ItemUsage.Eatable));
                }
            };

            rotateBtn = new Button(toolbarFrame);
            rotateBtn.AutoSizeToContents = true;
            rotateBtn.Padding = btnPadding;
            rotateBtn.Text = Localizer.Instance.GetValueForName("rotate");
            rotateBtn.X = useBtn.X - rotateBtn.Width - 8;
            rotateBtn.Y = (toolbarFrameSize - rotateBtn.Height) / 2;
            rotateBtn.IsDisabled = true;

            rotateBtn.Clicked += (sender, argument) => {
                if (rotateBtn.IsDisabled)
                    return;

                var pos = inventory.GetPositionOfItem(toggledBtn.Item);
                var item = inventory.TakeOut(pos);
                var prev_orientation = item.Orientation;
                item.Orientation =
                    item.Orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal;
                if (!inventory.Insert(item, pos))
                {
                    item.Orientation = prev_orientation;
                    if (!inventory.Insert(item, pos))
                    {
                        Logger.Log.AddLogEntry(LogLevel.Error, "InventoryGUI",
                            "Lost an inventory item while rotating!");
                        toggledBtn.DelayedDelete();
                        toggledBtn = null;
                        return;
                    }
                }
                toggledBtn.UpdateSize();
            };

            inventoryBar = new TextBox(canvasFrame);
            inventoryBar.Disable();
            inventoryBar.KeyboardInputEnabled = false;
            inventoryBar.Height = barBoxSize + 2;
            inventoryBar.Width = barBoxSize * inventory.InventoryBar.Length + 1;
            inventoryBar.Y = canvasFrame.Height - inventoryBar.Height;
            inventoryBar.X = (canvasFrame.Width - inventoryBar.Width) / 2;
            barSpaces = new InventoryBarSpace[inventory.InventoryBar.Length];
            for (int i = 0; i < inventory.InventoryBar.Length; i++)
            {
                barSpaces[i] = new InventoryBarSpace(inventoryBar, MessageProvider, inventory, this, barItems, barBoxSize);
                barSpaces[i].X = i * barBoxSize;
                barSpaces[i].Y = 1;
                barSpaces[i].Width = barBoxSize + 1;
                barSpaces[i].Height = barBoxSize + 1;
                barSpaces[i].DrawDebugOutlines = false;

                if (i == inventory.ActiveBarPosition)
                {
                    barSpaces[i].DrawDebugOutlines = true;
                    barSpaces[i].Children.ForEach(c => c.DrawDebugOutlines = false);
                }
            }

            window.SetSize (itemGridFrame.Width + itemInfoFrame.Width + 16,
                itemGridFrame.Height + toolbarFrameSize + 28);
            window.SetPosition ((canvasFrame.Width - window.Width) / 2,
                (canvasFrame.Height - window.Height - inventoryBar.Height) / 2);
            window.Hide();

            int w = 0, h = 0;

            for (int y = 0; y < inventory.Size.Y; y++)
            {
                for (int x = 0; x < inventory.Size.X; x++)
                {
                    spaces [x, y] = new InventorySpace (itemGridFrame, BoxSize, inventory);
                    spaces [x, y].X = w;
                    spaces [x, y].Y = h;
                    spaces [x, y].Width = BoxSize + 1;
                    spaces [x, y].Height = BoxSize + 1;

                    w += BoxSize;
                }
                h += BoxSize;
                w = 0;
            }

            imagePanel = new ImagePanel(itemInfoFrame);
            imagePanel.Width = infoFrameSize;
            imagePanelHeight = itemGridFrame.Height / 3;
            imagePanel.Hide();

            items = new List<InventoryButton>();
            inventory.Items.ForEach((item, position) => {
                AddItem(item, position);
            });
        }
Example #11
0
        public override void InitUi(Canvas canvas) {
            _canvas = canvas;
            Game.BackgroundColor = Color.Black;

            var windowAction = new WindowControl(canvas, "Options", false);
            windowAction.DisableResizing();
            windowAction.IsClosable = false;
            windowAction.SetSize(200, 150);
            windowAction.SetPosition(0, 0);

            var addScriptButton = new Button(windowAction);
            addScriptButton.SetText("Ajouter un script");
            addScriptButton.Clicked += (sender, arguments) => ShowAddScriptWindow(canvas);
            Align.CenterHorizontally(addScriptButton);


            // Fenêtre sur les informations du script sélectionné 
            _windowInfoScript = new WindowControl(canvas, "Paramètres du script");
            _windowInfoScript.DisableResizing();
            _windowInfoScript.IsClosable = false;
            _windowInfoScript.SetSize(200, 300);
            _windowInfoScript.SetPosition(Game.GetWindowSize().X - _windowInfoScript.Width, 0);

            var labelX = new Label(_windowInfoScript);
            labelX.SetPosition(0, 10);
            labelX.SetText("X :");

            _uiInfoTextBoxPosX = new TextBoxNumeric(_windowInfoScript);
            _uiInfoTextBoxPosX.SetSize(100, _uiInfoTextBoxPosX.Height);
            _uiInfoTextBoxPosX.TextChanged += (sender, arguments) => {
                if (_selectScript != null) {
                    _selectScript.RectShape.Position = new Vector2f((int) _uiInfoTextBoxPosX.Value,
                        _selectScript.RectShape.Position.Y);
                }
            };
            Align.PlaceRightBottom(_uiInfoTextBoxPosX, labelX, 10);

            var labelY = new Label(_windowInfoScript);
            labelY.SetText("Y :");
            Align.PlaceDownLeft(labelY, labelX, 10);

            _uiInfoTextBoxPosY = new TextBoxNumeric(_windowInfoScript);
            _uiInfoTextBoxPosY.SetSize(100, _uiInfoTextBoxPosY.Height);
            _uiInfoTextBoxPosY.TextChanged += (sender, arguments) => {
                if (_selectScript != null) {
                    _selectScript.RectShape.Position = new Vector2f(_selectScript.RectShape.Position.X,
                        (int) _uiInfoTextBoxPosY.Value);
                }
            };
            Align.PlaceRightBottom(_uiInfoTextBoxPosY, labelY, 10);

            var labelSizeX = new Label(_windowInfoScript);
            labelSizeX.SetText("Largeur :");
            Align.PlaceDownLeft(labelSizeX, labelY, 10);

            _uiInfoTextBoxSizeX = new TextBoxNumeric(_windowInfoScript);
            _uiInfoTextBoxSizeX.SetSize(100, _uiInfoTextBoxPosY.Height);
            _uiInfoTextBoxSizeX.TextChanged += (sender, arguments) => {
                if (_selectScript != null) {
                    _selectScript.RectShape.Size = new Vector2f((int)_uiInfoTextBoxSizeX.Value,
                        _selectScript.RectShape.Size.Y);
                    _selectScript.RectShape.Origin = new Vector2f(_selectScript.RectShape.Size.X / 2, _selectScript.RectShape.Size.Y / 2);
                }
            };
            Align.PlaceRightBottom(_uiInfoTextBoxSizeX, labelSizeX, 10);

            var labelSizeY = new Label(_windowInfoScript);
            labelSizeY.SetText("Hauteur :");
            Align.PlaceDownLeft(labelSizeY, labelSizeX, 10);

            _uiInfoTextBoxSizeY = new TextBoxNumeric(_windowInfoScript);
            _uiInfoTextBoxSizeY.SetSize(100, _uiInfoTextBoxSizeY.Height);
            _uiInfoTextBoxSizeY.TextChanged += (sender, arguments) => {
                if (_selectScript != null) {
                    _selectScript.RectShape.Size = new Vector2f(_selectScript.RectShape.Size.X,
                        (int)_uiInfoTextBoxSizeY.Value);
                    _selectScript.RectShape.Origin = new Vector2f(_selectScript.RectShape.Size.X / 2, _selectScript.RectShape.Size.Y / 2);
                }
            };
            Align.PlaceRightBottom(_uiInfoTextBoxSizeY, labelSizeY, 10);

            _uiInfoScriptImage = new ImagePanel(_windowInfoScript);
            _uiInfoScriptImage.SetSize(75, 75);
            _uiInfoScriptImage.Hide();

            Align.PlaceDownLeft(_uiInfoScriptImage, _uiInfoTextBoxSizeY, 10);
            Align.CenterHorizontally(_uiInfoScriptImage);

            UnSelect_SelectScript();
        }
Example #12
0
        protected void Rebuild()
        {
            m_Updating = true;

            DeleteAllChildren();

            Size size = Size.Zero;

            if (m_Document != null && m_Document.Paragraphs.Count > 0)
            {
#if USE_KNUTH_PLASS_LINE_BREAKING
                LineBreaker lineBreaker = new RichText.KnuthPlass.LineBreaker(Skin.Renderer, Skin.DefaultFont);
#else
                LineBreaker lineBreaker = new RichText.Simple.LineBreaker(Skin.Renderer, Skin.DefaultFont);
#endif

                int y = 0;
                int x;
                int width;
                int height;

                foreach (Paragraph paragraph in m_Document.Paragraphs)
                {
                    if (paragraph is ImageParagraph)
                    {
                        ImageParagraph imageParagraph = paragraph as ImageParagraph;

                        ImagePanel image = new ImagePanel(this);
                        image.ImageName = imageParagraph.ImageName;
                        if (imageParagraph.ImageSize != null)
                        {
                            image.Size = (Size)imageParagraph.ImageSize;
                        }
                        if (imageParagraph.TextureRect != null)
                        {
                            image.TextureRect = (Rectangle)imageParagraph.TextureRect;
                        }
                        if (imageParagraph.ImageColor != null)
                        {
                            image.ImageColor = (Color)imageParagraph.ImageColor;
                        }

                        image.DoMeasure(Size.Infinity);
                        image.DoArrange(paragraph.Margin.Left, y + paragraph.Margin.Top, image.MeasuredSize.Width, image.MeasuredSize.Height);

                        size.Width = Math.Max(size.Width, image.MeasuredSize.Width + paragraph.Margin.Left + paragraph.Margin.Right);

                        y += image.MeasuredSize.Height + paragraph.Margin.Top + paragraph.Margin.Bottom;
                    }
                    else
                    {
                        List <TextBlock> textBlocks = lineBreaker.LineBreak(paragraph, m_BuildWidth);

                        if (textBlocks != null)
                        {
                            x      = paragraph.Margin.Left;
                            y     += paragraph.Margin.Top;
                            width  = 0;
                            height = 0;

                            foreach (TextBlock textBlock in textBlocks)
                            {
                                if (textBlock.Part is LinkPart)
                                {
                                    LinkPart linkPart = textBlock.Part as LinkPart;

                                    LinkLabel link = new LinkLabel(this);
                                    link.Text         = textBlock.Text;
                                    link.Link         = linkPart.Link;
                                    link.Font         = linkPart.Font;
                                    link.LinkClicked += OnLinkClicked;
                                    if (linkPart.Color != null)
                                    {
                                        link.TextColor = (Color)linkPart.Color;
                                    }
                                    if (linkPart.HoverColor != null)
                                    {
                                        link.HoverColor = (Color)linkPart.HoverColor;
                                    }
                                    if (linkPart.HoverFont != null)
                                    {
                                        link.HoverFont = linkPart.HoverFont;
                                    }

                                    link.DoMeasure(Size.Infinity);
                                    link.DoArrange(new Rectangle(x + textBlock.Position.X, y + textBlock.Position.Y, textBlock.Size.Width, textBlock.Size.Height));

                                    width  = Math.Max(width, link.ActualRight);
                                    height = Math.Max(height, link.ActualBottom);
                                }
                                else if (textBlock.Part is TextPart)
                                {
                                    TextPart textPart = textBlock.Part as TextPart;

                                    Text text = new Text(this);
                                    text.String = textBlock.Text;
                                    text.Font   = textPart.Font;
                                    if (textPart.Color != null)
                                    {
                                        text.TextColor = (Color)textPart.Color;
                                    }

                                    text.DoMeasure(Size.Infinity);
                                    text.DoArrange(new Rectangle(x + textBlock.Position.X, y + textBlock.Position.Y, textBlock.Size.Width, textBlock.Size.Height));

                                    width  = Math.Max(width, text.ActualRight + 1);
                                    height = Math.Max(height, text.ActualBottom + 1);
                                }
                            }

                            size.Width = Math.Max(size.Width, width + paragraph.Margin.Right);

                            y = height + paragraph.Margin.Bottom;
                        }
                    }
                }

                size.Height = y;
            }

            m_TextSize = size;

            m_NeedsRebuild = false;

            m_Updating = false;
        }
Example #13
0
        public MainMenu (Application application, Action onPlayGame, CompositorColorCorrectionNode colorCorrectionNode)
        {
            this.application = application;
            this.onPlayGame = onPlayGame;

            ValidMessages = new[] { (int) MessageId.WindowResize, (int) MessageId.UpdateLocale };
            application.MessageManager += this;

            canvas = application.RendererContext.Canvas;
            var input = new FreezingArcherInput(application, application.MessageManager);
            input.Initialize (canvas);

            canvas.SetSize(application.Window.Size.X, application.Window.Size.Y);
            canvas.ShouldDrawBackground = false;

            settings = new SettingsMenu (application, canvas, colorCorrectionNode);
            tutorial = new TutorialMenu (application, canvas);

            background = new ImagePanel (canvas);
            background.ImageName = "Content/MainMenu.jpg";
            updateBackground();

            exitButton = new Button (canvas);
            exitButton.Text = Localizer.Instance.GetValueForName("quit_game");
            exitButton.Width = BUTTON_WIDTH;
            exitButton.X = 40;
            exitButton.Y = canvas.Height - exitButton.Height - 60;
            exitButton.Clicked += (sender, arguments) => application.Window.Close ();

            settingsButton = new Button (canvas);
            settingsButton.Text = Localizer.Instance.GetValueForName("settings");
            settingsButton.Width = BUTTON_WIDTH;
            settingsButton.X = 40;
            settingsButton.Y = exitButton.Y - settingsButton.Height - 40;
            settingsButton.Clicked += (sender, arguments) => settings.Show();

            tutorialButton = new Button (canvas);
            tutorialButton.Text = Localizer.Instance.GetValueForName("tutorial");
            tutorialButton.Width = BUTTON_WIDTH;
            tutorialButton.X = 40;
            tutorialButton.Y = settingsButton.Y - tutorialButton.Height - 40;
            tutorialButton.Clicked += (sender, arguments) => tutorial.Show();

            startButton = new Button (canvas);
            startButton.Text = Localizer.Instance.GetValueForName("start_game");
            startButton.Width = BUTTON_WIDTH;
            startButton.X = 40;
            startButton.Y = tutorialButton.Y - startButton.Height - 40;
            startButton.Clicked += (sender, arguments) => {
                application.MessageManager.UnregisterMessageConsumer(this);
                application.MessageManager.UnregisterMessageConsumer(settings);
                settings.Destroy();
                canvas.Dispose();
                onPlayGame();
            };

            acagamicsFoo = new ImagePanel (canvas);
            acagamicsFoo.ImageName = "Content/figure_color.png";
            acagamicsFoo.Width = 64;
            acagamicsFoo.Height = 106;
            acagamicsFoo.X = canvas.Width - acagamicsFoo.Width - 10;
            acagamicsFoo.Y = canvas.Height - acagamicsFoo.Height - 10;
        }
Example #14
0
        public void ConsumeMessage (IMessage msg)
        {
            if (msg.MessageId == (int) MessageId.GameEnded || msg.MessageId == (int)MessageId.GameEndedDied)
            {
                Application.Window.ReleaseMouse ();

                Canvas = Renderer.Canvas;
                Canvas.DeleteAllChildren();

                minuteCount = (float) (DateTime.Now - MazeTest.StartTime).TotalMinutes;

                exitButton = new Button (Canvas);
                exitButton.Text = Localizer.Instance.GetValueForName("quit_game");
                exitButton.Width = 300;
                exitButton.X = (Canvas.Width - exitButton.Width) / 2;
                exitButton.Y = Canvas.Height - exitButton.Height - 20;
                exitButton.Clicked += (sender, arguments) => Application.Window.Close ();

                surviveTimeLabel = new Label (Canvas);
                surviveTimeLabel.AutoSizeToContents = true;
                surviveTimeLabel.Text = string.Format("{0} {1:0.##} {2}", Localizer.Instance.GetValueForName("you_survived"),
                    minuteCount, Localizer.Instance.GetValueForName("minutes"));
                surviveTimeLabel.X = (Canvas.Width - surviveTimeLabel.Width) / 2;
                surviveTimeLabel.Y = exitButton.Y - surviveTimeLabel.Height - 40;

                labelWin = new ImagePanel (Canvas);
                labelWin.Width = 1211;
                labelWin.Height = 170;
                labelWin.X = (Canvas.Width - labelWin.Width) / 2;
                labelWin.Y = 100;
                labelWin.ImageName = "Content/YouEscapedTheMaze.png";
                labelWin.Hide();

                labelWin_de = new ImagePanel (Canvas);
                labelWin_de.Width = 1211;
                labelWin_de.Height = 170;
                labelWin_de.X = (Canvas.Width - labelWin_de.Width) / 2;
                labelWin_de.Y = 100;
                labelWin_de.ImageName = "Content/YouEscapedTheMaze_de.png";
                labelWin_de.Hide();

                labelLoose = new ImagePanel (Canvas);
                labelLoose.Width = 845;
                labelLoose.Height = 168;
                labelLoose.X = (Canvas.Width - labelLoose.Width) / 2;
                labelLoose.Y = 100;
                labelLoose.ImageName = "Content/YouAreDead.png";
                labelLoose.Hide();
                labelLoose_de = new ImagePanel (Canvas);
                labelLoose_de.Width = 845;
                labelLoose_de.Height = 168;
                labelLoose_de.X = (Canvas.Width - labelLoose_de.Width) / 2;
                labelLoose_de.Y = 100;
                labelLoose_de.ImageName = "Content/YouAreDead_de.png";
                labelLoose_de.Hide();
               
                if (msg.MessageId == (int) MessageId.GameEndedDied)
                {
                    if (Localizer.Instance.CurrentLocale == LocaleEnum.de_DE)
                    {
                        labelLoose_de.Show();
                    }
                    else
                    {
                        labelLoose.Show();
                    }
                    win = false;
                }
                else
                {
                    if (Localizer.Instance.CurrentLocale == LocaleEnum.de_DE)
                    {
                        labelWin_de.Show();
                    }
                    else
                    {
                        labelWin.Show();
                    }
                    win = true;
                }
            }

            if (msg.MessageId == (int) MessageId.WindowResize)
            {
                if (exitButton != null)
                {
                    exitButton.X = (Canvas.Width - exitButton.Width) / 2;
                    exitButton.Y = Canvas.Height - exitButton.Height - 20;
                }

                if (surviveTimeLabel != null)
                {
                    surviveTimeLabel.X = (Canvas.Width - surviveTimeLabel.Width) / 2;
                    surviveTimeLabel.Y = exitButton.Y - surviveTimeLabel.Height - 40;
                }

                if (labelWin != null)
                    labelWin.X = (Canvas.Width - labelWin.Width) / 2;

                if (labelWin_de != null)
                    labelWin_de.X = (Canvas.Width - labelWin_de.Width) / 2;

                if (labelLoose != null)
                    labelLoose.X = (Canvas.Width - labelLoose.Width) / 2;

                if (labelLoose_de != null)
                    labelLoose_de.X = (Canvas.Width - labelLoose_de.Width) / 2;
            }

            if (msg.MessageId == (int) MessageId.UpdateLocale)
            {
                surviveTimeLabel.Text = string.Format("{0} {1:#.##} {2}", Localizer.Instance.GetValueForName("you_survived"),
                    minuteCount, Localizer.Instance.GetValueForName("minutes"));
                exitButton.Text = Localizer.Instance.GetValueForName("quit_game");

                if (Localizer.Instance.CurrentLocale == LocaleEnum.de_DE)
                {
                    if (win && labelWin != null && labelWin_de != null)
                    {
                        labelWin.Hide();
                        labelWin_de.Show();
                    }
                    else if (labelLoose != null && labelLoose_de != null)
                    {
                        labelLoose.Hide();
                        labelLoose_de.Show();
                    }
                }
                else
                {
                    if (win && labelWin != null && labelWin_de != null)
                    {
                        labelWin_de.Hide();
                        labelWin.Show();
                    }
                    else if (labelLoose != null && labelLoose_de != null)
                    {
                        labelLoose_de.Hide();
                        labelLoose.Show();
                    }
                }
            }
        }