From 015c90e6c5884fcb416ff1db7da0105c1d27688e Mon Sep 17 00:00:00 2001 From: Kamesuta Date: Tue, 27 Sep 2016 02:17:59 +0900 Subject: [PATCH 1/7] ver --- info/info.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/info/info.json b/info/info.json index 7b02409f..1464f39b 100644 --- a/info/info.json +++ b/info/info.json @@ -10,12 +10,12 @@ } }, "1.8": { - "version": "2.1.5", - "remote": "https://github.com/Team-Fruit/SignPicture/releases/download/1.8-2.1.5/SignPicture-1.8-2.1.5-universal.jar", - "local": "SignPicture-1.8-2.1.5-universal.jar", - "message": "GUI Update! SignPicture 2.1.5 Released!", + "version": "2.2.2", + "remote": "https://github.com/Team-Fruit/SignPicture/releases/download/1.8.9-2.2.2/SignPicture-1.8.9-2.2.2-universal.jar", + "local": "SignPicture-1.8.9-2.2.2-universal.jar", + "message": "Offset And Rotations! More freely images! SignPicture 2.2.2 Released!", "message_local": { - "ja_JP": "遂にSignPictureにGUIが! SignPicture 2.1.5リリース!!" + "ja_JP": "オフセットと回転機能実装! さらに自由自在に画像を貼ろう! SignPicture 2.2.2 リリース!" } }, "1.9": { From 7a2eafe6da4b0712fb2748595361d9930ded8387 Mon Sep 17 00:00:00 2001 From: Kamesuta Date: Tue, 27 Sep 2016 22:14:43 +0900 Subject: [PATCH 2/7] Sign Format extend --- .../mc/bnnwidget/component/MTextField.java | 289 ------------------ .../kamesuta/mc/signpic/entry/EntryId.java | 25 +- 2 files changed, 14 insertions(+), 300 deletions(-) delete mode 100644 src/main/java/com/kamesuta/mc/bnnwidget/component/MTextField.java diff --git a/src/main/java/com/kamesuta/mc/bnnwidget/component/MTextField.java b/src/main/java/com/kamesuta/mc/bnnwidget/component/MTextField.java deleted file mode 100644 index ee284c65..00000000 --- a/src/main/java/com/kamesuta/mc/bnnwidget/component/MTextField.java +++ /dev/null @@ -1,289 +0,0 @@ -package com.kamesuta.mc.bnnwidget.component; - -import static org.lwjgl.opengl.GL11.*; - -import java.util.ArrayDeque; -import java.util.Deque; - -import org.apache.commons.lang3.StringUtils; -import org.lwjgl.input.Keyboard; - -import com.kamesuta.mc.bnnwidget.WBase; -import com.kamesuta.mc.bnnwidget.WEvent; -import com.kamesuta.mc.bnnwidget.position.Area; -import com.kamesuta.mc.bnnwidget.position.Point; -import com.kamesuta.mc.bnnwidget.position.R; -import com.kamesuta.mc.signpic.render.RenderHelper; - -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.util.ChatAllowedCharacters; - -@Deprecated -public class MTextField extends WBase { - protected String text = ""; - public String watermark; - protected int seek; - protected boolean isFocused; - protected boolean isEnabled; - public int maxStringLength; - public int cursorCounter; - public String actionCommand; - protected String allowedCharacters; - - protected Deque back = new ArrayDeque(); - protected Deque next = new ArrayDeque(); - - - public void setWatermark(final String watermark) { - this.watermark = watermark; - } - - public String getWatermark() { - return this.watermark; - } - - protected void log(final String s) { - if (!StringUtils.equals(s, this.back.peek())) { - final String t = this.next.poll(); - if (t!=null) - this.back.push(t); - this.next.clear(); - this.next.push(s); - } - //Reference.logger.info("log" + this.back + ":" + this.next); - } - - protected void next() { - if (!this.next.isEmpty()) { - final String s = getText(); - final String b = this.next.poll(); - this.back.push(s); - setTextRaw(b); - } - //Reference.logger.info("next" + this.back + ":" + this.next); - } - - protected void back() { - if (!this.back.isEmpty()) { - final String s = getText(); - final String b = this.back.poll(); - this.next.push(s); - setTextRaw(b); - } - //Reference.logger.info("back" + this.back + ":" + this.next); - } - - public MTextField(final R position) { - super(position); - this.isFocused = false; - this.isEnabled = true; - } - - public MTextField(final R position, final String watermark) { - this(position); - this.watermark = watermark; - } - - public boolean setText(final String s) { - if (setTextRaw(s)) { - log(s); - return true; - } - return false; - } - - public boolean setTextRaw(final String s) { - if ((s.length() <= this.maxStringLength) || (this.maxStringLength <= 0)) { - if (StringUtils.equals(s, getText())) { - return false; - } - final String oldText = getText(); - this.text = s; - onTextChanged(oldText); - return true; - } - return false; - } - - public final String getText() { - return this.text; - } - - protected void onTextChanged(final String oldText) { - } - - public final boolean isEnabled() { - return this.isEnabled; - } - - public void setEnabled(final boolean b) { - this.isEnabled = b; - if ((!this.isEnabled) && (this.isFocused)) { - setFocused(false); - } - } - - public final boolean isFocused() { - return this.isFocused; - } - - @Override - public void update(final WEvent ev, final Area pgp, final Point p) { - this.cursorCounter += 1; - } - - @Override - public void keyTyped(final WEvent ev, final Area pgp, final Point p, final char c, final int keycode) { - if ((!isEnabled()) || (!isFocused())) { - return; - } else if (keycode == Keyboard.KEY_LCONTROL || keycode == Keyboard.KEY_RCONTROL) { - return; - } else if (c == '\026') { - final String s = GuiScreen.getClipboardString(); - if (StringUtils.isEmpty(s)) { - return; - } - final StringBuilder stb = new StringBuilder(getText()); - int j = 0; - for (int i = 0; i < s.length(); i++) { - if ((getText().length() >= this.maxStringLength) && (this.maxStringLength > 0)) { - return; - } - final char tc = s.charAt(i); - if (canAddChar(tc)) { - stb.append(tc); - j++; - } - } - setText(stb.toString()); - this.seek += j; - } else if (c == '\031') { - next(); - } else if (c == '\032') { - back(); - } else if (keycode == Keyboard.KEY_BACK) { - final String s = getText(); - final int seek = getSeek(); - if (seek > 0) { - setText(s.substring(0, seek-1) + s.substring(seek, s.length())); - this.seek--; - } - } else if (keycode == Keyboard.KEY_DELETE) { - final String s = getText(); - final int seek = getSeek(); - if (seek < s.length()) - setText(s.substring(0, seek) + s.substring(seek+1, s.length())); - } else if (keycode == Keyboard.KEY_LEFT) { - this.seek--; - } else if (keycode == Keyboard.KEY_RIGHT) { - this.seek++; - } else if (keycode == Keyboard.KEY_HOME) { - this.seek = 0; - } else if (keycode == Keyboard.KEY_END) { - this.seek = getText().length(); - } else if (keycode == Keyboard.KEY_RETURN) { - setFocused(false); - } else if (((getText().length() < this.maxStringLength) || (this.maxStringLength == 0)) && (canAddChar(c))) { - final String s = getText(); - final int seek = getSeek(); - setText(s.substring(0, seek) + c + s.substring(seek, s.length())); - this.seek++; - } - } - - protected int getSeek() { - return this.seek = Math.min(getText().length(), Math.max(0, this.seek)); - } - - public boolean canAddChar(final char c) { - if (this.allowedCharacters == null) - return ChatAllowedCharacters.isAllowedCharacter(c); - else if (StringUtils.isEmpty(this.allowedCharacters)) - return true; - else - return this.allowedCharacters.indexOf(c) >= 0; - } - - @Override - public void mouseClicked(final WEvent ev, final Area pgp, final Point p, final int button) { - final Area gp = pgp.child(this.position); - if (gp.pointInside(p)) { - setFocused(true); - if (button == 1) { - setText(""); - } - final Area in = getGuiPosition(pgp).child(1, 1, -1, -1); - this.seek = font().trimStringToWidth(getText(), (int) (p.x() - (in.x1() + 4))).length(); - } else { - setFocused(false); - } - } - - public void setFocused(final boolean focus) { - if (focus == isFocused()) { - return; - } - this.isFocused = focus; - onFocusChanged(); - } - - public void onFocusChanged() { - if (isFocused()) { - this.cursorCounter = 0; - } - } - - @Override - public void draw(final WEvent ev, final Area pgp, final Point p, final float frame) { - final Area out = getGuiPosition(pgp); - final Area in = getGuiPosition(pgp).child(1, 1, -1, -1); - drawBackground(out, in); - drawWatermark(in); - drawText(in); - drawCursor(in); - } - - protected void drawBackground(final Area out, final Area in) { - RenderHelper.startShape(); - glColor4f(0.627451f, 0.627451f, 0.627451f, 1f); - drawRect(out); - glColor4f(0f, 0f, 0f, 1f); - drawRect(in); - } - - protected void drawWatermark(final Area a) { - RenderHelper.startTexture(); - if (!StringUtils.isEmpty(this.watermark)&& StringUtils.isEmpty(getText()) && !isFocused()) - drawString(this.watermark, a.x1() + 4, a.y1() + a.h() / 2 - 4, 0x777777); - } - - protected void drawText(final Area a) { - RenderHelper.startTexture(); - drawString(getText(), a.x1() + 4, a.y1() + a.h() / 2 - 4, getTextColour()); - } - - protected void drawCursor(final Area a) { - RenderHelper.startTexture(); - final String s = getText(); - final int seek = getSeek(); - final boolean blink = this.cursorCounter / 6 % 2 == 0; - if ((isEnabled()) && (isFocused())) { - if (blink) - drawCenteredString("\u2503", a.x1() + 4 + font().getStringWidth(s.substring(0, seek)), a.y1() + a.h() / 2 - 4, getTextColour()); - } - } - - public int getTextColour() { - return isEnabled() ? 14737632 : 7368816; - } - - public MTextField setMaxStringLength(final int i) { - this.maxStringLength = i; - return this; - } - - public MTextField setAllowedCharacters(final String s) { - this.allowedCharacters = s; - return this; - } -} diff --git a/src/main/java/com/kamesuta/mc/signpic/entry/EntryId.java b/src/main/java/com/kamesuta/mc/signpic/entry/EntryId.java index 5db4176d..e150273b 100644 --- a/src/main/java/com/kamesuta/mc/signpic/entry/EntryId.java +++ b/src/main/java/com/kamesuta/mc/signpic/entry/EntryId.java @@ -6,7 +6,6 @@ import com.kamesuta.mc.signpic.image.meta.ImageMeta; import net.minecraft.tileentity.TileEntitySign; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; public class EntryId { @@ -66,7 +65,7 @@ public static EntryId fromChats(final IChatComponent[] chats) { final StringBuilder stb = new StringBuilder(); for (final IChatComponent chat : chats) { if (chat!=null) - stb.append(chat.getFormattedText());new ChatComponentText("").getUnformattedText(); + stb.append(chat.getUnformattedText()); } return new EntryId(stb.toString()); } @@ -76,7 +75,13 @@ public boolean hasContentId() { } public boolean hasMeta() { - return StringUtils.endsWith(this.id, "]") && StringUtils.contains(this.id, "["); + return (StringUtils.endsWith(this.id, "]") && StringUtils.contains(this.id, "[")) || + (hasPrefix() && StringUtils.endsWith(this.id, "}") && StringUtils.contains(this.id, "{")); + } + + public boolean hasPrefix() { + final int i = StringUtils.indexOf(this.id, "#"); + return 0 <= i && i < 2; } public boolean isValid() { @@ -88,6 +93,8 @@ public ContentId getContentId() { String id; if (StringUtils.contains(this.id, "[")) id = StringUtils.substring(this.id, 0, StringUtils.lastIndexOf(this.id, "[")); + else if (hasPrefix() && StringUtils.contains(this.id, "{")) + id = StringUtils.substring(this.id, StringUtils.indexOf(this.id, "#")+1, StringUtils.lastIndexOf(this.id, "{")); else id = this.id; return new ContentId(id); @@ -97,7 +104,10 @@ public ContentId getContentId() { public ImageMeta getMeta() { if (hasMeta()) - return new ImageMeta().parse(StringUtils.substring(this.id, StringUtils.lastIndexOf(this.id, "[")+1, StringUtils.length(this.id)-1)); + if (StringUtils.endsWith(this.id, "}")) + return new ImageMeta().parse(StringUtils.substring(this.id, StringUtils.lastIndexOf(this.id, "{")+1, StringUtils.length(this.id)-1)); + else + return new ImageMeta().parse(StringUtils.substring(this.id, StringUtils.lastIndexOf(this.id, "[")+1, StringUtils.length(this.id)-1)); else return null; } @@ -119,11 +129,4 @@ public void toEntity(final TileEntitySign tile) { public Entry entry() { return EntryManager.instance.get(this); } - - @Deprecated - public String[] toStrings() { - final String[] strings = new String[4]; - toStrings(strings); - return strings; - } } From 6ae66a47c9744e6571aaa8db5d0d24ca9d82a491 Mon Sep 17 00:00:00 2001 From: Kamesuta Date: Tue, 27 Sep 2016 22:50:07 +0900 Subject: [PATCH 3/7] SignDelay --- .../mc/signpic/handler/CoreHandler.java | 16 ++++--- .../mc/signpic/handler/SignHandler.java | 42 ++++++++++++++++++- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java b/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java index 90a8cb43..2f764902 100644 --- a/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java +++ b/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java @@ -14,6 +14,7 @@ import cpw.mods.fml.common.gameevent.InputEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.client.event.MouseEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; @@ -73,11 +74,14 @@ public void onText(final RenderGameOverlayEvent.Text event) { @SubscribeEvent public void onTick(final ClientTickEvent event) { - Client.startSection("signpic_load"); - this.signEntryManager.onTick(); - this.contentManager.onTick(); - this.informationHandler.onTick(event); - EntrySlot.Tick(); - Client.endSection(); + if (event.phase == Phase.END) { + Client.startSection("signpic_load"); + this.signEntryManager.onTick(); + this.signHandler.onTick(); + this.contentManager.onTick(); + this.informationHandler.onTick(event); + EntrySlot.Tick(); + Client.endSection(); + } } } diff --git a/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java b/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java index 353cbadc..82990b61 100644 --- a/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java +++ b/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java @@ -1,5 +1,7 @@ package com.kamesuta.mc.signpic.handler; import java.lang.reflect.Field; +import java.util.ArrayDeque; +import java.util.Deque; import com.kamesuta.mc.signpic.Client; import com.kamesuta.mc.signpic.Reference; @@ -34,6 +36,44 @@ public static void init() { } } + private class SendPacketTask { + private int count; + private final EntryId id; + private final TileEntitySign entity; + + public SendPacketTask(final EntryId id, final TileEntitySign entity) { + this.count = 0; + this.id = id; + this.entity = entity; + } + + private void sendPacket() { + Sign.sendSign(this.id, this.entity); + } + + public boolean tick() { + this.count++; + if (this.count > sendPacketDelayTick) { + sendPacket(); + return true; + } + return false; + } + } + + public static final int sendPacketDelayTick = 1 * 20; + + private final Deque sendPacketQueue = new ArrayDeque(); + + @CoreEvent + public void onTick() { + final SendPacketTask task = this.sendPacketQueue.peek(); + if (task!=null) { + if (task.tick()) + this.sendPacketQueue.poll(); + } + } + @CoreEvent public void onSign(final GuiOpenEvent event) { if (CurrentMode.instance.isMode(CurrentMode.Mode.PLACE)) @@ -42,7 +82,7 @@ public void onSign(final GuiOpenEvent event) { try { final GuiEditSign ges = (GuiEditSign) event.gui; final TileEntitySign tileSign = (TileEntitySign) f.get(ges); - Sign.sendSign(CurrentMode.instance.getEntryId(), tileSign); + this.sendPacketQueue.offer(new SendPacketTask(CurrentMode.instance.getEntryId(), tileSign)); event.setCanceled(true); if (!CurrentMode.instance.isState(CurrentMode.State.CONTINUE)) { CurrentMode.instance.setMode(); From 63fd0b6484720bd025afd2470def5af414257fcd Mon Sep 17 00:00:00 2001 From: bebe0601 Date: Wed, 28 Sep 2016 15:27:50 +0900 Subject: [PATCH 4/7] # --- .../java/com/kamesuta/mc/bnnwidget/component/MButton.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/kamesuta/mc/bnnwidget/component/MButton.java b/src/main/java/com/kamesuta/mc/bnnwidget/component/MButton.java index 8074d10b..6fdcc717 100644 --- a/src/main/java/com/kamesuta/mc/bnnwidget/component/MButton.java +++ b/src/main/java/com/kamesuta/mc/bnnwidget/component/MButton.java @@ -9,8 +9,8 @@ import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.init.SoundEvents; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.SoundEvent; public class MButton extends WBase { public static final ResourceLocation button = new ResourceLocation("signpic", "textures/gui/buttons.png"); @@ -44,7 +44,7 @@ public void mouseClicked(final WEvent ev, final Area pgp, final Point p, final i if (this.actionCommand != null) ev.eventDispatch(this.actionCommand, Integer.valueOf(button)); mc.getSoundHandler() - .playSound(PositionedSoundRecord.getMasterRecord(new SoundEvent(new ResourceLocation("gui.button.press")), 1.0F)); + .playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F)); } } } From 3308605afe40d09a3ef8b2285cc43661f481e678 Mon Sep 17 00:00:00 2001 From: Kamesuta Date: Wed, 28 Sep 2016 16:39:38 +0900 Subject: [PATCH 5/7] GuiWating --- .../java/com/kamesuta/mc/bnnwidget/WGui.java | 39 +++--- .../com/kamesuta/mc/bnnwidget/WPanel.java | 4 +- .../mc/bnnwidget/component/MLabel.java | 8 +- .../kamesuta/mc/signpic/entry/EntryId.java | 4 + .../mc/signpic/gui/GuiPacketWait.java | 131 ++++++++++++++++++ .../mc/signpic/handler/CoreHandler.java | 1 - .../mc/signpic/handler/SignHandler.java | 50 +------ .../render/CustomTileEntitySignRenderer.java | 46 +++--- .../com/kamesuta/mc/signpic/util/Sign.java | 60 ++++++++ 9 files changed, 253 insertions(+), 90 deletions(-) create mode 100644 src/main/java/com/kamesuta/mc/signpic/gui/GuiPacketWait.java diff --git a/src/main/java/com/kamesuta/mc/bnnwidget/WGui.java b/src/main/java/com/kamesuta/mc/bnnwidget/WGui.java index 90b81999..694d06d4 100644 --- a/src/main/java/com/kamesuta/mc/bnnwidget/WGui.java +++ b/src/main/java/com/kamesuta/mc/bnnwidget/WGui.java @@ -114,7 +114,7 @@ public static void drawCenteredString(final String text, final float x, final fl /** * Renders the specified text to the screen. */ - public static void drawString(final String text, final float x, final float y, final int color) + public static void drawStringWithShadow(final String text, final float x, final float y, final int color) { glPushMatrix(); glTranslatef(x, y, 0f); @@ -122,6 +122,17 @@ public static void drawString(final String text, final float x, final float y, f glPopMatrix(); } + /** + * Renders the specified text to the screen. + */ + public static void drawString(final String text, final float x, final float y, final int color) + { + glPushMatrix(); + glTranslatef(x, y, 0f); + font().drawString(text, 0, 0, color); + glPopMatrix(); + } + /** * Draws a textured rectangle at the stored z-value. Args: x, y, u, v, width, height */ @@ -233,7 +244,7 @@ public static void drawCenteredString(final String text, final Area a, final int */ public static void drawString(final String text, final Area a, final int color) { - drawString(text, a.x1(), a.y1(), color); + drawStringWithShadow(text, a.x1(), a.y1(), color); } /** @@ -273,38 +284,34 @@ public static void translate(final Area p) { GL11.glTranslatef(p.x1(), p.y1(), 0f); } - public static void drawString(final String text, final int x, final int y, final int colour, final boolean shadow) { + public static void drawString(final String text, final float x, final float y, final int colour, final boolean shadow) { if (shadow) - font().drawStringWithShadow(text, x, y, colour); + drawStringWithShadow(text, x, y, colour); else - font().drawString(text, x, y, colour); - } - - public static void drawString(final String text, final int x, final int y, final int colour) { - drawString(text, x, y, colour, true); + drawString(text, x, y, colour); } - public static void drawStringC(final String text, final int x, final int y, final int w, final int h, final int colour, final boolean shadow) { + public static void drawStringC(final String text, final float x, final float y, final float w, final float h, final int colour, final boolean shadow) { drawString(text, x + (w - getStringWidth(text)) / 2, y + (h - 8) / 2, colour, shadow); } - public static void drawStringC(final String text, final int x, final int y, final int w, final int h, final int colour) { + public static void drawStringC(final String text, final float x, final float y, final float w, final float h, final int colour) { drawStringC(text, x, y, w, h, colour, true); } - public static void drawStringC(final String text, final int x, final int y, final int colour, final boolean shadow) { + public static void drawStringC(final String text, final float x, final float y, final int colour, final boolean shadow) { drawString(text, x - getStringWidth(text) / 2, y, colour, shadow); } - public static void drawStringC(final String text, final int x, final int y, final int colour) { - drawStringC(text, x, y, colour, true); + public static void drawStringC(final String text, final float f, final float g, final int colour) { + drawStringC(text, f, g, colour, true); } - public static void drawStringR(final String text, final int x, final int y, final int colour, final boolean shadow) { + public static void drawStringR(final String text, final float x, final float y, final int colour, final boolean shadow) { drawString(text, x - getStringWidth(text), y, colour, shadow); } - public static void drawStringR(final String text, final int x, final int y, final int colour) { + public static void drawStringR(final String text, final float x, final float y, final int colour) { drawStringR(text, x, y, colour, true); } diff --git a/src/main/java/com/kamesuta/mc/bnnwidget/WPanel.java b/src/main/java/com/kamesuta/mc/bnnwidget/WPanel.java index 745bb10e..4f3bbf1c 100644 --- a/src/main/java/com/kamesuta/mc/bnnwidget/WPanel.java +++ b/src/main/java/com/kamesuta/mc/bnnwidget/WPanel.java @@ -124,9 +124,7 @@ public boolean onCloseRequest() { boolean closable = true; for (final Iterator itr = this.widgets.iterator(); itr.hasNext();) { final WCommon widget = itr.next(); - if (widget.onCloseRequest()) - itr.remove(); - else { + if (!widget.onCloseRequest()) { this.removelist.offer(widget); closable = false; } diff --git a/src/main/java/com/kamesuta/mc/bnnwidget/component/MLabel.java b/src/main/java/com/kamesuta/mc/bnnwidget/component/MLabel.java index 632371a1..09f7f72e 100644 --- a/src/main/java/com/kamesuta/mc/bnnwidget/component/MLabel.java +++ b/src/main/java/com/kamesuta/mc/bnnwidget/component/MLabel.java @@ -19,15 +19,15 @@ public MLabel(final R position, final String text) { } public void setText(final String s) { - if (StringUtils.equals(s, this.text)) { + if (StringUtils.equals(s, getText())) { return; } - final String oldText = this.text; + final String oldText = getText(); this.text = s; onTextChanged(oldText); } - public final String getText() { + public String getText() { return this.text; } @@ -42,6 +42,6 @@ public void draw(final WEvent ev, final Area pgp, final Point p, final float fra protected void drawText(final Area a) { RenderHelper.startTexture(); - drawString(this.text, a.x1(), a.y1() + (a.h()-font().FONT_HEIGHT) / 2, this.textcolor); + drawStringC(getText(), a.x1()+a.w()/2, a.y1() + (a.h()-font().FONT_HEIGHT) / 2, this.textcolor); } } diff --git a/src/main/java/com/kamesuta/mc/signpic/entry/EntryId.java b/src/main/java/com/kamesuta/mc/signpic/entry/EntryId.java index e150273b..bc617d62 100644 --- a/src/main/java/com/kamesuta/mc/signpic/entry/EntryId.java +++ b/src/main/java/com/kamesuta/mc/signpic/entry/EntryId.java @@ -122,6 +122,10 @@ public void toStrings(final String[] sign) { sign[i] = StringUtils.substring(this.id, 15*i, Math.min(15*(i+1), length)); } + public int getLastLine() { + return StringUtils.length(this.id)/15; + } + public void toEntity(final TileEntitySign tile) { toStrings(tile.signText); } diff --git a/src/main/java/com/kamesuta/mc/signpic/gui/GuiPacketWait.java b/src/main/java/com/kamesuta/mc/signpic/gui/GuiPacketWait.java new file mode 100644 index 00000000..5dabea63 --- /dev/null +++ b/src/main/java/com/kamesuta/mc/signpic/gui/GuiPacketWait.java @@ -0,0 +1,131 @@ +package com.kamesuta.mc.signpic.gui; + +import static org.lwjgl.opengl.GL11.*; + +import org.apache.commons.lang3.StringUtils; + +import com.kamesuta.mc.bnnwidget.WBase; +import com.kamesuta.mc.bnnwidget.WEvent; +import com.kamesuta.mc.bnnwidget.WFrame; +import com.kamesuta.mc.bnnwidget.WPanel; +import com.kamesuta.mc.bnnwidget.component.MLabel; +import com.kamesuta.mc.bnnwidget.motion.Easings; +import com.kamesuta.mc.bnnwidget.motion.MCoord; +import com.kamesuta.mc.bnnwidget.position.Area; +import com.kamesuta.mc.bnnwidget.position.Coord; +import com.kamesuta.mc.bnnwidget.position.Point; +import com.kamesuta.mc.bnnwidget.position.RArea; +import com.kamesuta.mc.signpic.Client; +import com.kamesuta.mc.signpic.entry.EntryId; +import com.kamesuta.mc.signpic.mode.CurrentMode; +import com.kamesuta.mc.signpic.render.RenderHelper; +import com.kamesuta.mc.signpic.util.Sign.SendPacketTask; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntitySign; + +public class GuiPacketWait extends WFrame { + private final SendPacketTask task; + private boolean preview; + + public GuiPacketWait(final SendPacketTask task) { + this.task = task; + } + + @Override + protected void init() { + this.preview = CurrentMode.instance.isState(CurrentMode.State.PREVIEW); + CurrentMode.instance.setState(CurrentMode.State.PREVIEW, false); + + add(new WPanel(RArea.diff(0, 0, 0, 0)) { + private final int max = StringUtils.length(GuiPacketWait.this.task.id.id()); + private int cursor; + private boolean close = true; + private int c; + + @Override + protected void initWidget() { + add(new WBase(RArea.diff(0, 0, 0, 0)) { + MCoord c = new MCoord(0f).add(Easings.easeLinear.move(.25f, .2f)).start(); + + @Override + public void draw(final WEvent ev, final Area pgp, final Point p, final float frame) { + RenderHelper.startShape(); + glColor4f(0f, 0f, 0f, this.c.get()); + drawRect(getGuiPosition(pgp)); + } + }); + + final float f1 = 93.75F; + add(new WBase(new RArea(Coord.right(15), Coord.top(15), Coord.width(f1), Coord.height(f1))) { + @Override + public void draw(final WEvent ev, final Area pgp, final Point p, final float frame) { + final Area a = getGuiPosition(pgp); + + RenderHelper.startTexture(); + glColor4f(1f, 1f, 1f, 1f); + glPushMatrix(); + glTranslatef(a.x1()+a.w()/2, a.y1(), 50f); + glScalef(-f1, -f1, -f1); + glRotatef(180f, 0f, 1f, 0f); + Client.renderer.translateBase(GuiPacketWait.this.task.entity, -0.5D, -0.75D, -0.5D, -1f); + Client.renderer.renderSignPictureBase(GuiPacketWait.this.task.entity, -0.5D, -0.75D, -0.5D, 0.0F, 1f); + glPopMatrix(); + } + }); + + final int f = font().FONT_HEIGHT/2; + + add(new MLabel(new RArea(Coord.left(15), Coord.right(15), Coord.top(-f), Coord.bottom(+f)), "") { + @Override + public String getText() { + return String.format("Please Wait ( %d / %d letters )", c, max); + } + }); + + add(new MLabel(new RArea(Coord.left(15), Coord.right(15), Coord.top(+f), Coord.bottom(-f)), "") { + @Override + public String getText() { + return String.format("Esc for Cancel ( %.2f / %.2f seconds )", GuiPacketWait.this.task.timer.getTime(), GuiPacketWait.this.task.limit / 1000f); + } + }); + } + + @Override + public void update(final WEvent ev, final Area pgp, final Point p) { + if (this.close) { + if (!GuiPacketWait.this.task.tick()) { + this.c = (int) (GuiPacketWait.this.task.timer.getTime() * 1000 / GuiPacketWait.this.task.limit * this.max); + if (this.cursor != this.c) { + final EntryId id = new EntryId(StringUtils.substring(GuiPacketWait.this.task.id.id(), 0, this.c)); + final int last = id.getLastLine(); + id.toEntity(GuiPacketWait.this.task.entity); + GuiPacketWait.this.task.entity.lineBeingEdited = last; + final TileEntity e1 = Client.mc.theWorld.getTileEntity(GuiPacketWait.this.task.entity.xCoord, GuiPacketWait.this.task.entity.yCoord, GuiPacketWait.this.task.entity.zCoord); + if (e1 instanceof TileEntitySign) { + final TileEntitySign tileSign = (TileEntitySign) e1; + id.toEntity(tileSign); + tileSign.lineBeingEdited = last; + } + } + this.cursor = this.c; + } else { + this.close = false; + requestClose(); + } + } + super.update(ev, pgp, p); + } + }); + } + + @Override + public boolean doesGuiPauseGame() { + return false; + } + + @Override + public void onGuiClosed() { + CurrentMode.instance.setState(CurrentMode.State.PREVIEW, this.preview); + } +} diff --git a/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java b/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java index 2f764902..712db04f 100644 --- a/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java +++ b/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java @@ -77,7 +77,6 @@ public void onTick(final ClientTickEvent event) { if (event.phase == Phase.END) { Client.startSection("signpic_load"); this.signEntryManager.onTick(); - this.signHandler.onTick(); this.contentManager.onTick(); this.informationHandler.onTick(event); EntrySlot.Tick(); diff --git a/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java b/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java index 82990b61..225f93f3 100644 --- a/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java +++ b/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java @@ -1,16 +1,16 @@ package com.kamesuta.mc.signpic.handler; import java.lang.reflect.Field; -import java.util.ArrayDeque; -import java.util.Deque; import com.kamesuta.mc.signpic.Client; import com.kamesuta.mc.signpic.Reference; import com.kamesuta.mc.signpic.entry.Entry; import com.kamesuta.mc.signpic.entry.EntryId; +import com.kamesuta.mc.signpic.gui.GuiPacketWait; import com.kamesuta.mc.signpic.mode.CurrentMode; import com.kamesuta.mc.signpic.preview.SignEntity; import com.kamesuta.mc.signpic.util.ChatBuilder; import com.kamesuta.mc.signpic.util.Sign; +import com.kamesuta.mc.signpic.util.Sign.SendPacketTask; import net.minecraft.client.gui.inventory.GuiEditSign; import net.minecraft.client.resources.I18n; @@ -36,44 +36,6 @@ public static void init() { } } - private class SendPacketTask { - private int count; - private final EntryId id; - private final TileEntitySign entity; - - public SendPacketTask(final EntryId id, final TileEntitySign entity) { - this.count = 0; - this.id = id; - this.entity = entity; - } - - private void sendPacket() { - Sign.sendSign(this.id, this.entity); - } - - public boolean tick() { - this.count++; - if (this.count > sendPacketDelayTick) { - sendPacket(); - return true; - } - return false; - } - } - - public static final int sendPacketDelayTick = 1 * 20; - - private final Deque sendPacketQueue = new ArrayDeque(); - - @CoreEvent - public void onTick() { - final SendPacketTask task = this.sendPacketQueue.peek(); - if (task!=null) { - if (task.tick()) - this.sendPacketQueue.poll(); - } - } - @CoreEvent public void onSign(final GuiOpenEvent event) { if (CurrentMode.instance.isMode(CurrentMode.Mode.PLACE)) @@ -82,7 +44,7 @@ public void onSign(final GuiOpenEvent event) { try { final GuiEditSign ges = (GuiEditSign) event.gui; final TileEntitySign tileSign = (TileEntitySign) f.get(ges); - this.sendPacketQueue.offer(new SendPacketTask(CurrentMode.instance.getEntryId(), tileSign)); + Client.mc.displayGuiScreen(new GuiPacketWait(new SendPacketTask(CurrentMode.instance.getEntryId(), tileSign))); event.setCanceled(true); if (!CurrentMode.instance.isState(CurrentMode.State.CONTINUE)) { CurrentMode.instance.setMode(); @@ -112,10 +74,8 @@ public void onClick(final MouseEvent event) { if (CurrentMode.instance.isMode(CurrentMode.Mode.SETPREVIEW)) { Sign.preview.capturePlace(); event.setCanceled(true); - if (!CurrentMode.instance.isState(CurrentMode.State.CONTINUE)) { - CurrentMode.instance.setMode(); - Client.openEditor(); - } + CurrentMode.instance.setMode(); + Client.openEditor(); } else if (CurrentMode.instance.isMode(CurrentMode.Mode.LOAD)) { final TileEntitySign tilesign = Client.getTileSignLooking(); if (tilesign != null) { diff --git a/src/main/java/com/kamesuta/mc/signpic/render/CustomTileEntitySignRenderer.java b/src/main/java/com/kamesuta/mc/signpic/render/CustomTileEntitySignRenderer.java index b4d4af27..f5e5748e 100644 --- a/src/main/java/com/kamesuta/mc/signpic/render/CustomTileEntitySignRenderer.java +++ b/src/main/java/com/kamesuta/mc/signpic/render/CustomTileEntitySignRenderer.java @@ -87,6 +87,30 @@ public void renderSignPicture(final Entry entry, final float opacity) { glPopMatrix(); } + public void translateBase(final TileEntitySign tile, final double x, final double y, final double z, final float rotateratio) { + // Vanilla Translate + final Block block = tile.getBlockType(); + final float f1 = 0.6666667F; + float f3; + + if (block == Blocks.standing_sign) { + glTranslatef((float)x + 0.5F, (float)y + 0.75F * f1, (float)z + 0.5F); + final float f2 = tile.getBlockMetadata() * 360 / 16.0F; + glRotatef(-f2 * rotateratio, 0.0F, 1.0F, 0.0F); + } else { + final int j = tile.getBlockMetadata(); + f3 = 0.0F; + + if (j == 2) f3 = 180.0F; + if (j == 4) f3 = 90.0F; + if (j == 5) f3 = -90.0F; + + glTranslatef((float)x + 0.5F, (float)y + 0.75F * f1, (float)z + 0.5F); + glRotatef(-f3 * rotateratio, 0.0F, 1.0F, 0.0F); + glTranslatef(0.0F, 0.0F, -0.4375F); + } + } + public void renderSignPictureBase(final TileEntitySign tile, final double x, final double y, final double z, final float partialTicks, final float opacity) { final Entry entry = EntryId.fromTile(tile).entry(); if (entry.isValid()) { @@ -96,28 +120,8 @@ public void renderSignPictureBase(final TileEntitySign tile, final double x, fin super.renderTileEntityAt(tile, x, y, z, partialTicks); } - // Vanilla Translate - final Block block = tile.getBlockType(); glPushMatrix(); - final float f1 = 0.6666667F; - float f3; - - if (block == Blocks.standing_sign) { - glTranslatef((float)x + 0.5F, (float)y + 0.75F * f1, (float)z + 0.5F); - final float f2 = tile.getBlockMetadata() * 360 / 16.0F; - glRotatef(-f2, 0.0F, 1.0F, 0.0F); - } else { - final int j = tile.getBlockMetadata(); - f3 = 0.0F; - - if (j == 2) f3 = 180.0F; - if (j == 4) f3 = 90.0F; - if (j == 5) f3 = -90.0F; - - glTranslatef((float)x + 0.5F, (float)y + 0.75F * f1, (float)z + 0.5F); - glRotatef(-f3, 0.0F, 1.0F, 0.0F); - glTranslatef(0.0F, 0.0F, -0.4375F); - } + translateBase(tile, x, y, z, 1f); // Draw Canvas glDisable(GL_CULL_FACE); diff --git a/src/main/java/com/kamesuta/mc/signpic/util/Sign.java b/src/main/java/com/kamesuta/mc/signpic/util/Sign.java index 77144cd8..4012173f 100644 --- a/src/main/java/com/kamesuta/mc/signpic/util/Sign.java +++ b/src/main/java/com/kamesuta/mc/signpic/util/Sign.java @@ -1,5 +1,7 @@ package com.kamesuta.mc.signpic.util; +import org.lwjgl.util.Timer; + import com.kamesuta.mc.signpic.Client; import com.kamesuta.mc.signpic.entry.EntryId; import com.kamesuta.mc.signpic.entry.EntryIdBuilder; @@ -27,4 +29,62 @@ public static void sendSign(final EntryId entryId, final TileEntitySign sourceen nethandlerplayclient.addToSendQueue(new C12PacketUpdateSign(sourceentity.xCoord, sourceentity.yCoord, sourceentity.zCoord, sourceentity.signText)); sourceentity.setEditable(true); } + + public static class SendPacketTask { + public final long limit; + public final EntryId id; + public final String[] lines; + public final TileEntitySign entity; + public final Timer timer; + + public SendPacketTask(final EntryId id, final TileEntitySign entity) { + this.timer = new Timer(); + this.lines = new String[4]; + id.toStrings(this.lines); + this.limit = getExpectedEditTime(this.lines, false); + this.id = id; + this.entity = entity; + } + + private void sendPacket() { + Sign.sendSign(this.id, this.entity); + } + + public boolean tick() { + if (this.timer.getTime() * 1000 > this.limit) { + sendPacket(); + return true; + } + return false; + } + + /** Fastest time "possible" estimate for an empty sign. */ + private static long minEditTime = 150; + /** Minimum time needed to add one extra line (not the first). */ + private static long minLineTime = 50; + /** Minimum time needed to type a character. */ + private static long minCharTime = 50; + + public static long getExpectedEditTime(final String[] lines, final boolean skipEmpty) { + long expected = minEditTime; + int n = 0; + for (String line : lines){ + if (line != null){ + line = line.trim().toLowerCase(); + if (!line.isEmpty()){ + final int chars = line.length(); + n += 1; + expected += minCharTime * chars; + } + } + } + if (skipEmpty && n == 0) { + return 0; + } + if (n > 1){ + expected += minLineTime * n; + } + return expected; + } + } } From a7b23460650c621c0ce8d6125e1bde954e6fb9b5 Mon Sep 17 00:00:00 2001 From: Kamesuta Date: Wed, 28 Sep 2016 22:50:42 +0900 Subject: [PATCH 6/7] Prevent Anti-AutoSign & Config --- .../java/com/kamesuta/mc/signpic/Client.java | 2 - .../java/com/kamesuta/mc/signpic/Config.java | 120 +++++++++++++++++- .../com/kamesuta/mc/signpic/Reference.java | 1 + .../com/kamesuta/mc/signpic/SignPicture.java | 4 +- .../mc/signpic/entry/EntryManager.java | 5 +- .../kamesuta/mc/signpic/entry/EntrySlot.java | 9 +- .../content/ContentCapacityOverException.java | 20 +++ .../entry/content/ContentDownloader.java | 6 + .../signpic/entry/content/ContentManager.java | 55 ++++---- .../mc/signpic/entry/content/ContentSlot.java | 9 +- .../gui/{GuiPacketWait.java => GuiPAAS.java} | 31 ++--- .../mc/signpic/gui/config/ConfigGui.java | 52 ++++++++ .../signpic/gui/config/ConfigGuiFactory.java | 35 +++++ .../mc/signpic/handler/CoreHandler.java | 8 ++ .../mc/signpic/handler/SignHandler.java | 4 +- .../mc/signpic/image/ImageIOLoader.java | 7 +- .../mc/signpic/image/RemoteImage.java | 4 + .../mc/signpic/image/meta/ImageSize.java | 5 +- .../information/InformationChecker.java | 38 +++--- .../mc/signpic/proxy/ClientProxy.java | 2 - .../render/CustomTileEntitySignRenderer.java | 3 +- .../mc/signpic/render/SignPicRender.java | 5 +- .../com/kamesuta/mc/signpic/util/Sign.java | 24 ++-- .../resources/assets/signpic/lang/en_US.lang | 11 +- .../resources/assets/signpic/lang/ja_JP.lang | 11 +- 25 files changed, 371 insertions(+), 100 deletions(-) create mode 100644 src/main/java/com/kamesuta/mc/signpic/entry/content/ContentCapacityOverException.java rename src/main/java/com/kamesuta/mc/signpic/gui/{GuiPacketWait.java => GuiPAAS.java} (72%) create mode 100644 src/main/java/com/kamesuta/mc/signpic/gui/config/ConfigGui.java create mode 100644 src/main/java/com/kamesuta/mc/signpic/gui/config/ConfigGuiFactory.java diff --git a/src/main/java/com/kamesuta/mc/signpic/Client.java b/src/main/java/com/kamesuta/mc/signpic/Client.java index c3404f1a..cf748f54 100644 --- a/src/main/java/com/kamesuta/mc/signpic/Client.java +++ b/src/main/java/com/kamesuta/mc/signpic/Client.java @@ -25,8 +25,6 @@ public class Client { public static File mcDir; public static File signpicDir; public static File signpicCacheDir; - public static File configDir; - public static File configFile; public static File modDir; public static File modFile; diff --git a/src/main/java/com/kamesuta/mc/signpic/Config.java b/src/main/java/com/kamesuta/mc/signpic/Config.java index 345c6a97..3dd6887b 100644 --- a/src/main/java/com/kamesuta/mc/signpic/Config.java +++ b/src/main/java/com/kamesuta/mc/signpic/Config.java @@ -1,7 +1,119 @@ package com.kamesuta.mc.signpic; -// TODO -public class Config { - public Config() { +import java.io.File; + +import org.apache.commons.lang3.StringUtils; + +import com.kamesuta.mc.signpic.handler.CoreEvent; + +import cpw.mods.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; + +public final class Config extends Configuration { + public static Config instance; + + private final File configFile; + public boolean updatable; + + public int imageWidthLimit = 512; + public int imageHeightLimit = 512; + public boolean imageAnimationGif = true; + + public int entryGCtick = 15; + + public int contentLoadThreads = 3; + public int contentMaxByte = 0; + public int contentGCtick = 15 * 20; + public int contentAsyncTick = 0; + public int contentSyncTick = 0; + + public boolean informationNotice = true; + public boolean informationJoinBeta = false; + + public boolean multiplayPAAS = true; + /** Fastest time "possible" estimate for an empty sign. */ + public int multiplayPAASMinEditTime = 150; + /** Minimum time needed to add one extra line (not the first). */ + public int multiplayPAASMinLineTime = 50; + /** Minimum time needed to type a character. */ + public int multiplayPAASMinCharTime = 50; + + public float renderSeeOpacity = .5f; + public float renderPreviewFixedOpacity = .7f; + public float renderPreviewFloatedOpacity = .7f; + + public Config( final File configFile ) { + super( configFile ); + this.configFile = configFile; + + this.imageWidthLimit = get( "Image", "WidthLimit", this.imageWidthLimit ).setRequiresMcRestart(true).getInt( this.imageWidthLimit ); + this.imageHeightLimit = get( "Image", "HeightLimit", this.imageHeightLimit ).setRequiresMcRestart(true).getInt( this.imageHeightLimit ); + this.imageAnimationGif = get( "Image", "AnimateGif", this.imageAnimationGif ).setRequiresMcRestart(true).getBoolean( this.imageAnimationGif ); + + addCustomCategoryComment("Entry", "Entry(sign text parse cache) Management"); + + addCustomCategoryComment("Content", "Content Data Management"); + + this.informationNotice = get( "Version", "Notice", this.informationNotice ).setRequiresMcRestart(true).getBoolean( this.informationNotice ); + this.informationJoinBeta = get( "Version", "JoinBeta", this.informationJoinBeta ).setRequiresMcRestart(true).getBoolean( this.informationJoinBeta ); + + addCustomCategoryComment("MultiplayPreventAntiAutoSign", "Prevent from Anti-AutoSign Plugin such as NoCheatPlus. (ms)"); + + changeableSync(); + + this.updatable = true; + } + + private void changeableSync() { + this.entryGCtick = get( "Entry", "GCDelayTick", this.entryGCtick ).getInt( this.entryGCtick ); + + this.contentLoadThreads = addComment(get( "Content", "LoadThreads", this.contentLoadThreads ), "parallel processing number such as Downloading").setRequiresMcRestart(true).getInt( this.contentLoadThreads ); + this.contentMaxByte = addComment(get( "Content", "MaxByte", this.contentMaxByte ), "limit of size before downloading").getInt( this.contentMaxByte ); + this.contentGCtick = addComment(get( "Content", "GCDelayTick", this.contentGCtick ), "delay ticks of Garbage Collection").getInt( this.contentGCtick ); + this.contentAsyncTick = addComment(get( "Content", "AsyncLoadDelayTick", this.contentAsyncTick ), "ticks of Async process starting delay (Is other threads, it does not disturb the operation) such as Downloading, File Loading...").getInt( this.contentAsyncTick ); + this.contentSyncTick = addComment(get( "Content", "SyncLoadIntervalTick", this.contentSyncTick ), "ticks of Sync process interval (A drawing thread, affects the behavior. Please increase the value if the operation is heavy.) such as Gl Texture Uploading").getInt( this.contentSyncTick ); + + this.multiplayPAAS = get( "MultiplayPreventAntiAutoSign", "Enable", this.multiplayPAAS ).getBoolean( this.multiplayPAAS ); + this.multiplayPAASMinEditTime = get( "MultiplayPreventAntiAutoSign", "minEditTime", this.multiplayPAASMinEditTime ).getInt( this.multiplayPAASMinEditTime ); + this.multiplayPAASMinLineTime = get( "MultiplayPreventAntiAutoSign", "minLineTime", this.multiplayPAASMinLineTime ).getInt( this.multiplayPAASMinLineTime ); + this.multiplayPAASMinCharTime = get( "MultiplayPreventAntiAutoSign", "minCharTime", this.multiplayPAASMinCharTime ).getInt( this.multiplayPAASMinCharTime ); + + this.renderSeeOpacity = (float) get( "Render", "ViewSignOpacity", this.renderSeeOpacity ).getDouble( this.renderSeeOpacity ); + this.renderPreviewFixedOpacity = (float) get( "Render", "PreviewFixedSignOpacity", this.renderPreviewFixedOpacity ).getDouble( this.renderPreviewFixedOpacity ); + this.renderPreviewFloatedOpacity = (float) get( "Render", "PreviewFloatedSignOpacity", this.renderPreviewFloatedOpacity ).getDouble( this.renderPreviewFloatedOpacity ); + } + + private Property addComment(final Property prop, final String comment) { + prop.comment = comment; + return prop; + } + + @Override + public void save() + { + if( hasChanged() ) + { + super.save(); + } + } + + @CoreEvent + public void onConfigChanged( final ConfigChangedEvent.OnConfigChangedEvent eventArgs ) + { + if( StringUtils.equals(eventArgs.modID, Reference.MODID) ) + { + changeableSync(); + + if( this.updatable ) + { + save(); + } + } + } + + public String getFilePath() + { + return this.configFile.getPath(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kamesuta/mc/signpic/Reference.java b/src/main/java/com/kamesuta/mc/signpic/Reference.java index 0ed99e47..bbd7e342 100644 --- a/src/main/java/com/kamesuta/mc/signpic/Reference.java +++ b/src/main/java/com/kamesuta/mc/signpic/Reference.java @@ -11,6 +11,7 @@ public class Reference { public static final String MINECRAFT = "${mcversion}"; public static final String PROXY_SERVER = "com.kamesuta.mc.signpic.proxy.CommonProxy"; public static final String PROXY_CLIENT = "com.kamesuta.mc.signpic.proxy.ClientProxy"; + public static final String GUI_FACTORY = "com.kamesuta.mc.signpic.gui.config.ConfigGuiFactory"; public static Logger logger = LogManager.getLogger(Reference.MODID); } diff --git a/src/main/java/com/kamesuta/mc/signpic/SignPicture.java b/src/main/java/com/kamesuta/mc/signpic/SignPicture.java index 0e23e169..5575c355 100644 --- a/src/main/java/com/kamesuta/mc/signpic/SignPicture.java +++ b/src/main/java/com/kamesuta/mc/signpic/SignPicture.java @@ -14,7 +14,7 @@ import cpw.mods.fml.common.network.NetworkCheckHandler; import cpw.mods.fml.relauncher.Side; -@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION) +@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) public class SignPicture { @Instance(Reference.MODID) public static SignPicture instance; @@ -29,6 +29,7 @@ public boolean checkModList(final Map versions, final Side side) @EventHandler public void preInit(final FMLPreInitializationEvent event) { + Config.instance = new Config(event.getSuggestedConfigurationFile()); proxy.preInit(event); } @@ -40,5 +41,6 @@ public void init(final FMLInitializationEvent event) { @EventHandler public void postInit(final FMLPostInitializationEvent event) { proxy.postInit(event); + Config.instance.save(); } } diff --git a/src/main/java/com/kamesuta/mc/signpic/entry/EntryManager.java b/src/main/java/com/kamesuta/mc/signpic/entry/EntryManager.java index f7f49e2d..3fb3a255 100644 --- a/src/main/java/com/kamesuta/mc/signpic/entry/EntryManager.java +++ b/src/main/java/com/kamesuta/mc/signpic/entry/EntryManager.java @@ -2,8 +2,6 @@ import java.util.Iterator; import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import com.google.common.collect.Maps; import com.kamesuta.mc.signpic.handler.CoreEvent; @@ -11,10 +9,9 @@ public class EntryManager implements ITickEntry { public static final EntryManager instance = new EntryManager(); - public final ExecutorService threadpool = Executors.newFixedThreadPool(3); private final Map> registry = Maps.newHashMap(); - public Entry get(final EntryId id) { + protected Entry get(final EntryId id) { final EntrySlot entries = this.registry.get(id); if (entries!=null) return entries.get(); diff --git a/src/main/java/com/kamesuta/mc/signpic/entry/EntrySlot.java b/src/main/java/com/kamesuta/mc/signpic/entry/EntrySlot.java index 545fdc61..be3e22af 100644 --- a/src/main/java/com/kamesuta/mc/signpic/entry/EntrySlot.java +++ b/src/main/java/com/kamesuta/mc/signpic/entry/EntrySlot.java @@ -1,7 +1,8 @@ package com.kamesuta.mc.signpic.entry; +import com.kamesuta.mc.signpic.Config; + public class EntrySlot { - public static final int CollectTimes = 20 * 15; protected static long times = 0; protected final T entry; @@ -23,10 +24,14 @@ public EntrySlot used() { } public boolean shouldCollect() { - return times - this.time > CollectTimes; + return times - this.time > getCollectTimes(); } public static void Tick() { times++; } + + protected int getCollectTimes() { + return Config.instance.entryGCtick; + } } diff --git a/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentCapacityOverException.java b/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentCapacityOverException.java new file mode 100644 index 00000000..29e3be22 --- /dev/null +++ b/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentCapacityOverException.java @@ -0,0 +1,20 @@ +package com.kamesuta.mc.signpic.entry.content; + +import java.io.IOException; + +public class ContentCapacityOverException extends IOException { + public ContentCapacityOverException() { + } + + public ContentCapacityOverException(final String message) { + super(message); + } + + public ContentCapacityOverException(final Throwable cause) { + super(cause); + } + + public ContentCapacityOverException(final String message, final Throwable cause) { + super(message, cause); + } +} diff --git a/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentDownloader.java b/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentDownloader.java index fbf844f6..4284681b 100644 --- a/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentDownloader.java +++ b/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentDownloader.java @@ -14,6 +14,7 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpUriRequest; +import com.kamesuta.mc.signpic.Config; import com.kamesuta.mc.signpic.entry.IAsyncProcessable; import com.kamesuta.mc.signpic.util.Downloader; @@ -38,6 +39,11 @@ public void onAsyncProcess() throws URISyntaxException, IllegalStateException, I final HttpResponse response = Downloader.downloader.client.execute(req); final HttpEntity entity = response.getEntity(); + final long max = Config.instance.contentMaxByte; + final long size = entity.getContentLength(); + if (max > 0 && (size < 0 || size > max)) + throw new ContentCapacityOverException(); + this.content.state.progress.overall = entity.getContentLength(); input = entity.getContent(); countoutput = new CountingOutputStream(new BufferedOutputStream(new FileOutputStream(local))) { diff --git a/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentManager.java b/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentManager.java index 15e73458..06f45c45 100644 --- a/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentManager.java +++ b/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentManager.java @@ -8,6 +8,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import com.kamesuta.mc.signpic.Config; import com.kamesuta.mc.signpic.entry.IAsyncProcessable; import com.kamesuta.mc.signpic.entry.IDivisionProcessable; import com.kamesuta.mc.signpic.entry.ITickEntry; @@ -16,15 +17,17 @@ public class ContentManager implements ITickEntry { public static ContentManager instance = new ContentManager(); - public final ExecutorService threadpool = Executors.newFixedThreadPool(3); + public final ExecutorService threadpool = Executors.newFixedThreadPool(Config.instance.contentLoadThreads); protected final HashMap> registry = new HashMap>(); public Deque asyncqueue = new ArrayDeque(); public Deque divisionqueue = new ArrayDeque(); + private int asynctick = 0; + private int divisiontick = 0; - public ContentManager() { + private ContentManager() { } - public Content get(final ContentId id) { + protected Content get(final ContentId id) { final ContentSlot entries = this.registry.get(id); if (entries!=null) return entries.get(); @@ -38,28 +41,36 @@ public Content get(final ContentId id) { @CoreEvent @Override public void onTick() { - IAsyncProcessable asyncprocess; - if ((asyncprocess = this.asyncqueue.poll()) != null) { - final IAsyncProcessable asyncprocessexec = asyncprocess; - this.threadpool.execute(new Runnable() { - @Override - public void run() { - try { - asyncprocessexec.onAsyncProcess(); - } catch (final Exception e) { - e.printStackTrace(); + this.asynctick++; + if (this.asynctick > Config.instance.contentAsyncTick) { + this.asynctick = 0; + IAsyncProcessable asyncprocess; + if ((asyncprocess = this.asyncqueue.poll()) != null) { + final IAsyncProcessable asyncprocessexec = asyncprocess; + this.threadpool.execute(new Runnable() { + @Override + public void run() { + try { + asyncprocessexec.onAsyncProcess(); + } catch (final Exception e) { + e.printStackTrace(); + } } - } - }); + }); + } } - IDivisionProcessable divisionprocess; - if ((divisionprocess = this.divisionqueue.peek()) != null) { - try { - if (divisionprocess.onDivisionProcess()) { - this.divisionqueue.poll(); + this.divisiontick++; + if (this.divisiontick > Config.instance.contentAsyncTick) { + this.divisiontick = 0; + IDivisionProcessable divisionprocess; + if ((divisionprocess = this.divisionqueue.peek()) != null) { + try { + if (divisionprocess.onDivisionProcess()) { + this.divisionqueue.poll(); + } + } catch (final Exception e) { + e.printStackTrace(); } - } catch (final Exception e) { - e.printStackTrace(); } } diff --git a/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentSlot.java b/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentSlot.java index 17e64a74..edc45078 100644 --- a/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentSlot.java +++ b/src/main/java/com/kamesuta/mc/signpic/entry/content/ContentSlot.java @@ -1,13 +1,11 @@ package com.kamesuta.mc.signpic.entry.content; +import com.kamesuta.mc.signpic.Config; import com.kamesuta.mc.signpic.entry.EntrySlot; import com.kamesuta.mc.signpic.entry.ICollectable; import com.kamesuta.mc.signpic.entry.IInitable; public class ContentSlot extends EntrySlot implements IInitable, ICollectable { - public static int CollectTimes = 20 * 15; - public static long times = 0; - private boolean init = true; public ContentSlot(final T entry) { @@ -28,4 +26,9 @@ public boolean shouldInit() { public void onCollect() { this.entry.onCollect(); } + + @Override + protected int getCollectTimes() { + return Config.instance.contentGCtick; + } } \ No newline at end of file diff --git a/src/main/java/com/kamesuta/mc/signpic/gui/GuiPacketWait.java b/src/main/java/com/kamesuta/mc/signpic/gui/GuiPAAS.java similarity index 72% rename from src/main/java/com/kamesuta/mc/signpic/gui/GuiPacketWait.java rename to src/main/java/com/kamesuta/mc/signpic/gui/GuiPAAS.java index 5dabea63..47046e91 100644 --- a/src/main/java/com/kamesuta/mc/signpic/gui/GuiPacketWait.java +++ b/src/main/java/com/kamesuta/mc/signpic/gui/GuiPAAS.java @@ -21,14 +21,15 @@ import com.kamesuta.mc.signpic.render.RenderHelper; import com.kamesuta.mc.signpic.util.Sign.SendPacketTask; +import net.minecraft.client.resources.I18n; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; -public class GuiPacketWait extends WFrame { +public class GuiPAAS extends WFrame { private final SendPacketTask task; private boolean preview; - public GuiPacketWait(final SendPacketTask task) { + public GuiPAAS(final SendPacketTask task) { this.task = task; } @@ -38,7 +39,7 @@ protected void init() { CurrentMode.instance.setState(CurrentMode.State.PREVIEW, false); add(new WPanel(RArea.diff(0, 0, 0, 0)) { - private final int max = StringUtils.length(GuiPacketWait.this.task.id.id()); + private final int max = StringUtils.length(GuiPAAS.this.task.id.id()); private int cursor; private boolean close = true; private int c; @@ -68,8 +69,8 @@ public void draw(final WEvent ev, final Area pgp, final Point p, final float fra glTranslatef(a.x1()+a.w()/2, a.y1(), 50f); glScalef(-f1, -f1, -f1); glRotatef(180f, 0f, 1f, 0f); - Client.renderer.translateBase(GuiPacketWait.this.task.entity, -0.5D, -0.75D, -0.5D, -1f); - Client.renderer.renderSignPictureBase(GuiPacketWait.this.task.entity, -0.5D, -0.75D, -0.5D, 0.0F, 1f); + Client.renderer.translateBase(GuiPAAS.this.task.entity, -0.5D, -0.75D, -0.5D, -1f); + Client.renderer.renderSignPictureBase(GuiPAAS.this.task.entity, -0.5D, -0.75D, -0.5D, 0.0F, 1f); glPopMatrix(); } }); @@ -78,15 +79,15 @@ public void draw(final WEvent ev, final Area pgp, final Point p, final float fra add(new MLabel(new RArea(Coord.left(15), Coord.right(15), Coord.top(-f), Coord.bottom(+f)), "") { @Override - public String getText() { - return String.format("Please Wait ( %d / %d letters )", c, max); + public void update(final WEvent ev, final Area pgp, final Point p) { + setText(I18n.format("signpic.gui.paas.count", String.format("%d", c), String.format("%d", max))); } }); add(new MLabel(new RArea(Coord.left(15), Coord.right(15), Coord.top(+f), Coord.bottom(-f)), "") { @Override - public String getText() { - return String.format("Esc for Cancel ( %.2f / %.2f seconds )", GuiPacketWait.this.task.timer.getTime(), GuiPacketWait.this.task.limit / 1000f); + public void update(final WEvent ev, final Area pgp, final Point p) { + setText(I18n.format("signpic.gui.paas.time", String.format("%.1f", GuiPAAS.this.task.timer.getTime()), String.format("%.1f", GuiPAAS.this.task.limit / 1000f))); } }); } @@ -94,14 +95,14 @@ public String getText() { @Override public void update(final WEvent ev, final Area pgp, final Point p) { if (this.close) { - if (!GuiPacketWait.this.task.tick()) { - this.c = (int) (GuiPacketWait.this.task.timer.getTime() * 1000 / GuiPacketWait.this.task.limit * this.max); + if (!GuiPAAS.this.task.tick()) { + this.c = (int) (GuiPAAS.this.task.timer.getTime() * 1000 / GuiPAAS.this.task.limit * this.max); if (this.cursor != this.c) { - final EntryId id = new EntryId(StringUtils.substring(GuiPacketWait.this.task.id.id(), 0, this.c)); + final EntryId id = new EntryId(StringUtils.substring(GuiPAAS.this.task.id.id(), 0, this.c)); final int last = id.getLastLine(); - id.toEntity(GuiPacketWait.this.task.entity); - GuiPacketWait.this.task.entity.lineBeingEdited = last; - final TileEntity e1 = Client.mc.theWorld.getTileEntity(GuiPacketWait.this.task.entity.xCoord, GuiPacketWait.this.task.entity.yCoord, GuiPacketWait.this.task.entity.zCoord); + id.toEntity(GuiPAAS.this.task.entity); + GuiPAAS.this.task.entity.lineBeingEdited = last; + final TileEntity e1 = Client.mc.theWorld.getTileEntity(GuiPAAS.this.task.entity.xCoord, GuiPAAS.this.task.entity.yCoord, GuiPAAS.this.task.entity.zCoord); if (e1 instanceof TileEntitySign) { final TileEntitySign tileSign = (TileEntitySign) e1; id.toEntity(tileSign); diff --git a/src/main/java/com/kamesuta/mc/signpic/gui/config/ConfigGui.java b/src/main/java/com/kamesuta/mc/signpic/gui/config/ConfigGui.java new file mode 100644 index 00000000..c90d6fd7 --- /dev/null +++ b/src/main/java/com/kamesuta/mc/signpic/gui/config/ConfigGui.java @@ -0,0 +1,52 @@ +package com.kamesuta.mc.signpic.gui.config; +import java.util.ArrayList; +import java.util.List; + +import com.kamesuta.mc.signpic.Config; +import com.kamesuta.mc.signpic.Reference; + +import cpw.mods.fml.client.config.GuiConfig; +import cpw.mods.fml.client.config.IConfigElement; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.ConfigElement; + +public class ConfigGui extends GuiConfig +{ + + public ConfigGui( final GuiScreen parent ) + { + super( parent, getConfigElements(), Reference.MODID, false, false, GuiConfig.getAbridgedConfigPath( Config.instance.getFilePath() ) ); + } + + @SuppressWarnings("rawtypes") + private static List getConfigElements() + { + final List list = new ArrayList(); + + for( final String cat : Config.instance.getCategoryNames() ) + { + if( cat.equals( "versionchecker" ) ) + { + continue; + } + + if( cat.equals( "settings" ) ) + { + continue; + } + + final ConfigCategory cc = Config.instance.getCategory( cat ); + + if( cc.isChild() ) + { + continue; + } + + final ConfigElement ce = new ConfigElement( cc ); + list.add( ce ); + } + + return list; + } +} \ No newline at end of file diff --git a/src/main/java/com/kamesuta/mc/signpic/gui/config/ConfigGuiFactory.java b/src/main/java/com/kamesuta/mc/signpic/gui/config/ConfigGuiFactory.java new file mode 100644 index 00000000..8b88b8a4 --- /dev/null +++ b/src/main/java/com/kamesuta/mc/signpic/gui/config/ConfigGuiFactory.java @@ -0,0 +1,35 @@ +package com.kamesuta.mc.signpic.gui.config; +import java.util.Set; + +import cpw.mods.fml.client.IModGuiFactory; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; + + +public class ConfigGuiFactory implements IModGuiFactory +{ + + @Override + public void initialize( final Minecraft minecraftInstance ) + { + + } + + @Override + public Class mainConfigGuiClass() + { + return ConfigGui.class; + } + + @Override + public Set runtimeGuiCategories() + { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor( final RuntimeOptionCategoryElement element ) + { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java b/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java index 712db04f..2044dee7 100644 --- a/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java +++ b/src/main/java/com/kamesuta/mc/signpic/handler/CoreHandler.java @@ -3,12 +3,14 @@ import org.lwjgl.util.Timer; import com.kamesuta.mc.signpic.Client; +import com.kamesuta.mc.signpic.Config; import com.kamesuta.mc.signpic.entry.EntryManager; import com.kamesuta.mc.signpic.entry.EntrySlot; import com.kamesuta.mc.signpic.entry.content.ContentManager; import com.kamesuta.mc.signpic.information.InformationChecker; import com.kamesuta.mc.signpic.render.SignPicRender; +import cpw.mods.fml.client.event.ConfigChangedEvent; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent; @@ -22,6 +24,7 @@ import net.minecraftforge.common.MinecraftForge; public class CoreHandler { + public final Config configHandler = Config.instance; public final KeyHandler keyHandler = new KeyHandler(); public final SignHandler signHandler = new SignHandler(); public final EntryManager signEntryManager = EntryManager.instance; @@ -72,6 +75,11 @@ public void onText(final RenderGameOverlayEvent.Text event) { this.renderHandler.onText(event); } + @SubscribeEvent + public void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent eventArgs) { + this.configHandler.onConfigChanged(eventArgs); + } + @SubscribeEvent public void onTick(final ClientTickEvent event) { if (event.phase == Phase.END) { diff --git a/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java b/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java index 225f93f3..8ff9323c 100644 --- a/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java +++ b/src/main/java/com/kamesuta/mc/signpic/handler/SignHandler.java @@ -5,12 +5,10 @@ import com.kamesuta.mc.signpic.Reference; import com.kamesuta.mc.signpic.entry.Entry; import com.kamesuta.mc.signpic.entry.EntryId; -import com.kamesuta.mc.signpic.gui.GuiPacketWait; import com.kamesuta.mc.signpic.mode.CurrentMode; import com.kamesuta.mc.signpic.preview.SignEntity; import com.kamesuta.mc.signpic.util.ChatBuilder; import com.kamesuta.mc.signpic.util.Sign; -import com.kamesuta.mc.signpic.util.Sign.SendPacketTask; import net.minecraft.client.gui.inventory.GuiEditSign; import net.minecraft.client.resources.I18n; @@ -44,7 +42,7 @@ public void onSign(final GuiOpenEvent event) { try { final GuiEditSign ges = (GuiEditSign) event.gui; final TileEntitySign tileSign = (TileEntitySign) f.get(ges); - Client.mc.displayGuiScreen(new GuiPacketWait(new SendPacketTask(CurrentMode.instance.getEntryId(), tileSign))); + Sign.placeSign(CurrentMode.instance.getEntryId(), tileSign); event.setCanceled(true); if (!CurrentMode.instance.isState(CurrentMode.State.CONTINUE)) { CurrentMode.instance.setMode(); diff --git a/src/main/java/com/kamesuta/mc/signpic/image/ImageIOLoader.java b/src/main/java/com/kamesuta/mc/signpic/image/ImageIOLoader.java index aca4cf17..14763ef8 100644 --- a/src/main/java/com/kamesuta/mc/signpic/image/ImageIOLoader.java +++ b/src/main/java/com/kamesuta/mc/signpic/image/ImageIOLoader.java @@ -18,6 +18,7 @@ import org.apache.commons.io.IOUtils; import com.google.common.collect.Lists; +import com.kamesuta.mc.signpic.Config; import com.kamesuta.mc.signpic.entry.content.Content; import com.kamesuta.mc.signpic.entry.content.ContentLocation; import com.kamesuta.mc.signpic.entry.content.ContentStateType; @@ -30,7 +31,9 @@ import net.minecraft.util.ResourceLocation; public class ImageIOLoader { - public static final ImageSize MAX_SIZE = new ImageSize().setSize(512, 512); + public static final ImageSize MAX_SIZE = new ImageSize().setSize( + ((Config.instance.imageWidthLimit > 0) ? Config.instance.imageWidthLimit : ImageSize.unknownSize), + ((Config.instance.imageHeightLimit > 0) ? Config.instance.imageHeightLimit : ImageSize.unknownSize)); protected Content content; protected InputStream input; @@ -62,7 +65,7 @@ public ImageTextures load() throws IOException { this.content.state.setType(ContentStateType.LOADING); ImageTextures textures; - if (reader.getFormatName()=="gif") { + if (Config.instance.imageAnimationGif && reader.getFormatName()=="gif") { textures = loadGif(data); } else { textures = loadImage(reader, imagestream); diff --git a/src/main/java/com/kamesuta/mc/signpic/image/RemoteImage.java b/src/main/java/com/kamesuta/mc/signpic/image/RemoteImage.java index 2201d010..a8a8b35e 100644 --- a/src/main/java/com/kamesuta/mc/signpic/image/RemoteImage.java +++ b/src/main/java/com/kamesuta/mc/signpic/image/RemoteImage.java @@ -7,6 +7,7 @@ import com.kamesuta.mc.signpic.Client; import com.kamesuta.mc.signpic.entry.content.Content; +import com.kamesuta.mc.signpic.entry.content.ContentCapacityOverException; import com.kamesuta.mc.signpic.entry.content.ContentDownloader; import com.kamesuta.mc.signpic.entry.content.ContentManager; import com.kamesuta.mc.signpic.entry.content.ContentStateType; @@ -38,6 +39,9 @@ public void onAsyncProcess() { } catch (final URISyntaxException e) { this.content.state.setType(ContentStateType.ERROR); this.content.state.setMessage(I18n.format("signpic.advmsg.invalidurl")); + } catch (final ContentCapacityOverException e) { + this.content.state.setType(ContentStateType.ERROR); + this.content.state.setMessage(I18n.format("signpic.advmsg.capacityover")); } catch (final InvaildImageException e) { this.content.state.setType(ContentStateType.ERROR); this.content.state.setMessage(I18n.format("signpic.advmsg.invalidimage")); diff --git a/src/main/java/com/kamesuta/mc/signpic/image/meta/ImageSize.java b/src/main/java/com/kamesuta/mc/signpic/image/meta/ImageSize.java index a10e1d81..40572e5e 100644 --- a/src/main/java/com/kamesuta/mc/signpic/image/meta/ImageSize.java +++ b/src/main/java/com/kamesuta/mc/signpic/image/meta/ImageSize.java @@ -80,7 +80,10 @@ else if (imagesize.vaildHeight()) } public ImageSize setSize(final ImageSizes s, final float rawWidth, final float rawHeight, final float maxWidth, final float maxHeight) { - s.size(this, rawWidth, rawHeight, maxWidth, maxHeight); + if ((rawWidth == unknownSize && maxWidth == unknownSize) || (rawHeight == unknownSize && maxHeight == unknownSize)) + throw new IllegalArgumentException("No Size Defined"); + s.size(this, rawWidth != unknownSize ? rawWidth : maxWidth, rawHeight != unknownSize ? rawHeight : maxHeight, + maxWidth != unknownSize ? maxWidth : rawWidth, maxHeight != unknownSize ? maxHeight : rawHeight); return this; } diff --git a/src/main/java/com/kamesuta/mc/signpic/information/InformationChecker.java b/src/main/java/com/kamesuta/mc/signpic/information/InformationChecker.java index 376d29e6..518fec80 100644 --- a/src/main/java/com/kamesuta/mc/signpic/information/InformationChecker.java +++ b/src/main/java/com/kamesuta/mc/signpic/information/InformationChecker.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.math.NumberUtils; import com.kamesuta.mc.signpic.Client; +import com.kamesuta.mc.signpic.Config; import com.kamesuta.mc.signpic.Reference; import com.kamesuta.mc.signpic.handler.CoreEvent; import com.kamesuta.mc.signpic.util.ChatBuilder; @@ -30,29 +31,25 @@ public void onTick() { final EntityPlayer player = Client.mc.thePlayer; if(this.doneChecking && player != null && !this.triedToWarnPlayer) { final String lang = Client.mc.gameSettings.language; - if (!StringUtils.equals(Reference.VERSION, "${version}")) { + if (Config.instance.informationNotice && !StringUtils.equals(Reference.VERSION, "${version}")) { try { final String[] client = Reference.VERSION.split("\\."); - if (client.length>=2) { + if (client.length>=3) { final int clientBuild1 = Integer.parseInt(client[0]); final int clientBuild2 = Integer.parseInt(client[1]); + final int clientBuild3 = Integer.parseInt(client[2]); boolean betaneedupdate = false; - if (this.unstableVersion!=null && this.unstableVersion.version!=null) { - if (client.length>=4 &&StringUtils.equals(client[3], "beta")) { - if (NumberUtils.isNumber(client[2])) { - final int clientBuild3 = NumberUtils.toInt(client[2]); - final String[] beta = this.unstableVersion.version.split("\\."); - if (beta.length>=4 &&StringUtils.equals(beta[3], "beta")) { - if (NumberUtils.isNumber(beta[0]) && NumberUtils.isNumber(beta[1]) && NumberUtils.isNumber(beta[2])) { - final int betaBuild1 = NumberUtils.toInt(beta[0]); - final int betaBuild2 = NumberUtils.toInt(beta[1]); - final int betaBuild3 = NumberUtils.toInt(beta[2]); - betaneedupdate = (betaBuild1 > clientBuild1) || - (betaBuild1 == clientBuild1 && betaBuild2 > clientBuild2) || - (betaBuild1 == clientBuild1 && betaBuild2 == clientBuild2 && betaBuild3 > clientBuild3); - } - } + if (Config.instance.informationJoinBeta && this.unstableVersion!=null && this.unstableVersion.version!=null) { + final String[] beta = this.unstableVersion.version.split("\\."); + if (beta.length>=4 &&StringUtils.equals(beta[3], "beta")) { + if (NumberUtils.isNumber(beta[0]) && NumberUtils.isNumber(beta[1]) && NumberUtils.isNumber(beta[2])) { + final int betaBuild1 = NumberUtils.toInt(beta[0]); + final int betaBuild2 = NumberUtils.toInt(beta[1]); + final int betaBuild3 = NumberUtils.toInt(beta[2]); + betaneedupdate = (betaBuild1 > clientBuild1) || + (betaBuild1 == clientBuild1 && betaBuild2 > clientBuild2) || + (betaBuild1 == clientBuild1 && betaBuild2 == clientBuild2 && betaBuild3 > clientBuild3); } } } @@ -63,12 +60,15 @@ public void onTick() { if (this.onlineVersion!=null && this.onlineVersion.version!=null) { final String[] online = this.onlineVersion.version.split("\\."); - if (online.length>=2) { + if (online.length>=3) { boolean needupdate = false; if (!betaneedupdate) { final int onlineBuild1 = Integer.parseInt(online[0]); final int onlineBuild2 = Integer.parseInt(online[1]); - needupdate = (onlineBuild1 > clientBuild1) || (onlineBuild1 == clientBuild1 && onlineBuild2 > clientBuild2); + final int onlineBuild3 = Integer.parseInt(online[2]); + needupdate = (onlineBuild1 > clientBuild1) || + (onlineBuild1 == clientBuild1 && onlineBuild2 > clientBuild2) || + (onlineBuild1 == clientBuild1 && onlineBuild2 == clientBuild2 && onlineBuild3 > clientBuild3); } if(betaneedupdate || needupdate) { diff --git a/src/main/java/com/kamesuta/mc/signpic/proxy/ClientProxy.java b/src/main/java/com/kamesuta/mc/signpic/proxy/ClientProxy.java index f2b602b6..f6e7c304 100644 --- a/src/main/java/com/kamesuta/mc/signpic/proxy/ClientProxy.java +++ b/src/main/java/com/kamesuta/mc/signpic/proxy/ClientProxy.java @@ -58,8 +58,6 @@ public void preInit(final FMLPreInitializationEvent event) { Client.mcDir = mcdir; Client.signpicDir = signpicdir; Client.signpicCacheDir = cachedir; - Client.configDir = event.getModConfigurationDirectory(); - Client.configFile = event.getSuggestedConfigurationFile(); Client.modDir = new File(mcdir, "mods"); Client.modFile = event.getSourceFile(); diff --git a/src/main/java/com/kamesuta/mc/signpic/render/CustomTileEntitySignRenderer.java b/src/main/java/com/kamesuta/mc/signpic/render/CustomTileEntitySignRenderer.java index f5e5748e..e41edf18 100644 --- a/src/main/java/com/kamesuta/mc/signpic/render/CustomTileEntitySignRenderer.java +++ b/src/main/java/com/kamesuta/mc/signpic/render/CustomTileEntitySignRenderer.java @@ -3,6 +3,7 @@ import static org.lwjgl.opengl.GL11.*; import com.kamesuta.mc.signpic.Client; +import com.kamesuta.mc.signpic.Config; import com.kamesuta.mc.signpic.entry.Entry; import com.kamesuta.mc.signpic.entry.EntryId; import com.kamesuta.mc.signpic.entry.content.Content; @@ -116,7 +117,7 @@ public void renderSignPictureBase(final TileEntitySign tile, final double x, fin if (entry.isValid()) { if (CurrentMode.instance.isState(CurrentMode.State.SEE)) { RenderHelper.startTexture(); - glColor4f(1f, 1f, 1f, opacity * .5f); + glColor4f(1f, 1f, 1f, opacity * Config.instance.renderSeeOpacity); super.renderTileEntityAt(tile, x, y, z, partialTicks); } diff --git a/src/main/java/com/kamesuta/mc/signpic/render/SignPicRender.java b/src/main/java/com/kamesuta/mc/signpic/render/SignPicRender.java index 09f6bda5..edeccb4b 100644 --- a/src/main/java/com/kamesuta/mc/signpic/render/SignPicRender.java +++ b/src/main/java/com/kamesuta/mc/signpic/render/SignPicRender.java @@ -4,6 +4,7 @@ import com.kamesuta.mc.bnnwidget.WGui; import com.kamesuta.mc.signpic.Client; +import com.kamesuta.mc.signpic.Config; import com.kamesuta.mc.signpic.entry.Entry; import com.kamesuta.mc.signpic.entry.EntryId; import com.kamesuta.mc.signpic.entry.content.Content; @@ -29,10 +30,10 @@ public SignPicRender() { @CoreEvent public void onRender(final RenderWorldLastEvent event) { - float opacity = 0.7f; + float opacity = Config.instance.renderPreviewFixedOpacity; if (CurrentMode.instance.isMode(CurrentMode.Mode.SETPREVIEW) || CurrentMode.instance.isMode(CurrentMode.Mode.PLACE)) { Sign.preview.capturePlace(); - opacity *= 0.7f; + opacity = Config.instance.renderPreviewFloatedOpacity; } if (CurrentMode.instance.isState(CurrentMode.State.PREVIEW)) { if (Sign.preview.isRenderable() && Sign.preview.isVisible()) { diff --git a/src/main/java/com/kamesuta/mc/signpic/util/Sign.java b/src/main/java/com/kamesuta/mc/signpic/util/Sign.java index 4012173f..be2a48e4 100644 --- a/src/main/java/com/kamesuta/mc/signpic/util/Sign.java +++ b/src/main/java/com/kamesuta/mc/signpic/util/Sign.java @@ -3,8 +3,10 @@ import org.lwjgl.util.Timer; import com.kamesuta.mc.signpic.Client; +import com.kamesuta.mc.signpic.Config; import com.kamesuta.mc.signpic.entry.EntryId; import com.kamesuta.mc.signpic.entry.EntryIdBuilder; +import com.kamesuta.mc.signpic.gui.GuiPAAS; import com.kamesuta.mc.signpic.preview.SignEntity; import net.minecraft.client.network.NetHandlerPlayClient; @@ -30,6 +32,13 @@ public static void sendSign(final EntryId entryId, final TileEntitySign sourceen sourceentity.setEditable(true); } + public static void placeSign(final EntryId entryId, final TileEntitySign sourceentity) { + if (Config.instance.multiplayPAAS && !Client.mc.isSingleplayer()) + Client.mc.displayGuiScreen(new GuiPAAS(new SendPacketTask(entryId, sourceentity))); + else + sendSign(entryId, sourceentity); + } + public static class SendPacketTask { public final long limit; public final EntryId id; @@ -58,15 +67,8 @@ public boolean tick() { return false; } - /** Fastest time "possible" estimate for an empty sign. */ - private static long minEditTime = 150; - /** Minimum time needed to add one extra line (not the first). */ - private static long minLineTime = 50; - /** Minimum time needed to type a character. */ - private static long minCharTime = 50; - - public static long getExpectedEditTime(final String[] lines, final boolean skipEmpty) { - long expected = minEditTime; + private static long getExpectedEditTime(final String[] lines, final boolean skipEmpty) { + long expected = Config.instance.multiplayPAASMinEditTime; int n = 0; for (String line : lines){ if (line != null){ @@ -74,7 +76,7 @@ public static long getExpectedEditTime(final String[] lines, final boolean skipE if (!line.isEmpty()){ final int chars = line.length(); n += 1; - expected += minCharTime * chars; + expected += Config.instance.multiplayPAASMinCharTime * chars; } } } @@ -82,7 +84,7 @@ public static long getExpectedEditTime(final String[] lines, final boolean skipE return 0; } if (n > 1){ - expected += minLineTime * n; + expected += Config.instance.multiplayPAASMinLineTime * n; } return expected; } diff --git a/src/main/resources/assets/signpic/lang/en_US.lang b/src/main/resources/assets/signpic/lang/en_US.lang index f80ad552..49e8f4ee 100644 --- a/src/main/resources/assets/signpic/lang/en_US.lang +++ b/src/main/resources/assets/signpic/lang/en_US.lang @@ -21,6 +21,7 @@ signpic.key.category=Sign Picture signpic.key.gui=Open GUI # GUI +## Sign Editor signpic.gui.editor.see=View Sign signpic.gui.editor.preview=Preview signpic.gui.editor.continue=Continue @@ -28,7 +29,7 @@ signpic.gui.editor.load=Load signpic.gui.editor.place=Place signpic.gui.editor.cancel=Cancel signpic.gui.editor.textfield=Place URL Here! -## Size +### Size signpic.gui.editor.size.category=Size signpic.gui.editor.size.width=W signpic.gui.editor.size.height=H @@ -36,7 +37,7 @@ signpic.gui.editor.size.width.neg=- signpic.gui.editor.size.width.pos=+ signpic.gui.editor.size.height.neg=- signpic.gui.editor.size.height.pos=+ -## Offset +### Offset signpic.gui.editor.offset.category=Offset signpic.gui.editor.offset.x=X signpic.gui.editor.offset.x.neg=⇦ @@ -47,7 +48,7 @@ signpic.gui.editor.offset.y.pos=⇧ signpic.gui.editor.offset.z=Z signpic.gui.editor.offset.z.neg=↗ signpic.gui.editor.offset.z.pos=↙ -## Rotation +### Rotation signpic.gui.editor.rotation.category=Rotation signpic.gui.editor.rotation.up=↑ signpic.gui.editor.rotation.down=↓ @@ -58,6 +59,9 @@ signpic.gui.editor.rotation.remove=- signpic.gui.editor.rotation.add=+ signpic.gui.editor.rotation.neg=- signpic.gui.editor.rotation.pos=+ +## Prevent Anti-AutoSign +signpic.gui.paas.count=Please Wait ( %d / %d letters ) +signpic.gui.paas.time=Esc for Cancel ( %.2f / %.2f seconds ) # Image State signpic.state.init=Waiting... @@ -72,6 +76,7 @@ signpic.state.error=ERROR # Image State Additional Message signpic.advmsg.invalidurl=Invalid URL +signpic.advmsg.capacityover=CapacityOver signpic.advmsg.invalidimage=Invalid Image signpic.advmsg.ioerror=Failed to Read: §7%s signpic.advmsg.unknown=Unknown Error: §7%s diff --git a/src/main/resources/assets/signpic/lang/ja_JP.lang b/src/main/resources/assets/signpic/lang/ja_JP.lang index bba1ae0d..4b1fa9aa 100644 --- a/src/main/resources/assets/signpic/lang/ja_JP.lang +++ b/src/main/resources/assets/signpic/lang/ja_JP.lang @@ -8,6 +8,7 @@ signpic.over.mode.setpreview=ブロックをクリックしてプレビュー位 signpic.chat.error.place=[§6SignPicture§r] 申し訳ございませんがエラーが発生したためこの機能をご利用になることができません。 # GUI +## Sign Editor signpic.gui.editor.see=実体表示 signpic.gui.editor.preview=プレビュー signpic.gui.editor.continue=連続 @@ -15,14 +16,17 @@ signpic.gui.editor.load=ロード signpic.gui.editor.place=設置 signpic.gui.editor.cancel=キャンセル signpic.gui.editor.textfield=ここにURLを入力! -## Size +### Size signpic.gui.editor.size.category=サイズ signpic.gui.editor.size.width=幅 signpic.gui.editor.size.height=高さ -## Offset +### Offset signpic.gui.editor.offset.category=オフセット -## Rotation +### Rotation signpic.gui.editor.rotation.category=回転 +## Prevent Anti-AutoSign +signpic.gui.paas.count=しばらくお待ちください ( %s / %s 文字 ) +signpic.gui.paas.time=Esc でキャンセル ( %s / %s 秒 ) # Image State signpic.state.init=待機中... @@ -37,6 +41,7 @@ signpic.state.error=エラー # Image State Additional Message signpic.advmsg.invalidurl=不正なURL +signpic.advmsg.capacityover=容量オーバー signpic.advmsg.invalidimage=不正な画像 signpic.advmsg.ioerror=ファイル読み込み失敗: §7%s signpic.advmsg.unknown=不明なエラー: §7%s From 06beb21cf13c402bb78e9b42db584a943f405504 Mon Sep 17 00:00:00 2001 From: Kamesuta Date: Wed, 28 Sep 2016 23:12:08 +0900 Subject: [PATCH 7/7] version --- gradle.properties | 4 +-- info/info.json | 27 ++++++++++++------- .../java/com/kamesuta/mc/signpic/Config.java | 9 ++++++- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index 35a712d7..c39ced8f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ group=com.kamesuta.mc modid=signpic modname=SignPicture version_major=2 -version_minor=2 -version_micro=2 +version_minor=3 +version_micro=0 version_minecraft=1.7.10 version_forge=10.13.4.1558-1.7.10 version_minforge=10.13.4.1558 \ No newline at end of file diff --git a/info/info.json b/info/info.json index 1464f39b..57619602 100644 --- a/info/info.json +++ b/info/info.json @@ -1,15 +1,15 @@ { "versions": { "1.7.10": { - "version": "2.2.2", - "remote": "https://github.com/Team-Fruit/SignPicture/releases/download/1.7.10-2.2.2/SignPicture-1.7.10-2.2.2-universal.jar", - "local": "SignPicture-1.7.10-2.2.2-universal.jar", - "message": "Offset And Rotations! More freely images! SignPicture 2.2.2 Released!", + "version": "2.3.0", + "remote": "https://github.com/Team-Fruit/SignPicture/releases/download/1.7.10-2.3.0/SignPicture-1.7.10-2.3.0-universal.jar", + "local": "SignPicture-1.7.10-2.3.0-universal.jar", + "message": "Config & Prevent Anti-AutoSign Mode added. SignPicture 2.3.0 Released.", "message_local": { - "ja_JP": "オフセットと回転機能実装! さらに自由自在に画像を貼ろう! SignPicture 2.2.2 リリース!" + "ja_JP": "Anti-AutoSign回避モードとコンフィグの追加 SignPicture 2.3.0 リリース!" } }, - "1.8": { + "1.8.9": { "version": "2.2.2", "remote": "https://github.com/Team-Fruit/SignPicture/releases/download/1.8.9-2.2.2/SignPicture-1.8.9-2.2.2-universal.jar", "local": "SignPicture-1.8.9-2.2.2-universal.jar", @@ -18,10 +18,19 @@ "ja_JP": "オフセットと回転機能実装! さらに自由自在に画像を貼ろう! SignPicture 2.2.2 リリース!" } }, - "1.9": { + "1.9.4": { + "version": "2.1.5", + "remote": "https://github.com/Team-Fruit/SignPicture/releases/download/1.9.4-2.1.5/SignPicture-1.9.4-2.1.5-universal.jar", + "local": "SignPicture-1.9.4-2.1.5-universal.jar", + "message": "GUI Update! SignPicture 2.1.5 Released!", + "message_local": { + "ja_JP": "遂にSignPictureにGUIが! SignPicture 2.1.5リリース!!" + } + }, + "1.10.2": { "version": "2.1.5", - "remote": "https://github.com/Team-Fruit/SignPicture/releases/download/1.9-2.1.5/SignPicture-1.9-2.1.5-universal.jar", - "local": "SignPicture-1.9-2.1.5-universal.jar", + "remote": "https://github.com/Team-Fruit/SignPicture/releases/download/1.10.2-2.1.5/SignPicture-1.10.2-2.1.5-universal.jar", + "local": "SignPicture-1.10.2-2.1.5-universal.jar", "message": "GUI Update! SignPicture 2.1.5 Released!", "message_local": { "ja_JP": "遂にSignPictureにGUIが! SignPicture 2.1.5リリース!!" diff --git a/src/main/java/com/kamesuta/mc/signpic/Config.java b/src/main/java/com/kamesuta/mc/signpic/Config.java index 3dd6887b..9052fb9c 100644 --- a/src/main/java/com/kamesuta/mc/signpic/Config.java +++ b/src/main/java/com/kamesuta/mc/signpic/Config.java @@ -56,7 +56,14 @@ public Config( final File configFile ) { addCustomCategoryComment("Content", "Content Data Management"); this.informationNotice = get( "Version", "Notice", this.informationNotice ).setRequiresMcRestart(true).getBoolean( this.informationNotice ); - this.informationJoinBeta = get( "Version", "JoinBeta", this.informationJoinBeta ).setRequiresMcRestart(true).getBoolean( this.informationJoinBeta ); + + final Property joinBeta = get( "Version", "JoinBeta", this.informationJoinBeta ); + final String[] v = StringUtils.split(Reference.VERSION, "\\."); + if (v.length>=4 &&StringUtils.equals(v[3], "beta")) { + this.informationJoinBeta = true; + joinBeta.set(true); + } + this.informationJoinBeta = joinBeta.setRequiresMcRestart(true).getBoolean( this.informationJoinBeta ); addCustomCategoryComment("MultiplayPreventAntiAutoSign", "Prevent from Anti-AutoSign Plugin such as NoCheatPlus. (ms)");