Пример #1
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 TestBindableFloat()
        {
            float lastUpdated = 0.0f;
            var   bindable    = new BindableFloat();

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

            Assert.AreEqual(float.MinValue, bindable.MinValue, FloatDelta);
            Assert.AreEqual(float.MaxValue, bindable.MaxValue, FloatDelta);
            Assert.AreEqual(0.0, bindable.Value, FloatDelta);

            bindable.MinValue = 1.0f;
            Assert.AreEqual(1.0f, bindable.MinValue, FloatDelta);
            Assert.AreEqual(1.0f, bindable.Value, FloatDelta);
            Assert.AreEqual(1.0f, lastUpdated, FloatDelta);

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

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

            Assert.AreEqual(-100.0f, bindable.MinValue, FloatDelta);
            Assert.AreEqual(100.0f, bindable.MaxValue, FloatDelta);
            Assert.AreEqual(5.0f, bindable.Value, FloatDelta);

            bindable.MaxValue = -1;
            Assert.AreEqual(-1.0f, bindable.MaxValue, FloatDelta);
            Assert.AreEqual(-1.0f, bindable.Value, FloatDelta);
            Assert.AreEqual(-1.0f, lastUpdated, FloatDelta);
        }
        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;
        }
Пример #4
0
 public SplashInfoOverlay(SplashPosition position, float minHeight, float fontSize)
 {
     this.minHeight = minHeight;
     this.fontSize  = fontSize;
     this.position  = position;
     targetHeight   = new BindableFloat(minHeight);
 }
Пример #5
0
        public void TestRestoreDefaultValueButtonPrecision(float initialValue)
        {
            BindableFloat                     current   = null;
            SettingsSlider <float>            sliderBar = null;
            RestoreDefaultValueButton <float> restoreDefaultValueButton = null;

            AddStep("create settings item", () =>
            {
                Child = sliderBar = new SettingsSlider <float>
                {
                    Current = current = new BindableFloat(initialValue)
                    {
                        MinValue  = 0f,
                        MaxValue  = 10f,
                        Precision = 0.1f,
                    }
                };
            });
            AddUntilStep("wait for loaded", () => sliderBar.IsLoaded);
            AddStep("retrieve restore default button", () => restoreDefaultValueButton = sliderBar.ChildrenOfType <RestoreDefaultValueButton <float> >().Single());

            AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0);

            AddStep("change value to next closest", () => sliderBar.Current.Value += current.Precision * 0.6f);
            AddUntilStep("restore button shown", () => restoreDefaultValueButton.Alpha > 0);

            AddStep("restore default", () => sliderBar.Current.SetDefault());
            AddUntilStep("restore button hidden", () => restoreDefaultValueButton.Alpha == 0);
        }
        public void TestParsingFloat(float value)
        {
            var bindable = new BindableFloat();

            bindable.Parse(value);

            Assert.AreEqual(value, bindable.Value);
        }
        public void TestParsingString(string value, float expected)
        {
            var bindable = new BindableFloat();

            bindable.Parse(value);

            Assert.AreEqual(expected, bindable.Value);
        }
        public void TestSet(float value)
        {
            var bindable = new BindableFloat {
                Value = value
            };

            Assert.AreEqual(value, bindable.Value);
        }
Пример #9
0
        public void TestValueChanging()
        {
            var bf1 = new BindableFloat(15, 0, 100, BindableActionHandler);

            Assert.AreEqual(bf1.Value, 15);
            Assert.AreEqual(bf1.MinValue, 0);
            Assert.AreEqual(bf1.MaxValue, 100);
        }
Пример #10
0
 public Page()
 {
     Speed = new BindableFloat {
         MinValue = 0.1f, MaxValue = 4f
     };
     Zoom = new BindableFloat {
         MinValue = 0.6f, MaxValue = 8f
     };
 }
        public void TestParsingStringWithRange(string value, float minValue, float maxValue, float expected)
        {
            var bindable = new BindableFloat {
                MinValue = minValue, MaxValue = maxValue
            };

            bindable.Parse(value);

            Assert.AreEqual(expected, bindable.Value);
        }
