-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #9 - makes the Pokemon used configurable
also adds an Easter egg - MissingNo. is returned used if all Pokemon are turned off
- Loading branch information
Showing
12 changed files
with
259 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/com/kagof/intellij/plugins/pokeprogress/PokemonPicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.kagof.intellij.plugins.pokeprogress; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Random; | ||
import java.util.stream.Collectors; | ||
|
||
import com.kagof.intellij.plugins.pokeprogress.configuration.PokemonProgressState; | ||
|
||
public class PokemonPicker { | ||
private static final Random RANDOM = new Random(); | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
public static Pokemon get() { | ||
if (Pokemon.TARGET != null) { | ||
return Pokemon.TARGET; | ||
} | ||
|
||
final List<String> enabledPokemonNumbers = Optional.ofNullable(PokemonProgressState.getInstance()) | ||
.map(PokemonPicker::getEnabledPokemonNumbers) | ||
.orElse(null); | ||
if (enabledPokemonNumbers == null || enabledPokemonNumbers.isEmpty()) { | ||
return Pokemon.MISSINGNO; | ||
} | ||
return Pokemon.getByNumber(enabledPokemonNumbers.get(RANDOM.nextInt(enabledPokemonNumbers.size()))); | ||
} | ||
|
||
private static List<String> getEnabledPokemonNumbers(final PokemonProgressState state) { | ||
return state.pokemonNumbersEnabled.entrySet().stream().filter(Map.Entry::getValue).map(Map.Entry::getKey).collect(Collectors.toList()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...va/com/kagof/intellij/plugins/pokeprogress/configuration/PokemonProgressConfigurable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.kagof.intellij.plugins.pokeprogress.configuration; | ||
|
||
import javax.swing.JComponent; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.intellij.openapi.options.Configurable; | ||
import com.intellij.openapi.options.ConfigurationException; | ||
import com.intellij.openapi.util.NlsContexts; | ||
|
||
public class PokemonProgressConfigurable implements Configurable { | ||
private PokemonProgressConfigurationComponent component; | ||
|
||
@Override | ||
@NlsContexts.ConfigurableName | ||
public String getDisplayName() { | ||
return "Pokémon Progress"; | ||
} | ||
|
||
@Override | ||
public @Nullable JComponent createComponent() { | ||
component = new PokemonProgressConfigurationComponent(); | ||
return component.getPanel(); | ||
} | ||
|
||
@Override | ||
public boolean isModified() { | ||
PokemonProgressState state = PokemonProgressState.getInstance(); | ||
return !state.pokemonNumbersEnabled.equals(component.getEnabledNumberMap()); | ||
} | ||
|
||
@Override | ||
public void apply() throws ConfigurationException { | ||
PokemonProgressState state = PokemonProgressState.getInstance(); | ||
state.pokemonNumbersEnabled = component.getEnabledNumberMap(); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
PokemonProgressState state = PokemonProgressState.getInstance(); | ||
component.updateUi(state); | ||
} | ||
|
||
@Override | ||
public void disposeUIResources() { | ||
component = null; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...of/intellij/plugins/pokeprogress/configuration/PokemonProgressConfigurationComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.kagof.intellij.plugins.pokeprogress.configuration; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ItemEvent; | ||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.swing.JButton; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
|
||
import com.intellij.ui.components.JBCheckBox; | ||
import com.intellij.ui.roots.ScalableIconComponent; | ||
import com.intellij.util.ui.FormBuilder; | ||
import com.kagof.intellij.plugins.pokeprogress.Pokemon; | ||
|
||
public class PokemonProgressConfigurationComponent { | ||
private JPanel mainPanel; | ||
private final Map<String, JBCheckBox> checkboxes = new HashMap<>(); | ||
private final JButton selectAll = new JButton("Select all"); | ||
private final JButton deselectAll = new JButton("Deselect all"); | ||
private final JLabel label = new JLabel("?/? selected"); | ||
private final AtomicInteger numSelected = new AtomicInteger(0); | ||
|
||
|
||
public PokemonProgressConfigurationComponent() { | ||
createUi(); | ||
} | ||
|
||
void createUi() { | ||
final FormBuilder formBuilder = FormBuilder.createFormBuilder(); | ||
selectAll.addActionListener(a -> { | ||
if (a.getID() == ActionEvent.ACTION_PERFORMED) { | ||
checkboxes.values().forEach(c -> c.setSelected(true)); | ||
} | ||
}); | ||
deselectAll.addActionListener(a -> { | ||
if (a.getID() == ActionEvent.ACTION_PERFORMED) { | ||
checkboxes.values().forEach(c -> c.setSelected(false)); | ||
} | ||
}); | ||
formBuilder.addComponent(label); | ||
formBuilder.addComponent(selectAll); | ||
formBuilder.addComponent(deselectAll); | ||
|
||
Pokemon.DEFAULT_POKEMON.values().stream().sorted().forEach(pokemon -> { | ||
final JBCheckBox checkBox = new JBCheckBox(pokemon.getNameWithNumber(), true); | ||
checkBox.addItemListener(c -> { | ||
if (c.getStateChange() == ItemEvent.SELECTED) { | ||
numSelected.incrementAndGet(); | ||
} else if (c.getStateChange() == ItemEvent.DESELECTED){ | ||
numSelected.decrementAndGet(); | ||
} | ||
refreshSelectAllButtons(); | ||
}); | ||
formBuilder.addLabeledComponent(new ScalableIconComponent(pokemon.getIcon()), checkBox); | ||
checkboxes.put(pokemon.getNumber(), checkBox); | ||
numSelected.incrementAndGet(); | ||
}); | ||
refreshSelectAllButtons(); | ||
mainPanel = formBuilder.getPanel(); | ||
} | ||
|
||
void updateUi(final PokemonProgressState state) { | ||
if (state != null) { | ||
state.pokemonNumbersEnabled | ||
.forEach((pokemon, enabled) -> checkboxes.computeIfPresent(pokemon, (p, check) -> { | ||
check.setSelected(enabled); | ||
return check; | ||
})); | ||
} | ||
} | ||
|
||
public JPanel getPanel() { | ||
return mainPanel; | ||
} | ||
|
||
public Map<String, Boolean> getEnabledNumberMap() { | ||
return checkboxes.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().isSelected())); | ||
} | ||
|
||
private void refreshSelectAllButtons() { | ||
final int i = numSelected.get(); | ||
deselectAll.setEnabled(i > 0); | ||
selectAll.setEnabled(i < checkboxes.size()); | ||
label.setText(i + "/" + checkboxes.size() + " selected"); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...main/java/com/kagof/intellij/plugins/pokeprogress/configuration/PokemonProgressState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.kagof.intellij.plugins.pokeprogress.configuration; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.intellij.openapi.components.PersistentStateComponent; | ||
import com.intellij.openapi.components.ServiceManager; | ||
import com.intellij.openapi.components.State; | ||
import com.intellij.openapi.components.Storage; | ||
import com.intellij.util.xmlb.XmlSerializerUtil; | ||
import com.intellij.util.xmlb.annotations.Transient; | ||
import com.kagof.intellij.plugins.pokeprogress.Pokemon; | ||
|
||
@State( | ||
name = "com.kagof.intellij.plugins.pokeprogress.configuration.PokemonProgressState", | ||
storages = {@Storage("PokemonProgress.xml")} | ||
) | ||
public class PokemonProgressState implements PersistentStateComponent<PokemonProgressState> { | ||
|
||
public Map<String, Boolean> pokemonNumbersEnabled = Pokemon.DEFAULT_POKEMON.keySet().stream().collect(Collectors.toMap(Function.identity(), p -> true)); | ||
|
||
public static PokemonProgressState getInstance() { | ||
return ServiceManager.getService(PokemonProgressState.class); | ||
} | ||
|
||
@Override | ||
public PokemonProgressState getState() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public void loadState(@NotNull final PokemonProgressState state) { | ||
XmlSerializerUtil.copyBean(state, this); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+597 Bytes
src/main/resources/com/kagof/intellij/plugins/pokeprogress/sprites/missingNo..gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.45 KB
...ain/resources/com/kagof/intellij/plugins/pokeprogress/sprites/missingNo.@2x.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+599 Bytes
...main/resources/com/kagof/intellij/plugins/pokeprogress/sprites/missingNo._r.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.45 KB
...n/resources/com/kagof/intellij/plugins/pokeprogress/sprites/missingNo._r@2x.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters