Skip to content

Commit

Permalink
Merge pull request #82 from kagof/release/2.1.1
Browse files Browse the repository at this point in the history
Release/2.1.1
  • Loading branch information
kagof committed Sep 10, 2022
2 parents e92872a + 76ba00c commit 08e188f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 43 deletions.
14 changes: 14 additions & 0 deletions changenotes.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
<ul>
<li>
<b>
<a href="https://github.com/kagof/intellij-pokemon-progress/releases/tag/2.1.1">
2.1.1
</a>
</b>
<!--2.1.1-->
<ul>
<li>Fixes a bug where an exception is thrown when uninstalling the plugin, leading to the plugin not being
uninstalled
</li>
</ul>
<!--/2.1.1-->
</li>
<li>
<b>
<a href="https://github.com/kagof/intellij-pokemon-progress/releases/tag/2.1.0">
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
group=com.kagof
name=pokemon-progress
version=2.1.0
version=2.1.1
changenotesFile=changenotes.html
descriptionFile=description.html
org.gradle.parallel=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.RoundRectangle2D;
import java.util.function.BooleanSupplier;
import java.util.function.IntSupplier;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;

import javax.swing.Icon;
Expand Down Expand Up @@ -52,47 +52,47 @@ public class PokemonProgressBarUi extends BasicProgressBarUI {
private final Supplier<Float> acceleration;
private final Supplier<PaintTheme> theme;
private final Supplier<ColorScheme> colorScheme;
private final BooleanSupplier transparencyOnIndeterminate;
private final BooleanSupplier transparencyOnDeterminate;
private final BooleanSupplier drawSprites;
private final BooleanSupplier addToolTips;
private final BooleanSupplier restrictMaxHeight;
private final IntSupplier maxHeight;
private final BooleanSupplier restrictMinHeight;
private final IntSupplier minHeight;
private final Supplier<Boolean> transparencyOnIndeterminate;
private final Supplier<Boolean> transparencyOnDeterminate;
private final Supplier<Boolean> drawSprites;
private final Supplier<Boolean> addToolTips;
private final Supplier<Boolean> restrictMaxHeight;
private final Supplier<Integer> maxHeight;
private final Supplier<Boolean> restrictMinHeight;
private final Supplier<Integer> minHeight;

private volatile int pos = 0;
private volatile float velocity = 0;

public PokemonProgressBarUi(final Pokemon pokemon) {
this(pokemon,
() -> PokemonProgressState.getInstance().initialVelocity,
() -> PokemonProgressState.getInstance().acceleration,
() -> PaintThemes.getByIdOrDefault(PokemonProgressState.getInstance().theme),
() -> ColorSchemes.getByIdOrDefault(PokemonProgressState.getInstance().colorScheme),
() -> PokemonProgressState.getInstance().transparencyOnIndeterminate,
() -> PokemonProgressState.getInstance().transparencyOnDeterminate,
() -> PokemonProgressState.getInstance().drawSprites,
() -> PokemonProgressState.getInstance().addToolTips,
() -> PokemonProgressState.getInstance().restrictMaximumHeight,
() -> PokemonProgressState.getInstance().maximumHeight,
() -> PokemonProgressState.getInstance().restrictMinimumHeight,
() -> PokemonProgressState.getInstance().minimumHeight);
safeGetFromState(s -> s.initialVelocity, 1.0f),
safeGetFromState(s -> s.acceleration, 0.4f),
safeGetFromState(s -> PaintThemes.getByIdOrDefault(s.theme), PaintThemes.getDefaultTheme()),
safeGetFromState(s -> ColorSchemes.getByIdOrDefault(s.colorScheme), ColorSchemes.getDefaultScheme()),
safeGetFromState(s -> s.transparencyOnIndeterminate, true),
safeGetFromState(s -> s.transparencyOnDeterminate, false),
safeGetFromState(s -> s.drawSprites, true),
safeGetFromState(s -> s.addToolTips, true),
safeGetFromState(s -> s.restrictMaximumHeight, false),
safeGetFromState(s -> s.maximumHeight, 20),
safeGetFromState(s -> s.restrictMinimumHeight, false),
safeGetFromState(s -> s.minimumHeight, 20));
}

