Skip to content

Commit

Permalink
Stage rules screen and general fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cibernet83 committed Feb 23, 2024
1 parent 80a5663 commit 2078568
Show file tree
Hide file tree
Showing 17 changed files with 453 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,31 @@ public boolean mouseClicked(double mouseX, double mouseY, int clickButton)
{
if(canClickButtons())
for (MenuButton button : buttons)
if(button.isActive())
if(button.isActive() && button.isHovered())
button.mouseClicked(mouseX, mouseY, clickButton);
return super.mouseClicked(mouseX, mouseY, clickButton);
}

@Override
public boolean mouseReleased(double mouseX, double mouseY, int clickButton)
{
if(canClickButtons())
for (MenuButton button : buttons)
button.mouseReleased(mouseX, mouseY, clickButton);
return super.mouseClicked(mouseX, mouseY, clickButton);
}


@Override
public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, double p_94702_, double p_94703_)
{
if(canClickButtons())
for (MenuButton button : buttons)
if(button.isActive())
button.mouseDragged(mouseX, mouseY, mouseButton, p_94702_, p_94703_);
return super.mouseDragged(mouseX, mouseY, mouseButton, p_94702_, p_94703_);
}

private void renderTooltips(PoseStack poseStack, int mouseX, int mouseY)
{
for(MenuButton button : buttons)
Expand All @@ -126,7 +146,7 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic

for (MenuButton button : buttons) {
button.setHovered(false);
if (isMouseOver(mouseX, mouseY, button))
if (button.isActive() && isMouseOver(mouseX, mouseY, button))
hoveredButton = button;
}

Expand All @@ -138,6 +158,7 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic


renderBackground(poseStack);
handleWidgets(poseStack, mouseX, mouseY, partialTicks);

int x = (width - imageWidth) / 2;
int y = (height - imageHeight) / 2;
Expand All @@ -150,12 +171,11 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic
button.y = button.relativeY + y;
}

handleWidgets(poseStack, mouseX, mouseY, partialTicks);
super.render(poseStack, mouseX, mouseY, partialTicks);
renderTooltips(poseStack, mouseX, mouseY);


buttons.forEach(b -> b.renderButton(poseStack));
buttons.forEach(b -> b.render(poseStack, mouseX, mouseY, partialTicks));
textFields.forEach(t -> t.render(poseStack, mouseX, mouseY, partialTicks));
}

Expand Down Expand Up @@ -271,14 +291,17 @@ public boolean canClickButtons()
{
return true;
}

public abstract void onStagesUpdate();

public abstract void handleWidgets(PoseStack poseStack, int mouseX, int mouseY, float partialTicks);

protected void addOptionsTabs(Component label, String stageId, Screen mainMenu)
{
addButton(new MenuButton(10, 12, 14, 12, goToScreen(() -> mainMenu), Button.NO_TOOLTIP, drawIcon(WIDGETS, 1, 0, 244, 24, 12, 12), MenuButton.ButtonColor.GREEN));
addButton(new MenuButton(24, 12, 44, 12, goToScreen(() -> new StageSettingsScreen(label, stageId, mainMenu)), Button.NO_TOOLTIP, drawText(new TranslatableComponent("gui.stage_pad.tab.settings"), true), MenuButton.ButtonColor.PURPLE));
addButton(new MenuButton(68, 12, 44, 12, goToScreen(() -> new StageRulesScreen(label, stageId, mainMenu)), Button.NO_TOOLTIP, drawText(new TranslatableComponent("gui.stage_pad.tab.rules"), true), MenuButton.ButtonColor.PURPLE));
addButton(new MenuButton(112, 12, 44, 12, goToScreen(() -> new StageSettingsScreen(label, stageId, mainMenu)), Button.NO_TOOLTIP, drawText(new TranslatableComponent("gui.stage_pad.tab.teams"), true), MenuButton.ButtonColor.PURPLE));
addButton(new MenuButton(112, 12, 44, 12, goToScreen(() -> new StageTeamsScreen(label, stageId, mainMenu)), Button.NO_TOOLTIP, drawText(new TranslatableComponent("gui.stage_pad.tab.teams"), true), MenuButton.ButtonColor.PURPLE));
addButton(new MenuButton(156, 12, 44, 12, goToScreen(() -> new StageActionsScreen(label, stageId, mainMenu)), Button.NO_TOOLTIP, drawText(new TranslatableComponent("gui.stage_pad.tab.actions"), true), MenuButton.ButtonColor.PURPLE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,21 @@ public MenuButton(int x, int y, int width, int height, OnPress onPress, OnToolti
relativeY = y;
}

public void renderButton(PoseStack poseStack) {
@Override
public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks)
{
if (this.visible)
{
//this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
this.renderButton(poseStack, mouseX, mouseY, partialTicks);

//if(isHoveredOrFocused())
// this.renderToolTip(poseStack, mouseX, mouseY);
}
}

@Override
public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) {
if(!visible)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class StageActionsScreen extends AbstractStagePadScreen
{
private static final ResourceLocation TEXTURES = new ResourceLocation(Splatcraft.MODID, "textures/gui/stage_pad/stage_actions.png");
private final Stage stage;
private Stage stage;
private final StageSelectionScreen.ToggleMenuButton scanMode;
public StageActionsScreen(Component label, String stageId, Screen mainMenu)
{
Expand All @@ -46,6 +46,14 @@ public StageActionsScreen(Component label, String stageId, Screen mainMenu)
addButton(new MenuButton(50, 78, 110, 12, goToScreen(() -> mainMenu), Button.NO_TOOLTIP, drawText(new TranslatableComponent("gui.stage_pad.button.pair_remote"), true), MenuButton.ButtonColor.GREEN));
}

@Override
public void onStagesUpdate()
{

stage = Stage.getStage(getMinecraft().level, stage.id);

}

@Override
public void handleWidgets(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ private void updateId()
String savedId = stageName.getValue().replace(' ', '_');
String newId = savedId;

if(getMinecraft().getSingleplayerServer() != null && !newId.isEmpty())
if(getMinecraft().level != null && !newId.isEmpty())
{
HashMap<String, Stage> stages = SaveInfoCapability.get(getMinecraft().getSingleplayerServer()).getStages();
HashMap<String, Stage> stages = SaveInfoCapability.get(getMinecraft().level.getServer()).getStages();
for (int i = 1; stages.containsKey(newId); i++)
newId = savedId + "_" + i;
} else newId = "";
Expand Down Expand Up @@ -210,6 +210,12 @@ public void renderBackground(PoseStack poseStack)

}

@Override
public void onStagesUpdate()
{
updateId();
}

public String getStageId() {
return stageId;
}
Expand Down
Loading

0 comments on commit 2078568

Please sign in to comment.