Пример #1
0
        void CreateDraggableFish()
        {
            var cache    = ResourceCache;
            var graphics = Graphics;

            // Create a draggable Fish button
            draggableFish           = new Button();
            draggableFish.Texture   = cache.GetTexture2D("Textures/UrhoDecal.dds");           // Set texture
            draggableFish.BlendMode = BlendMode.Add;
            draggableFish.SetSize(128, 128);
            draggableFish.SetPosition((graphics.Width - draggableFish.Width) / 2, 200);
            draggableFish.Name = "Fish";
            uiRoot.AddChild(draggableFish);

            // Add a tooltip to Fish button
            ToolTip toolTip = new ToolTip();

            draggableFish.AddChild(toolTip);
            toolTip.Position = new IntVector2(draggableFish.Width + 5, draggableFish.Width / 2);
            // slightly offset from close button
            BorderImage textHolder = new BorderImage();

            toolTip.AddChild(textHolder);
            textHolder.SetStyle("ToolTipBorderImage", null);
            var toolTipText = new Text();

            textHolder.AddChild(toolTipText);
            toolTipText.SetStyle("ToolTipText", null);
            toolTipText.Value = "Please drag me!";

            // Subscribe draggableFish to Drag Events (in order to make it draggable)
            draggableFish.SubscribeToDragBegin(HandleDragBegin);
            draggableFish.SubscribeToDragMove(HandleDragMove);
            draggableFish.SubscribeToDragEnd(HandleDragEnd);
        }
Пример #2
0
        public BorderImage CreateBorderImage(string name = "", uint index = 4294967295)
        {
            BorderImage newBorderImage = ElementWithChildren.CreateBorderImage(name, index);

            InitElement(newBorderImage);
            return(newBorderImage);
        }
Пример #3
0
            public Screen(LevelSettingsScreen proxy, out string errorMessage)
                : base(proxy)
            {
                this.proxy = proxy;
                Game.UI.LoadLayoutToElement(MenuUIManager.MenuRoot, Game.ResourceCache, "UI/LevelSettingsScreenLayout.xml");

                window = (Window)MenuUIManager.MenuRoot.GetChild("LevelSettingsWindow");

                customSettingsWindow = (Window)window.GetChild("CustomSettings", true);

                UIElement descriptionTextElement = Game.UI.LoadLayout(Game.PackageManager.GetXmlFile("UI/DescriptionTextLayout.xml", true),
                                                                      MenuUIManager.MenuRoot.GetDefaultStyle());

                descriptionText       = (Text)descriptionTextElement.GetChild("DescriptionText");
                descriptionText.Value = Level.Description;
                descriptionScrollView = (ScrollView)window.GetChild("DescriptionScrollView", true);

                descriptionScrollView.ContentElement = descriptionTextElement;

                mapImage           = (BorderImage)window.GetChild("MapImage");
                mapImage.Texture   = Level.Thumbnail;
                mapImage.ImageRect = new Urho.IntRect(0, 0, Level.Thumbnail.Width, Level.Thumbnail.Height);

                playerList = (ListView)window.GetChild("PlayerListView");

                ((Button)window.GetChild("PlayButton", true)).Released += PlayButtonReleased;
                ((Button)window.GetChild("BackButton", true)).Released += BackButtonReleased;

                InsigniaGetter insigniaGetter = new InsigniaGetter();

                PlayerItem.CreateAndAddToList(playerList,
                                              this,
                                              insigniaGetter.MarkUsed(PlayerInsignia.NeutralPlayerInsignia),
                                              0,
                                              PlayerTypeCategory.Neutral);

                PlayerItem.CreateAndAddToList(playerList,
                                              this,
                                              insigniaGetter.GetNextUnusedInsignia(),
                                              1,
                                              PlayerTypeCategory.Human);

                for (int i = 0; i < Level.MaxNumberOfPlayers - 1; i++)
                {
                    PlayerItem.CreateAndAddToList(playerList, this, insigniaGetter.GetNextUnusedInsignia(), i + 2, PlayerTypeCategory.AI);
                }

                try {
                    pluginCustomSettings = Level.LevelLogicType.GetCustomSettings(customSettingsWindow, Game);
                    errorMessage         = null;
                }
                catch (Exception e) {
                    string message =
                        $"Level plugin threw an exception when getting the Custom settings window contents: {e.Message}";
                    Urho.IO.Log.Write(Urho.LogLevel.Error, message);
                    pluginCustomSettings = null;
                    errorMessage         = message;
                }
            }
