Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. /*
  2.  
  3. FightCaveOverlay.java
  4.  
  5. * Copyright (c) 2017, Devin French <https://github.com/devinfrench>
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright notice, this
  12. * list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  21. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. package net.runelite.client.plugins.fightcave;
  29.  
  30. import java.awt.Color;
  31. import java.awt.Dimension;
  32. import java.awt.Graphics2D;
  33. import java.awt.image.BufferedImage;
  34. import javax.inject.Inject;
  35. import net.runelite.api.Client;
  36. import net.runelite.api.SpriteID;
  37. import net.runelite.client.game.SpriteManager;
  38. import net.runelite.client.ui.overlay.Overlay;
  39. import net.runelite.client.ui.overlay.OverlayPosition;
  40. import net.runelite.client.ui.overlay.OverlayPriority;
  41. import net.runelite.client.ui.overlay.components.ComponentConstants;
  42. import net.runelite.client.ui.overlay.components.ImageComponent;
  43. import net.runelite.client.ui.overlay.components.PanelComponent;
  44.  
  45. public class FightCaveOverlay extends Overlay
  46. {
  47. private static final Color NOT_ACTIVATED_BACKGROUND_COLOR = new Color(150, 0, 0, 150);
  48.  
  49. private final Client client;
  50. private final FightCavePlugin plugin;
  51. private final SpriteManager spriteManager;
  52. private final PanelComponent imagePanelComponent = new PanelComponent();
  53.  
  54. @Inject
  55. private FightCaveOverlay(Client client, FightCavePlugin plugin, SpriteManager spriteManager)
  56. {
  57. setPosition(OverlayPosition.BOTTOM_RIGHT);
  58. setPriority(OverlayPriority.HIGH);
  59. this.client = client;
  60. this.plugin = plugin;
  61. this.spriteManager = spriteManager;
  62. }
  63.  
  64. @Override
  65. public Dimension render(Graphics2D graphics)
  66. {
  67. final JadAttack attack = plugin.getAttack();
  68.  
  69. if (attack == null)
  70. {
  71. return null;
  72. }
  73.  
  74. final BufferedImage prayerImage = getPrayerImage(attack);
  75.  
  76. imagePanelComponent.getChildren().clear();
  77. imagePanelComponent.getChildren().add(new ImageComponent(prayerImage));
  78. imagePanelComponent.setBackgroundColor(client.isPrayerActive(attack.getPrayer())
  79. ? ComponentConstants.STANDARD_BACKGROUND_COLOR
  80. : NOT_ACTIVATED_BACKGROUND_COLOR);
  81.  
  82. return imagePanelComponent.render(graphics);
  83. }
  84.  
  85. private BufferedImage getPrayerImage(JadAttack attack)
  86. {
  87. final int prayerSpriteID = attack == JadAttack.MAGIC ? SpriteID.PRAYER_PROTECT_FROM_MAGIC : SpriteID.PRAYER_PROTECT_FROM_MISSILES;
  88. return spriteManager.getSprite(prayerSpriteID, 0);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement