Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hu.NVL.NVLWarpdriveExtensions.client_only.gui_components;
- import net.minecraft.client.gui.*;
- import java.util.*;
- public class NVLGuiListHelper
- {
- private final int LINEHEIGHT = 11;
- public int listStartX;
- public int listStartY;
- public NVLGuiButton upButton;
- public NVLGuiButton downButton;
- public String prefix;
- public int top;
- public int left;
- public int width;
- public int height;
- public ArrayList<String> userList;
- public int barPos;
- public int startPos;
- private int baseID;
- protected String selectedItem;
- protected boolean visible;
- private boolean enabled;
- private int buttonHeight;
- public NVLGuiListHelper(final int idBase, final int newLeft, final int newTop, final int newWidth, final int newHeight, final int newButtonHeight, final String newPrefix) {
- this.listStartX = 0;
- this.listStartY = 0;
- this.upButton = null;
- this.downButton = null;
- this.prefix = "";
- this.top = 0;
- this.left = 0;
- this.width = 0;
- this.height = 0;
- this.userList = null;
- this.barPos = 0;
- this.startPos = 0;
- this.baseID = 0;
- this.selectedItem = "";
- this.visible = true;
- this.enabled = true;
- this.buttonHeight = 20;
- this.width = newWidth;
- this.height = newHeight;
- this.prefix = newPrefix;
- this.left = newLeft;
- this.top = newTop;
- this.baseID = idBase;
- this.buttonHeight = newButtonHeight;
- (this.upButton = new NVLGuiButton(idBase, 0, 0, 14, this.buttonHeight, "^", newPrefix + "U")).setTexture("nvl_widgets.png");
- (this.downButton = new NVLGuiButton(idBase + 1, 0, 0, 14, this.buttonHeight, "v", newPrefix + "D")).setTexture("nvl_widgets.png");
- this.userList = new ArrayList<String>();
- }
- public void setScreenDimensionsForButtons(final int screenWidth, final int heightOffset) {
- final int guiLeft = screenWidth / 2 - 128;
- this.upButton.field_146128_h = guiLeft + this.left + this.width - 14;
- this.upButton.field_146129_i = heightOffset + this.top;
- this.downButton.field_146128_h = guiLeft + this.left + this.width - 14;
- this.downButton.field_146129_i = heightOffset + this.top + this.height * 11 - this.buttonHeight;
- }
- public int getBarTop() {
- return this.top + this.barPos * 11;
- }
- public int getBarLeft() {
- return this.left;
- }
- public int getBarRight() {
- return this.left + this.width - 14;
- }
- public int getBarBottom() {
- return this.top + (this.barPos + 1) * 11;
- }
- public int getMainTop() {
- return this.top;
- }
- public int getMainLeft() {
- return this.left;
- }
- public int getMainRight() {
- return this.left + this.width - 14;
- }
- public int getMainBottom() {
- return this.top + this.height * 11;
- }
- public int getButtonHeight() {
- return this.buttonHeight;
- }
- public void drawItems(final FontRenderer fr, final int screenWidth, final int heightOffset) {
- final int guiLeft = screenWidth / 2 - 128;
- if (this.userList != null && this.visible && this.userList != null && this.userList.size() > 0) {
- for (int i = 0; i < this.height; ++i) {
- if (this.startPos + i < this.userList.size()) {
- fr.func_78276_b((String)this.userList.get(this.startPos + i), guiLeft + this.left + 2, heightOffset + this.top + i * 11 + 2, 7864319);
- }
- }
- }
- }
- public boolean handleClick(final int x, final int y, final int screenWidth, final int heightOffset) {
- final int guiLeft = screenWidth / 2 - 128;
- boolean r = false;
- if (this.visible && this.enabled) {
- if (x > guiLeft + this.left && x < guiLeft + this.left + this.width - 14 && y > heightOffset + this.top && y < heightOffset + this.top + this.height * 11) {
- final int tgt = (y - this.top - heightOffset) / 11;
- if (this.userList != null && tgt < this.userList.size()) {
- this.barPos = tgt;
- }
- r = true;
- }
- this.updateSelectedItem();
- this.setButtonStates();
- }
- return r;
- }
- public void handleButtons(final int id) {
- if (this.visible && this.enabled) {
- if (id == this.baseID) {
- if (this.barPos > 0) {
- --this.barPos;
- }
- else if (this.startPos > 0) {
- --this.startPos;
- }
- }
- if (id == this.baseID + 1 && this.userList != null && this.startPos + this.barPos < this.userList.size()) {
- if (this.barPos < this.height - 1) {
- ++this.barPos;
- }
- else if (this.startPos + this.barPos < this.userList.size()) {
- ++this.startPos;
- }
- }
- this.updateSelectedItem();
- this.setButtonStates();
- }
- }
- private void updateSelectedItem() {
- this.selectedItem = "";
- if (this.barPos + this.startPos >= this.userList.size()) {
- this.startPos = 0;
- this.barPos = 0;
- }
- if (this.userList.size() > 0) {
- this.selectedItem = this.userList.get(this.barPos + this.startPos);
- }
- }
- public void importArray(final String[] arr) {
- if (arr != null) {
- this.userList.clear();
- for (int i = 0; i < arr.length; ++i) {
- this.userList.add(arr[i]);
- }
- Collections.sort(this.userList);
- }
- this.setButtonStates();
- this.updateSelectedItem();
- }
- public void importArrayList(final ArrayList<String> arr) {
- if (arr != null) {
- this.userList.clear();
- this.userList.addAll(arr);
- Collections.sort(this.userList);
- }
- this.setButtonStates();
- this.updateSelectedItem();
- }
- public void addItem(final String item) {
- this.userList.add(item);
- Collections.sort(this.userList);
- this.setButtonStates();
- this.updateSelectedItem();
- }
- public void resetBar() {
- this.startPos = 0;
- this.barPos = 0;
- this.updateSelectedItem();
- }
- private void setButtonStates() {
- if (this.enabled) {
- if (this.userList.size() <= this.height) {
- this.upButton.field_146124_l = false;
- this.downButton.field_146124_l = false;
- this.startPos = 0;
- }
- else {
- this.upButton.field_146124_l = (this.startPos > 0 || this.barPos > 0);
- this.downButton.field_146124_l = (this.startPos + this.barPos < this.userList.size() - 1);
- }
- }
- else {
- this.upButton.field_146124_l = false;
- this.downButton.field_146124_l = false;
- }
- }
- public String getSelectedItem() {
- return this.selectedItem;
- }
- public void setVisibility(final boolean state) {
- this.upButton.field_146125_m = state;
- this.downButton.field_146125_m = state;
- this.visible = state;
- }
- public void setEnabled(final boolean state) {
- this.enabled = state;
- this.setButtonStates();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment