Research render test

This commit is contained in:
DBotThePony 2021-08-22 19:22:30 +07:00
parent 20a0a96c84
commit 9e726e1779
Signed by: DBot
GPG Key ID: DCC23B5715498507
14 changed files with 232 additions and 152 deletions

View File

@ -10,6 +10,7 @@ public class AndroidAirBagsType extends AndroidFeatureType<AndroidAirBags> {
@Nullable
@Override
public AndroidFeatureResearchNode getResearchNodeInner() {
return new AndroidFeatureResearchNode(this, new AndroidFeatureResearchCost(18));
return new AndroidFeatureResearchNode(this, new AndroidFeatureResearchCost(18))
.withDescription();
}
}

View File

@ -3,10 +3,13 @@ package ru.dbotthepony.mc.otm.capability.android;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.network.MatteryNetworking;
import ru.dbotthepony.mc.otm.network.android.AndroidResearchRequestPacket;
import ru.dbotthepony.mc.otm.screen.RenderHelper;
import ru.dbotthepony.mc.otm.screen.SkinElement;
import java.util.HashSet;
import java.util.List;
@ -19,11 +22,21 @@ public class AndroidFeatureResearchNode {
public final Set<AndroidFeatureType<?>> predecessors = new HashSet<>();
protected final Component name;
protected final Component description;
public boolean with_description = false;
public SkinElement icon;
public AndroidFeatureResearchNode(AndroidFeatureType<?> type, AndroidFeatureResearchCost cost) {
this.type = type;
this.cost = cost;
name = new TranslatableComponent("android_feature." + type.getRegistryName().getNamespace() + "." + type.getRegistryName().getPath());
description = new TranslatableComponent("android_feature." + type.getRegistryName().getNamespace() + "." + type.getRegistryName().getPath() + ".description");
}
public AndroidFeatureResearchNode(AndroidFeatureType<?> type, AndroidFeatureResearchCost cost, SkinElement icon) {
this(type, cost);
this.icon = icon;
}
public AndroidFeatureResearchNode addPredecessor(AndroidFeatureType<?> value) {
@ -31,6 +44,11 @@ public class AndroidFeatureResearchNode {
return this;
}
public AndroidFeatureResearchNode withDescription() {
with_description = true;
return this;
}
public boolean canResearch(Player ply, AndroidCapabilityPlayer cap) {
for (var prec : predecessors) {
if (!cap.hasFeature(prec))
@ -69,7 +87,15 @@ public class AndroidFeatureResearchNode {
return name;
}
public Component getDescription() {
return description;
}
public List<Component> getTooltip() {
if (with_description) {
return List.of(getName(), getDescription());
}
return List.of(getName());
}
}

View File

@ -2,34 +2,96 @@ package ru.dbotthepony.mc.otm.screen;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.capability.android.AndroidCapabilityPlayer;
import ru.dbotthepony.mc.otm.capability.android.AndroidFeatureResearchNode;
import ru.dbotthepony.mc.otm.menu.AndroidStationMenu;
import ru.dbotthepony.mc.otm.screen.panels.Dock;
import ru.dbotthepony.mc.otm.screen.panels.EditBoxPanel;
import ru.dbotthepony.mc.otm.screen.panels.EditablePanel;
import ru.dbotthepony.mc.otm.screen.panels.FramePanel;
import ru.dbotthepony.mc.otm.screen.panels.*;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class AndroidStationScreen extends MatteryScreen<AndroidStationMenu> {
private static final ResourceLocation CONTAINER_BACKGROUND = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/android_station.png");
class AndroidFeatureButton extends EditablePanel {
public static final int BUTTON_SIZE = 16;
private final AndroidFeatureResearchNode node;
@Override
protected ResourceLocation CONTAINER_BACKGROUND() {
return CONTAINER_BACKGROUND;
public static final RGBAColor RESEARCHED = new RGBAColor(150, 150, 200);
public static final RGBAColor CAN_BE_RESEARCHED = new RGBAColor(150, 200, 150);
public static final RGBAColor CAN_NOT_BE_RESEARCHED = new RGBAColor(200, 150, 150);
public AndroidFeatureButton(@Nullable EditablePanel parent, AndroidFeatureResearchNode node) {
super(AndroidStationScreen.this, parent, 0, 0, BUTTON_SIZE, BUTTON_SIZE);
this.node = node;
setDockMargin(2, 2, 0, 0);
}
@Override
protected void innerRender(PoseStack stack, float mouse_x, float mouse_y, float flag) {
Minecraft.getInstance().player.getCapability(MatteryCapability.ANDROID).ifPresent(_cap -> {
if (_cap instanceof AndroidCapabilityPlayer cap) {
if (cap.hasFeature(node.type)) {
RenderHelper.setDrawColor(RESEARCHED);
} else if (node.canResearch(Minecraft.getInstance().player, cap)) {
RenderHelper.setDrawColor(CAN_BE_RESEARCHED);
} else {
RenderHelper.setDrawColor(CAN_NOT_BE_RESEARCHED);
}
RenderHelper.drawRect(stack, 0, 0, getWidth(), getHeight());
}
});
}
@Override
protected boolean mouseClickedInner(double mouse_x, double mouse_y, int flag) {
node.researchClient();
return true;
}
@Override
protected boolean innerRenderTooltips(PoseStack stack, float mouse_x, float mouse_y, float flag) {
if (is_hovered) {
var list = new ArrayList<>(node.getTooltip());
Minecraft.getInstance().player.getCapability(MatteryCapability.ANDROID).ifPresent(_cap -> {
if (_cap instanceof AndroidCapabilityPlayer cap) {
if (cap.hasFeature(node.type)) {
list.add(new TranslatableComponent("otm.android_station.research.researched").withStyle(ChatFormatting.DARK_AQUA));
} else if (node.canResearch(Minecraft.getInstance().player, cap)) {
list.add(new TranslatableComponent("otm.android_station.research.can_be_researched").withStyle(ChatFormatting.DARK_GREEN));
} else {
list.add(new TranslatableComponent("otm.android_station.research.can_not_be_researched").withStyle(ChatFormatting.DARK_RED));
}
}
});
renderComponentTooltip(stack, list, (int) mouse_x, (int) mouse_y);
}
return is_hovered;
}
}
private final Set<AndroidFeatureResearchNode> nodes = new HashSet<>();
private FramePanel frame = new FramePanel(this, null, 0, 0, 80, 120, new TextComponent("test"));
public static final int FRAME_WIDTH = 210;
public static final int GRID_WIDTH = 6;
public static final int GRID_HEIGHT = 5;
public static final int FRAME_HEIGHT = 120;
public AndroidStationScreen(AndroidStationMenu p_97741_, Inventory p_97742_, Component p_97743_) {
super(p_97741_, p_97742_, p_97743_);
@ -43,32 +105,23 @@ public class AndroidStationScreen extends MatteryScreen<AndroidStationMenu> {
}
}
@Nullable
@Override
public boolean mouseClicked(double mouseX, double mouseY, int p_97750_) {
int x = leftPos + 40;
int y = topPos + 10;
protected FramePanel makeMainFrame() {
var frame = new FramePanel(this, null, 0, 0, FRAME_WIDTH, FRAME_HEIGHT, getTitle());
for (var node : nodes) {
if (mouseX >= x && mouseX <= x + 16 && mouseY >= y && mouseY <= y + 16) {
node.researchClient();
return true;
var grid = new GridPanel(this, frame, 0, 0, GRID_WIDTH * 18, 0, GRID_WIDTH, GRID_HEIGHT);
for (var feature : Registry.ANDROID_FEATURES().getValues()) {
var node = feature.getResearchNode();
if (node != null) {
new AndroidFeatureButton(grid, node);
}
}
return super.mouseClicked(mouseX, mouseY, p_97750_);
}
grid.setDocking(Dock.RIGHT);
@Override
protected void renderTooltip(PoseStack pose, int mouseX, int mouseY) {
super.renderTooltip(pose, mouseX, mouseY);
int x = leftPos + 40;
int y = topPos + 10;
for (var node : nodes) {
if (mouseX >= x && mouseX <= x + 16 && mouseY >= y && mouseY <= y + 16) {
renderComponentTooltip(pose, node.getTooltip(), mouseX, mouseY);
}
}
return frame;
}
}

View File

@ -45,9 +45,6 @@ import java.util.Set;
* @param <T> type of menu, which extends MatteryMenu
*/
public abstract class MatteryScreen<T extends MatteryMenu> extends AbstractContainerScreen<T> {
protected static final ResourceLocation CONTAINER_BASE = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/generic_machine.png");
public static final ResourceLocation WIDGETS = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets.png");
public static final float SNAPBACK_SPEED = 100.0F;
public static final int QUICKDROP_DELAY = 500;
public static final int DOUBLECLICK_SPEED = 250;
@ -98,10 +95,6 @@ public abstract class MatteryScreen<T extends MatteryMenu> extends AbstractConta
protected boolean doubleclick;
protected ItemStack lastQuickMoved = ItemStack.EMPTY;
protected ResourceLocation CONTAINER_BACKGROUND() {
return CONTAINER_BASE;
}
protected final ArrayList<EditablePanel> panels = new ArrayList<>();
public FramePanel inventory_frame;
public FramePanel main_frame;

View File

@ -181,108 +181,6 @@ public class RenderHelper {
drawTexturedRectUV(stack, x, y, width, height, 0, 0, 1, 1);
}
public record SkinElement(ResourceLocation texture, float image_x, float image_y, float rect_w, float rect_h, float defined_width, float defined_height) {
public void render(PoseStack stack, float x, float y, float width, float height) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
drawTexturedRectUV(
stack,
x,
y,
width,
height,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
public void render(PoseStack stack, float x, float y) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
drawTexturedRectUV(
stack,
x,
y,
rect_w,
rect_h,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
public void renderW(PoseStack stack, float x, float y, float width) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
drawTexturedRectUV(
stack,
x,
y,
width,
rect_h,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
public void renderH(PoseStack stack, float x, float y, float height) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
drawTexturedRectUV(
stack,
x,
y,
rect_w,
height,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
public void renderRaw(PoseStack stack, float x, float y, float width, float height) {
// RenderSystem.setShader(GameRenderer::getPositionTexShader);
// RenderSystem.setShaderTexture(0, texture);
drawTexturedRectUV(
stack,
x,
y,
width,
height,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
public void renderRaw(PoseStack stack, float x, float y) {
// RenderSystem.setShader(GameRenderer::getPositionTexShader);
// RenderSystem.setShaderTexture(0, texture);
drawTexturedRectUV(
stack,
x,
y,
rect_w,
rect_h,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
}
public static final SkinElement top_left_window_corner = new SkinElement(
WIDGETS,
18,

View File

@ -0,0 +1,111 @@
package ru.dbotthepony.mc.otm.screen;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.resources.ResourceLocation;
/**
* Represents a texture element on atlas
*/
public record SkinElement(ResourceLocation texture, float image_x, float image_y, float rect_w, float rect_h,
float defined_width, float defined_height) {
public void render(PoseStack stack, float x, float y, float width, float height) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderHelper.drawTexturedRectUV(
stack,
x,
y,
width,
height,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
public void render(PoseStack stack, float x, float y) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderHelper.drawTexturedRectUV(
stack,
x,
y,
rect_w,
rect_h,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
public void renderW(PoseStack stack, float x, float y, float width) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderHelper.drawTexturedRectUV(
stack,
x,
y,
width,
rect_h,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
public void renderH(PoseStack stack, float x, float y, float height) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderHelper.drawTexturedRectUV(
stack,
x,
y,
rect_w,
height,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
public void renderRaw(PoseStack stack, float x, float y, float width, float height) {
// RenderSystem.setShader(GameRenderer::getPositionTexShader);
// RenderSystem.setShaderTexture(0, texture);
RenderHelper.drawTexturedRectUV(
stack,
x,
y,
width,
height,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
public void renderRaw(PoseStack stack, float x, float y) {
// RenderSystem.setShader(GameRenderer::getPositionTexShader);
// RenderSystem.setShaderTexture(0, texture);
RenderHelper.drawTexturedRectUV(
stack,
x,
y,
rect_w,
rect_h,
image_x / defined_width,
image_y / defined_height,
(image_x + rect_w) / defined_width,
(image_y + rect_h) / defined_height);
}
}

View File

@ -43,9 +43,9 @@ public class GridPanel extends EditablePanel {
}
if (child.getVisible()) {
line_y = Math.max(line_y, child.getHeight());
child.setPos(current_x, current_y);
current_x += child.getWidth();
line_y = Math.max(line_y, child.getHeight() + child.getDockMargin().top() + child.getDockMargin().bottom());
child.setPos(current_x + child.getDockMargin().left(), current_y + child.getDockMargin().top());
current_x += child.getWidth() + child.getDockMargin().left() + child.getDockMargin().right();
} else {
column--;
}

View File

@ -36,6 +36,13 @@
"otm.gui.matter_task.in_progress": "In progress: %s",
"otm.gui.matter_task.finished": "Finished: %s",
"otm.android_station.research.researched": "Researched!",
"otm.android_station.research.can_be_researched": "Ready to research!",
"otm.android_station.research.can_not_be_researched": "Can not afford!",
"android_feature.overdrive_that_matters.air_bags": "Air bags",
"android_feature.overdrive_that_matters.air_bags.description": "Allows to swim in water",
"otm.suffix.merge": "%s %s",
"otm.suffix.kilo": "%s k%s",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB