예제 #1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            // Only keep 1 "new" empty preset
            int existingPresetIndex = Program.Presets.FindIndex(v => v.Name == "New");

            if (existingPresetIndex != -1)
            {
                comboBoxPreset.SelectedIndex = existingPresetIndex;
                return;
            }

            Program.Preset newPreset = new Program.Preset
            {
                Name      = "New",
                AppId     = "",
                Details   = "",
                State     = "",
                LargeKey  = "",
                LargeText = "",
                SmallKey  = "",
                SmallText = ""
            };

            Program.Presets.Add(newPreset);

            comboBoxPreset.Items.Add("New");
            comboBoxPreset.SelectedIndex = comboBoxPreset.Items.Count - 1;
        }
예제 #2
0
        private void comboBoxApp_SelectedIndexChanged(object sender, EventArgs e)
        {
            //await Task.Delay(2000);

            // Clear fields
            comboBoxImageLarge.Items.Clear();
            comboBoxImageLarge.Items.Add("(None)");
            comboBoxImageLarge.SelectedIndex = 0;

            comboBoxImageSmall.Items.Clear();
            comboBoxImageSmall.Items.Add("(None)");
            comboBoxImageSmall.SelectedIndex = 0;

            pictureBoxApp.ImageLocation = null;


            if (comboBoxApp.SelectedIndex == -1)
            {
                return;
            }


            Program.DiscordApplication app = Program.Applications.Find(v => v.Name == (string)comboBoxApp.SelectedItem);

            if (app.Icon != "")
            {
                pictureBoxApp.ImageLocation = Path.Combine(Program.appIconsPath, app.Id + app.Icon);
            }


            // Load app assets
            foreach (Program.Asset asset in app.Assets)
            {
                comboBoxImageLarge.Items.Add(asset.Name);
                comboBoxImageSmall.Items.Add(asset.Name);
            }


            // Reload preset when needed
            if (loadAppPreset)
            {
                loadAppPreset = false;

                Program.Preset preset = Program.Presets.Find(v => v.Name == (string)comboBoxPreset.SelectedItem);

                comboBoxImageLarge.SelectedIndex = comboBoxImageLarge.Items.IndexOf(preset.LargeKey);
                textBoxImageLarge.Text           = preset.LargeText;
                comboBoxImageSmall.SelectedIndex = comboBoxImageSmall.Items.IndexOf(preset.SmallKey);
                textBoxImageSmall.Text           = preset.SmallText;
            }
        }
예제 #3
0
        private void ReloadCurrentPreset()
        {
            int index = comboBoxPreset.SelectedIndex;

            Program.Preset             preset = Program.Presets.Find(v => v.Name == (string)comboBoxPreset.SelectedItem);
            Program.DiscordApplication app    = Program.Applications.Find(v => v.Id == preset.AppId);

            textBoxName.Text = preset.Name;

            textBoxDetails.Text = preset.Details;
            textBoxState.Text   = preset.State;

            loadAppPreset             = true;
            comboBoxApp.SelectedIndex = comboBoxApp.Items.IndexOf(app?.Name ?? ""); // app = null!

            comboBoxImageLarge.SelectedIndex = comboBoxImageLarge.Items.IndexOf(preset.LargeKey);
            textBoxImageLarge.Text           = preset.LargeText;
            comboBoxImageSmall.SelectedIndex = comboBoxImageSmall.Items.IndexOf(preset.SmallKey);
            textBoxImageSmall.Text           = preset.SmallText;

            if (app != null)
            {
                /*int appIndex = comboBoxApp.Items.IndexOf(app.Name);
                 * comboBoxApp.SelectedIndex = appIndex;*/

                /*if (appIndex != -1 && app.Icon != "")
                 *  pictureBoxApp.ImageLocation = Path.Combine(Program.appIconsPath, app.Id + app.Icon);
                 * else
                 *  pictureBoxApp.ImageLocation = null;*/
            }

            else
            {
                //comboBoxApp.SelectedIndex = -1;
                //comboBoxImageLarge.SelectedIndex = 0;
                //comboBoxImageSmall.SelectedIndex = 0;

                /*pictureBoxApp.ImageLocation = null;
                 * pictureBoxImageLarge.ImageLocation = null;
                 * pictureBoxImageSmall.ImageLocation = null;*/
            }
        }
예제 #4
0
        private void buttonArrowDown_Click(object sender, EventArgs e)
        {
            if (comboBoxPreset.SelectedIndex + 2 > comboBoxPreset.Items.Count)
            {
                return;
            }

            int index = comboBoxPreset.SelectedIndex;

            Program.Preset belowPreset    = Program.Presets[index + 1];
            Program.Preset currentPresent = Program.Presets[index];

            Program.Presets[index + 1] = currentPresent;
            Program.Presets[index]     = belowPreset;

            comboBoxPreset.Items[index + 1] = currentPresent.Name;
            comboBoxPreset.Items[index]     = belowPreset.Name;

            comboBoxPreset.SelectedIndex = index + 1;

            Program.SaveData();
        }
예제 #5
0
        private void buttonArrowUp_Click(object sender, EventArgs e)
        {
            if (comboBoxPreset.SelectedIndex < 1)
            {
                return;
            }

            int index = comboBoxPreset.SelectedIndex;

            Program.Preset abovePreset   = Program.Presets[index - 1];
            Program.Preset currentPreset = Program.Presets[index];

            Program.Presets[index - 1] = currentPreset;
            Program.Presets[index]     = abovePreset;

            comboBoxPreset.Items[index - 1] = currentPreset.Name;
            comboBoxPreset.Items[index]     = abovePreset.Name;

            comboBoxPreset.SelectedIndex = index - 1;

            Program.SaveData();
        }
예제 #6
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            // Update preset
            Program.Preset preset = new Program.Preset
            {
                Name      = textBoxName.Text,
                AppId     = Program.Applications.Find(v => v.Name == (string)comboBoxApp.SelectedItem)?.Id ?? "",
                Details   = textBoxDetails.Text,
                State     = textBoxState.Text,
                LargeKey  = comboBoxImageLarge.SelectedIndex > 0 ? (string)comboBoxImageLarge.SelectedItem : "",
                LargeText = textBoxImageLarge.Text,
                SmallKey  = comboBoxImageSmall.SelectedIndex > 0 ? (string)comboBoxImageSmall.SelectedItem : "",
                SmallText = textBoxImageSmall.Text
            };


            if (preset.Name == "")
            {
                MessageBox.Show(null, "Preset name cannot be empty.", "Discord RPC Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (preset.AppId == "")
            {
                MessageBox.Show(null, "Preset must have a valid Application.", "Discord RPC Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            else
            {
                int index = Program.Presets.FindIndex(v => v.Name == (string)comboBoxPreset.SelectedItem);

                Program.Presets[index] = preset;
                comboBoxPreset.Items[comboBoxPreset.SelectedIndex] = preset.Name;
                Program.SaveData();
            }
        }
예제 #7
0
        private void buttonRemove_Click(object sender, EventArgs e)
        {
            if (comboBoxPreset.Items.Count < 1)
            {
                return;
            }

            int index = comboBoxPreset.SelectedIndex;

            Program.Preset preset = Program.Presets.Find(v => v.Name == (string)comboBoxPreset.SelectedItem);
            Program.Presets.Remove(preset);
            comboBoxPreset.Items.RemoveAt(index);

            // Add default preset
            if (comboBoxPreset.Items.Count < 1)
            {
                buttonAdd_Click(sender, e);
            }

            else
            {
                comboBoxPreset.SelectedIndex = index == 0 ? 0 : index - 1;
            }
        }