Add dropdown for font style for in-game overlays

This commit is contained in:
Reasel
2018-04-20 07:18:58 -07:00
committed by Adam
parent 0375702622
commit 19895c83a6
5 changed files with 82 additions and 10 deletions

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2018, Tanner <https://github.com/Reasel>
* 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 lombok.RequiredArgsConstructor;
import lombok.Getter;
import net.runelite.client.ui.FontManager;
import java.awt.Font;
@Getter
@RequiredArgsConstructor
public enum FontType
{
REGULAR("Regular", FontManager.getRunescapeFont()),
BOLD("Bold", FontManager.getRunescapeBoldFont()),
SMALL("Small", FontManager.getRunescapeSmallFont());
private final String name;
private final Font font;
@Override
public String toString()
{
return name;
}
}

View File

@@ -116,12 +116,12 @@ public interface RuneLiteConfig extends Config
} }
@ConfigItem( @ConfigItem(
keyName = "useSmallFont", keyName = "fontType",
name = "Small font in dynamic overlays", name = "Dynamic Overlay Font",
description = "Toggles between small and regular RuneScape font for in-game overlays" description = "Configures what font type is used for in-game overlays such as player name, ground items, etc."
) )
default boolean useSmallFont() default FontType fontType()
{ {
return true; return FontType.SMALL;
} }
} }

View File

@@ -34,6 +34,7 @@ public class FontManager
{ {
private static final Font runescapeFont; private static final Font runescapeFont;
private static final Font runescapeSmallFont; private static final Font runescapeSmallFont;
private static final Font runescapeBoldFont;
static static
{ {
@@ -58,6 +59,15 @@ public class FontManager
runescapeSmallFont = StyleContext.getDefaultStyleContext() runescapeSmallFont = StyleContext.getDefaultStyleContext()
.getFont(smallFont.getName(), Font.PLAIN, 16); .getFont(smallFont.getName(), Font.PLAIN, 16);
ge.registerFont(runescapeSmallFont); ge.registerFont(runescapeSmallFont);
Font boldFont = Font.createFont(Font.TRUETYPE_FONT,
FontManager.class.getResourceAsStream("runescape_bold.ttf"))
.deriveFont(Font.PLAIN, 16);
ge.registerFont(boldFont);
runescapeBoldFont = StyleContext.getDefaultStyleContext()
.getFont(boldFont.getName(), Font.PLAIN, 16);
ge.registerFont(runescapeBoldFont);
} }
catch (FontFormatException ex) catch (FontFormatException ex)
{ {
@@ -78,4 +88,9 @@ public class FontManager
{ {
return runescapeSmallFont; return runescapeSmallFont;
} }
public static Font getRunescapeBoldFont()
{
return runescapeBoldFont;
}
} }

View File

@@ -506,11 +506,19 @@ public class OverlayRenderer extends MouseListener implements KeyListener
final OverlayPosition position = overlay.getPosition(); final OverlayPosition position = overlay.getPosition();
// Set font based on configuration // Set font based on configuration
subGraphics.setFont((position == OverlayPosition.DYNAMIC if (position == OverlayPosition.DYNAMIC)
|| position == OverlayPosition.TOOLTIP) {
&& runeLiteConfig.useSmallFont() subGraphics.setFont(runeLiteConfig.fontType().getFont());
? FontManager.getRunescapeSmallFont() }
: FontManager.getRunescapeFont()); else if (position == OverlayPosition.TOOLTIP)
{
subGraphics.setFont(FontManager.getRunescapeSmallFont());
}
else
{
subGraphics.setFont(FontManager.getRunescapeFont());
}
subGraphics.translate(point.x, point.y); subGraphics.translate(point.x, point.y);
final Dimension dimension = MoreObjects.firstNonNull(overlay.render(subGraphics), new Dimension()); final Dimension dimension = MoreObjects.firstNonNull(overlay.render(subGraphics), new Dimension());