Пример #1
0
        public void AddGems(int count)
        {
            gems += count;

            attachedHud?.ShowGems(gems);

            PlaySound("PickupGem", 1f, MathF.Min(0.7f + gemsPitch * 0.05f, 1.3f));

            gemsTimer = 120f;
            gemsPitch++;
        }
Пример #2
0
        public void AddGems(int count)
        {
            gems += count;
#if !SERVER
            attachedHud?.ShowGems(gems);
#endif
            PlaySound("PickupGem", 1f, MathF.Min(0.7f + gemsPitch * 0.05f, 1.3f));

            gemsTimer = 120f;
            gemsPitch++;

#if MULTIPLAYER && SERVER
            ((LevelHandler)levelHandler).OnPlayerAddGems(this, count);
#endif
        }
Пример #3
0
        public bool AddFastFire(int count)
        {
            const int FastFireLimit = 9;

            int current = (weaponUpgrades[(int)WeaponType.Blaster] >> 1);

            if (current >= FastFireLimit)
            {
                return(false);
            }

            current = MathF.Min(current + count, FastFireLimit);

            weaponUpgrades[(int)WeaponType.Blaster] = (byte)((weaponUpgrades[(int)WeaponType.Blaster] & 0x1) | (current << 1));

            PlaySound("PickupAmmo");

#if MULTIPLAYER && SERVER
            ((LevelHandler)levelHandler).OnPlayerRefreshWeaponUpgrades(this, WeaponType.Blaster, weaponUpgrades[(int)WeaponType.Blaster]);
#endif
            return(true);
        }
Пример #4
0
        public override void OnUpdate()
        {
            if (animation < 1f)
            {
                animation = Math.Min(animation + Time.TimeMult * 0.016f, 1f);
            }

            if (ControlScheme.MenuActionHit(PlayerActions.Fire))
            {
                if (levelList.Count > 0)
                {
                    api.PlaySound("MenuSelect", 0.5f);
                    api.SwitchToSection(new StartGameOptionsSection(levelList[selectedIndex].EpisodeName, levelList[selectedIndex].LevelName, null));
                }
            }
            else if (ControlScheme.MenuActionHit(PlayerActions.Menu))
            {
                api.PlaySound("MenuSelect", 0.5f);
                api.LeaveSection(this);
            }

            if (levelList.Count > 1)
            {
                if (ControlScheme.MenuActionPressed(PlayerActions.Up))
                {
                    if (animation >= 1f - (pressedCount * 0.05f) || ControlScheme.MenuActionHit(PlayerActions.Up))
                    {
                        api.PlaySound("MenuSelect", 0.4f);
                        animation = 0f;
                        if (selectedIndex > 0)
                        {
                            selectedIndex--;
                            if (selectedIndex < scrollOffset)
                            {
                                scrollOffset = selectedIndex;
                            }
                        }
                        else
                        {
                            selectedIndex = levelList.Count - 1;
                            scrollOffset  = Math.Max(0, selectedIndex - (maxVisibleItems - 1));
                        }
                        pressedCount = Math.Min(pressedCount + 4, 19);
                    }
                }
                else if (ControlScheme.MenuActionPressed(PlayerActions.Down))
                {
                    if (animation >= 1f - (pressedCount * 0.05f) || ControlScheme.MenuActionHit(PlayerActions.Down))
                    {
                        api.PlaySound("MenuSelect", 0.4f);
                        animation = 0f;
                        if (selectedIndex < levelList.Count - 1)
                        {
                            selectedIndex++;
                            if (selectedIndex >= scrollOffset + maxVisibleItems)
                            {
                                scrollOffset = selectedIndex - (maxVisibleItems - 1);
                            }
                        }
                        else
                        {
                            selectedIndex = 0;
                            scrollOffset  = 0;
                        }
                        pressedCount = Math.Min(pressedCount + 4, 19);
                    }
                }
                else
                {
                    pressedCount = 0;
                }

                if (DualityApp.Keyboard.KeyHit(Key.PageUp))
                {
                    api.PlaySound("MenuSelect", 0.4f);
                    animation = 0f;

                    selectedIndex = MathF.Max(0, selectedIndex - maxVisibleItems);
                    if (selectedIndex < scrollOffset)
                    {
                        scrollOffset = selectedIndex;
                    }
                }
                else if (DualityApp.Keyboard.KeyHit(Key.PageDown))
                {
                    api.PlaySound("MenuSelect", 0.4f);
                    animation = 0f;

                    selectedIndex = MathF.Min(levelList.Count - 1, selectedIndex + maxVisibleItems);
                    if (selectedIndex >= scrollOffset + maxVisibleItems)
                    {
                        scrollOffset = selectedIndex - (maxVisibleItems - 1);
                    }
                }
            }
        }
