Exemplo n.º 1
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <param name="dialog"></param>
        /// <param name="name"></param>
        /// <param name="bindable"></param>
        public SettingsSlider(SettingsDialog dialog, string name, BindableInt bindable) : base(dialog, name)
        {
            Bindable = bindable;
            bindable.ValueChanged += OnValueChanged;

            Value = new SpriteText(Fonts.Exo2Medium, $"{bindable.Value.ToString()}", 13)
            {
                Parent    = this,
                Alignment = Alignment.MidRight,
                X         = -30,
                UsePreviousSpriteBatchOptions = true
            };

            var slider = new Slider(bindable, Vector2.One, FontAwesome.Get(FontAwesomeIcon.fa_circle))
            {
                Parent    = this,
                Alignment = Alignment.MidRight,
                X         = -90,
                UsePreviousSpriteBatchOptions = true,
                Width        = 350,
                Height       = 2,
                ProgressBall =
                {
                    UsePreviousSpriteBatchOptions = true
                }
            };
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        /// <summary>
        ///     Creates a new SliderButton. Takes in a BindableInt as an argument.
        /// </summary>
        /// <param name="binded"></param>
        /// <param name="size"></param>
        /// <param name="progressBall"></param>
        /// <param name="vertical"></param>
        public Slider(BindableInt binded, Vector2 size, Texture2D progressBall, bool vertical = false)
        {
            BindedValue = binded;
            IsVertical  = vertical;

            Width  = size.X;
            Height = size.Y;
            Tint   = Color.White;

            ActiveColor = new Sprite()
            {
                Parent = this,
                Size   = Size,
                Tint   = Color.White
            };

            // Create the progress sliding thing.
            ProgressBall = new Sprite()
            {
                Alignment = IsVertical ? Alignment.TopCenter : Alignment.MidLeft,
                Image     = progressBall,
                Size      = ProgressBallSize,
                Tint      = Color.White,
                Parent    = this
            };

            // Whenever the value changes, we need to update the slider accordingly,
            // so hook onto this event with a handler.
            BindedValue.ValueChanged += OnValueChanged;
        }
        private SettingsTab CreateTabData(string name, string iconName)
        {
            BindableFloat bindableFloat = new BindableFloat(10f, -1, 20f);
            bindableFloat.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableFloat)} value: {val}");

            Bindable<string> bindableString = new Bindable<string>("My Text");
            bindableString.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableString)} value: {val}");

            BindableInt bindableInt = new BindableInt(-10, -20, 0);
            bindableInt.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableInt)} value: {val}");

            Bindable<TestType> bindableEnum = new Bindable<TestType>(TestType.TypeB);
            bindableEnum.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableEnum)} value: {val}");

            BindableBool bindableBool = new BindableBool(false);
            bindableBool.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableBool)} value: {val}");

            BindableBool bindableBool2 = new BindableBool(true);
            bindableBool2.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableBool2)} value: {val}");

            var tabData = new SettingsTab(name, iconName);
            tabData.AddEntry(new SettingsEntryFloat(nameof(bindableFloat), bindableFloat));
            tabData.AddEntry(new SettingsEntryString(nameof(bindableString), bindableString));
            tabData.AddEntry(new SettingsEntryInt(nameof(bindableInt), bindableInt));
            tabData.AddEntry(new SettingsEntryAction("Do action!", () => Debug.Log("Performed action")));
            tabData.AddEntry(new SettingsEntryEnum<TestType>(nameof(bindableEnum), bindableEnum));
            tabData.AddEntry(new SettingsEntryBool(nameof(bindableBool), bindableBool));
            tabData.AddEntry(new SettingsEntryBool(nameof(bindableBool2), bindableBool2));

            return tabData;
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <param name="dialog"></param>
        /// <param name="name"></param>
        /// <param name="bindable"></param>
        public SettingsSlider(SettingsDialog dialog, string name, BindableInt bindable, Func <int, string> display = null) : base(dialog, name)
        {
            Display  = display ?? (x => x.ToString());
            Bindable = bindable;
            bindable.ValueChanged += OnValueChanged;

            Value = new SpriteText(Fonts.Exo2Medium, Display(bindable.Value), 13)
            {
                Parent    = this,
                Alignment = Alignment.MidRight,
                X         = -30,
                UsePreviousSpriteBatchOptions = true
            };

            var slider = new Slider(bindable, Vector2.One, FontAwesome.Get(FontAwesomeIcon.fa_circle))
            {
                Parent    = this,
                Alignment = Alignment.MidRight,
                X         = -110,
                UsePreviousSpriteBatchOptions = true,
                Width        = 330,
                Height       = 2,
                ProgressBall =
                {
                    UsePreviousSpriteBatchOptions = true
                }
            };
        }
