-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from FTBTeam/feature/1.21/better-widget-controll
[1.21] Allow Sidebar Buttons to be moveable
- Loading branch information
Showing
29 changed files
with
1,184 additions
and
861 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
32 changes: 32 additions & 0 deletions
32
common/src/main/java/dev/ftb/mods/ftblibrary/api/sidebar/ButtonOverlayRender.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,32 @@ | ||
package dev.ftb.mods.ftblibrary.api.sidebar; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import dev.ftb.mods.ftblibrary.icon.Color4I; | ||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public interface ButtonOverlayRender { | ||
|
||
/** | ||
* Called when the button is rendering | ||
* graphics is aligned so that 0, 0 is the top left corner of the button | ||
* @param graphics The graphics object | ||
* @param font The font object | ||
* @param buttonSize The size of the button | ||
*/ | ||
void render(GuiGraphics graphics, Font font, int buttonSize); | ||
|
||
static ButtonOverlayRender ofSimpleString(Supplier<String> customTextHandler) { | ||
return (graphics, font, buttonSize) -> { | ||
String text = customTextHandler.get(); | ||
if (!text.isEmpty()) { | ||
var nw = font.width(text); | ||
Color4I.LIGHT_RED.draw(graphics, buttonSize - nw, -1, nw + 1, 9); | ||
graphics.drawString(font, text, buttonSize - nw + 1, 0, 0xFFFFFFFF); | ||
RenderSystem.setShaderColor(1F, 1F, 1F, 1F); | ||
} | ||
}; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
common/src/main/java/dev/ftb/mods/ftblibrary/api/sidebar/SidebarButton.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,35 @@ | ||
package dev.ftb.mods.ftblibrary.api.sidebar; | ||
|
||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.List; | ||
import java.util.function.BooleanSupplier; | ||
import java.util.function.Supplier; | ||
|
||
public interface SidebarButton { | ||
|
||
/** | ||
* @return the id of the button used for saving config data created from the location button in resource path | ||
*/ | ||
ResourceLocation getId(); | ||
|
||
/** | ||
* Register a condition that must be met for the button to be visible | ||
* @param condition a condition that must be met for the button to be visible | ||
*/ | ||
void addVisibilityCondition(BooleanSupplier condition); | ||
|
||
/** | ||
* Register a custom overlay renderer to render on top of the button icon | ||
* @param renderer the renderer to render on top of the button icon | ||
*/ | ||
void addOverlayRender(ButtonOverlayRender renderer); | ||
|
||
/** | ||
* Override the default tooltip displayed when hovering over the button | ||
* @param tooltipOverride a supplier that returns the tooltip to be displayed when hovering over the button | ||
*/ | ||
void setTooltipOverride(Supplier<List<Component>> tooltipOverride); | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
common/src/main/java/dev/ftb/mods/ftblibrary/api/sidebar/SidebarButtonCreatedEvent.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,21 @@ | ||
package dev.ftb.mods.ftblibrary.api.sidebar; | ||
|
||
import dev.architectury.event.Event; | ||
import dev.architectury.event.EventFactory; | ||
import dev.ftb.mods.ftblibrary.sidebar.RegisteredSidebarButton; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public class SidebarButtonCreatedEvent { | ||
public static final Event<Consumer<SidebarButtonCreatedEvent>> EVENT = EventFactory.createConsumerLoop(SidebarButtonCreatedEvent.class); | ||
|
||
private final RegisteredSidebarButton button; | ||
|
||
public SidebarButtonCreatedEvent(RegisteredSidebarButton button) { | ||
this.button = button; | ||
} | ||
|
||
public RegisteredSidebarButton getButton() { | ||
return button; | ||
} | ||
} |
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
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
Oops, something went wrong.