diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-09-09 21:57:11 +0300 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-09-09 21:57:11 +0300 |
commit | 510906753e5f0d94681ac23932926f82a94532a8 (patch) | |
tree | 384077232b377f8848ba5a6eb0cf175de207f91b /src/main | |
parent | 9f810d320dbdb9c58f5f8b6807c24cff9715fe5a (diff) | |
parent | cc01e089d361f56382eb43560aee952674211dd2 (diff) | |
download | LibGui-510906753e5f0d94681ac23932926f82a94532a8.tar.gz LibGui-510906753e5f0d94681ac23932926f82a94532a8.tar.bz2 LibGui-510906753e5f0d94681ac23932926f82a94532a8.zip |
Merge branch 'master' into unstable/9.0
Diffstat (limited to 'src/main')
11 files changed, 56 insertions, 52 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java index 0c1af59..a0c04be 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java @@ -5,11 +5,17 @@ import net.fabricmc.api.Environment; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.screen.narration.NarrationPart; +import net.minecraft.util.Identifier; -import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import io.github.cottonmc.cotton.gui.client.BackgroundPainter; +import io.github.cottonmc.cotton.gui.impl.LibGuiCommon; import io.github.cottonmc.cotton.gui.impl.client.NarrationMessages; +import io.github.cottonmc.cotton.gui.impl.client.NinePatchTextureRendererImpl; import io.github.cottonmc.cotton.gui.widget.data.Axis; import io.github.cottonmc.cotton.gui.widget.data.InputResult; +import juuxel.libninepatch.NinePatch; + +import static io.github.cottonmc.cotton.gui.client.BackgroundPainter.createNinePatch; public class WScrollBar extends WWidget { private static final int SCROLLING_SPEED = 4; @@ -41,63 +47,40 @@ public class WScrollBar extends WWidget { @Environment(EnvType.CLIENT) @Override public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { + var matrices = context.getMatrices(); boolean darkMode = shouldRenderInDarkMode(); - if (darkMode) { - ScreenDrawing.drawBeveledPanel(context, x, y, width, height, 0xFF_212121, 0xFF_2F2F2F, 0xFF_5D5D5D); - } else { - ScreenDrawing.drawBeveledPanel(context, x, y, width, height, 0xFF_373737, 0xFF_8B8B8B, 0xFF_FFFFFF); - } - if (maxValue<=0) return; + Painters.BACKGROUND.paintBackground(context, x, y, this); + + NinePatch<Identifier> painter = (darkMode ? Painters.SCROLL_BAR_DARK : Painters.SCROLL_BAR); - // Handle colors - int top, middle, bottom; + if (maxValue <= 0) return; if (sliding) { - if (darkMode) { - top = 0xFF_6C6C6C; - middle = 0xFF_2F2F2F; - bottom = 0xFF_212121; - } else { - top = 0xFF_FFFFFF; - middle = 0xFF_8B8B8B; - bottom = 0xFF_555555; - } + painter = (darkMode ? Painters.SCROLL_BAR_PRESSED_DARK : Painters.SCROLL_BAR_PRESSED); } else if (isWithinBounds(mouseX, mouseY)) { - if (darkMode) { - top = 0xFF_5F6A9D; - middle = 0xFF_323F6E; - bottom = 0xFF_0B204A; - } else { - top = 0xFF_CFD0F7; - middle = 0xFF_8791C7; - bottom = 0xFF_343E75; - } - } else { - if (darkMode) { - top = 0xFF_6C6C6C; - middle = 0xFF_414141; - bottom = 0xFF_212121; - } else { - top = 0xFF_FFFFFF; - middle = 0xFF_C6C6C6; - bottom = 0xFF_555555; - } + painter = (darkMode ? Painters.SCROLL_BAR_HOVERED_DARK : Painters.SCROLL_BAR_HOVERED); } - if (axis==Axis.HORIZONTAL) { - ScreenDrawing.drawBeveledPanel(context, x+1+getHandlePosition(), y+1, getHandleSize(), height-2, top, middle, bottom); + matrices.push(); + + if (axis == Axis.HORIZONTAL) { + matrices.translate(x + 1 + getHandlePosition(), y + 1, 0); + painter.draw(NinePatchTextureRendererImpl.INSTANCE, context, getHandleSize(), height - 2); if (isFocused()) { - drawBeveledOutline(context, x+1+getHandlePosition(), y+1, getHandleSize(), height-2, 0xFF_FFFFA7, 0xFF_8C8F39); + Painters.FOCUS.draw(NinePatchTextureRendererImpl.INSTANCE, context, getHandleSize(), height - 2); } } else { - ScreenDrawing.drawBeveledPanel(context, x+1, y+1+getHandlePosition(), width-2, getHandleSize(), top, middle, bottom); + matrices.translate(x + 1, y + 1 + getHandlePosition(), 0); + painter.draw(NinePatchTextureRendererImpl.INSTANCE, context, width - 2, getHandleSize()); if (isFocused()) { - drawBeveledOutline(context, x+1, y+1+getHandlePosition(), width-2, getHandleSize(), 0xFF_FFFFA7, 0xFF_8C8F39); + Painters.FOCUS.draw(NinePatchTextureRendererImpl.INSTANCE, context, width - 2, getHandleSize()); } } + + matrices.pop(); } @Override @@ -110,13 +93,6 @@ public class WScrollBar extends WWidget { return true; } - private static void drawBeveledOutline(DrawContext context, int x, int y, int width, int height, int topleft, int bottomright) { - ScreenDrawing.coloredRect(context, x, y, width, 1, topleft); //Top shadow - ScreenDrawing.coloredRect(context, x, y + 1, 1, height - 1, topleft); //Left shadow - ScreenDrawing.coloredRect(context, x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight - ScreenDrawing.coloredRect(context, x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight - } - /** * Gets the on-axis size of the scrollbar handle in gui pixels */ @@ -279,4 +255,19 @@ public class WScrollBar extends WWidget { builder.put(NarrationPart.TITLE, NarrationMessages.SCROLL_BAR_TITLE); builder.put(NarrationPart.USAGE, NarrationMessages.SLIDER_USAGE); } + + @Environment(EnvType.CLIENT) + static final class Painters { + static final NinePatch<Identifier> SCROLL_BAR = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_light.png")).cornerSize(4).cornerUv(0.25f).build(); + static final NinePatch<Identifier> SCROLL_BAR_DARK = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_dark.png")).cornerSize(4).cornerUv(0.25f).build(); + static final NinePatch<Identifier> SCROLL_BAR_PRESSED = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_pressed_light.png")).cornerSize(4).cornerUv(0.25f).build(); + static final NinePatch<Identifier> SCROLL_BAR_PRESSED_DARK = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_pressed_dark.png")).cornerSize(4).cornerUv(0.25f).build(); + static final NinePatch<Identifier> SCROLL_BAR_HOVERED = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_hovered_light.png")).cornerSize(4).cornerUv(0.25f).build(); + static final NinePatch<Identifier> SCROLL_BAR_HOVERED_DARK = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_hovered_dark.png")).cornerSize(4).cornerUv(0.25f).build(); + static final BackgroundPainter BACKGROUND = BackgroundPainter.createLightDarkVariants( + createNinePatch(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/background_light.png")), + createNinePatch(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/background_dark.png")) + ); + static final NinePatch<Identifier> FOCUS = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/focus.png")).cornerSize(4).cornerUv(0.25f).build(); + } } diff --git a/src/main/resources/assets/libgui/lang/fr_fr.json b/src/main/resources/assets/libgui/lang/fr_fr.json index ec80d8d..b3ce28d 100644 --- a/src/main/resources/assets/libgui/lang/fr_fr.json +++ b/src/main/resources/assets/libgui/lang/fr_fr.json @@ -1,4 +1,17 @@ { - "options.libgui.libgui_settings": "Paramètres de LibGui", - "option.libgui.darkmode": "Mode sombre" -} + "options.libgui.libgui_settings": "Paramètres de LibGui", + "option.libgui.darkmode": "Mode sombre", + "widget.libgui.item_slot.narration.title": "Emplacement %s sur %s", + "widget.libgui.labeled_slider.narration.title": "%s slider: at %s between %s and %s", + "widget.libgui.scroll_bar.narration.title": "Barre de défilement", + "widget.libgui.slider.narration.title": "Curseur: à %s entre %s et %s", + "widget.libgui.slider.narration.usage": "Déplacer en tirant ou avec les flêches directionnelles", + "widget.libgui.tab.narration.title": "Onglet %s", + "widget.libgui.tab.narration.position": "Onglet %s sur %s", + "widget.libgui.text_field.narration.title": "Champ textuel: %s", + "widget.libgui.text_field.narration.suggestion": "Suggestion: %s", + "widget.libgui.toggle_button.narration.unnamed": "Bouton à bascule: %s", + "widget.libgui.toggle_button.narration.named": "Bouton à bascule: %s (%s)", + "widget.libgui.toggle_button.narration.on": "Activé", + "widget.libgui.toggle_button.narration.off": "Désactivé" +}
\ No newline at end of file diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_dark.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_dark.png Binary files differnew file mode 100644 index 0000000..3df12e3 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_dark.png diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_light.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_light.png Binary files differnew file mode 100644 index 0000000..38c6ef8 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_light.png diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/focus.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/focus.png Binary files differnew file mode 100644 index 0000000..955aa7e --- /dev/null +++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/focus.png diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_dark.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_dark.png Binary files differnew file mode 100644 index 0000000..4c2aab0 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_dark.png diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_dark.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_dark.png Binary files differnew file mode 100644 index 0000000..472db90 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_dark.png diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_light.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_light.png Binary files differnew file mode 100644 index 0000000..b0695ed --- /dev/null +++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_light.png diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_light.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_light.png Binary files differnew file mode 100644 index 0000000..6d802e7 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_light.png diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_dark.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_dark.png Binary files differnew file mode 100644 index 0000000..8835712 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_dark.png diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_light.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_light.png Binary files differnew file mode 100644 index 0000000..9df19b0 --- /dev/null +++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_light.png |