Exemplo n.º 5
0
        private void Init()
        {
            if (isUsingActualConfig)
            {
                // Load configurations
                GameConfiguration.Load();
                settingsData = GameConfiguration.Settings;
            }
            else
            {
                settingsData = new SettingsData();
                var a = settingsData.AddTabData(new SettingsTab("A", "icon-arrow-left"));
                a.AddEntry(new SettingsEntryBool("a-a", testDataAA            = new BindableBool(false)));
                a.AddEntry(new SettingsEntryBool("a-b", testDataAB            = new BindableBool(true)));
                a.AddEntry(new SettingsEntryEnum <TestType>("a-c", testDataAC = new Bindable <TestType>(TestType.TypeB)));

                var b = settingsData.AddTabData(new SettingsTab("B", "icon-backward"));
                b.AddEntry(new SettingsEntryFloat("b-a", testDataBA = new BindableFloat(0f, -10f, 10f)));
                b.AddEntry(new SettingsEntryFloat("b-b", testDataBB = new BindableFloat(5f, 10f, 20f)));
                b.AddEntry(new SettingsEntryInt("b-c", testDataBC   = new BindableInt(0, -20, 5)));
            }

            // Create nav bar.
            navBar = RootMain.CreateChild <NavBar>("nav-bar");
            {
                navBar.Size = new Vector2(64f, 400f);
                navBar.SetSettingsData(settingsData);
            }
        }
        public void TestMaxValueChangedWithUpstreamRejection()
        {
            BindableInt bindable1 = new BindableInt(1337); // Won't change
            BindableInt bindable2 = new BindableInt();

            bindable2.BindTo(bindable1);

            int changed1 = 0, changed2 = 0;

            bindable1.MaxValueChanged += v => changed1++;
            bindable2.MaxValueChanged += _ =>
            {
                bindable2.MaxValue = 1337;
                changed2++;
            };

            bindable1.MaxValue = 2;

            Assert.AreEqual(1337, bindable1.MaxValue);
            Assert.AreEqual(bindable1.MaxValue, bindable2.MaxValue);

            // bindable1 should only receive the final value changed, skipping the intermediary (overidden) one.
            Assert.AreEqual(1, changed1);
            Assert.AreEqual(2, changed2);
        }
        public void TestBindableInt()
        {
            int lastUpdated = 0;
            var bindable    = new BindableInt();

            bindable.OnValueChanged += (v, _) => lastUpdated = v;

            Assert.AreEqual(int.MinValue, bindable.MinValue);
            Assert.AreEqual(int.MaxValue, bindable.MaxValue);
            Assert.AreEqual(0, bindable.Value);

            bindable.MinValue = 1;
            Assert.AreEqual(1, bindable.MinValue);
            Assert.AreEqual(1, bindable.Value);
            Assert.AreEqual(1, lastUpdated);

            bindable.Value = 2;
            Assert.AreEqual(2, bindable.Value);
            Assert.AreEqual(2, lastUpdated);

            bindable = new BindableInt(5, -100, 100);
            bindable.OnValueChanged += (v, _) => lastUpdated = v;

            Assert.AreEqual(-100, bindable.MinValue);
            Assert.AreEqual(100, bindable.MaxValue);
            Assert.AreEqual(5, bindable.Value);

            bindable.MaxValue = -1;
            Assert.AreEqual(-1, bindable.MaxValue);
            Assert.AreEqual(-1, bindable.Value);
            Assert.AreEqual(-1, lastUpdated);
        }