Пример #4
0
        private void Init()
        {
            var cache = Application.ResourceCache;

            label = new Text()
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
            };
            label.SetColor(new Color(1.0f, 1.0f, 1.0f));
            label.SetFont(cache.GetFont("Fonts/OpenSans-Bold.ttf"), 20);

            background = new BorderImage()
            {
                //Texture = cache.GetTexture2D("Textures/UI.png"),
                //ImageRect = new IntRect(48, 0, 64, 16),
                //Border = new IntRect(4, 4, 4, 4),
                Texture   = cache.GetTexture2D("Textures/Panel.png"),
                ImageRect = new IntRect(0, 0, 64, 64),
                Border    = new IntRect(30, 30, 30, 30),
                BlendMode = BlendMode.Alpha,
            };

            panel = Node.CreateComponent <UIComponent>();
            panel.Material.SetTechnique(0, cache.GetTechnique("Techniques/DiffUnlitAlpha.xml"));
            panel.Root.LayoutMode          = LayoutMode.Free;
            panel.Root.HorizontalAlignment = HorizontalAlignment.Center;
            panel.Root.VerticalAlignment   = VerticalAlignment.Center;
            panel.Root.AddChild(background);
            panel.Root.AddChild(label);

            billboards = Node.CreateComponent <BillboardSet>();
            billboards.NumBillboards = 1;
            billboards.Material      = panel.Material;

            Node.Position = Position;

            var billboard = billboards.GetBillboardSafe(0);

            billboard.Enabled = false;
            billboards.Commit();


            /*
             * var node = Node.CreateChild();
             * node.Position = new Vector3(0.0f, 2.0f, 0.0f);
             * node.Scale = new Vector3(2.0f, 2.0f, 2.0f);
             */

            /*
             * var box = node.CreateComponent<StaticModel>();
             * box.Model = cache.GetModel("Models/Box.mdl");
             * //box.Material = Material.FromImage("Textures/StoneDiffuse.dds");
             */
        }
Пример #5
0
        void InitLoadingScreen()
        {
            var splashScreen = new BorderImage {
                Texture   = ResourceCache.GetTexture2D(AssetsCoordinates.Backgrounds.LoadingGameScreen.ResourcePath),
                ImageRect = AssetsCoordinates.Backgrounds.LoadingGameScreen.ImageRect,
                Size      = new IntVector2(ScreenInfo.SetX(1920), ScreenInfo.SetY(1080)),
                Position  = new IntVector2(ScreenInfo.SetX(0), ScreenInfo.SetY(0))
            };

            UI.Root.AddChild(splashScreen);
            Engine.RunFrame();
        }
Пример #6
0
                protected PlayerItem(Screen screen, PlayerInsignia insignia, int initialTeamID, PlayerTypeCategory playerTypeCategory)
                {
                    this.Insignia = insignia;

                    elementToTypeMap = new Dictionary <UIElement, PlayerType>();
                    elementToTeamMap = new Dictionary <UIElement, int>();

                    var child =
                        screen.Game.UI.LoadLayout(screen.Game.PackageManager.GetXmlFile("UI/PlayerItemLayout.xml", true));

                    AddChild(child);

                    BorderImage playerShield = (BorderImage)child.GetChild("PlayerShield", true);

                    playerTypeList = (DropDownList)child.GetChild("PlayerTypeList", true);
                    teamList       = (DropDownList)child.GetChild("TeamList", true);

                    playerShield.Texture   = insignia.ShieldTexture;
                    playerShield.ImageRect = insignia.ShieldRectangle;

                    foreach (var player in screen.Level.GamePack.GetPlayersWithTypeCategory(playerTypeCategory))
                    {
                        var item = InitTypeItem(player, screen.Game, screen.MenuUIManager);
                        playerTypeList.AddItem(item);
                        elementToTypeMap.Add(item, player);
                    }

                    if (playerTypeCategory != PlayerTypeCategory.Neutral)
                    {
                        for (int teamID = 1; teamID <= screen.Level.MaxNumberOfPlayers; teamID++)
                        {
                            UIElement item = InitTeamItem(teamID, screen.Game, screen.MenuUIManager);
                            teamList.AddItem(item);
                            elementToTeamMap.Add(item, teamID);

                            if (teamID == initialTeamID)
                            {
                                teamList.Selection = teamList.NumItems - 1;
                            }
                        }
                    }
                    else
                    {
                        teamList.Visible = false;
                    }
                }
Пример #7
0
        private static ToolTip SetToolTip(this UIElement ele, string tip)
        {
            // Add a tooltip to Fish button
            ToolTip toolTip = new ToolTip();

            toolTip.Position = new IntVector2(ele.Width + 5, ele.Width / 2);
            // slightly offset from close button
            BorderImage textHolder = new BorderImage();

            toolTip.AddChild(textHolder);
            textHolder.SetStyle("ToolTipBorderImage", null);
            var toolTipText = GetText(tip, "ToolTipText");

            textHolder.AddChild(toolTipText);
            ele.AddChild(toolTip);
            return(toolTip);
        }
Пример #8
0
                static UIElement InitTypeItem(PlayerType player, MHUrhoApp game, MenuUIManager menuUIManager)
                {
                    var newElement = game.UI.LoadLayout(game.PackageManager.GetXmlFile("UI/PlayerTypeItemLayout.xml", true),
                                                        menuUIManager.MenuRoot.GetDefaultStyle());

                    BorderImage playerIcon        = (BorderImage)newElement.GetChild("PlayerIcon");
                    Text        playerName        = (Text)newElement.GetChild("PlayerName");
                    Text        playerDescription = (Text)newElement.GetChild("PlayerDescription", true);

                    playerIcon.Texture   = player.Package.PlayerIconTexture;
                    playerIcon.ImageRect = player.IconRectangle;

                    playerName.Value = player.Name;
                    //FUTURE: Description
                    playerDescription.Value = "Nothing for now";

                    return(newElement);
                }
