Fix layering of tooltips and make buttons more hmmmhmmmhmmm

This commit is contained in:
Sollace 2018-07-27 19:42:37 +02:00
parent 063d9bfbd0
commit 25230a384c
9 changed files with 71 additions and 97 deletions

View file

@ -0,0 +1,7 @@
package com.minelittlepony.gui;
import net.minecraft.client.Minecraft;
public interface IGuiTooltipped {
void renderToolTip(Minecraft mc, int mouseX, int mouseY);
}

View file

@ -7,7 +7,7 @@ import com.google.common.base.Splitter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
public class Button extends GuiButton implements IActionable {
public class Button extends GuiButton implements IActionable, IGuiTooltipped {
private IGuiAction<Button> action;
@ -38,8 +38,8 @@ public class Button extends GuiButton implements IActionable {
return setTooltip(Splitter.on("\r\n").splitToList(GameGui.format(tooltip)));
}
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
super.drawButton(mc, mouseX, mouseY, partialTicks);
@Override
public void renderToolTip(Minecraft mc, int mouseX, int mouseY) {
if (visible && isMouseOver() && tooltip != null) {
mc.currentScreen.drawHoveringText(tooltip, mouseX, mouseY);
}

View file

@ -16,4 +16,19 @@ public abstract class GameGui extends GuiScreen {
protected static String format(String string) {
return I18n.format(string);
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawContents(mouseX, mouseY, partialTicks);
buttonList.forEach(button -> {
if (button instanceof IGuiTooltipped) {
((IGuiTooltipped)button).renderToolTip(mc, mouseX, mouseY);
}
});
}
protected void drawContents(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View file

@ -271,28 +271,28 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
clearListeners.add(listener);
}
public static void clearSkinCache() {
public void clearSkinCache() {
LiteLoaderLogger.info("Clearing local player skin cache");
try {
FileUtils.deleteDirectory(new File(LiteLoader.getAssetsDirectory(), "skins"));
FileUtils.deleteDirectory(new File(LiteLoader.getAssetsDirectory(), "hd"));
TextureManager textures = Minecraft.getMinecraft().getTextureManager();
INSTANCE.skinCache.values().stream()
skinCache.values().stream()
.flatMap(m -> m.values().stream())
.forEach(textures::deleteTexture);
INSTANCE.skinCache.clear();
INSTANCE.skins.invalidateAll();
} catch (IOException var1) {
var1.printStackTrace();
skinCache.clear();
skins.invalidateAll();
} catch (IOException e) {
e.printStackTrace();
}
INSTANCE.clearListeners = INSTANCE.clearListeners.stream()
.filter(HDSkinManager::onSkinCacheCleared)
clearListeners = clearListeners.stream()
.filter(this::onSkinCacheCleared)
.collect(Collectors.toList());
}
private static boolean onSkinCacheCleared(ISkinCacheClearListener callback) {
private boolean onSkinCacheCleared(ISkinCacheClearListener callback) {
try {
return callback.onSkinCacheCleared();
} catch (Exception e) {

View file

@ -55,7 +55,7 @@ public class LiteModHDSkins implements InitCompleteListener, ViewportListener, C
@Override
public void upgradeSettings(String version, File configPath, File oldConfigPath) {
HDSkinManager.clearSkinCache();
HDSkinManager.INSTANCE.clearSkinCache();
}
@Override

View file

@ -20,12 +20,14 @@ import com.voxelmodpack.hdskins.skins.SkinUploadResponse;
import com.voxelmodpack.hdskins.upload.awt.ThreadOpenFilePNG;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
@ -242,7 +244,7 @@ public class GuiSkins extends GameGui {
})).setEnabled(!thinArmType).setTooltip("hdskins.mode.skinny");
addButton(new Button(width - 25, height - 65, 20, 20, "?", sender -> {
mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.ENTITY_VILLAGER_YES, 1));
})).setTooltip(Splitter.on("\r\n").splitToList(HDSkinManager.INSTANCE.getGatewayServer().toString()));
}
@ -288,6 +290,8 @@ public class GuiSkins extends GameGui {
}
protected void switchSkinMode(Button sender, boolean thin, Type newType, ItemStack stack) {
mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.BLOCK_BREWING_STAND_BREW, 1));
thinArmType = thin;
textureType = newType;
@ -360,7 +364,7 @@ public class GuiSkins extends GameGui {
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTick) {
protected void drawContents(int mouseX, int mouseY, float partialTick) {
float deltaTime = panorama.getDelta(partialTick);
panorama.render(partialTick, zLevel);
@ -376,7 +380,7 @@ public class GuiSkins extends GameGui {
drawGradientRect(30, horizon, mid - 30, bottom, 0x80FFFFFF, 0xffffff);
drawGradientRect(mid + 30, horizon, width - 30, bottom, 0x80FFFFFF, 0xffffff);
super.drawScreen(mouseX, mouseY, partialTick);
super.drawContents(mouseX, mouseY, partialTick);
popAttrib();
enableClipping(bottom);

View file

@ -1,50 +1,23 @@
package com.voxelmodpack.hdskins.gui;
import com.mumfrey.liteloader.client.gui.GuiCheckbox;
import com.minelittlepony.gui.Button;
import com.minelittlepony.gui.Checkbox;
import com.minelittlepony.gui.SettingsPanel;
import com.mumfrey.liteloader.core.LiteLoader;
import com.mumfrey.liteloader.modconfig.ConfigPanel;
import com.mumfrey.liteloader.modconfig.ConfigPanelHost;
import com.voxelmodpack.hdskins.HDSkinManager;
import com.voxelmodpack.hdskins.LiteModHDSkins;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
public class HDSkinsConfigPanel implements ConfigPanel {
private GuiButton button;
private GuiCheckbox checkbox;
private LiteModHDSkins mod;
public class HDSkinsConfigPanel extends SettingsPanel {
@Override
public void onPanelShown(ConfigPanelHost host) {
this.mod = LiteLoader.getInstance().getMod(LiteModHDSkins.class);
public void initGui() {
final LiteModHDSkins mod = LiteLoader.getInstance().getMod(LiteModHDSkins.class);
this.button = new GuiButton(0, 40, 70, 100, 20, "Clear Skin Cache");
this.checkbox = new GuiCheckbox(1, 40, 40, "Experimental Skin Drop");
this.checkbox.checked = mod.experimentalSkinDrop;
}
@Override
public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) {
Minecraft mc = Minecraft.getMinecraft();
this.button.drawButton(mc, mouseX, mouseY, partialTicks);
this.checkbox.drawButton(mc, mouseX, mouseY, partialTicks);
}
@Override
public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) {
Minecraft mc = Minecraft.getMinecraft();
if (button.mousePressed(mc, mouseX, mouseY)) {
HDSkinManager.clearSkinCache();
} else if (checkbox.mousePressed(mc, mouseX, mouseY)) {
checkbox.checked = !checkbox.checked;
mod.experimentalSkinDrop = checkbox.checked;
addButton(new Button(40, 70, 100, 20, "Clear Skin Cache", sender ->{
HDSkinManager.INSTANCE.clearSkinCache();
}));
addButton(new Checkbox(40, 40, "Experimental Skin Drop", mod.experimentalSkinDrop, checked -> {
System.out.println(checked);
mod.experimentalSkinDrop = checked;
LiteLoader.getInstance().writeConfig(mod);
@ -53,40 +26,13 @@ public class HDSkinsConfigPanel implements ConfigPanel {
} else {
GLWindow.dispose();
}
}
return checked;
}));
}
@Override
public String getPanelTitle() {
protected String getTitle() {
return "HD Skins Settings";
}
@Override
public int getContentHeight() {
return 0;
}
@Override
public void keyPressed(ConfigPanelHost host, char keyChar, int keyCode) {
}
@Override
public void mouseMoved(ConfigPanelHost host, int mouseX, int mouseY) {
}
@Override
public void mouseReleased(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) {
}
@Override
public void onPanelHidden() {
}
@Override
public void onPanelResize(ConfigPanelHost host) {
}
@Override
public void onTick(ConfigPanelHost host) {
}
}

View file

@ -64,9 +64,9 @@ public class GuiPonySettings extends SettingsPanel {
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
public void drawContents(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
super.drawContents(mouseX, mouseY, partialTicks);
}
@Override

View file

@ -10,7 +10,9 @@ import com.voxelmodpack.hdskins.gui.EntityPlayerModel;
import com.voxelmodpack.hdskins.gui.GuiItemStackButton;
import com.voxelmodpack.hdskins.gui.GuiSkins;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
@ -42,17 +44,11 @@ public class GuiSkinsMineLP extends GuiSkins {
super.initGui();
addButton(btnModeWet = new GuiItemStackButton(width - 25, 139, new ItemStack(Items.WATER_BUCKET), sender -> {
if (!isWet) {
setWet(true);
}
})).setTooltip("minelp.mode.wet");
addButton(btnModeDry = new GuiItemStackButton(width - 25, 120, new ItemStack(Items.BUCKET), sender -> {
if (isWet) {
setWet(false);
}
})).setTooltip("minelp.mode.dry");
setWet(false);
})).setEnabled(false).setTooltip("minelp.mode.dry");
}
@Override
@ -63,6 +59,12 @@ public class GuiSkinsMineLP extends GuiSkins {
}
protected void setWet(boolean wet) {
if (wet == isWet) {
return;
}
mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.BLOCK_BREWING_STAND_BREW, 1));
isWet = wet;
localPlayer.releaseTextures();