TechnoParadox

Untitled

Aug 14th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 7.63 KB | None | 0 0
  1. package hu.NVL.NVLWarpdriveExtensions.client_only.gui_components;
  2.  
  3. import net.minecraft.client.gui.*;
  4. import java.util.*;
  5.  
  6. public class NVLGuiListHelper
  7. {
  8.     private final int LINEHEIGHT = 11;
  9.     public int listStartX;
  10.     public int listStartY;
  11.     public NVLGuiButton upButton;
  12.     public NVLGuiButton downButton;
  13.     public String prefix;
  14.     public int top;
  15.     public int left;
  16.     public int width;
  17.     public int height;
  18.     public ArrayList<String> userList;
  19.     public int barPos;
  20.     public int startPos;
  21.     private int baseID;
  22.     protected String selectedItem;
  23.     protected boolean visible;
  24.     private boolean enabled;
  25.     private int buttonHeight;
  26.    
  27.     public NVLGuiListHelper(final int idBase, final int newLeft, final int newTop, final int newWidth, final int newHeight, final int newButtonHeight, final String newPrefix) {
  28.         this.listStartX = 0;
  29.         this.listStartY = 0;
  30.         this.upButton = null;
  31.         this.downButton = null;
  32.         this.prefix = "";
  33.         this.top = 0;
  34.         this.left = 0;
  35.         this.width = 0;
  36.         this.height = 0;
  37.         this.userList = null;
  38.         this.barPos = 0;
  39.         this.startPos = 0;
  40.         this.baseID = 0;
  41.         this.selectedItem = "";
  42.         this.visible = true;
  43.         this.enabled = true;
  44.         this.buttonHeight = 20;
  45.         this.width = newWidth;
  46.         this.height = newHeight;
  47.         this.prefix = newPrefix;
  48.         this.left = newLeft;
  49.         this.top = newTop;
  50.         this.baseID = idBase;
  51.         this.buttonHeight = newButtonHeight;
  52.         (this.upButton = new NVLGuiButton(idBase, 0, 0, 14, this.buttonHeight, "^", newPrefix + "U")).setTexture("nvl_widgets.png");
  53.         (this.downButton = new NVLGuiButton(idBase + 1, 0, 0, 14, this.buttonHeight, "v", newPrefix + "D")).setTexture("nvl_widgets.png");
  54.         this.userList = new ArrayList<String>();
  55.     }
  56.    
  57.     public void setScreenDimensionsForButtons(final int screenWidth, final int heightOffset) {
  58.         final int guiLeft = screenWidth / 2 - 128;
  59.         this.upButton.field_146128_h = guiLeft + this.left + this.width - 14;
  60.         this.upButton.field_146129_i = heightOffset + this.top;
  61.         this.downButton.field_146128_h = guiLeft + this.left + this.width - 14;
  62.         this.downButton.field_146129_i = heightOffset + this.top + this.height * 11 - this.buttonHeight;
  63.     }
  64.    
  65.     public int getBarTop() {
  66.         return this.top + this.barPos * 11;
  67.     }
  68.    
  69.     public int getBarLeft() {
  70.         return this.left;
  71.     }
  72.    
  73.     public int getBarRight() {
  74.         return this.left + this.width - 14;
  75.     }
  76.    
  77.     public int getBarBottom() {
  78.         return this.top + (this.barPos + 1) * 11;
  79.     }
  80.    
  81.     public int getMainTop() {
  82.         return this.top;
  83.     }
  84.    
  85.     public int getMainLeft() {
  86.         return this.left;
  87.     }
  88.    
  89.     public int getMainRight() {
  90.         return this.left + this.width - 14;
  91.     }
  92.    
  93.     public int getMainBottom() {
  94.         return this.top + this.height * 11;
  95.     }
  96.    
  97.     public int getButtonHeight() {
  98.         return this.buttonHeight;
  99.     }
  100.    
  101.     public void drawItems(final FontRenderer fr, final int screenWidth, final int heightOffset) {
  102.         final int guiLeft = screenWidth / 2 - 128;
  103.         if (this.userList != null && this.visible && this.userList != null && this.userList.size() > 0) {
  104.             for (int i = 0; i < this.height; ++i) {
  105.                 if (this.startPos + i < this.userList.size()) {
  106.                     fr.func_78276_b((String)this.userList.get(this.startPos + i), guiLeft + this.left + 2, heightOffset + this.top + i * 11 + 2, 7864319);
  107.                 }
  108.             }
  109.         }
  110.     }
  111.    
  112.     public boolean handleClick(final int x, final int y, final int screenWidth, final int heightOffset) {
  113.         final int guiLeft = screenWidth / 2 - 128;
  114.         boolean r = false;
  115.         if (this.visible && this.enabled) {
  116.             if (x > guiLeft + this.left && x < guiLeft + this.left + this.width - 14 && y > heightOffset + this.top && y < heightOffset + this.top + this.height * 11) {
  117.                 final int tgt = (y - this.top - heightOffset) / 11;
  118.                 if (this.userList != null && tgt < this.userList.size()) {
  119.                     this.barPos = tgt;
  120.                 }
  121.                 r = true;
  122.             }
  123.             this.updateSelectedItem();
  124.             this.setButtonStates();
  125.         }
  126.         return r;
  127.     }
  128.    
  129.     public void handleButtons(final int id) {
  130.         if (this.visible && this.enabled) {
  131.             if (id == this.baseID) {
  132.                 if (this.barPos > 0) {
  133.                     --this.barPos;
  134.                 }
  135.                 else if (this.startPos > 0) {
  136.                     --this.startPos;
  137.                 }
  138.             }
  139.             if (id == this.baseID + 1 && this.userList != null && this.startPos + this.barPos < this.userList.size()) {
  140.                 if (this.barPos < this.height - 1) {
  141.                     ++this.barPos;
  142.                 }
  143.                 else if (this.startPos + this.barPos < this.userList.size()) {
  144.                     ++this.startPos;
  145.                 }
  146.             }
  147.             this.updateSelectedItem();
  148.             this.setButtonStates();
  149.         }
  150.     }
  151.    
  152.     private void updateSelectedItem() {
  153.         this.selectedItem = "";
  154.         if (this.barPos + this.startPos >= this.userList.size()) {
  155.             this.startPos = 0;
  156.             this.barPos = 0;
  157.         }
  158.         if (this.userList.size() > 0) {
  159.             this.selectedItem = this.userList.get(this.barPos + this.startPos);
  160.         }
  161.     }
  162.    
  163.     public void importArray(final String[] arr) {
  164.         if (arr != null) {
  165.             this.userList.clear();
  166.             for (int i = 0; i < arr.length; ++i) {
  167.                 this.userList.add(arr[i]);
  168.             }
  169.             Collections.sort(this.userList);
  170.         }
  171.         this.setButtonStates();
  172.         this.updateSelectedItem();
  173.     }
  174.    
  175.     public void importArrayList(final ArrayList<String> arr) {
  176.         if (arr != null) {
  177.             this.userList.clear();
  178.             this.userList.addAll(arr);
  179.             Collections.sort(this.userList);
  180.         }
  181.         this.setButtonStates();
  182.         this.updateSelectedItem();
  183.     }
  184.    
  185.     public void addItem(final String item) {
  186.         this.userList.add(item);
  187.         Collections.sort(this.userList);
  188.         this.setButtonStates();
  189.         this.updateSelectedItem();
  190.     }
  191.    
  192.     public void resetBar() {
  193.         this.startPos = 0;
  194.         this.barPos = 0;
  195.         this.updateSelectedItem();
  196.     }
  197.    
  198.     private void setButtonStates() {
  199.         if (this.enabled) {
  200.             if (this.userList.size() <= this.height) {
  201.                 this.upButton.field_146124_l = false;
  202.                 this.downButton.field_146124_l = false;
  203.                 this.startPos = 0;
  204.             }
  205.             else {
  206.                 this.upButton.field_146124_l = (this.startPos > 0 || this.barPos > 0);
  207.                 this.downButton.field_146124_l = (this.startPos + this.barPos < this.userList.size() - 1);
  208.             }
  209.         }
  210.         else {
  211.             this.upButton.field_146124_l = false;
  212.             this.downButton.field_146124_l = false;
  213.         }
  214.     }
  215.    
  216.     public String getSelectedItem() {
  217.         return this.selectedItem;
  218.     }
  219.    
  220.     public void setVisibility(final boolean state) {
  221.         this.upButton.field_146125_m = state;
  222.         this.downButton.field_146125_m = state;
  223.         this.visible = state;
  224.     }
  225.    
  226.     public void setEnabled(final boolean state) {
  227.         this.enabled = state;
  228.         this.setButtonStates();
  229.     }
  230. }
  231.  
Advertisement
Add Comment
Please, Sign In to add comment