Exemplo n.º 8
0
        public void TestSet(int value)
        {
            var bindable = new BindableInt {
                Value = value
            };

            Assert.AreEqual(value, bindable.Value);
        }
Exemplo n.º 9
0
        public void TestParsingInt(int value)
        {
            var bindable = new BindableInt();

            bindable.Parse(value);

            Assert.AreEqual(value, bindable.Value);
        }
Exemplo n.º 10
0
        public SettingsSliderAudioBufferLength(SettingsDialog dialog, string name, BindableInt bindable,
                                               BindableInt devicePeriod, Func <int, int, string> display) : base(dialog, name, bindable, x => display(x, devicePeriod.Value))
        {
            DevicePeriod = devicePeriod;
            Display      = display;

            DevicePeriod.ValueChanged += OnDevicePeriodChanged;
        }
Exemplo n.º 11
0
        public void TestParsingString(string value, int expected)
        {
            var bindable = new BindableInt();

            bindable.Parse(value);

            Assert.AreEqual(expected, bindable.Value);
        }
Exemplo n.º 12
0
        public void TestValueUpdatedOnMinValueChange()
        {
            var bindable = new BindableInt(2)
            {
                MinValue = 3
            };

            Assert.That(bindable.Value, Is.EqualTo(3));
        }
Exemplo n.º 13
0
        public void TestValueUpdatedOnPrecisionChange()
        {
            var bindable = new BindableInt(2)
            {
                Precision = 3
            };

            Assert.That(bindable.Value, Is.EqualTo(3));
        }
Exemplo n.º 14
0
 protected ScoreManager(IClock clock)
 {
     this.clock = clock;
     Score      = new BindableInt {
         MinValue = 0
     };
     Combo = new BindableInt {
         MinValue = 0
     };
 }
Exemplo n.º 15
0
        public void TestParsingStringWithRange(string value, int minValue, int maxValue, int expected)
        {
            var bindable = new BindableInt {
                MinValue = minValue, MaxValue = maxValue
            };

            bindable.Parse(value);

            Assert.AreEqual(expected, bindable.Value);
        }
Exemplo n.º 16
0
        public void TestIntFromDerivedType()
        {
            var toSerialize = new BindableInt {
                Value = 1337
            };

            var deserialized = JsonConvert.DeserializeObject <Bindable <int> >(JsonConvert.SerializeObject(toSerialize));

            Assert.AreEqual(toSerialize.Value, deserialized.Value);
        }
Exemplo n.º 17
0
        public void ApplyToDrawableRuleset(DrawableRuleset <SentakkiHitObject> drawableRuleset)
        {
            int maxLives = (int)LiveSetting.Value;

            LivesLeft = new BindableInt()
            {
                Value    = maxLives,
                MaxValue = maxLives,
            };

            (drawableRuleset.Playfield as SentakkiPlayfield).AccentContainer.Add(new LiveCounter(LivesLeft));
        }
Exemplo n.º 18
0
        public override void Reset()
        {
            base.Reset();

            KeyCounterCollection kc = new KeyCounterCollection
            {
                Origin     = Anchor.Centre,
                Anchor     = Anchor.Centre,
                IsCounting = true,
                Children   = new KeyCounter[]
                {
                    new KeyCounterKeyboard(Key.Z),
                    new KeyCounterKeyboard(Key.X),
                    new KeyCounterMouse(MouseButton.Left),
                    new KeyCounterMouse(MouseButton.Right),
                },
            };
            BindableInt bindable = new BindableInt {
                MinValue = 0, MaxValue = 200, Default = 50
            };

            bindable.ValueChanged += delegate { kc.FadeTime = bindable.Value; };
            AddStep("Add Random", () =>
            {
                Key key = (Key)((int)Key.A + RNG.Next(26));
                kc.Add(new KeyCounterKeyboard(key));
            });

            TestSliderBar <int> sliderBar;

            Add(new Container
            {
                Anchor       = Anchor.TopRight,
                Origin       = Anchor.TopRight,
                AutoSizeAxes = Axes.Both,
                Children     = new Drawable[]
                {
                    new SpriteText {
                        Text = "FadeTime"
                    },
                    sliderBar = new TestSliderBar <int>
                    {
                        Width          = 150,
                        Height         = 10,
                        SelectionColor = Color4.Orange,
                    }
                }
            });

            sliderBar.Current.BindTo(bindable);

            Add(kc);
        }