Пример #9
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (BorderImage.Length != 0)
            {
                hash ^= BorderImage.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (color_ != null)
            {
                hash ^= Color.GetHashCode();
            }
            if (IsMetallic != false)
            {
                hash ^= IsMetallic.GetHashCode();
            }
            if (FrameMesh.Length != 0)
            {
                hash ^= FrameMesh.GetHashCode();
            }
            if (NormalMap.Length != 0)
            {
                hash ^= NormalMap.GetHashCode();
            }
            if (AlbedoMap.Length != 0)
            {
                hash ^= AlbedoMap.GetHashCode();
            }
            if (Roughness != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(Roughness);
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #10
0
        public void Update(IEnumerable <BarData> newData)
        {
            if (newData.Count() != data.Count)
            {
                graphRoot.Size = new IntVector2(MAX_BAR_WIDTH + labelWidth, newData.Count() * HEIGHT);

                graphRoot.RemoveAllChildren();
                for (int i = 0; i < newData.Count(); ++i)
                {
                    var row = new UIElement();

                    var label = new Text()
                    {
                        TextAlignment       = HorizontalAlignment.Right,
                        HorizontalAlignment = HorizontalAlignment.Right
                    };
                    label.SetColor(new Color(1.0f, 1.0f, 1.0f));
                    label.SetFont(barFont, 22);
                    label.Position = new IntVector2(labelWidth, i * HEIGHT);
                    label.Width    = labelWidth;
                    row.AddChild(label);

                    var bar = new BorderImage()
                    {
                        Texture   = barTex,
                        ImageRect = new IntRect(0, 0, 32, 32),
                        Border    = new IntRect(6, 9, 6, 9),

                        MinSize   = new IntVector2(20, 20),
                        BlendMode = BlendMode.Alpha
                    };
                    bar.Position = new IntVector2(labelWidth + LABEL_GAP, i * HEIGHT);
                    row.AddChild(bar);

                    graphRoot.AddChild(row);
                }
            }
            data.Clear();
            data.AddRange(newData);

            var selected = data.Select(bd => bd.Value);
            // TODO: Check whether this should be in or out

            /*if (!selected.Any()) {
             *  return;
             * }*/
            var maxValue      = selected.Max();
            int maxLabelWidth = -1;

            for (int i = 0; i < data.Count; ++i)
            {
                var row = graphRoot.GetChild((uint)i);

                var label = row.GetChild(0) as Text;
                label.Value   = data[i].Label;
                maxLabelWidth = (int)Math.Max(label.GetRowWidth(0), maxLabelWidth);

                var bar = row.GetChild(1) as BorderImage;
                if (data[i].Color.HasValue)
                {
                    bar.SetColor(data[i].Color.Value);
                }
                else
                {
                    bar.SetColor(colorCycle[i % colorCycle.Length]);
                }
                bar.Size = new IntVector2((int)(MAX_BAR_WIDTH * (data[i].Value / maxValue)), HEIGHT);
            }

            if (maxLabelWidth != labelWidth)
            {
                labelWidth = maxLabelWidth;
                for (int i = 0; i < data.Count; ++i)
                {
                    var row   = graphRoot.GetChild((uint)i);
                    var label = row.GetChild(0) as Text;
                    var bar   = row.GetChild(1) as BorderImage;

                    label.Position = new IntVector2(labelWidth, i * HEIGHT);
                    label.Width    = labelWidth;
                    bar.Position   = new IntVector2(labelWidth + LABEL_GAP, i * HEIGHT);
                }
            }

            var billboard = billboards.GetBillboardSafe(0);

            billboard.Size    = new Vector2(0.001f * (MAX_BAR_WIDTH + labelWidth), 0.002f * (HEIGHT * data.Count));
            billboard.Enabled = true;
            billboards.Commit();
        }
Пример #11
0
        /// <summary>
        /// Returns the name of the UI Element
        /// </summary>
        /// <returns>Splash screen.</returns>
        /// <param name="GameInstance">Game instance.</param>
        public static string CreateSplashScreen(Game GameInstance, Node parent, bool randomLevel = false)
        {
            // Get data
            var data    = TrackManager.Instance.LoadingScreenFacts;
            var rnd     = new Random();
            var argIdx  = rnd.Next(0, data.LoadingScreens.Count);
            var arg     = data.LoadingScreens[argIdx];
            var factIdx = rnd.Next(0, arg.Facts.Count);
            var fact    = arg.Facts[factIdx];

            // get poster asset
            IntRect poster;

            switch (arg.Type)
            {
            case LoadingScreenType.CLI:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Climate;
                break;

            case LoadingScreenType.ENV:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Environment;
                break;

            case LoadingScreenType.RES:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Resources;
                break;

            case LoadingScreenType.WASTE:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Waste;
                break;

            case LoadingScreenType.WILD:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Wild;
                break;

            default:
                poster = AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Environment;
                break;
            }

            var splashscreen = new Window {
                Name                = "SplashUI",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(0), GameInstance.ScreenInfo.SetY(0)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(1920), GameInstance.ScreenInfo.SetY(1080)),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Texture             = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Backgrounds.FixedBackground.ResourcePath),
                ImageRect           = AssetsCoordinates.Backgrounds.FixedBackground.ImageRect,
                Priority            = 999
            };

            GameInstance.UI.Root.AddChild(splashscreen);

            // TOP BAR
            var topBar = new Sprite();

            splashscreen.AddChild(topBar);
            topBar.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.TopBar.ResourcePath);
            topBar.ImageRect = AssetsCoordinates.Generic.TopBar.Rectangle;
            topBar.Opacity   = 0.5f;
            topBar.SetPosition(GameInstance.ScreenInfo.SetX(0), GameInstance.ScreenInfo.SetY(30));
            topBar.SetSize(GameInstance.ScreenInfo.SetX(2000), GameInstance.ScreenInfo.SetY(120));

            Button screenTitle = new Button();

            //screenTitle.SetStyleAuto(null);
            screenTitle.HorizontalAlignment = HorizontalAlignment.Right;
            screenTitle.VerticalAlignment   = VerticalAlignment.Center;
            screenTitle.SetPosition(GameInstance.ScreenInfo.SetX(-150), GameInstance.ScreenInfo.SetY(0));
            screenTitle.SetSize(GameInstance.ScreenInfo.SetX(400), GameInstance.ScreenInfo.SetY(95));
            screenTitle.Texture           = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            screenTitle.ImageRect         = AssetsCoordinates.Generic.Boxes.BoxTitle;
            screenTitle.Enabled           = false;
            screenTitle.UseDerivedOpacity = false;
            topBar.AddChild(screenTitle);

            Text buttonTitleText = new Text();

            screenTitle.AddChild(buttonTitleText);
            buttonTitleText.SetAlignment(HorizontalAlignment.Left, VerticalAlignment.Center);
            buttonTitleText.SetPosition(GameInstance.ScreenInfo.SetX(20), GameInstance.ScreenInfo.SetY(0));
            buttonTitleText.SetFont(GameInstance.ResourceCache.GetFont(GameInstance.defaultFont), GameInstance.ScreenInfo.SetX(35));
            buttonTitleText.Value             = "LOADING";
            buttonTitleText.UseDerivedOpacity = false;

            BorderImage wheel = new BorderImage();

            screenTitle.AddChild(wheel);
            wheel.SetAlignment(HorizontalAlignment.Right, VerticalAlignment.Center);
            wheel.SetPosition(GameInstance.ScreenInfo.SetX(-15), GameInstance.ScreenInfo.SetY(0));
            wheel.SetSize(100, 100);
            wheel.Texture           = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            wheel.ImageRect         = AssetsCoordinates.Generic.Icons.LoadingWheel;
            wheel.UseDerivedOpacity = false;

            /*
             * ValueAnimation textAnimation = new ValueAnimation();
             * textAnimation.SetKeyFrame(0.0f, Color.Blue);
             * textAnimation.SetKeyFrame(1.0f, Color.Red);
             * textAnimation.SetKeyFrame(2.0f, Color.Green);
             *
             * Debug.WriteLine($"Name: {nameof(UIElement.Position)}");
             * buttonTitleText.SetAttributeAnimation(nameof(Color), textAnimation, WrapMode.Loop);
             *
             * ValueAnimation positionAnimation = new ValueAnimation {
             *  InterpolationMethod = InterpMethod.Spline
             * };
             * positionAnimation.SetKeyFrame(0.0f, new IntVector2(-25,0));
             * positionAnimation.SetKeyFrame(1.0f, new IntVector2(-35, 0));
             * positionAnimation.SetKeyFrame(2.0f, new IntVector2(-45, 0));
             * positionAnimation.SetKeyFrame(3.0f, new IntVector2(-55, 0));
             * positionAnimation.SetKeyFrame(4.0f, new IntVector2(-65, 0));
             *
             * wheel.SetAttributeAnimation(nameof(UIElement.Position), positionAnimation);
             * wheel.AnimationEnabled = true;
             * wheel.ApplyAttributes();
             */

            // BODY
            if (randomLevel)
            {
                var text = new Text();
                text.SetFont(GameInstance.ResourceCache.GetFont(GameInstance.defaultFont), 17);
                text.SetPosition(GameInstance.ScreenInfo.SetX(20), GameInstance.ScreenInfo.SetY(172));
                text.Value             = "*Coins and items collected in the random level are not saved.";
                text.UseDerivedOpacity = false;
                splashscreen.AddChild(text);
            }

            var posterImage = new Window {
                Name                = "PosterUI",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(200), GameInstance.ScreenInfo.SetY(50)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(500), GameInstance.ScreenInfo.SetY(636)),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Center,
                Texture             = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Backgrounds.LoadingScreen.Posters.Path),
                ImageRect           = poster
            };

            splashscreen.AddChild(posterImage);

            var textWindow = new Window {
                Name                = "splashScreenTextWindow",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(750), GameInstance.ScreenInfo.SetY(50)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(1000), GameInstance.ScreenInfo.SetY(636)),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Center
            };

            textWindow.SetColor(Color.Transparent);
            splashscreen.AddChild(textWindow);

            var titleBox = new Text {
                Name                = "splashScreenTitle",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(10), GameInstance.ScreenInfo.SetY(-20)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(1000), GameInstance.ScreenInfo.SetY(60)),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Wordwrap            = true
            };

            titleBox.SetFont(GameInstance.ResourceCache.GetFont(GameInstance.defaultFont), GameInstance.ScreenInfo.SetX(50));
            titleBox.Value = arg.Title;
            textWindow.AddChild(titleBox);

            var textBox = new Text {
                Name                = "splashScreenText",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(10), GameInstance.ScreenInfo.SetY(75)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(1000), GameInstance.ScreenInfo.SetY(350)),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Wordwrap            = true
            };

            textBox.SetFont(GameInstance.ResourceCache.GetFont(GameInstance.defaultFont), GameInstance.ScreenInfo.SetX(30));
            textBox.Value = fact.Message;
            textWindow.AddChild(textBox);

            var btnContinue = new Button {
                Texture             = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath),
                ImageRect           = AssetsCoordinates.Generic.Boxes.GroupSelected,
                Name                = "ButtonContinue",
                Position            = new IntVector2(GameInstance.ScreenInfo.SetX(0), GameInstance.ScreenInfo.SetY(0)),
                Size                = new IntVector2(GameInstance.ScreenInfo.SetX(400), GameInstance.ScreenInfo.SetY(95)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Bottom
            };

            btnContinue.Visible = false;
            textWindow.AddChild(btnContinue);

            Text btnContinueText = new Text();

            btnContinueText.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            btnContinueText.SetPosition(GameInstance.ScreenInfo.SetX(-10), GameInstance.ScreenInfo.SetY(0));
            btnContinueText.SetFont(GameInstance.ResourceCache.GetFont(GameInstance.defaultFont), GameInstance.ScreenInfo.SetX(35));
            btnContinueText.Value = "CONTINUE";
            btnContinue.AddChild(btnContinueText);

            return(splashscreen.Name);
        }
