/** Call this method from you GuiScreen to process the keys into textbox. */ public boolean textboxKeyTyped(char par1, int par2) { if (this.isEnabled && this.isFocused) { switch (par1) { case 1: this.setCursorPositionEnd(); this.setSelectionPos(0); return true; case 3: GuiScreen.setClipboardString(this.getSelectedtext()); return true; case 22: this.writeText(GuiScreen.getClipboardString()); return true; case 24: GuiScreen.setClipboardString(this.getSelectedtext()); this.writeText(""); return true; default: switch (par2) { case 14: if (GuiScreen.isCtrlKeyDown()) { this.deleteWords(-1); } else { this.deleteFromCursor(-1); } return true; case 199: if (GuiScreen.isShiftKeyDown()) { this.setSelectionPos(0); } else { this.setCursorPositionZero(); } return true; case 203: if (GuiScreen.isShiftKeyDown()) { if (GuiScreen.isCtrlKeyDown()) { this.setSelectionPos(this.getNthWordFromPos(-1, this.getSelectionEnd())); } else { this.setSelectionPos(this.getSelectionEnd() - 1); } } else if (GuiScreen.isCtrlKeyDown()) { this.setCursorPosition(this.getNthWordFromCursor(-1)); } else { this.moveCursorBy(-1); } return true; case 205: if (GuiScreen.isShiftKeyDown()) { if (GuiScreen.isCtrlKeyDown()) { this.setSelectionPos(this.getNthWordFromPos(1, this.getSelectionEnd())); } else { this.setSelectionPos(this.getSelectionEnd() + 1); } } else if (GuiScreen.isCtrlKeyDown()) { this.setCursorPosition(this.getNthWordFromCursor(1)); } else { this.moveCursorBy(1); } return true; case 207: if (GuiScreen.isShiftKeyDown()) { this.setSelectionPos(this.text.length()); } else { this.setCursorPositionEnd(); } return true; case 211: if (GuiScreen.isCtrlKeyDown()) { this.deleteWords(1); } else { this.deleteFromCursor(1); } return true; default: if (ChatAllowedCharacters.isAllowedCharacter(par1)) { this.writeText(Character.toString(par1)); return true; } else { return false; } } } } else { return false; } }
/** Call this method from your GuiScreen to process the keys into the textbox */ public boolean textboxKeyTyped(char p_146201_1_, int p_146201_2_) { if (!this.field_146213_o) { return false; } else { switch (p_146201_1_) { case 1: this.func_146202_e(); this.func_146199_i(0); return true; case 3: GuiScreen.setClipboardString(this.func_146207_c()); return true; case 22: if (this.field_146226_p) { this.func_146191_b(GuiScreen.getClipboardString()); } return true; case 24: GuiScreen.setClipboardString(this.func_146207_c()); if (this.field_146226_p) { this.func_146191_b(""); } return true; default: switch (p_146201_2_) { case 14: if (GuiScreen.isCtrlKeyDown()) { if (this.field_146226_p) { this.func_146177_a(-1); } } else if (this.field_146226_p) { this.func_146175_b(-1); } return true; case 199: if (GuiScreen.isShiftKeyDown()) { this.func_146199_i(0); } else { this.func_146196_d(); } return true; case 203: if (GuiScreen.isShiftKeyDown()) { if (GuiScreen.isCtrlKeyDown()) { this.func_146199_i(this.func_146183_a(-1, this.func_146186_n())); } else { this.func_146199_i(this.func_146186_n() - 1); } } else if (GuiScreen.isCtrlKeyDown()) { this.func_146190_e(this.func_146187_c(-1)); } else { this.func_146182_d(-1); } return true; case 205: if (GuiScreen.isShiftKeyDown()) { if (GuiScreen.isCtrlKeyDown()) { this.func_146199_i(this.func_146183_a(1, this.func_146186_n())); } else { this.func_146199_i(this.func_146186_n() + 1); } } else if (GuiScreen.isCtrlKeyDown()) { this.func_146190_e(this.func_146187_c(1)); } else { this.func_146182_d(1); } return true; case 207: if (GuiScreen.isShiftKeyDown()) { this.func_146199_i(this.field_146216_j.length()); } else { this.func_146202_e(); } return true; case 211: if (GuiScreen.isCtrlKeyDown()) { if (this.field_146226_p) { this.func_146177_a(1); } } else if (this.field_146226_p) { this.func_146175_b(1); } return true; default: if (ChatAllowedCharacters.isAllowedCharacter(p_146201_1_)) { if (this.field_146226_p) { this.func_146191_b(Character.toString(p_146201_1_)); } return true; } else { return false; } } } } }
@Override public void action(GuiBase gui) { GuiMoarSign guiM = (GuiMoarSign) gui; GuiScreen.setClipboardString(guiM.guiTextFields[guiM.selectedTextField].getSelectedText()); guiM.guiTextFields[guiM.selectedTextField].deleteFromCursor(0); }
@Override public boolean onKeyTyped(char charTyped, int keyTyped) { if (!isFocused()) { return false; } switch (charTyped) { case 1: // ^A selectionEnd = caret = textLength; selectionStart = 0; findRenderStart(); return true; case 3: // ^C if (selectionStart != selectionEnd) { GuiScreen.setClipboardString(getSelectedText()); } return true; case 24: // ^X if (selectionStart != selectionEnd) { GuiScreen.setClipboardString(getSelectedText()); clearSelection(); } return true; case 22: // ^V writeText(GuiScreen.getClipboardString()); return true; default: switch (keyTyped) { case Keyboard.KEY_ESCAPE: setFocused(false); return !isFocused(); case Keyboard.KEY_RETURN: case Keyboard.KEY_NUMPADENTER: return onEnter(); case Keyboard.KEY_INSERT: if (GuiScreen.isShiftKeyDown()) { writeText(GuiScreen.getClipboardString()); } else { caretInsert = !caretInsert; } return true; case Keyboard.KEY_CLEAR: // mac only (clear selection) clearSelection(); return true; case Keyboard.KEY_DELETE: // delete if (!GuiScreen.isShiftKeyDown()) { if (selectionStart != selectionEnd) { clearSelection(); } else if (GuiScreen.isCtrlKeyDown()) { int size = seekNextCaretLocation(caret, true) - caret; selectionStart = caret; selectionEnd = caret + size; clearSelection(); } else { if (caret < textLength && textLength > 0) { --textLength; System.arraycopy(text, caret + 1, text, caret, textLength - caret); } } if (caret <= renderStart) { renderStart = MathHelper.clampI(caret - 3, 0, textLength); } findRenderStart(); onCharacterEntered(true); return true; } // continue.. (shift+delete = backspace) case Keyboard.KEY_BACK: // backspace if (selectionStart != selectionEnd) { clearSelection(); } else if (GuiScreen.isCtrlKeyDown()) { int size = seekNextCaretLocation(caret, false) - caret; selectionStart = caret + size; selectionEnd = caret; clearSelection(); } else { if (caret > 0 && textLength > 0) { --caret; System.arraycopy(text, caret + 1, text, caret, textLength - caret); --textLength; } } if (caret <= renderStart) { renderStart = MathHelper.clampI(caret - 3, 0, textLength); } findRenderStart(); onCharacterEntered(true); return true; case Keyboard.KEY_HOME: // home if (GuiScreen.isShiftKeyDown()) { if (caret > selectionEnd) { selectionEnd = selectionStart; } selectionStart = 0; } else { selectionStart = selectionEnd = 0; } renderStart = caret = 0; return true; case Keyboard.KEY_END: // end if (GuiScreen.isShiftKeyDown()) { if (caret < selectionStart) { selectionStart = selectionEnd; } selectionEnd = textLength; } else { selectionStart = selectionEnd = textLength; } caret = textLength; findRenderStart(); return true; case Keyboard.KEY_LEFT: // left arrow case Keyboard.KEY_RIGHT: // right arrow int size = keyTyped == 203 ? -1 : 1; if (GuiScreen.isCtrlKeyDown()) { size = seekNextCaretLocation(caret, keyTyped == 205) - caret; } if (selectionStart == selectionEnd || !GuiScreen.isShiftKeyDown()) { selectionStart = selectionEnd = caret; } { int t = caret; caret = MathHelper.clampI(caret + size, 0, textLength); size = caret - t; } findRenderStart(); if (GuiScreen.isShiftKeyDown()) { if (caret == selectionStart + size) { selectionStart = caret; } else if (caret == selectionEnd + size) { selectionEnd = caret; } // this logic is 'broken' in that the selection doesn't wrap // such that a|bc|def becomes abc|def| but it will highlight // the rest of the word the caret is on i.e., a|bc|def -> a|bcdef| // i don't know that it matters (home+end exhibit the former) if (selectionStart > selectionEnd) { int t = selectionStart; selectionStart = selectionEnd; selectionEnd = t; } } return true; default: if (isAllowedCharacter(charTyped)) { boolean typed = insertCharacter(charTyped); clearSelection(); findRenderStart(); onCharacterEntered(typed); return true; } else { return false; } } } }
@Override public boolean run(Screenshot screen) { try { String title = ConfigHandler.SAVE_DATE_FORMAT.format(new Date()); String description = "A minecraft screenshot "; if (Minecraft.getMinecraft().isSingleplayer()) { description += "in " + Minecraft.getMinecraft().getIntegratedServer().getFolderName(); } else { ServerData data = Minecraft.getMinecraft().func_147104_D(); description += "on " + data.serverIP + (data.field_82821_f != 25565 ? ":" + data.field_82821_f : ""); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(screen.image, "png", baos); String data = Base64.encodeBase64String(baos.toByteArray()); List<NameValuePair> arguments = new ArrayList<NameValuePair>(3); arguments.add(new BasicNameValuePair("client_id", ImgurAuthHandler.CLIENT_ID)); arguments.add(new BasicNameValuePair("image", data)); arguments.add(new BasicNameValuePair("type", "base64")); arguments.add(new BasicNameValuePair("title", title)); arguments.add(new BasicNameValuePair("description", description)); HttpPost hpost = new HttpPost("https://api.imgur.com/3/upload"); hpost.setEntity(new UrlEncodedFormEntity(arguments)); if (ImgurAuthHandler.getInstance().getAccessToken() != null) { hpost.addHeader( "Authorization", "Bearer " + ImgurAuthHandler.getInstance().getAccessToken()); } else { hpost.addHeader("Authorization", "Client-ID " + ImgurAuthHandler.CLIENT_ID); } HttpClient client = HttpClientBuilder.create().build(); HttpResponse resp = client.execute(hpost); String result = EntityUtils.toString(resp.getEntity()); JsonObject responce = new JsonParser().parse(result).getAsJsonObject(); JsonObject responceData = responce.get("data").getAsJsonObject(); if (responce.has("success") && responce.get("success").getAsBoolean()) { final String uploadUrl = responceData.get("link").getAsString(); HistoryHandler.addUploadedImage( new UploadedImage(title, uploadUrl, screen, new ImgurImageSource(uploadUrl))); IChatComponent message = new ChatComponentTranslation("image.upload.success"); IChatComponent url = new ChatComponentText("Imgur"); IChatComponent tooltip = new ChatComponentText(uploadUrl) .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.AQUA)); url.setChatStyle( new ChatStyle() .setColor(EnumChatFormatting.GOLD) .setBold(true) .setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltip)) .setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, uploadUrl))); message.appendSibling(url); MessageHandler.sendChatMessage(message); if (ConfigHandler.COPY_URL_TO_CLIPBOARD) { GuiScreen.setClipboardString(uploadUrl); MessageHandler.sendChatMessage("image.upload.copy"); } } else { MessageHandler.sendChatMessage( "image.upload.fail", "Imgur", responce.get("status").getAsInt()); MessageHandler.sendChatMessage(responceData.get("error").getAsString()); return false; } return true; } catch (Exception ex) { ex.printStackTrace(); MessageHandler.sendChatMessage("image.upload.fail", "Imgur", ex.getMessage()); return false; } }