Exemplo n.º 1
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();
        }
Exemplo n.º 2
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);
            });
        }
Exemplo n.º 3
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();
                    }
                }
            }
        }