config: add support for integer config items to have units
This commit is contained in:
@@ -33,4 +33,5 @@ public class ConfigItemDescriptor
|
|||||||
private final Class<?> type;
|
private final Class<?> type;
|
||||||
private final Range range;
|
private final Range range;
|
||||||
private final Alpha alpha;
|
private final Alpha alpha;
|
||||||
|
private final Units units;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -455,7 +455,8 @@ public class ConfigManager
|
|||||||
m.getDeclaredAnnotation(ConfigItem.class),
|
m.getDeclaredAnnotation(ConfigItem.class),
|
||||||
m.getReturnType(),
|
m.getReturnType(),
|
||||||
m.getDeclaredAnnotation(Range.class),
|
m.getDeclaredAnnotation(Range.class),
|
||||||
m.getDeclaredAnnotation(Alpha.class)
|
m.getDeclaredAnnotation(Alpha.class),
|
||||||
|
m.getDeclaredAnnotation(Units.class)
|
||||||
))
|
))
|
||||||
.sorted((a, b) -> ComparisonChain.start()
|
.sorted((a, b) -> ComparisonChain.start()
|
||||||
.compare(a.getItem().position(), b.getItem().position())
|
.compare(a.getItem().position(), b.getItem().position())
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Hydrox6 <ikada@protonmail.ch>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.client.config;
|
||||||
|
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used with ConfigItem, defines what units are shown to the side of the box.
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Documented
|
||||||
|
public @interface Units
|
||||||
|
{
|
||||||
|
String MILLISECONDS = "ms";
|
||||||
|
String MINUTES = " mins";
|
||||||
|
String PERCENT = "%";
|
||||||
|
String PIXELS = "px";
|
||||||
|
String SECONDS = "s";
|
||||||
|
String TICKS = " ticks";
|
||||||
|
|
||||||
|
String value();
|
||||||
|
}
|
||||||
@@ -36,6 +36,7 @@ import java.awt.event.ItemEvent;
|
|||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
@@ -66,6 +67,7 @@ import net.runelite.client.config.ConfigManager;
|
|||||||
import net.runelite.client.config.Keybind;
|
import net.runelite.client.config.Keybind;
|
||||||
import net.runelite.client.config.ModifierlessKeybind;
|
import net.runelite.client.config.ModifierlessKeybind;
|
||||||
import net.runelite.client.config.Range;
|
import net.runelite.client.config.Range;
|
||||||
|
import net.runelite.client.config.Units;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.events.ExternalPluginsChanged;
|
import net.runelite.client.events.ExternalPluginsChanged;
|
||||||
import net.runelite.client.events.PluginChanged;
|
import net.runelite.client.events.PluginChanged;
|
||||||
@@ -256,6 +258,16 @@ class ConfigPanel extends PluginPanel
|
|||||||
spinnerTextField.setColumns(SPINNER_FIELD_WIDTH);
|
spinnerTextField.setColumns(SPINNER_FIELD_WIDTH);
|
||||||
spinner.addChangeListener(ce -> changeConfiguration(spinner, cd, cid));
|
spinner.addChangeListener(ce -> changeConfiguration(spinner, cd, cid));
|
||||||
|
|
||||||
|
Units units = cid.getUnits();
|
||||||
|
if (units != null)
|
||||||
|
{
|
||||||
|
DecimalFormat df = ((JSpinner.NumberEditor) spinner.getEditor()).getFormat();
|
||||||
|
df.setPositiveSuffix(units.value());
|
||||||
|
df.setNegativeSuffix(units.value());
|
||||||
|
// Force update the spinner to have it add the units initially
|
||||||
|
spinnerTextField.setValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
item.add(spinner, BorderLayout.EAST);
|
item.add(spinner, BorderLayout.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user