Пример #5
0
        public override void OnDraw(Canvas canvas, ref Vector2 pos, bool focused, float animation)
        {
            int charOffset = 0;

            if (focused)
            {
                float size = 0.5f + Ease.OutElastic(animation) * 0.6f;

                api.DrawMaterial("MenuGlow", pos.X, pos.Y, Alignment.Center, ColorRgba.White.WithAlpha(0.4f * size), (title.Length + 3) * 0.5f * size, 4f * size);

                if (description != null)
                {
                    api.DrawMaterial("MenuGlow", pos.X, pos.Y + 20f, Alignment.Center, ColorRgba.White.WithAlpha(0.3f * MathF.Min(1f, animation * 6f)), (description.Length + 3) * 0.4f, 3f);

                    api.DrawString(ref charOffset, description, pos.X, pos.Y + 20f, Alignment.Center,
                                   new ColorRgba(0.44f, 0.42f, 0.4f, 0.5f), 0.7f);
                }

                api.DrawStringShadow(ref charOffset, title, pos.X, pos.Y,
                                     Alignment.Center, null, size, 0.7f, 1.1f, 1.1f, charSpacing: 0.9f);
            }
            else if (!enabled)
            {
                api.DrawString(ref charOffset, title, pos.X, pos.Y, Alignment.Center,
                               new ColorRgba(0.4f, 0.3f), 0.9f);
            }
            else
            {
                api.DrawString(ref charOffset, description, pos.X, pos.Y + 20f, Alignment.Center,
                               new ColorRgba(0.44f, 0.42f, 0.4f, 0.5f), 0.7f);

                api.DrawString(ref charOffset, title, pos.X, pos.Y, Alignment.Center,
                               ColorRgba.TransparentBlack, 0.9f);
            }

            if (description != null)
            {
                pos.Y += 55f;
            }
            else
            {
                pos.Y += 40f;
            }
        }
