Example #1
0
        public override void _Ready()
        {
            var button1 = GetNode <TextureButton>("Buttons/Control/Level1Button");

            button1.Connect("pressed", this, nameof(OnLevel1ButtonPressed));
            //button1.TextureHover = GetHighlightedTexture(button1.TextureNormal);
            button1.TexturePressed = new ImageTexture();

            var button2 = GetNode <TextureButton>("Buttons/Control/Level2Button");

            button2.Connect("pressed", this, nameof(OnLevel2ButtonPressed));
            //button2.TextureHover = GetHighlightedTexture(button2.TextureNormal);
            button2.TexturePressed = new ImageTexture();

            var button3 = GetNode <TextureButton>("Buttons/Control/Level3Button");

            button3.Connect("pressed", this, nameof(OnLevel3ButtonPressed));
            //button3.TextureHover = GetHighlightedTexture(button3.TextureNormal);
            button3.TexturePressed = new ImageTexture();

            _settingsWindow = GetNode <ConfirmationDialog>("SettingsWindow");

            _settingsWindow.Connect("confirmed", this, nameof(_on_SettingsWindow_confirmed));
            _settingsWindow.GetCancel().Connect("pressed", this, nameof(_on_SettingsWindow_canceled));
            _settingsWindow.GetCloseButton().Connect("pressed", this, nameof(_on_SettingsWindow_canceled));

            _settingsWindow.GetOk().Text = "Apply";
            _settingsWindow.GetLabel().AddFontOverride("font", Font);
            _settingsWindow.GetOk().AddFontOverride("font", Font);
            _settingsWindow.GetCancel().AddFontOverride("font", Font);
            _settingsWindow.GetCloseButton().AddFontOverride("font", Font);

            _resolutionsOption  = GetNode <OptionButton>("SettingsWindow/MarginContainer/GridContainer/ResolutionOptionButton");
            _displayModeOption  = GetNode <OptionButton>("SettingsWindow/MarginContainer/GridContainer/DisplayModeOptionButton");
            _masterVolumeSlider = GetNode <ValueSlider>("SettingsWindow/MarginContainer/GridContainer/MasterVolumeValueSlider");

            foreach (var res in ResolutionsNames)
            {
                _resolutionsOption.AddItem(res);
            }

            foreach (var mode in DisplayModesNames)
            {
                _displayModeOption.AddItem(mode);
            }

            _resolutionsOption.Selected = 1;
            _displayModeOption.Selected = 0;
            _masterVolumeSlider.Value   = 50;

            _settings = new Settings {
                Resolution = ResolutionsNames[1], DisplayMode = DisplayModesNames[0], MasterVolume = 50
            };

            var saveFile = new File();

            if (saveFile.FileExists(SettingsFileName))
            {
                saveFile.Open(SettingsFileName, File.ModeFlags.Read);
                _settings = JsonConvert.DeserializeObject <Settings>(saveFile.GetLine());
                saveFile.Close();

                _resolutionsOption.Selected = Array.IndexOf(ResolutionsNames, _settings.Resolution);
                _displayModeOption.Selected = Array.IndexOf(DisplayModesNames, _settings.DisplayMode);
                _masterVolumeSlider.Value   = _settings.MasterVolume;
            }

            ApplySettings();
        }