Пример #12
0
        void CreateDraggableFish()
        {
            var cache = ResourceCache;
            var graphics = Graphics;

            // Create a draggable Fish button
            draggableFish = new Button();
            draggableFish.Texture = cache.GetTexture2D("Textures/UrhoDecal.dds"); // Set texture
            draggableFish.BlendMode = BlendMode.Add;
            draggableFish.SetSize(128, 128);
            draggableFish.SetPosition((graphics.Width - draggableFish.Width)/2, 200);
            draggableFish.Name = "Fish";
            uiRoot.AddChild(draggableFish);

            // Add a tooltip to Fish button
            ToolTip toolTip = new ToolTip();
            draggableFish.AddChild(toolTip);
            toolTip.Position = new IntVector2(draggableFish.Width + 5, draggableFish.Width/2);
            // slightly offset from close button
            BorderImage textHolder = new BorderImage();
            toolTip.AddChild(textHolder);
            textHolder.SetStyle("ToolTipBorderImage", null);
            var toolTipText = new Text();
            textHolder.AddChild(toolTipText);
            toolTipText.SetStyle("ToolTipText", null);
            toolTipText.Value = "Please drag me!";

            // Subscribe draggableFish to Drag Events (in order to make it draggable)
            draggableFish.SubscribeToDragBegin(HandleDragBegin);
            draggableFish.SubscribeToDragMove(HandleDragMove);
            draggableFish.SubscribeToDragEnd(HandleDragEnd);
        }
Пример #13
0
        void CreateUpgradeBars()
        {
            var contBase = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Garage.ContBase.ResourcePath);

            // UPDGRADES
            _contUpgrade         = _root.CreateSprite();
            _contUpgrade.Texture = contBase;
            _contUpgrade.SetSize((int)(_dim.XScreenRatio * 1200), (int)(_dim.YScreenRatio * 300));
            _contUpgrade.SetPosition((int)(_dim.XScreenRatio * 0), (int)(_dim.YScreenRatio * 750));
            _contUpgrade.ImageRect = AssetsCoordinates.Generic.Garage.ContBase.TrasparentItem;

            _performanceBar = new BorderImage();
            _contUpgrade.AddChild(_performanceBar);
            _performanceBar.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            _performanceBar.ImageRect = AssetsCoordinates.Generic.Boxes.BoxPerformanceUpgrade;
            _performanceBar.SetSize((int)(_dim.XScreenRatio * 550), (int)(_dim.YScreenRatio * 95));
            _performanceBar.SetPosition((int)(_dim.XScreenRatio * 1000), (int)(_dim.YScreenRatio * 100));



            _suspensionsBar = new BorderImage();
            _contUpgrade.AddChild(_suspensionsBar);
            _suspensionsBar.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            _suspensionsBar.ImageRect = AssetsCoordinates.Generic.Boxes.BoxSuspensionUpgrade;
            _suspensionsBar.SetSize((int)(_dim.XScreenRatio * 550), (int)(_dim.YScreenRatio * 95));
            _suspensionsBar.SetPosition((int)(_dim.XScreenRatio * 1000), (int)(_dim.YScreenRatio * 200));

            _wheelBar = new BorderImage();
            _contUpgrade.AddChild(_wheelBar);
            _wheelBar.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            _wheelBar.ImageRect = AssetsCoordinates.Generic.Boxes.BoxWheelUpgrade;
            _wheelBar.SetSize((int)(_dim.XScreenRatio * 550), (int)(_dim.YScreenRatio * 95));
            _wheelBar.SetPosition((int)(_dim.XScreenRatio * 440), (int)(_dim.YScreenRatio * 100));

            _brakeBar = new BorderImage();
            _contUpgrade.AddChild(_brakeBar);
            _brakeBar.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            _brakeBar.ImageRect = AssetsCoordinates.Generic.Boxes.BoxBrakeUpgrade;
            _brakeBar.SetSize((int)(_dim.XScreenRatio * 550), (int)(_dim.YScreenRatio * 95));
            _brakeBar.SetPosition((int)(_dim.XScreenRatio * 440), (int)(_dim.YScreenRatio * 200));

            // COMPONENTS
            _contComponents         = _root.CreateSprite();
            _contComponents.Texture = contBase;
            _contComponents.SetSize(_dim.SetX(1920), _dim.SetY(300));
            _contComponents.SetPosition(_dim.SetX(0), _dim.SetY(720));
            _contComponents.ImageRect = new IntRect(0, 0, 56, 56);

            Body = new BorderImage();
            _contComponents.AddChild(Body);
            Body.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            Body.ImageRect = AssetsCoordinates.Generic.Boxes.ComponentBodyRed;
            Body.SetSize(_dim.SetX(150), _dim.SetY(150));
            Body.SetPosition(_dim.SetX(-300), _dim.SetY(150));
            Body.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Top);

            Engine = new BorderImage();
            _contComponents.AddChild(Engine);
            Engine.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            Engine.ImageRect = AssetsCoordinates.Generic.Boxes.ComponentEngineRed;
            Engine.SetSize(_dim.SetX(150), _dim.SetY(150));
            Engine.SetPosition(_dim.SetX(-130), _dim.SetY(150));
            Engine.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Top);

            Suspensions = new BorderImage();
            _contComponents.AddChild(Suspensions);
            Suspensions.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            Suspensions.ImageRect = AssetsCoordinates.Generic.Boxes.ComponentSuspensionRed;
            Suspensions.SetSize(_dim.SetX(150), _dim.SetY(150));
            Suspensions.SetPosition(_dim.SetX(130), _dim.SetY(150));
            Suspensions.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Top);

            Wheel = new BorderImage();
            _contComponents.AddChild(Wheel);
            Wheel.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Boxes.ResourcePath);
            Wheel.ImageRect = AssetsCoordinates.Generic.Boxes.ComponentWheelRed;
            Wheel.SetSize(_dim.SetX(150), _dim.SetY(150));
            Wheel.SetPosition(_dim.SetX(300), _dim.SetY(150));
            Wheel.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Top);


            // UPDGRADES
            _contUpgradeCost         = _root.CreateSprite();
            _contUpgradeCost.Texture = contBase;
            _contUpgradeCost.SetSize((int)(_dim.XScreenRatio * 1200), (int)(_dim.YScreenRatio * 300));
            _contUpgradeCost.SetPosition((int)(_dim.XScreenRatio * 0), (int)(_dim.YScreenRatio * 750));
            _contUpgradeCost.ImageRect = AssetsCoordinates.Generic.Garage.ContBase.TrasparentItem;

            _performanceCost = new BorderImage();
            _contUpgradeCost.AddChild(_performanceCost);
            _performanceCost.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            _performanceCost.ImageRect = AssetsCoordinates.Generic.Icons.UpgradeCost;
            _performanceCost.SetSize((int)(_dim.XScreenRatio * 90), (int)(_dim.YScreenRatio * 90));
            _performanceCost.SetPosition((int)(_dim.XScreenRatio * 1550), (int)(_dim.YScreenRatio * 100));

            _performanceUpBtn = new Button();
            _performanceCost.AddChild(_performanceUpBtn);
            _performanceUpBtn.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            _performanceUpBtn.ImageRect = AssetsCoordinates.Generic.Icons.UpgradeRight;
            _performanceUpBtn.SetSize((int)(_dim.XScreenRatio * 85), (int)(_dim.YScreenRatio * 90));
            _performanceUpBtn.SetPosition((int)(_dim.XScreenRatio * 100), (int)(_dim.YScreenRatio * 0));
            _performanceUpBtn.Pressed += args => {
                UpgradeComponent(0);
            };

            perCost = new Text();
            _performanceCost.AddChild(perCost);
            perCost.SetPosition((int)(_dim.XScreenRatio * 0), (int)(_dim.YScreenRatio * 0));
            perCost.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            perCost.SetFont(_font, _dim.XScreenRatio * 20);
            perCost.SetColor(Color.Black);

            _wheelCost = new BorderImage();
            _contUpgradeCost.AddChild(_wheelCost);
            _wheelCost.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            _wheelCost.ImageRect = AssetsCoordinates.Generic.Icons.UpgradeCost;
            _wheelCost.SetSize((int)(_dim.XScreenRatio * 90), (int)(_dim.YScreenRatio * 90));
            _wheelCost.SetPosition((int)(_dim.XScreenRatio * 345), (int)(_dim.YScreenRatio * 100));

            _wheelUpBtn = new Button();
            _wheelCost.AddChild(_wheelUpBtn);
            _wheelUpBtn.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            _wheelUpBtn.ImageRect = AssetsCoordinates.Generic.Icons.UpgradeLeft;
            _wheelUpBtn.SetSize((int)(_dim.XScreenRatio * 85), (int)(_dim.YScreenRatio * 90));
            _wheelUpBtn.SetPosition((int)(_dim.XScreenRatio * -100), (int)(_dim.YScreenRatio * 0));
            _wheelUpBtn.Pressed += args => {
                UpgradeComponent(1);
            };

            wheCost = new Text();
            _wheelCost.AddChild(wheCost);
            wheCost.SetPosition((int)(_dim.XScreenRatio * 0), (int)(_dim.YScreenRatio * 0));
            wheCost.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            wheCost.SetFont(_font, _dim.XScreenRatio * 20);
            wheCost.SetColor(Color.Black);

            _suspensionsCost = new BorderImage();
            _contUpgradeCost.AddChild(_suspensionsCost);
            _suspensionsCost.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            _suspensionsCost.ImageRect = AssetsCoordinates.Generic.Icons.UpgradeCost;
            _suspensionsCost.SetSize((int)(_dim.XScreenRatio * 90), (int)(_dim.YScreenRatio * 90));
            _suspensionsCost.SetPosition((int)(_dim.XScreenRatio * 1550), (int)(_dim.YScreenRatio * 200));

            _suspensionsUpBtn = new Button();
            _suspensionsCost.AddChild(_suspensionsUpBtn);
            _suspensionsUpBtn.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            _suspensionsUpBtn.ImageRect = AssetsCoordinates.Generic.Icons.UpgradeRight;
            _suspensionsUpBtn.SetSize((int)(_dim.XScreenRatio * 85), (int)(_dim.YScreenRatio * 90));
            _suspensionsUpBtn.SetPosition((int)(_dim.XScreenRatio * 100), (int)(_dim.YScreenRatio * 0));
            _suspensionsUpBtn.Pressed += args => {
                UpgradeComponent(2);
            };

            susCost = new Text();
            _suspensionsCost.AddChild(susCost);
            susCost.SetPosition((int)(_dim.XScreenRatio * 0), (int)(_dim.YScreenRatio * 0));
            susCost.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
            susCost.SetFont(_font, _dim.XScreenRatio * 20);
            susCost.SetColor(Color.Black);

            _brakeCost = new BorderImage();
            _contUpgradeCost.AddChild(_brakeCost);
            _brakeCost.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            _brakeCost.ImageRect = AssetsCoordinates.Generic.Icons.UpgradeCost;
            _brakeCost.SetSize((int)(_dim.XScreenRatio * 90), (int)(_dim.YScreenRatio * 90));
            _brakeCost.SetPosition((int)(_dim.XScreenRatio * 345), (int)(_dim.YScreenRatio * 200));

            _brakeUpBtn = new Button();
            _brakeCost.AddChild(_brakeUpBtn);
            _brakeUpBtn.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            _brakeUpBtn.ImageRect = AssetsCoordinates.Generic.Icons.UpgradeLeft;
            _brakeUpBtn.SetSize((int)(_dim.XScreenRatio * 85), (int)(_dim.YScreenRatio * 90));
            _brakeUpBtn.SetPosition((int)(_dim.XScreenRatio * -100), (int)(_dim.YScreenRatio * 0));
            _brakeUpBtn.Pressed += args => {
                UpgradeComponent(3);
            };

            SetUpgrade();
            SetCollectedComponents();
            GetCarImg();
        }
