Advertisement
Guest User

GuiFurnace

a guest
Aug 2nd, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.86 KB | None | 0 0
  1. @SideOnly(Side.CLIENT)
  2. public class GuiRCFurnace extends GuiScreen {
  3. private static final ResourceLocation resourceLocation = new ResourceLocation("runecraft2:textures/gui/furnacegui.png");
  4. protected static final ResourceLocation widgetTextures = new ResourceLocation("runecraft2:textures/gui/furnaceicons.png");
  5.  
  6. public static final int GUI_ID = 21;
  7.  
  8. private static final int SPELL_ICON_SIZE = 16;
  9. private static final int SPELL_ICON_SPACING = SPELL_ICON_SIZE + 4;
  10. private static final int SPELL_ICON_BASE_U_OFFSET = 0;
  11. private static final int SPELL_ICON_BASE_V_OFFSET = 198;
  12. private static final int SPELL_ICONS_PER_ROW = 11;
  13.  
  14. public String tooltipNewlineDelimeter = "_p";
  15.  
  16. public long tooltipDelay = 900;
  17.  
  18. /**
  19. * The maximum width in pixels a tooltip can occupy before word wrapping
  20. * occurs
  21. */
  22. public int tooltipMaxWidth = 150;
  23.  
  24. protected int tooltipXOffset = 0;
  25. protected int tooltipYOffset = 10;
  26.  
  27. private final static int LINE_HEIGHT = 11;
  28.  
  29. private long mouseoverTime = 0;
  30. private long prevSystemTime = -1;
  31.  
  32. public boolean bronzebarselected, ironbarselected,
  33. silverbarselected, steelbarselected, goldbarselected,
  34. mithrilbarselected, adamantbarselected, runebarselected = false;
  35.  
  36. int xSize = 248;
  37. int ySize = 134;
  38. int xStart = (width / 2) - (xSize / 2);
  39. int yStart = (height / 2) - (ySize / 2);
  40. int iconyStart = yStart + 22;
  41. int iconxStart = xStart + 17;
  42.  
  43. int bronzeminx, bronzemaxx, bronzeminy,
  44. bronzemaxy, ironminx, ironmaxx, ironminy, ironmaxy, silverminx,
  45. silvermaxx, silverminy, silvermaxy, steelminx, steelmaxx,
  46. steelminy, steelmaxy, goldminx, goldmaxx, goldminy, goldmaxy,
  47. mithrilminx, mithrilmaxx, mithrilminy, mithrilmaxy, adamantminx,
  48. adamantmaxx, adamantminy, adamantmaxy, runeminx, runemaxx,
  49. runeminy, runemaxy;
  50.  
  51. int frame = 1;
  52. private GuiButton doneBtn, craftallBtn,
  53. customcraftBtn, onecraftBtn, fivecraftBtn, tencraftBtn, craftBtn,
  54. rightBtn, leftBtn;
  55. private GuiTextField codeTextField;
  56.  
  57. public void initGui() {
  58. int xSize = 256;
  59. int ySize = 256;
  60. int xStart = (width / 2) - (xSize / 2);
  61. int yStart = (height / 2) - (ySize / 2);
  62. int iconyStart = yStart + 22;
  63. int iconxStart = xStart + 17;
  64. buttonList.clear();
  65. buttonList.add(doneBtn = new GuiButton(1, this.width / 2 - 100, this.height / 4 + 96 + 12, "Done"));
  66.  
  67. buttonList.add(craftallBtn = new GuiButton(2, xStart + 6, yStart + 89, "All"));
  68.  
  69. buttonList.add(onecraftBtn = new GuiButton(4, xStart + 38, yStart + 89, "1"));
  70. buttonList.add(fivecraftBtn = new GuiButton(5, xStart + 70, yStart + 89, "5"));
  71. buttonList.add(tencraftBtn = new GuiButton(6, xStart + 102, yStart + 89, "10"));
  72. buttonList.add(customcraftBtn = new GuiButton(3, xStart + 134, yStart + 89, "Custom"));
  73. buttonList.add(craftBtn = new GuiButton(7, xStart + 180, yStart + 109, "Craft"));
  74.  
  75. buttonList.add(rightBtn = new GuiButton(8, xStart + 223, yStart + 87, ">"));
  76.  
  77. buttonList.add(leftBtn = new GuiButton(9, xStart + 223, yStart + 109, "<"));
  78. Keyboard.enableRepeatEvents(true);
  79.  
  80. // this.codeTextField.setMaxStringLength(32767);
  81. // this.codeTextField.setFocused(true);
  82. }
  83.  
  84. public void drawScreen(int par1, int par2, float par3) {
  85.  
  86. int xSize = 256;
  87. int ySize = 256;
  88. int xStart = (width / 2) - (xSize / 2);
  89. int yStart = (height / 2) - (ySize / 2);
  90. int iconyStart = yStart + 22;
  91. int iconxStart = xStart + 17;
  92.  
  93. rightBtn.width = leftBtn.width = 20;
  94. rightBtn.height = leftBtn.height = 20;
  95. onecraftBtn.width = fivecraftBtn.width = tencraftBtn.width = 30;
  96. onecraftBtn.height = fivecraftBtn.height = tencraftBtn.height = 20;
  97. craftallBtn.width = 30;
  98. craftallBtn.height = craftBtn.height = customcraftBtn.height = 20;
  99. customcraftBtn.width = 40;
  100. craftBtn.width = 35;
  101.  
  102. this.codeTextField = new GuiTextField(this.fontRendererObj, this.width / 2 - 150, 60, 300, 20);
  103.  
  104. this.drawCenteredString(this.fontRendererObj, "Furnace:", this.width / 2, (this.height / 2) - (ySize / 2) - 20, 16777215);
  105.  
  106. // this.codeTextField.drawTextBox();
  107. this.drawBackground(0);
  108. this.doesGuiPauseGame();
  109. this.IsButtonMouseovered(par1, par2, null);
  110. this.drawBars();
  111. //this.DrawTooltipScreen();
  112. super.drawScreen(par1, par2, par3);
  113. }
  114.  
  115. protected void actionPerformed(GuiButton button) {
  116.  
  117. if (button == doneBtn) {
  118. System.out.println("Testing");
  119. this.mc.thePlayer.closeScreen();
  120.  
  121. } else if (button == rightBtn && button != leftBtn) {
  122. if (frame < 5 && button == rightBtn) {
  123. frame++;
  124.  
  125. }
  126.  
  127. } else if (button == leftBtn && button != rightBtn) {
  128. if (frame > 1 && button == leftBtn) {
  129. System.out.println(frame);
  130. frame = frame - 2;
  131. System.out.println(frame);
  132. }
  133. }
  134.  
  135.  
  136. }
  137.  
  138. public void drawBackground(int p_146278_1_) {
  139. int xSize = 256;
  140. int ySize = 256;
  141. int xStart = (width / 2) - (xSize / 2);
  142. int yStart = (height / 2) - (ySize / 2);
  143.  
  144. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  145. this.mc.getTextureManager().bindTexture(resourceLocation);
  146. this.drawTexturedModalRect(xStart, yStart, 0, 0, xSize, ySize);
  147. }
  148.  
  149. public boolean doesGuiPauseGame(boolean var1) {
  150. return false;
  151.  
  152. }
  153.  
  154. public void drawBars() {
  155. int xSize = 256;
  156. int ySize = 256;
  157. int xStart = (width / 2) - (xSize / 2);
  158. int yStart = (height / 2) - (ySize / 2);
  159. int iconyStart = yStart + 25;
  160. int iconxStart = xStart + 13;
  161. int width = 53;
  162. int height = 55;
  163. ExtendedPlayer props = ExtendedPlayer.get(this.mc.thePlayer);
  164.  
  165. switch (frame) {
  166. case 0:
  167. mc.getTextureManager().bindTexture(this.widgetTextures);
  168. this.drawTexturedModalRect(iconxStart, iconyStart, 108, 57, width, height);
  169. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  170.  
  171. bronzeminx = iconxStart;
  172. bronzemaxx = iconxStart + width;
  173. bronzeminy = iconyStart;
  174. bronzemaxy = iconyStart + height;
  175.  
  176. mc.getTextureManager().bindTexture(this.widgetTextures);
  177. this.drawTexturedModalRect(iconxStart + width + 4, iconyStart, 162, 57, width, height);
  178.  
  179. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  180. ironminx = iconxStart;
  181. ironmaxx = iconxStart + width;
  182. ironminy = iconyStart;
  183. ironmaxy = iconyStart + height;
  184.  
  185. mc.getTextureManager().bindTexture(this.widgetTextures);
  186. this.drawTexturedModalRect(iconxStart + width * 2 + 4 * 2, iconyStart, 108, 0, width, height);
  187. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  188. silverminx = iconxStart + SPELL_ICON_SPACING;
  189. silvermaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  190. silverminy = iconyStart;
  191. silvermaxy = iconyStart + 16;
  192.  
  193. mc.getTextureManager().bindTexture(this.widgetTextures);
  194. this.drawTexturedModalRect(iconxStart + width * 3 + 4 * 3, iconyStart, 162, 0, width, height);
  195. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  196. steelminx = iconxStart + SPELL_ICON_SPACING;
  197. steelmaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  198. steelminy = iconyStart;
  199. steelmaxy = iconyStart + 16;
  200.  
  201. break;
  202. case 1:
  203. mc.getTextureManager().bindTexture(this.widgetTextures);
  204. this.drawTexturedModalRect(iconxStart, iconyStart, 108, 57, width, height);
  205. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  206.  
  207. bronzeminx = iconxStart;
  208. bronzemaxx = iconxStart + width;
  209. bronzeminy = iconyStart;
  210. bronzemaxy = iconyStart + height;
  211.  
  212. mc.getTextureManager().bindTexture(this.widgetTextures);
  213. this.drawTexturedModalRect(iconxStart + width + 4, iconyStart, 162, 57, width, height);
  214.  
  215. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  216. ironminx = iconxStart;
  217. ironmaxx = iconxStart + width;
  218. ironminy = iconyStart;
  219. ironmaxy = iconyStart + height;
  220.  
  221. mc.getTextureManager().bindTexture(this.widgetTextures);
  222. this.drawTexturedModalRect(iconxStart + width * 2 + 4 * 2, iconyStart, 108, 0, width, height);
  223. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  224. silverminx = iconxStart + SPELL_ICON_SPACING;
  225. silvermaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  226. silverminy = iconyStart;
  227. silvermaxy = iconyStart + 16;
  228.  
  229. mc.getTextureManager().bindTexture(this.widgetTextures);
  230. this.drawTexturedModalRect(iconxStart + width * 3 + 4 * 3, iconyStart, 162, 0, width, height);
  231. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  232. steelminx = iconxStart + SPELL_ICON_SPACING;
  233. steelmaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  234. steelminy = iconyStart;
  235. steelmaxy = iconyStart + 16;
  236.  
  237. break;
  238. case 2:
  239. mc.getTextureManager().bindTexture(this.widgetTextures);
  240. this.drawTexturedModalRect(iconxStart, iconyStart, 162, 57, width, height);
  241. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  242.  
  243. ironminx = iconxStart;
  244. ironmaxx = iconxStart + width;
  245. ironminy = iconyStart;
  246. ironmaxy = iconyStart + height;
  247.  
  248. mc.getTextureManager().bindTexture(this.widgetTextures);
  249. this.drawTexturedModalRect(iconxStart + width + 4, iconyStart, 108, 0, width, height);
  250.  
  251. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  252. silverminx = iconxStart;
  253. silvermaxx = iconxStart + width;
  254. silverminy = iconyStart;
  255. silvermaxy = iconyStart + height;
  256.  
  257. mc.getTextureManager().bindTexture(this.widgetTextures);
  258. this.drawTexturedModalRect(iconxStart + width * 2 + 4 * 2, iconyStart, 162, 0, width, height);
  259. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  260. steelminx = iconxStart + SPELL_ICON_SPACING;
  261. steelmaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  262. steelminy = iconyStart;
  263. steelmaxy = iconyStart + 16;
  264.  
  265. mc.getTextureManager().bindTexture(this.widgetTextures);
  266. this.drawTexturedModalRect(iconxStart + width * 3 + 4 * 3, iconyStart, 0, 57, width, height);
  267. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  268. goldminx = iconxStart + SPELL_ICON_SPACING;
  269. goldmaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  270. goldminy = iconyStart;
  271. goldmaxy = iconyStart + 16;
  272.  
  273. break;
  274. case 3:
  275. mc.getTextureManager().bindTexture(this.widgetTextures);
  276. this.drawTexturedModalRect(iconxStart, iconyStart, 108, 0, width, height);
  277. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  278.  
  279. silverminx = iconxStart;
  280. silvermaxx = iconxStart + width;
  281. silverminy = iconyStart;
  282. silvermaxy = iconyStart + height;
  283.  
  284. mc.getTextureManager().bindTexture(this.widgetTextures);
  285. this.drawTexturedModalRect(iconxStart + width + 4, iconyStart, 162, 0, width, height);
  286.  
  287. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  288. steelminx = iconxStart;
  289. steelmaxx = iconxStart + width;
  290. steelminy = iconyStart;
  291. steelmaxy = iconyStart + height;
  292.  
  293. mc.getTextureManager().bindTexture(this.widgetTextures);
  294. this.drawTexturedModalRect(iconxStart + width * 2 + 4 * 2, iconyStart, 0, 57, width, height);
  295. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  296. goldminx = iconxStart + SPELL_ICON_SPACING;
  297. goldmaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  298. goldminy = iconyStart;
  299. goldmaxy = iconyStart + 16;
  300.  
  301. mc.getTextureManager().bindTexture(this.widgetTextures);
  302. this.drawTexturedModalRect(iconxStart + width * 3 + 4 * 3, iconyStart, 0, 0, width, height);
  303. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  304. mithrilminx = iconxStart + SPELL_ICON_SPACING;
  305. mithrilmaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  306. mithrilminy = iconyStart;
  307. mithrilmaxy = iconyStart + 16;
  308.  
  309. break;
  310. case 4:
  311. mc.getTextureManager().bindTexture(this.widgetTextures);
  312. this.drawTexturedModalRect(iconxStart, iconyStart, 162, 0, width, height);
  313. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  314.  
  315. steelminx = iconxStart;
  316. steelmaxx = iconxStart + width;
  317. steelminy = iconyStart;
  318. steelmaxy = iconyStart + height;
  319.  
  320. mc.getTextureManager().bindTexture(this.widgetTextures);
  321. this.drawTexturedModalRect(iconxStart + width + 4, iconyStart, 0, 57, width, height);
  322.  
  323. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  324. goldminx = iconxStart;
  325. goldmaxx = iconxStart + width;
  326. goldminy = iconyStart;
  327. goldmaxy = iconyStart + height;
  328.  
  329. mc.getTextureManager().bindTexture(this.widgetTextures);
  330. this.drawTexturedModalRect(iconxStart + width * 2 + 4 * 2, iconyStart, 0, 0, width, height);
  331. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  332. mithrilminx = iconxStart + SPELL_ICON_SPACING;
  333. mithrilmaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  334. mithrilminy = iconyStart;
  335. mithrilmaxy = iconyStart + 16;
  336.  
  337. mc.getTextureManager().bindTexture(this.widgetTextures);
  338. this.drawTexturedModalRect(iconxStart + width * 3 + 4 * 3, iconyStart, 54, 57, width, height);
  339. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  340. adamantminx = iconxStart + SPELL_ICON_SPACING;
  341. adamantmaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  342. adamantminy = iconyStart;
  343. adamantmaxy = iconyStart + 16;
  344.  
  345. break;
  346. case 5:
  347. mc.getTextureManager().bindTexture(this.widgetTextures);
  348. this.drawTexturedModalRect(iconxStart, iconyStart, 0, 57, width, height);
  349. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  350.  
  351. goldminx = iconxStart;
  352. goldmaxx = iconxStart + width;
  353. goldminy = iconyStart;
  354. goldmaxy = iconyStart + height;
  355.  
  356. mc.getTextureManager().bindTexture(this.widgetTextures);
  357. this.drawTexturedModalRect(iconxStart + width + 4, iconyStart, 0, 0, width, height);
  358.  
  359. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  360. mithrilminx = iconxStart;
  361. mithrilmaxx = iconxStart + width;
  362. mithrilminy = iconyStart;
  363. mithrilmaxy = iconyStart + height;
  364.  
  365. mc.getTextureManager().bindTexture(this.widgetTextures);
  366. this.drawTexturedModalRect(iconxStart + width * 2 + 4 * 2, iconyStart, 54, 57, width, height);
  367. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  368. adamantminx = iconxStart + SPELL_ICON_SPACING;
  369. adamantmaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  370. adamantminy = iconyStart;
  371. adamantmaxy = iconyStart + 16;
  372.  
  373. mc.getTextureManager().bindTexture(this.widgetTextures);
  374. this.drawTexturedModalRect(iconxStart + width * 3 + 4 * 3, iconyStart, 54, 0, width, height);
  375. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  376. runeminx = iconxStart + SPELL_ICON_SPACING;
  377. runemaxx = iconxStart + SPELL_ICON_SPACING + SPELL_ICON_SIZE;
  378. runeminy = iconyStart;
  379. runemaxy = iconyStart + 16;
  380.  
  381. break;
  382. }
  383.  
  384. }
  385.  
  386. protected void mouseClicked(int varx, int vary, int p_73864_3_) {
  387. if (varx > doneBtn.xPosition && varx < doneBtn.xPosition + doneBtn.width && vary > doneBtn.yPosition && vary < doneBtn.yPosition + doneBtn.height) {
  388. actionPerformed(doneBtn);
  389. }
  390. if (varx > craftallBtn.xPosition && varx < craftallBtn.xPosition + craftallBtn.width && vary > craftallBtn.yPosition && vary < doneBtn.yPosition + doneBtn.height) {
  391. actionPerformed(craftallBtn);
  392. }
  393. if (varx > customcraftBtn.xPosition && varx < customcraftBtn.xPosition + customcraftBtn.width && vary > customcraftBtn.yPosition && vary < doneBtn.yPosition + doneBtn.height) {
  394. actionPerformed(customcraftBtn);
  395. }
  396. if (varx > onecraftBtn.xPosition && varx < onecraftBtn.xPosition + onecraftBtn.width && vary > onecraftBtn.yPosition && vary < doneBtn.yPosition + doneBtn.height) {
  397. actionPerformed(onecraftBtn);
  398. }
  399. if (varx > fivecraftBtn.xPosition && varx < fivecraftBtn.xPosition + fivecraftBtn.width && vary > fivecraftBtn.yPosition && vary < doneBtn.yPosition + doneBtn.height) {
  400. actionPerformed(fivecraftBtn);
  401. }
  402. if (varx > tencraftBtn.xPosition && varx < tencraftBtn.xPosition + tencraftBtn.width && vary > tencraftBtn.yPosition && vary < doneBtn.yPosition + doneBtn.height) {
  403. actionPerformed(tencraftBtn);
  404. }
  405. if (varx > craftBtn.xPosition && varx < craftBtn.xPosition + craftBtn.width && vary > craftBtn.yPosition && vary < doneBtn.yPosition + doneBtn.height) {
  406. actionPerformed(craftBtn);
  407. }
  408. if (varx > rightBtn.xPosition && varx < rightBtn.xPosition + rightBtn.width && vary > rightBtn.yPosition && vary < doneBtn.yPosition + doneBtn.height) {
  409. actionPerformed(rightBtn);
  410. }
  411. if (varx > leftBtn.xPosition && varx < leftBtn.xPosition + leftBtn.width && vary > leftBtn.yPosition && vary < doneBtn.yPosition + doneBtn.height) {
  412. actionPerformed(leftBtn);
  413. }
  414.  
  415. // ExtendedPlayer props = ExtendedPlayer.get(this.mc.thePlayer);
  416. // System.out.println("Mouse was click at x " + varx + " and y " +
  417. // vary);
  418. // if (asminx < varx && varx < asmaxx && asminy < vary && vary < asmaxy)
  419. // {
  420. // airstrikeselected = !airstrikeselected;
  421. // System.out.println(airstrikeselected);
  422. // }
  423. //
  424. // if (airstrikeselected) {
  425. // props.currentSpell = "airstrike";
  426. // hometeleportselected = false;
  427. // waterstrikeselected = false;
  428. // }
  429. // if (!airstrikeselected) {
  430. // props.currentSpell = "";
  431. // }
  432. // if (htminx < varx && varx < htmaxx && htminy < vary && vary < htmaxy)
  433. // {
  434. // hometeleportselected = !hometeleportselected;
  435. // }
  436. // if (hometeleportselected) {
  437. // props.currentSpell = "hometeleport";
  438. // airstrikeselected = false;
  439. // waterstrikeselected = false;
  440. // }
  441.  
  442. }
  443.  
  444. protected boolean IsButtonMouseovered(int varx, int vary, GuiButton button) {
  445.  
  446.  
  447. switch (frame) {
  448. case 0:if (bronzeminx < varx && varx < bronzemaxx && bronzeminy < vary && vary < bronzemaxy)
  449. {
  450.  
  451. this.RenderTooltip(varx, vary, "_lBronze Bar:_r _p" +
  452. "1x Copper Ore_p" + "1x Tin Ore");
  453.  
  454. }
  455. case 1:if (bronzeminx < varx && varx < bronzemaxx && bronzeminy < vary && vary < bronzemaxy)
  456. {
  457.  
  458. this.RenderTooltip(varx, vary, "_lBronze Bar:_r _p" +
  459. "1x Copper Ore_p" + "1x Tin Ore");
  460.  
  461. }
  462. case 2:
  463. case 3:
  464. case 4:
  465. case 5:
  466. }
  467. return true;
  468. }
  469.  
  470. private void DrawTooltipScreen(int varx, int vary, String string) {
  471. this.renderToolTip(new ItemStack(Items.bronzeBar), varx,vary);
  472.  
  473. }
  474.  
  475. protected void RenderTooltip(int x, int y, String tooltip) {
  476. String[] tooltipArray = ParseTooltipArrayFromString(tooltip);
  477.  
  478. int tooltipWidth = GetTooltipWidth(tooltipArray);
  479. int tooltipHeight = GetTooltipHeight(tooltipArray);
  480.  
  481. int tooltipX = x + tooltipXOffset;
  482. int tooltipY = y + tooltipYOffset;
  483.  
  484. if (tooltipX > width - tooltipWidth - 7)
  485. tooltipX = width - tooltipWidth - 7;
  486. if (tooltipY > height - tooltipHeight - 8)
  487. tooltipY = height - tooltipHeight - 8;
  488.  
  489. // render the background inside box
  490. int innerAlpha = -0xFEFFFF0; // very very dark purple
  491. drawGradientRect(tooltipX, tooltipY - 1, tooltipX + tooltipWidth + 6, tooltipY, innerAlpha, innerAlpha);
  492. drawGradientRect(tooltipX, tooltipY + tooltipHeight + 6, tooltipX + tooltipWidth + 6, tooltipY + tooltipHeight + 7, innerAlpha, innerAlpha);
  493. drawGradientRect(tooltipX, tooltipY, tooltipX + tooltipWidth + 6, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
  494. drawGradientRect(tooltipX - 1, tooltipY, tooltipX, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
  495. drawGradientRect(tooltipX + tooltipWidth + 6, tooltipY, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6, innerAlpha, innerAlpha);
  496.  
  497. // render the background outside box
  498. int outerAlpha1 = 0x505000FF;
  499. int outerAlpha2 = (outerAlpha1 & 0xFEFEFE) >> 1 | outerAlpha1 & -0x1000000;
  500. drawGradientRect(tooltipX, tooltipY + 1, tooltipX + 1, tooltipY + tooltipHeight + 6 - 1, outerAlpha1, outerAlpha2);
  501. drawGradientRect(tooltipX + tooltipWidth + 5, tooltipY + 1, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6 - 1, outerAlpha1, outerAlpha2);
  502. drawGradientRect(tooltipX, tooltipY, tooltipX + tooltipWidth + 3, tooltipY + 1, outerAlpha1, outerAlpha1);
  503. drawGradientRect(tooltipX, tooltipY + tooltipHeight + 5, tooltipX + tooltipWidth + 7, tooltipY + tooltipHeight + 6, outerAlpha2, outerAlpha2);
  504.  
  505. // render the foreground text
  506. int lineCount = 0;
  507. for (String s : tooltipArray) {
  508. mc.fontRenderer.drawStringWithShadow(s, tooltipX + 2, tooltipY + 2 + lineCount * LINE_HEIGHT, 0xFFFFFF);
  509. lineCount++;
  510. }
  511. }
  512.  
  513. /**
  514. * Converts a String representation of a tooltip into a String[], and also
  515. * decodes any font codes used.
  516. *
  517. * @param s
  518. * Ex: "Hello,_nI am your _ltooltip_r and you love me."
  519. * @return An array of Strings such that each String width does not exceed
  520. * tooltipMaxWidth
  521. */
  522. protected String[] ParseTooltipArrayFromString(String s) {
  523. s = DecodeStringCodes(s);
  524. String[] tooltipSections = s.split(tooltipNewlineDelimeter);
  525. ArrayList<String> tooltipArrayList = new ArrayList<String>();
  526.  
  527. for (String section : tooltipSections) {
  528. String tooltip = "";
  529. String[] tooltipWords = section.split(" ");
  530.  
  531. for (int i = 0; i < tooltipWords.length; i++) {
  532. int lineWidthWithNextWord = mc.fontRenderer.getStringWidth(tooltip + tooltipWords[i]);
  533. if (lineWidthWithNextWord > tooltipMaxWidth) {
  534. tooltipArrayList.add(tooltip.trim());
  535. tooltip = tooltipWords[i] + " ";
  536. } else {
  537. tooltip += tooltipWords[i] + " ";
  538. }
  539. }
  540.  
  541. tooltipArrayList.add(tooltip.trim());
  542. }
  543.  
  544. String[] tooltipArray = new String[tooltipArrayList.size()];
  545. tooltipArrayList.toArray(tooltipArray);
  546.  
  547. return tooltipArray;
  548. }
  549.  
  550. /**
  551. * Decodes any font codes into something useable by the FontRenderer.
  552. *
  553. * @param s
  554. * E.x.: "Hello,_nI am your _ltooltip_r and you love me."
  555. * @return E.x. output (html not included): <br>
  556. * "Hello,<br>
  557. * I am your <b>tooltip</b> and you love me."
  558. */
  559. private String DecodeStringCodes(String s) {
  560. return s.replace("_0", FontCodes.BLACK).replace("_1", FontCodes.DARK_BLUE).replace("_2", FontCodes.DARK_GREEN).replace("_3", FontCodes.DARK_AQUA).replace("_4", FontCodes.DARK_RED).replace("_5", FontCodes.DARK_PURPLE).replace("_6", FontCodes.GOLD).replace("_7", FontCodes.GRAY).replace("_8", FontCodes.DARK_GREY).replace("_9", FontCodes.BLUE).replace("_a", FontCodes.GREEN).replace("_b", FontCodes.AQUA).replace("_c", FontCodes.RED).replace("_d", FontCodes.LIGHT_PURPLE).replace("_e", FontCodes.YELLOW).replace("_f", FontCodes.WHITE).replace("_k", FontCodes.OBFUSCATED).replace("_l", FontCodes.BOLD).replace("_m", FontCodes.STRIKETHROUGH).replace("_n", FontCodes.UNDERLINE).replace("_o", FontCodes.ITALICS).replace("_r", FontCodes.RESET);
  561. }
  562.  
  563. /***
  564. * Gets the width of the tooltip in pixels.
  565. *
  566. * @param tooltipArray
  567. * @return
  568. */
  569. private int GetTooltipWidth(String[] tooltipArray) {
  570. int longestWidth = 0;
  571. for (String s : tooltipArray) {
  572. int width = mc.fontRenderer.getStringWidth(s);
  573. if (width > longestWidth)
  574. longestWidth = width;
  575. }
  576. return longestWidth;
  577. }
  578.  
  579. /**
  580. * Gets the height of the tooltip in pixels.
  581. *
  582. * @param tooltipArray
  583. * @return
  584. */
  585. private int GetTooltipHeight(String[] tooltipArray) {
  586. int tooltipHeight = mc.fontRenderer.FONT_HEIGHT - 2;
  587. if (tooltipArray.length > 1) {
  588. tooltipHeight += (tooltipArray.length - 1) * LINE_HEIGHT;
  589. }
  590. return tooltipHeight;
  591. }
  592.  
  593. /**
  594. * Gets a protected/private field from a class using reflection.
  595. *
  596. * @param <T>
  597. * The return type of the field you are getting
  598. * @param <E>
  599. * The class the field is in
  600. * @param classToAccess
  601. * The ".class" of the class the field is in
  602. * @param instance
  603. * The instance of the class
  604. * @param fieldNames
  605. * comma seperated names the field may have (i.e. obfuscated, non
  606. * obfuscated). Obfustated field names can be found in
  607. * fml/conf/fields.csv
  608. * @return
  609. */
  610. public static <T, E> T GetFieldByReflection(Class<? super E> classToAccess, E instance, String... fieldNames) {
  611. Field field = null;
  612. for (String fieldName : fieldNames) {
  613. try {
  614. field = classToAccess.getDeclaredField(fieldName);
  615. } catch (NoSuchFieldException e) {
  616. }
  617.  
  618. if (field != null)
  619. break;
  620. }
  621.  
  622. if (field != null) {
  623. field.setAccessible(true);
  624. T fieldT = null;
  625. try {
  626. fieldT = (T) field.get(instance);
  627. } catch (IllegalArgumentException e) {
  628. } catch (IllegalAccessException e) {
  629. }
  630.  
  631. return fieldT;
  632. }
  633.  
  634. return null;
  635. }
  636.  
  637. public class FontCodes {
  638. // color codes for rendered strings
  639. public static final String BLACK = "\2470";
  640. public static final String DARK_BLUE = "\2471";
  641. public static final String DARK_GREEN = "\2472";
  642. public static final String DARK_AQUA = "\2473";
  643. public static final String DARK_RED = "\2474";
  644. public static final String DARK_PURPLE = "\2475";
  645. public static final String GOLD = "\2476";
  646. public static final String GRAY = "\2477";
  647. public static final String DARK_GREY = "\2478";
  648. public static final String BLUE = "\2479";
  649. public static final String GREEN = "\247a";
  650. public static final String AQUA = "\247b";
  651. public static final String RED = "\247c";
  652. public static final String LIGHT_PURPLE = "\247d";
  653. public static final String YELLOW = "\247e";
  654. public static final String WHITE = "\247f";
  655.  
  656. // font styles
  657. public static final String OBFUSCATED = "\247k";
  658. public static final String BOLD = "\247l";
  659. public static final String STRIKETHROUGH = "\247m";
  660. public static final String UNDERLINE = "\247n";
  661. public static final String ITALICS = "\247o";
  662.  
  663. public static final String RESET = "\247r";
  664. }
  665.  
  666. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement