Skip to content

Commit 5a2f9f3

Browse files
committed
minor gui tweaks
1 parent 8128f2d commit 5a2f9f3

4 files changed

Lines changed: 36 additions & 26 deletions

File tree

common/src/main/java/com/evandev/fieldguide/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class Constants {
2929
public static final ResourceLocation CELL_BACKGROUND_TEXTURE = new ResourceLocation(MOD_ID, "textures/gui/cell_background.png");
3030
public static final ResourceLocation ITEM_BACKGROUND_TEXTURE = new ResourceLocation(MOD_ID, "textures/gui/item_background.png");
3131
public static final ResourceLocation CELL_BACKGROUND_HOVER_TEXTURE = new ResourceLocation(MOD_ID, "textures/gui/cell_background_hover.png");
32+
public static final ResourceLocation HEALTH_FRAME_TEXTURE = new ResourceLocation(MOD_ID, "textures/gui/health_frame.png");
3233

3334
// ICONS
3435
public static final ResourceLocation SEARCH_ICON = new ResourceLocation(MOD_ID, "textures/gui/icons/search.png");

common/src/main/java/com/evandev/fieldguide/client/gui/screens/FieldGuideEntryScreen.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,31 +190,38 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
190190
return false;
191191
}
192192

193-
private void renderAttributeTextAndIcon(GuiGraphics guiGraphics, int iconOffset, String text, Bounds bounds) {
193+
private void renderAttributes(GuiGraphics guiGraphics, LivingEntity entity) {
194+
RenderSystem.setShaderTexture(0, Constants.ATTRIBUTES_TEXTURE);
194195
int iconSize = 9;
195-
int iconSpacing = 4;
196-
int width = iconSize + iconSpacing + font.width(text);
196+
int iconSpacing = 2;
197+
int gap = 8;
197198

198-
// Center within given bounds
199-
int y = bounds.y_center() - iconSize / 2;
200-
int x = bounds.x_center() - width / 2;
199+
int yPos = leftPageBounds.top() + 13;
201200

202-
guiGraphics.blit(Constants.ATTRIBUTES_TEXTURE, x, y, 0, iconOffset, iconSize, iconSize, 32, 32);
203-
guiGraphics.drawString(this.font, text, x + iconSize + iconSpacing, y + 1, Constants.TEXT_COLOR, false);
204-
}
201+
String health = String.valueOf((int)entity.getMaxHealth() / 2);
202+
String armor = String.valueOf(entity.getArmorValue());
203+
boolean showArmor = !armor.equals("0");
205204

206-
private void renderAttributes(GuiGraphics guiGraphics, LivingEntity entity) {
207-
RenderSystem.setShaderTexture(0, Constants.ATTRIBUTES_TEXTURE);
205+
int healthWidth = this.font.width(health) + iconSpacing + iconSize;
206+
int armorWidth = this.font.width(armor) + iconSpacing + iconSize;
207+
int totalWidth = healthWidth + (showArmor ? gap + armorWidth : 0);
208208

209-
// Health
210-
String health = String.valueOf((int)entity.getMaxHealth() / 2);
211-
Bounds healthBounds = new Bounds(leftPageBounds.left(), leftPageBounds.bottom() - 48, leftPageBounds.width() / 2, 20);
212-
renderAttributeTextAndIcon(guiGraphics, 0, health, healthBounds);
209+
int xPos = this.leftPageBounds.x_center() - (totalWidth / 2);
213210

214-
// Armor
215-
String armor = String.valueOf(entity.getArmorValue());
216-
Bounds armorBounds = new Bounds(leftPageBounds.x_center(), leftPageBounds.bottom() - 48, leftPageBounds.width() / 2, 20);
217-
renderAttributeTextAndIcon(guiGraphics, 9, armor, armorBounds);
211+
// Draw Health
212+
guiGraphics.blit(Constants.ATTRIBUTES_TEXTURE, xPos, yPos, 0, 0, iconSize, iconSize, 32, 32);
213+
guiGraphics.drawString(this.font, health, xPos + iconSize + iconSpacing, yPos + 1, Constants.TEXT_COLOR, false);
214+
215+
// Draw Frame
216+
guiGraphics.blit(Constants.HEALTH_FRAME_TEXTURE, xPos - 9, yPos - 4, 0, 0, 8, 16, 16, 16);
217+
guiGraphics.blit(Constants.HEALTH_FRAME_TEXTURE, xPos + totalWidth + 1, yPos - 4, 8, 0, 8, 16, 16, 16);
218+
219+
if (showArmor) {
220+
// Draw Armor
221+
xPos = xPos + healthWidth + gap;
222+
guiGraphics.blit(Constants.ATTRIBUTES_TEXTURE, xPos, yPos, 0, iconSize, iconSize, iconSize, 32, 32);
223+
guiGraphics.drawString(this.font, armor, xPos + iconSize + iconSpacing, yPos + 1, Constants.TEXT_COLOR, false);
224+
}
218225
}
219226

220227
@Override
@@ -289,7 +296,7 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
289296
}
290297

291298
int xPos = leftPageBounds.x_center();
292-
int yPos = leftPageBounds.y_center() - 20;
299+
int yPos = leftPageBounds.y_center();
293300

294301
if (entry instanceof EntityType && renderedEntity instanceof LivingEntity living) {
295302
if (unlocked) {

common/src/main/java/com/evandev/fieldguide/client/gui/screens/FieldGuideScreen.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,10 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
374374
ResourceLocation texture = new ResourceLocation(biomeId.getNamespace(), "textures/immersiveoverlays/" + biomeId.getPath() + ".png");
375375
int iconSize = 16;
376376
int iconY = titleY - 5;
377-
guiGraphics.blit(texture, this.leftPageBounds.left(), iconY, 0, 0, iconSize, iconSize, iconSize, iconSize);
377+
int iconX = this.leftPageBounds.left() - 3;
378+
guiGraphics.blit(texture, iconX, iconY, 0, 0, iconSize, iconSize, iconSize, iconSize);
378379
Component searchTitle = Component.translatable("biome." + biomeId.getNamespace() + "." + biomeId.getPath());
379-
guiGraphics.drawString(this.font, searchTitle, this.leftPageBounds.left() + iconSize + 4, titleY, Constants.TEXT_COLOR, false);
380+
guiGraphics.drawString(this.font, searchTitle, iconX + iconSize + 4, titleY, Constants.TEXT_COLOR, false);
380381
}
381382
} else if (searchQuery.startsWith("=^")) {
382383
guiGraphics.drawString(this.font, "Drops " + searchQuery.substring(2), this.leftPageBounds.left(), titleY, Constants.TEXT_COLOR, false);
@@ -406,14 +407,15 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
406407
}
407408
}
408409

409-
if (currentPage > 0 || isSearching) {
410-
renderGrid(guiGraphics, mouseX, mouseY);
411-
}
412-
413410
// Back button
414411
this.backButton.visible = this.isSearching;
415412

416413
super.render(guiGraphics, mouseX, mouseY, partialTick);
414+
415+
// Render grid
416+
if (currentPage > 0 || isSearching) {
417+
renderGrid(guiGraphics, mouseX, mouseY);
418+
}
417419
}
418420

419421
private void renderCategoryInfo(GuiGraphics guiGraphics) {
166 Bytes
Loading

0 commit comments

Comments
 (0)