Пример #6
0
        public override void OnPaint(Canvas canvas, Rect view)
        {
            IDrawDevice device = canvas.DrawDevice;

            Vector2 center = device.TargetSize * 0.5f;

            const float topLine    = 131f;
            float       bottomLine = device.TargetSize.Y - 42;

            api.DrawMaterial("MenuDim", center.X, (topLine + bottomLine) * 0.5f, Alignment.Center, ColorRgba.White, 55f, (bottomLine - topLine) * 0.063f, new Rect(0f, 0.3f, 1f, 0.4f));

            api.DrawMaterial("MenuLine", 0, center.X, topLine, Alignment.Center, ColorRgba.White, 1.6f);
            api.DrawMaterial("MenuLine", 1, center.X, bottomLine, Alignment.Center, ColorRgba.White, 1.6f);

            int charOffset = 0;

            api.DrawStringShadow(ref charOffset, "menu/play story/title".T(), center.X, 110f,
                                 Alignment.Center, new ColorRgba(0.5f, 0.5f), 0.9f, 0.4f, 0.6f, 0.6f, 8f, charSpacing: 0.88f);

            if (episodes.Count > 0)
            {
                float topItem       = topLine - 5f;
                float bottomItem    = bottomLine + 5f;
                float contentHeight = bottomItem - topItem;
                float itemSpacing   = contentHeight / (episodes.Count + 1);

                topItem += itemSpacing;
                float topItemSelected = 0f;

                for (int i = 0; i < episodes.Count; i++)
                {
                    if (selectedIndex == i)
                    {
                        topItemSelected = topItem;
                    }
                    else
                    {
                        if (episodes[i].IsAvailable)
                        {
                            api.DrawString(ref charOffset, episodes[i].Episode.Name, center.X, topItem,
                                           Alignment.Center, ColorRgba.TransparentBlack, 0.9f);
                        }
                        else
                        {
                            api.DrawString(ref charOffset, episodes[i].Episode.Name, center.X, topItem,
                                           Alignment.Center, new ColorRgba(0.4f, 0.4f), 0.9f);
                        }
                    }

                    topItem += itemSpacing;
                }

                // Selected item last
                float expandedAnimation2 = Math.Min(expandedAnimation * 6f, 1f);
                float expandedAnimation3 = (expandedAnimation2 * expandedAnimation2 * (3.0f - 2.0f * expandedAnimation2));

                float size = 0.5f + Ease.OutElastic(selectAnimation) * 0.5f + (1f - expandedAnimation3) * 0.2f;

                if (episodes[selectedIndex].IsAvailable)
                {
                    if (episodes[selectedIndex].Logo.IsAvailable)
                    {
                        api.DrawString(ref charOffset, episodes[selectedIndex].Episode.Name, center.X, topItemSelected,
                                       Alignment.Center, new ColorRgba(0.44f, 0.5f * MathF.Max(0f, 1f - selectAnimation * 2f)), 0.9f - selectAnimation * 0.5f);

                        ContentRef <Material> logo = episodes[selectedIndex].Logo;
                        Texture texture            = logo.Res.MainTexture.Res;

                        Vector2 originPos = new Vector2(center.X, topItemSelected);
                        Vector2 logoSize  = new Vector2(texture.InternalWidth * size, texture.InternalHeight * size);
                        Alignment.Center.ApplyTo(ref originPos, logoSize);

                        ColorRgba logoColor = ColorRgba.White.WithAlpha(1f - expandedAnimation3 * 0.5f);

                        canvas.State.SetMaterial(logo);
                        canvas.State.ColorTint = logoColor;
                        canvas.FillRect(originPos.X, originPos.Y, texture.InternalWidth * size, texture.InternalHeight * size);

                        if (episodes[selectedIndex].IsComplete)
                        {
                            api.DrawMaterial("EpisodeComplete", originPos.X + logoSize.X * 0.7f, originPos.Y + logoSize.Y * 0.4f, Alignment.TopLeft, logoColor, size, size);
                        }

                        if (episodes[selectedIndex].CanContinue)
                        {
                            float moveX = expandedAnimation3 * -24f;

                            api.DrawString(ref charOffset, ">", center.X + 80f + moveX, topItemSelected,
                                           Alignment.Right, new ColorRgba(0.5f, 0.5f * MathF.Min(1f, 0.4f + selectAnimation)), 0.8f, charSpacing: 0.9f);

                            if (expanded)
                            {
                                float expandedAnimation4 = Ease.OutElastic(expandedAnimation) * 0.8f;

                                api.DrawStringShadow(ref charOffset, "menu/play story/restart".T(), center.X + 110f, topItemSelected,
                                                     Alignment.Center, new ColorRgba(0.62f, 0.44f, 0.34f, 0.5f * MathF.Min(1f, 0.4f + expandedAnimation3)), expandedAnimation4, 0.4f, 0.6f, 0.6f, 8f, charSpacing: 0.8f);
                            }
                        }
                    }
                    else
                    {
                        api.DrawStringShadow(ref charOffset, episodes[selectedIndex].Episode.Name, center.X, topItemSelected,
                                             Alignment.Center, null, size, charSpacing: 0.9f);
                    }
                }
                else
                {
                    api.DrawString(ref charOffset, episodes[selectedIndex].Episode.Name, center.X, topItemSelected,
                                   Alignment.Center, new ColorRgba(0.4f, MathF.Max(0.3f, 0.4f - selectAnimation * 0.4f)), MathF.Max(0.7f, 0.9f - selectAnimation * 0.6f));

                    int     index = episodes.IndexOfFirst(entry => entry.Episode.Token == episodes[selectedIndex].Episode.PreviousEpisode);
                    Episode previousEpisode;
                    if (index == -1)
                    {
                        previousEpisode = null;
                    }
                    else
                    {
                        previousEpisode = episodes[index].Episode;
                    }

                    string info;
                    if (previousEpisode == null)
                    {
                        info = "menu/play story/locked".T();
                    }
                    else
                    {
                        info = "menu/play story/locked prev".T(previousEpisode.Name);
                    }

                    api.DrawStringShadow(ref charOffset, info, center.X, topItemSelected,
                                         Alignment.Center, new ColorRgba(0.66f, 0.42f, 0.32f, MathF.Min(0.5f, 0.2f + 2f * selectAnimation)), 0.7f * size, charSpacing: 0.9f);
                }
            }
            else
            {
                api.DrawStringShadow(ref charOffset, "menu/play story/empty".T(), center.X, center.Y, Alignment.Center,
                                     new ColorRgba(0.62f, 0.44f, 0.34f, 0.5f), 0.9f, 0.4f, 0.6f, 0.6f, 8f, charSpacing: 0.88f);
            }
        }