Exemplo n.º 19
0
        public LiveCounter(BindableInt livesBindable)
        {
            LivesLeft.BindTo(livesBindable);
            Anchor = Anchor.Centre;
            Origin = Anchor.Centre;

            InternalChild = livesText = new LiveRollingCounter();

            LivesLeft.BindValueChanged(v =>
            {
                this.FadeColour(Color4.Red, 160).Then().FadeColour(Color4.White, 320);
                Shake();
            }, true);
        }
Exemplo n.º 20
0
        internal VolumeControl(BindableInt volume, string text, Vector2 pos, Vector2 textOffset, float scale, bool active, EventHandler onReceivedHover, EventHandler renewVisibleTime) : base(GameBase.Instance)
        {
            Visible = false;

            this.volume = volume;

            volume.ValueChanged += renewVisibleTime;

            receivedHover         += onReceivedHover;
            this.renewVisibleTime += renewVisibleTime;
            Scale = scale;

            background             = new pSprite(TextureManager.Load(@"volume-circle-bg", SkinSource.Osu), Fields.BottomRight, Origins.Centre, Clocks.Game, pos, 0.968f, true, colourInactive);
            background.HandleInput = true;
            background.OnHover    += background_OnHover;
            background.OnClick    += Background_OnClick;
            spriteManager.Add(background);

            backgroundMax = new pSprite(TextureManager.Load(@"volume-circle-bg-max", SkinSource.Osu), Fields.BottomRight, Origins.Centre, Clocks.Game, pos, 0.97f, true, Color.TransparentWhite);
            spriteManager.Add(backgroundMax);

            spriteManager.Add(progress = new CircularProgressBar()
            {
                Radius    = 50,
                LineWidth = 8,
                Depth     = 0.971f
            });

            percentageDisplay = new pText(string.Empty, 14, pos, 0.991f, true, Color.White)
            {
                Field  = Fields.BottomRight,
                Origin = Origins.Centre
            };
            spriteManagerFg.Add(percentageDisplay);

            pText textSprite = new pText(text, 12, new Vector2(pos.X + 36 * scale, pos.Y) - textOffset, 0.991f, true, Color.White)
            {
                Field  = Fields.BottomRight,
                Origin = Origins.CentreRight
            };

            spriteManagerText.Add(textSprite);

            spriteManagerFg.SpriteList.ForEach(s => s.Alpha   = 0);
            spriteManager.SpriteList.ForEach(s => s.Alpha     = 0);
            spriteManagerText.SpriteList.ForEach(s => s.Alpha = 0);

            Active = active;
        }
Exemplo n.º 21
0
        public TestSceneTotalCommentsCounter()
        {
            var count = new BindableInt();

            Add(new TotalCommentsCounter
            {
                Anchor  = Anchor.Centre,
                Origin  = Anchor.Centre,
                Current = { BindTarget = count }
            });

            AddStep(@"Set 100", () => count.Value    = 100);
            AddStep(@"Set 0", () => count.Value      = 0);
            AddStep(@"Set random", () => count.Value = RNG.Next(0, int.MaxValue));
        }
Exemplo n.º 22
0
        public void TestSetValueWithoutTrigger()
        {
            BindableInt bindableInt  = new BindableInt(0);
            int         updatedValue = bindableInt.Value;

            bindableInt.OnNewValue += (val) => updatedValue = val;

            bindableInt.Value = 1;
            Assert.AreEqual(1, bindableInt.Value);
            Assert.AreEqual(bindableInt.Value, updatedValue);

            bindableInt.SetWithoutTrigger(5);
            Assert.AreEqual(5, bindableInt.Value);
            Assert.AreEqual(1, updatedValue);
        }