public PokemonProgressBarUi(final Pokemon pokemon,
final Supplier<Float> initialVelocity,
final Supplier<Float> acceleration,
final Supplier<PaintTheme> theme,
final Supplier<ColorScheme> colorScheme,
final BooleanSupplier transparencyOnIndeterminate,
final BooleanSupplier transparencyOnDeterminate,
final BooleanSupplier drawSprites,
final BooleanSupplier addToolTips,
final BooleanSupplier restrictMaxHeight,
final IntSupplier maxHeight,
final BooleanSupplier restrictMinHeight,
final IntSupplier minHeight) {
final Supplier<Boolean> transparencyOnIndeterminate,
final Supplier<Boolean> transparencyOnDeterminate,
final Supplier<Boolean> drawSprites,
final Supplier<Boolean> addToolTips,
final Supplier<Boolean> restrictMaxHeight,
final Supplier<Integer> maxHeight,
final Supplier<Boolean> restrictMinHeight,
final Supplier<Integer> minHeight) {
super();
this.pokemon = pokemon;
this.initialVelocity = initialVelocity;
Expand All @@ -111,7 +111,7 @@ public PokemonProgressBarUi(final Pokemon pokemon,

iconForward = PokemonResourceLoader.getIcon(pokemon);
iconReversed = PokemonResourceLoader.getReversedIcon(pokemon);
if (restrictMaxHeight.getAsBoolean() || restrictMinHeight.getAsBoolean()) {
if (restrictMaxHeight.get() || restrictMinHeight.get()) {
computeScaledIcons();
}
}
Expand All @@ -129,9 +129,9 @@ protected int getBoxLength(final int availableLength, final int otherDimension)

@Override
public Dimension getPreferredSize(final JComponent c) {
int height = restrictMaxHeight.getAsBoolean() ? Math.min(maxHeight.getAsInt(), pokemon.getHeight())
int height = restrictMaxHeight.get() ? Math.min(maxHeight.get(), pokemon.getHeight())
: pokemon.getHeight();
height = restrictMinHeight.getAsBoolean() ? Math.max(minHeight.getAsInt(), height) : height;
height = restrictMinHeight.get() ? Math.max(minHeight.get(), height) : height;
return new Dimension(super.getPreferredSize(c).width, JBUI.scale(height));
}

Expand Down Expand Up @@ -242,8 +242,8 @@ private void drawTypePaint(final int width, final int height, final int progress
: new Rectangle(progress, 0, progressBar.getWidth(), height));
graphics2D.fill(rectangle);

if ((progressBar.isIndeterminate() && transparencyOnIndeterminate.getAsBoolean())
|| (!progressBar.isIndeterminate() && transparencyOnDeterminate.getAsBoolean())) {
if ((progressBar.isIndeterminate() && transparencyOnIndeterminate.get())
|| (!progressBar.isIndeterminate() && transparencyOnDeterminate.get())) {
graphics2D.setPaint(getTransparencyPaint(progressBar.getBackground(), width, movingRight));
graphics2D.setClip(movingRight ? new Rectangle(progress, height)
: new Rectangle(progress, 0, progressBar.getWidth(), height));
Expand All @@ -262,7 +262,7 @@ private static Paint getTransparencyPaint(final Color backgroundColor, final int
}

private void setToolTipText() {
if (addToolTips.getAsBoolean()) {
if (addToolTips.get()) {
progressBar.setToolTipText(pokemon.getNameWithNumber());
}
}
Expand All @@ -280,14 +280,14 @@ private void drawBorder(final RoundRectangle2D rectangle, final Graphics2D graph
}

private void drawPokemonIcon(final int amountFull, final Graphics2D graphics2D, final Shape clip) {
if (!drawSprites.getAsBoolean()) {
if (!drawSprites.get()) {
return;
}
final Shape previousClip = graphics2D.getClip();

graphics2D.setClip(clip);
final Icon icon;
if (restrictMaxHeight.getAsBoolean() || restrictMinHeight.getAsBoolean()) {
if (restrictMaxHeight.get() || restrictMinHeight.get()) {
icon = velocity >= 0 ? iconForwardScaled : iconReversedScaled;
} else {
icon = velocity >= 0 ? iconForward : iconReversed;
Expand Down Expand Up @@ -330,11 +330,11 @@ private void updatePosition() {
}

private int scaleToHeightRestrictions(final int value) {
if (restrictMaxHeight.getAsBoolean() && pokemon.getHeight() > maxHeight.getAsInt()) {
return Math.round(((float) maxHeight.getAsInt() / pokemon.getHeight()) * value);
if (restrictMaxHeight.get() && pokemon.getHeight() > maxHeight.get()) {
return Math.round(((float) maxHeight.get() / pokemon.getHeight()) * value);
}
if (restrictMinHeight.getAsBoolean() && pokemon.getHeight() < minHeight.getAsInt()) {
return Math.round(((float) minHeight.getAsInt() / pokemon.getHeight()) * value);
if (restrictMinHeight.get() && pokemon.getHeight() < minHeight.get()) {
return Math.round(((float) minHeight.get() / pokemon.getHeight()) * value);
}
return value;
}
Expand All @@ -347,4 +347,11 @@ private void resetPositionAndVelocity() {
private static boolean isEven(final int n) {
return (n & 1) == 0;
}

private static <T> Supplier<T> safeGetFromState(final Function<PokemonProgressState, T> getter,
final T defaultIfStateNull) {
return () -> Optional.ofNullable(PokemonProgressState.getInstance())
.map(getter)
.orElse(defaultIfStateNull);
}
}

0 comments on commit 08e188f

Please sign in to comment.