Пример #12
0
        public void TestDefaultCheck(float value, float def, float precision)
        {
            var bindable = new BindableFloat {
                Value = def, Default = def, Precision = precision
            };

            Assert.IsTrue(bindable.IsDefault);

            bindable.Value = value;
            Assert.IsFalse(bindable.IsDefault);
        }
        public void TestDefaultCheck(float value, float def, float?precision = null)
        {
            var bindable = new BindableFloat {
                Value = def, Default = def
            };

            if (precision.HasValue)
            {
                bindable.Precision = precision.Value;
            }

            Assert.IsTrue(bindable.IsDefault);

            bindable.Value = value;
            Assert.IsFalse(bindable.IsDefault);
        }
        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);
            }
        }
Пример #15
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();
        }
Пример #16
0
        void load(DrawableEditor editor)
        {
            _editor = editor;

            _fontSize = editor.FontSize.GetBoundCopy() as BindableFloat;
            _fontSize.BindValueChanged(s => Scheduler.AddOnce(() =>
            {
                Size = new Vector2(3, s);
                ResetFlicker();
            }));

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

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

            // This updates the caret
            _fontSize.TriggerChange();
        }
        public void TestEntryFloat()
        {
            BindableFloat data = new BindableFloat(1, -10, 10);

            SettingsEntryFloat floatEntry = new SettingsEntryFloat("test-float", data);

            Assert.AreEqual("test-float", floatEntry.Name);
            Assert.AreEqual(data.Value, floatEntry.Value);
            Assert.AreEqual(data.MaxValue, floatEntry.MaxValue);
            Assert.AreEqual(data.MinValue, floatEntry.MinValue);

            data.MinValue = -11;
            data.MaxValue = 11;
            Assert.AreEqual(-11, floatEntry.MinValue);
            Assert.AreEqual(11, floatEntry.MaxValue);

            data.Value = 8;
            Assert.AreEqual(8, floatEntry.Value);

            floatEntry.Value = 10;
            Assert.AreEqual(10, floatEntry.Value);
            Assert.AreEqual(10, data.Value);
        }
Пример #18
0
 public healthIndicatorCircle(BindableFloat Health)
 {
     health.BindTo(Health);
 }
Пример #19
0
        public static void OnTick()
        {
            if (started && EndTime < DateTimeOffset.Now)
            {
                started = false;
                if (!EmodjiVote)
                {
                    string text     = "Голосование окончено: ";
                    int    allVotes = 0;
                    SortedDictionary <int, int> votesCount = new SortedDictionary <int, int> {
                    };
                    foreach (var it in StandartVotes)
                    {
                        if (votesCount.ContainsKey(it.Value))
                        {
                            votesCount[it.Value]++;
                            allVotes++;
                        }
                        else
                        {
                            votesCount.Add(it.Value, 1);
                            allVotes++;
                        }
                    }

                    foreach (var it in votesCount)
                    {
                        var perc = new BindableFloat(((float)it.Value / (float)allVotes) * 100)
                        {
                            Precision = 0.01f, Value = (float)((float)it.Value / (float)allVotes) * 100
                        };
                        text += $"{StandartVariants[it.Key]}: {it.Value} <{perc.Value}> ";
                    }

                    if (text == "Голосование окончено: ")
                    {
                        StartChannel.SendMessage("Никто не проголосовал");
                    }
                    else
                    {
                        StartChannel.SendMessage(text);
                    }
                }
                else
                {
                    string text     = "Голосование окончено: ";
                    int    allVotes = 0;
                    SortedDictionary <string, int> votesCount = new SortedDictionary <string, int> {
                    };
                    foreach (var it in EmojiVotes)
                    {
                        if (votesCount.ContainsKey(it.Value))
                        {
                            votesCount[it.Value]++;
                            allVotes++;
                        }
                        else
                        {
                            votesCount.Add(it.Value, 1);
                            allVotes++;
                        }
                    }

                    foreach (var it in votesCount)
                    {
                        var perc = new BindableFloat(((float)it.Value / (float)allVotes) * 100)
                        {
                            Precision = 0.01f, Value = (float)((float)it.Value / (float)allVotes) * 100
                        };
                        try
                        {
                            text += $"[ {it.Key} {EmojiVariants[it.Key]}: {it.Value} <{perc.Value}>] ";
                        }
                        catch (Exception e)
                        {
                        }
                    }

                    if (text != "Голосование окончено: ")
                    {
                        StartChannel.SendMessage($"{text}");
                    }
                    else
                    {
                        StartChannel.SendMessage($"Никто не голосовал");
                    }
                }
            }
        }
Пример #20
0
 public HelpContainer(float minHeight)
 {
     this.minHeight = minHeight;
     targetHeight   = new BindableFloat(minHeight);
 }