Exemplo n.º 23
0
        public void TestParseBindableOfMatchingInterfaceType()
        {
            // both of these implement IBindable<int>
            var bindable1 = new BindableInt(10)
            {
                MaxValue = 15
            };
            var bindable2 = new Bindable <int>(20);

            bindable1.Parse(bindable2);
            // ensure MaxValue is still respected.
            Assert.That(bindable1.Value, Is.EqualTo(15));

            bindable2.Parse(bindable1);
            Assert.That(bindable2.Value, Is.EqualTo(15));
        }
Exemplo n.º 24
0
        /// <summary>
        ///     Reads an Int32 to a BindableInt
        /// </summary>
        /// <param name="name"></param>
        /// <param name="defaultVal"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="ini"></param>
        /// <returns></returns>
        private static BindableInt ReadInt(string name, int defaultVal, int min, int max, KeyDataCollection ini)
        {
            var binded = new BindableInt(name, defaultVal, min, max);

            // Try to read the int.
            try
            {
                binded.Value = int.Parse(ini[name]);
            }
            catch (Exception e)
            {
                binded.Value = defaultVal;
            }

            return(binded);
        }
        private void Init()
        {
            BindableFloat bindableFloat = new BindableFloat(10f, -1, 20f);

            bindableFloat.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableFloat)} value: {val}");

            Bindable <string> bindableString = new Bindable <string>("My Text");

            bindableString.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableString)} value: {val}");

            BindableInt bindableInt = new BindableInt(-10, -20, 0);

            bindableInt.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableInt)} value: {val}");

            Bindable <TestType> bindableEnum = new Bindable <TestType>(TestType.TypeB);

            bindableEnum.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableEnum)} value: {val}");

            BindableBool bindableBool = new BindableBool(false);

            bindableBool.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableBool)} value: {val}");

            BindableBool bindableBool2 = new BindableBool(true);

            bindableBool2.OnValueChanged += (val, _) => Debug.Log($"{nameof(bindableBool2)} value: {val}");

            tabData = new SettingsTab("A", "icon-arrow-left");
            tabData.AddEntry(new SettingsEntryFloat(nameof(bindableFloat), bindableFloat));
            tabData.AddEntry(new SettingsEntryString(nameof(bindableString), bindableString));
            tabData.AddEntry(new SettingsEntryInt(nameof(bindableInt), bindableInt));
            tabData.AddEntry(new SettingsEntryEnum <TestType>(nameof(bindableEnum), bindableEnum));
            tabData.AddEntry(new SettingsEntryBool(nameof(bindableBool), bindableBool));
            tabData.AddEntry(new SettingsEntryBool(nameof(bindableBool2), bindableBool2));

            var bg = RootMain.CreateChild <UguiSprite>("bg", -1);

            {
                bg.Size  = new Vector2(600f, 600f);
                bg.Alpha = 0.5f;
            }
            contentGroup = RootMain.CreateChild <ContentGroup>();
            {
                contentGroup.Width = 400f;
                contentGroup.SetTabData(tabData);
            }
        }
Exemplo n.º 26
0
        public void TestSerializeBindableInt()
        {
            BindableInt original = new BindableInt(100);

            original.OnValueChanged += (_, __) => { };
            string jsonStr = JToken.FromObject(original).ToString();

            Debug.Log(jsonStr);

            BindableInt reconstructed = JsonConvert.DeserializeObject <BindableInt>(jsonStr);

            Assert.AreEqual(original.Value, reconstructed.Value);
            Assert.AreEqual(original.MaxValue, reconstructed.MaxValue);
            Assert.AreEqual(original.MinValue, reconstructed.MinValue);
            Assert.AreEqual(original.TriggerWhenDifferent, reconstructed.TriggerWhenDifferent);
            Assert.AreEqual(original.RawValue, reconstructed.RawValue);
        }
