Search in sources :

Example 1 with EmojiLoadingDisplayStragegy

use of com.glitchcog.fontificator.config.EmojiLoadingDisplayStragegy in project ChatGameFontificator by GlitchCog.

the class ControlPanelEmoji method build.

@Override
protected void build() {
    enableAll = new JCheckBox("Enable Emoji");
    enableAnimation = new JCheckBox("Enable Animation");
    enableTwitchBadges = new JCheckBox("Enable Twitch Badges");
    enableFfzBadges = new JCheckBox("Enable FrankerFaceZ Badges");
    progressPanel = new EmojiLoadProgressPanel(chat, this);
    emojiScaleToLineHeight = new JCheckBox("Relative to Line Height");
    emojiScale = new LabeledSlider("Emoji Scale", "%", ConfigEmoji.MIN_SCALE, ConfigEmoji.MAX_SCALE, 100, 3);
    badgeScaleToLineHeight = new JCheckBox("Relative to Line Height");
    badgeScale = new LabeledSlider("Badge Scale", "%", ConfigEmoji.MIN_SCALE, ConfigEmoji.MAX_SCALE, 100, 3);
    badgeHeightOffset = new LabeledSlider("Badge Height Offset", "pixels", ConfigEmoji.MIN_BADGE_OFFSET, ConfigEmoji.MAX_BADGE_OFFSET, 0, 3);
    emojiLoadingDisplayStratLabel = new JLabel("Emoji Loading Display Strategy:");
    emojiLoadingDisplayStrat = new JComboBox<EmojiLoadingDisplayStragegy>(EmojiLoadingDisplayStragegy.values());
    enableTwitch = new JCheckBox("Enable Twitch Emotes");
    cacheTwitch = new JCheckBox("Cache Global Twitch Emotes");
    enableFrankerFaceZ = new JCheckBox("Enable FrankerFaceZ Emotes");
    cacheFrankerFaceZ = new JCheckBox("Cache FrankerFaceZ Emotes");
    enableBetterTtv = new JCheckBox("Enable BetterTTV Emotes");
    cacheBetterTtv = new JCheckBox("Cache BetterTTV Emotes");
    emojiScale.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            config.setEmojiScale(emojiScale.getValue());
            chat.repaint();
        }
    });
    badgeScale.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            config.setBadgeScale(badgeScale.getValue());
            chat.repaint();
        }
    });
    badgeHeightOffset.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            config.setBadgeHeightOffset(badgeHeightOffset.getValue());
            chat.repaint();
        }
    });
    emojiLoadingDisplayStrat.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            config.setDisplayStrategy((EmojiLoadingDisplayStragegy) emojiLoadingDisplayStrat.getSelectedItem());
            chat.repaint();
        }
    });
    // This action listener is for loading emotes and badges whenever a checkbox is checked while connected
    ActionListener cbal = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox source = (JCheckBox) e.getSource();
            if (bot.isConnected()) {
                Set<EmojiJob> jobsToRun = new HashSet<EmojiJob>();
                Set<EmojiJob> jobsToCancel = new HashSet<EmojiJob>();
                final boolean clickAll = enableAll.equals(source);
                final boolean clickFfzLoad = clickAll || enableFrankerFaceZ.equals(source);
                final boolean clickFfzCache = clickAll || cacheFrankerFaceZ.equals(source);
                final boolean clickBttvLoad = clickAll || enableBetterTtv.equals(source);
                final boolean clickBttvCache = clickAll || cacheBetterTtv.equals(source);
                // Badges is independent of enableAll
                final boolean clickTwitchBadges = !config.isTwitchBadgesLoaded(getConnectChannel()) && enableTwitchBadges.equals(source);
                final boolean clickFfzBadges = !config.isFfzBadgesLoaded(getConnectChannel()) && enableFfzBadges.equals(source);
                final String oauth = fProps.getProperty(FontificatorProperties.KEY_IRC_AUTH);
                if (clickFfzLoad && !config.isFfzLoaded(getConnectChannel())) {
                    EmojiJob jobA = new EmojiJob(oauth, EmojiType.FRANKERFACEZ_CHANNEL, EmojiOperation.LOAD, getConnectChannel());
                    EmojiJob jobB = new EmojiJob(oauth, EmojiType.FRANKERFACEZ_GLOBAL, EmojiOperation.LOAD);
                    if (enableAll.isSelected() && enableFrankerFaceZ.isSelected()) {
                        jobsToRun.add(jobA);
                        jobsToRun.add(jobB);
                    } else {
                        jobsToCancel.add(jobA);
                        jobsToCancel.add(jobB);
                    }
                }
                if (clickBttvLoad && !config.isBttvLoaded(getConnectChannel())) {
                    EmojiJob jobA = new EmojiJob(oauth, EmojiType.BETTER_TTV_CHANNEL, EmojiOperation.LOAD, getConnectChannel());
                    EmojiJob jobB = new EmojiJob(oauth, EmojiType.BETTER_TTV_GLOBAL, EmojiOperation.LOAD);
                    if (enableAll.isSelected() && enableBetterTtv.isSelected()) {
                        jobsToRun.add(jobA);
                        jobsToRun.add(jobB);
                    } else {
                        jobsToCancel.add(jobA);
                        jobsToCancel.add(jobB);
                    }
                }
                if (clickFfzCache && !config.isFfzCached()) {
                    EmojiJob jobA = new EmojiJob(oauth, EmojiType.FRANKERFACEZ_CHANNEL, EmojiOperation.CACHE);
                    EmojiJob jobB = new EmojiJob(oauth, EmojiType.FRANKERFACEZ_GLOBAL, EmojiOperation.CACHE);
                    if (enableAll.isSelected() && cacheFrankerFaceZ.isSelected()) {
                        jobsToRun.add(jobA);
                        jobsToRun.add(jobB);
                    } else {
                        jobsToCancel.add(jobA);
                        jobsToCancel.add(jobB);
                    }
                }
                if (clickBttvCache && !config.isBttvCached()) {
                    EmojiJob jobA = new EmojiJob(oauth, EmojiType.BETTER_TTV_CHANNEL, EmojiOperation.CACHE);
                    EmojiJob jobB = new EmojiJob(oauth, EmojiType.BETTER_TTV_GLOBAL, EmojiOperation.CACHE);
                    if (enableAll.isSelected() && cacheBetterTtv.isSelected()) {
                        jobsToRun.add(jobA);
                        jobsToRun.add(jobB);
                    } else {
                        jobsToCancel.add(jobA);
                        jobsToCancel.add(jobB);
                    }
                }
                if (clickTwitchBadges && !config.isTwitchBadgesLoaded(getConnectChannel())) {
                    EmojiJob job = new EmojiJob(oauth, EmojiType.TWITCH_BADGE, EmojiOperation.LOAD, getConnectChannel());
                    // No check for enable all here, because badges are independent of the emoji enableAll toggle
                    if (enableTwitchBadges.isSelected()) {
                        jobsToRun.add(job);
                    } else {
                        jobsToCancel.add(job);
                    }
                }
                if (clickFfzBadges && !config.isFfzBadgesLoaded(getConnectChannel())) {
                    EmojiJob job = new EmojiJob(oauth, EmojiType.FRANKERFACEZ_BADGE, EmojiOperation.LOAD, getConnectChannel());
                    // No check for enable all here, because badges are independent of the emoji enableAll toggle
                    if (enableFfzBadges.isSelected()) {
                        jobsToRun.add(job);
                    } else {
                        jobsToCancel.add(job);
                    }
                }
                loadEmojiWork(jobsToRun);
                cancelEmojiWork(jobsToCancel);
                if (!jobsToRun.isEmpty() && !progressPanel.isCurrentlyRunning()) {
                    runEmojiWork();
                }
            }
            // These are only the checkboxes handled in fillConfigFromInput()
            config.setEmojiEnabled(enableAll.isSelected());
            config.setAnimationEnabled(enableAnimation.isSelected());
            config.setTwitchBadgesEnabled(enableTwitchBadges.isSelected());
            config.setFfzBadgesEnabled(enableFfzBadges.isSelected());
            config.setTwitchEnabled(enableTwitch.isSelected());
            config.setTwitchCacheEnabled(cacheTwitch.isSelected());
            config.setFfzEnabled(enableFrankerFaceZ.isSelected());
            config.setFfzCacheEnabled(cacheFrankerFaceZ.isSelected());
            config.setBttvEnabled(enableBetterTtv.isSelected());
            config.setBttvCacheEnabled(cacheBetterTtv.isSelected());
            config.setEmojiScaleToLine(emojiScaleToLineHeight.isSelected());
            config.setBadgeScaleToLine(badgeScaleToLineHeight.isSelected());
            resolveEnables();
            chat.repaint();
        }
    };
    enableAll.addActionListener(cbal);
    enableAnimation.addActionListener(cbal);
    enableTwitchBadges.addActionListener(cbal);
    enableFfzBadges.addActionListener(cbal);
    emojiScaleToLineHeight.addActionListener(cbal);
    badgeScaleToLineHeight.addActionListener(cbal);
    enableTwitch.addActionListener(cbal);
    cacheTwitch.addActionListener(cbal);
    enableFrankerFaceZ.addActionListener(cbal);
    cacheFrankerFaceZ.addActionListener(cbal);
    enableBetterTtv.addActionListener(cbal);
    cacheBetterTtv.addActionListener(cbal);
    // Top row containing emoji toggle, animation, and badge toggles
    JPanel allEnabledPanel = new JPanel(new GridBagLayout());
    GridBagConstraints allGbc = getGbc();
    allGbc.weighty = 1.0;
    allGbc.fill = GridBagConstraints.NONE;
    allGbc.anchor = GridBagConstraints.WEST;
    allGbc.weightx = 0.25;
    allEnabledPanel.add(enableAll, allGbc);
    allGbc.gridx++;
    allEnabledPanel.add(enableAnimation, allGbc);
    allGbc.gridx++;
    allGbc.anchor = GridBagConstraints.EAST;
    allEnabledPanel.add(enableTwitchBadges, allGbc);
    allGbc.gridx++;
    allEnabledPanel.add(enableFfzBadges, allGbc);
    allGbc.gridx++;
    scaleAndDisplayPanel = new JPanel(new GridBagLayout());
    scaleAndDisplayPanel.setBorder(baseBorder);
    GridBagConstraints scaleAndDisplayGbc = getGbc();
    // Emoji scaling
    scaleAndDisplayGbc.anchor = GridBagConstraints.CENTER;
    scaleAndDisplayGbc.fill = GridBagConstraints.HORIZONTAL;
    scaleAndDisplayGbc.weightx = 1.0;
    scaleAndDisplayPanel.add(emojiScale, scaleAndDisplayGbc);
    scaleAndDisplayGbc.gridx++;
    scaleAndDisplayGbc.fill = GridBagConstraints.NONE;
    scaleAndDisplayGbc.weightx = 0.0;
    scaleAndDisplayPanel.add(emojiScaleToLineHeight, scaleAndDisplayGbc);
    scaleAndDisplayGbc.gridx = 0;
    scaleAndDisplayGbc.gridy++;
    // Badge scaling
    scaleAndDisplayGbc.anchor = GridBagConstraints.CENTER;
    scaleAndDisplayGbc.fill = GridBagConstraints.HORIZONTAL;
    scaleAndDisplayGbc.weightx = 1.0;
    scaleAndDisplayPanel.add(badgeScale, scaleAndDisplayGbc);
    scaleAndDisplayGbc.gridx++;
    scaleAndDisplayGbc.fill = GridBagConstraints.NONE;
    scaleAndDisplayGbc.weightx = 0.0;
    scaleAndDisplayPanel.add(badgeScaleToLineHeight, scaleAndDisplayGbc);
    scaleAndDisplayGbc.gridx = 0;
    scaleAndDisplayGbc.gridy++;
    scaleAndDisplayGbc.fill = GridBagConstraints.HORIZONTAL;
    scaleAndDisplayGbc.gridwidth = 2;
    scaleAndDisplayPanel.add(badgeHeightOffset, scaleAndDisplayGbc);
    scaleAndDisplayGbc.gridy++;
    scaleAndDisplayGbc.gridwidth = 2;
    scaleAndDisplayGbc.weightx = 1.0;
    scaleAndDisplayGbc.fill = GridBagConstraints.HORIZONTAL;
    scaleAndDisplayPanel.add(new JSeparator(SwingConstants.HORIZONTAL), scaleAndDisplayGbc);
    scaleAndDisplayGbc.gridy++;
    JPanel bottomOfScaleDisplayPanel = new JPanel();
    bottomOfScaleDisplayPanel.add(emojiLoadingDisplayStratLabel);
    bottomOfScaleDisplayPanel.add(emojiLoadingDisplayStrat);
    scaleAndDisplayPanel.add(bottomOfScaleDisplayPanel, scaleAndDisplayGbc);
    twitchPanel = new JPanel(new GridBagLayout());
    twitchPanel.setBorder(BorderFactory.createTitledBorder(baseBorder, "Twitch Emotes"));
    GridBagConstraints twitchGbc = getGbc();
    twitchPanel.add(enableTwitch, twitchGbc);
    twitchGbc.gridy++;
    twitchPanel.add(cacheTwitch, twitchGbc);
    twitchGbc.gridy++;
    frankerPanel = new JPanel(new GridBagLayout());
    frankerPanel.setBorder(BorderFactory.createTitledBorder(baseBorder, "FrankerFaceZ Emotes"));
    GridBagConstraints frankerGbc = getGbc();
    frankerPanel.add(enableFrankerFaceZ, frankerGbc);
    frankerGbc.gridy++;
    frankerPanel.add(cacheFrankerFaceZ, frankerGbc);
    frankerGbc.gridy++;
    betterPanel = new JPanel(new GridBagLayout());
    betterPanel.setBorder(BorderFactory.createTitledBorder(baseBorder, "BetterTTV Emotes"));
    GridBagConstraints betterGbc = getGbc();
    betterPanel.add(enableBetterTtv, betterGbc);
    betterGbc.gridy++;
    betterPanel.add(cacheBetterTtv, betterGbc);
    betterGbc.gridy++;
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.gridwidth = 3;
    add(allEnabledPanel, gbc);
    gbc.gridy++;
    gbc.gridwidth = 1;
    add(twitchPanel, gbc);
    gbc.gridx++;
    add(frankerPanel, gbc);
    gbc.gridx++;
    add(betterPanel, gbc);
    gbc.gridx++;
    gbc.gridx = 0;
    gbc.gridy++;
    gbc.gridwidth = 3;
    add(scaleAndDisplayPanel, gbc);
    gbc.gridy++;
    gbc.gridy++;
    gbc.anchor = GridBagConstraints.SOUTH;
    gbc.weighty = 1.0;
    gbc.weightx = 1.0;
    gbc.gridwidth = 3;
    gbc.fill = GridBagConstraints.BOTH;
    add(progressPanel, gbc);
    gbc.gridy++;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JSeparator(javax.swing.JSeparator) JCheckBox(javax.swing.JCheckBox) LabeledSlider(com.glitchcog.fontificator.gui.component.LabeledSlider) EmojiLoadProgressPanel(com.glitchcog.fontificator.gui.emoji.EmojiLoadProgressPanel) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) EmojiLoadingDisplayStragegy(com.glitchcog.fontificator.config.EmojiLoadingDisplayStragegy) ChangeListener(javax.swing.event.ChangeListener) HashSet(java.util.HashSet) EmojiJob(com.glitchcog.fontificator.emoji.EmojiJob)

Aggregations

EmojiLoadingDisplayStragegy (com.glitchcog.fontificator.config.EmojiLoadingDisplayStragegy)1 EmojiJob (com.glitchcog.fontificator.emoji.EmojiJob)1 LabeledSlider (com.glitchcog.fontificator.gui.component.LabeledSlider)1 EmojiLoadProgressPanel (com.glitchcog.fontificator.gui.emoji.EmojiLoadProgressPanel)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 HashSet (java.util.HashSet)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JSeparator (javax.swing.JSeparator)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1