Пример #14
0
        void DefineCurrVehicle()
        {
            if (_selectedVehicle != null)
            {
                _selectedVehicle.Remove();
            }

            _selectedVehicle = new Button();
            _vehicleBar.AddChild(_selectedVehicle);
            _selectedVehicle.UseDerivedOpacity = false;
            _selectedVehicle.Texture           = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Garage.FullVehicles.ResourcePath);
            _currentVehicleModel = VehicleManager.Instance.GetVehicleFromId(_idDVehicle);
            _selectedVehicle.SetSize((int)(_dim.XScreenRatio * 600), (int)(_dim.YScreenRatio * 600));
            _selectedVehicle.SetPosition((int)(_dim.XScreenRatio * 650), (int)(_dim.YScreenRatio * -100));

            _selectedVehicle.Pressed += args => {
                if (VehicleManager.Instance.UnlockedVehicles.VehicleModel.Count == 0)
                {
                    if (_currentVehicleModel.UnlockCost == -1)
                    {
                        ConfirmationWindow(string.Format("You can't select this vehicle at this moment."), true);
                    }
                    else
                    {
                        // Unlock vehicle
                        VehicleManager.Instance.SelectedVehicleModel = VehicleManager.Instance.Vehicles.VehicleModel.First(v => v.IdVehicle == _idDVehicle);
                        VehicleManager.Instance.UnlockVehicle();

                        Debug.WriteLine("Unlocked vehicle " + _currentVehicleModel.IdVehicle);
                        ConfirmationWindow(string.Format("{0} unlocked!", _selectedVehicle.Name), false, true);
                    }
                }
                else if (!VehicleManager.Instance.UnlockedVehicles.VehicleModel.Exists(v => v.IdVehicle == _currentVehicleModel.IdVehicle))
                {
                    // If selected and vehicle needs to be unlocked, unlock vehicle without changing scene
                    if (_currentVehicleModel.UnlockCost != -1)
                    {
                        if (CharacterManager.Instance.Wallet >= _currentVehicleModel.UnlockCost)
                        {
                            CharacterManager.Instance.Wallet -= _currentVehicleModel.UnlockCost;
                            _wallet.Value = CharacterManager.Instance.Wallet.ToString();
                            // Unlock vehicle
                            VehicleManager.Instance.SelectedVehicleModel = VehicleManager.Instance.Vehicles.VehicleModel.First(v => v.IdVehicle == _idDVehicle);
                            VehicleManager.Instance.UnlockVehicle();

                            Debug.WriteLine("Unlocked vehicle " + _currentVehicleModel.IdVehicle);
                            ConfirmationWindow(string.Format("{0} unlocked!", _selectedVehicle.Name), false, true);
                        }
                        else
                        {
                            ConfirmationWindow(string.Format("Collect more coins to unlock this vehicle."), true);
                        }
                    }
                    else
                    {
                        var components = VehicleManager.Instance.CollectedComponentsForVehicle(_currentVehicleModel.IdVehicle).VehicleComponents;
                        if (components.Brakes && components.Performance && components.Suspensions && components.Wheels)
                        {
                            // Unlock vehicle
                            VehicleManager.Instance.SelectedVehicleModel = VehicleManager.Instance.Vehicles.VehicleModel.First(v => v.IdVehicle == _idDVehicle);
                            VehicleManager.Instance.UnlockVehicle();

                            Debug.WriteLine("Unlocked vehicle " + _currentVehicleModel.IdVehicle);
                            ConfirmationWindow(string.Format(_selectedVehicle.Name + "unlocked!"), false, true);
                        }
                        else
                        {
                            ConfirmationWindow(string.Format("Collect all four components to unlock this vehicle."), true);
                        }
                    }
                }
                else
                {
                    VehicleManager.Instance.SelectedVehicleModel = VehicleManager.Instance.Vehicles.VehicleModel.First(v => v.IdVehicle == _idDVehicle);
                    GameInstance.LaunchScene(GameScenesEnumeration.MENU);
                }
            };

            _carName = new Text();
            _selectedVehicle.AddChild(_carName);
            _carName.SetPosition(_dim.SetX(0), _dim.SetY(-80));
            _carName.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Bottom);
            _carName.SetFont(_font, _dim.SetX(40));

            _unlockCost = new Text();
            _selectedVehicle.AddChild(_unlockCost);
            _unlockCost.SetPosition(_dim.SetX(40), _dim.SetY(-30));
            _unlockCost.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Bottom);
            _unlockCost.SetFont(_font, _dim.SetX(30));
            _unlockCost.Visible = false;

            _coinIcon = new BorderImage();
            _selectedVehicle.AddChild(_coinIcon);
            _coinIcon.SetPosition(_dim.SetX(-50), _dim.SetY(-30));
            _coinIcon.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Bottom);
            _coinIcon.Visible = false;
            _coinIcon.SetSize(_dim.SetX(50), _dim.SetY(50));
            _coinIcon.Texture           = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            _coinIcon.ImageRect         = AssetsCoordinates.Generic.Icons.IconCoin;
            _coinIcon.UseDerivedOpacity = false;

            _lockedVehicle = new Sprite();
            _selectedVehicle.AddChild(_lockedVehicle);
            _lockedVehicle.SetPosition((int)(_dim.XScreenRatio * 630), (int)(_dim.YScreenRatio * 200));
            _lockedVehicle.Texture   = GameInstance.ResourceCache.GetTexture2D(AssetsCoordinates.Generic.Icons.ResourcePath);
            _lockedVehicle.ImageRect = AssetsCoordinates.Generic.Icons.IconLocked;
            _lockedVehicle.SetSize(_dim.SetX(100), _dim.SetY(100));
        }