Exemplo n.º 27
0
        void load(DrawableEditor editor)
        {
            _editor = editor;

            _fontSize = editor.FontSize.GetBoundCopy() as BindableFloat;
            _fontSize.BindValueChanged(s => Scheduler.AddOnce(ResetFlicker));

            _lineNumberWidth = editor.LineNumberWidth.GetBoundCopy() as BindableInt;
            _lineNumberWidth.BindValueChanged(w => Scheduler.AddOnce(ResetFlicker));

            _selectionStart = _selection.Start.GetBoundCopy() as BindableInt;
            _selectionStart.BindValueChanged(i => Scheduler.AddOnce(ResetFlicker));

            _selectionEnd = _selection.End.GetBoundCopy() as BindableInt;
            _selectionEnd.BindValueChanged(i => Scheduler.AddOnce(ResetFlicker));

            _selectionEnd.TriggerChange();
        }
        public override void Reset()
        {
            base.Reset();

            iterationsBindable = new BindableInt(2000)
            {
                MinValue = 50,
                MaxValue = 20000,
            };

            SliderBar <int> iterations;

            Add(iterations = new BasicSliderBar <int>
            {
                Size           = new Vector2(200, 20),
                SelectionColor = Color4.Pink,
                KeyboardStep   = 100
            });

            Add(iterationsText = new SpriteText
            {
                X        = 210,
                TextSize = 16
            });

            iterations.Current.BindTo(iterationsBindable);
            iterations.Current.ValueChanged += v => Invalidate(Invalidation.DrawNode, shallPropagate: false);

            Add(scroll = new ScrollContainer
            {
                RelativeSizeAxes = Axes.Both,
                Y        = 25,
                Children = new[]
                {
                    flow = new FillFlowContainer <SpriteText>
                    {
                        AutoSizeAxes = Axes.Both,
                        Direction    = FillDirection.Vertical
                    }
                }
            });
        }
Exemplo n.º 29
0
        public void TestParseBindableOfExactSameType()
        {
            var bindable1 = new BindableInt();
            var bindable2 = new BindableDouble();
            var bindable3 = new BindableBool();
            var bindable4 = new Bindable <string>();

            bindable1.Parse(new BindableInt(3));
            bindable2.Parse(new BindableDouble(2.5));
            bindable3.Parse(new BindableBool(true));
            bindable4.Parse(new Bindable <string>("string value"));

            Assert.That(bindable1.Value, Is.EqualTo(3));
            Assert.That(bindable2.Value, Is.EqualTo(2.5));
            Assert.That(bindable3.Value, Is.EqualTo(true));
            Assert.That(bindable4.Value, Is.EqualTo("string value"));

            // parsing bindable of different type should throw exception.
            Assert.Throws <ArgumentException>(() => bindable1.Parse(new BindableDouble(3.0)));
        }
Exemplo n.º 30
0
        public void TestValueChangeEventOccursAfterPrecisionChangeEvent()
        {
            var bindable1 = new BindableInt(2);
            var bindable2 = new BindableInt {
                BindTarget = bindable1
            };
            int counter = 0, bindable1ValueChange = 0, bindable1PrecisionChange = 0, bindable2ValueChange = 0, bindable2PrecisionChange = 0;

            bindable1.ValueChanged     += _ => bindable1ValueChange = ++counter;
            bindable1.PrecisionChanged += _ => bindable1PrecisionChange = ++counter;
            bindable2.ValueChanged     += _ => bindable2ValueChange = ++counter;
            bindable2.PrecisionChanged += _ => bindable2PrecisionChange = ++counter;

            bindable1.Precision = 3;

            Assert.That(bindable2PrecisionChange, Is.EqualTo(1));
            Assert.That(bindable1PrecisionChange, Is.EqualTo(2));
            Assert.That(bindable2ValueChange, Is.EqualTo(3));
            Assert.That(bindable1ValueChange, Is.EqualTo(4));
        }