@@ -19,14 +19,18 @@ public class PagedGui extends Gui {
1919 private List <String > contents ;
2020 private List <Text > texts ;
2121 private Button leftButton ;
22+ private Button middleButton ;
2223 private Button rightButton ;
24+ private float contentSize = 1.3f ;
25+ private int contentSpacing = 60 ;
2326
2427 public PagedGui (String title , int page ) {
2528 super (UUID .randomUUID (), false );
2629
2730 this .page = page ;
2831 this .contents = new ArrayList <>();
2932 this .texts = new ArrayList <>();
33+ this .title = title ;
3034
3135 setSpacing (60 );
3236 }
@@ -42,9 +46,8 @@ public void open(Player player) {
4246 centerLocation = new Location (player .getWorld (), 0 , 0 , 0 );
4347
4448 for (int i = 0 ; i < 3 ; i ++) {
45- System .out .println ("Setting of: " + contents .get (i ));
4649 if (contents .size () >= i ) {
47- Text text = new Text (contents .get (i + page ), i + 1 ).setSize (1f );
50+ Text text = new Text (contents .get (i + page ), i + 1 ).setSize (contentSize );
4851 text .setGui (this );
4952 texts .add (text );
5053 components .put (text .getUniqueId (), text );
@@ -62,7 +65,7 @@ public void open(Player player) {
6265 leftButton .setGui (this );
6366 buttons .put (leftButton .getUniqueId (), leftButton );
6467
65- rightButton = new Button (">" , ">>" , 2 ).onClick (event -> {
68+ rightButton = new Button (">" , ">>" , 3 ).onClick (event -> {
6669 if (GuiApi .getInstance ().getGuis ().get (player .getUniqueId ()) instanceof PagedGui ) {
6770 PagedGui gui = (PagedGui ) GuiApi .getInstance ().getGuis ().get (player .getUniqueId ());
6871 System .out .println ("Page " + gui .getPage () + " texts size " + contents .size () + " bool " + (gui .getPage () < contents .size () - 3 ));
@@ -103,28 +106,28 @@ public void updatePosition(Location playerLoc) {
103106
104107 if (GuiApi .getInstance ().getVersion ().equals (ServerVersion .PRE_1_20_2 )) {
105108 for (Text text : texts ) {
106- Location newComponentLocation = Calculations .calculateComponentLocation (this , text , 3 , spacing );
109+ Location newComponentLocation = Calculations .calculateComponentLocation (this , text , 3 , contentSpacing );
107110
108111 TeleportInterpolator teleportInterpolator = new TeleportInterpolator (text .getEntity (), newComponentLocation , 5 , 1 );
109112 teleportInterpolator .startInterpolation ();
110113 }
111114
112115 for (Button button : buttons .values ()) {
113- Location newComponentLocation = Calculations .calculateComponentLocation (this , button , 2 , 35 );
116+ Location newComponentLocation = Calculations .calculateComponentLocation (this , button , 3 , spacing );
114117
115118 TeleportInterpolator teleportInterpolator = new TeleportInterpolator (button .getEntity (), newComponentLocation , 5 , 1 );
116119 teleportInterpolator .startInterpolation ();
117120 }
118121 } else {
119122 for (Text text : texts ) {
120- Location newComponentLocation = Calculations .calculateComponentLocation (this , text , 3 , spacing );
123+ Location newComponentLocation = Calculations .calculateComponentLocation (this , text , 3 , contentSpacing );
121124
122125 text .getDisplay ().setTeleportDuration (5 );
123126 text .getDisplay ().teleport (newComponentLocation );
124127 }
125128
126129 for (Button button : buttons .values ()) {
127- Location newComponentLocation = Calculations .calculateComponentLocation (this , button , 2 , 35 );
130+ Location newComponentLocation = Calculations .calculateComponentLocation (this , button , 3 , spacing );
128131
129132 button .getDisplay ().setTeleportDuration (5 );
130133 button .getDisplay ().teleport (newComponentLocation );
@@ -140,6 +143,17 @@ private void changePage(int newPage) {
140143 this .page = newPage ;
141144 }
142145
146+ public PagedGui addButton (Button button ) {
147+ if (middleButton == null ) {
148+ button .setSlot (2 );
149+ components .put (button .getUniqueId (), button );
150+ buttons .put (button .getUniqueId (), button );
151+ middleButton = button ;
152+ button .setGui (this );
153+ }
154+ return this ;
155+ }
156+
143157 public void setContents (List <String > contents ) {
144158 this .contents = contents ;
145159 }
@@ -154,6 +168,10 @@ public void addContent(String content) {
154168 this .contents .add (content );
155169 }
156170
171+ public List <String > getContents () {
172+ return contents ;
173+ }
174+
157175 public String getTitle () {
158176 return title ;
159177 }
@@ -162,7 +180,23 @@ public int getPage() {
162180 return page ;
163181 }
164182
165- public List <Text > getTexts () {
166- return texts ;
183+ public void setContentSize (float contentSize ) {
184+ this .contentSize = contentSize ;
185+ }
186+
187+ public void setContentSpacing (int contentSpacing ) {
188+ this .contentSpacing = contentSpacing ;
189+ }
190+
191+ public PagedGui setLeftButtonText (String text , String hoverText ) {
192+ leftButton .setTexture (text );
193+ leftButton .setHoverTexture (hoverText );
194+ return this ;
195+ }
196+
197+ public PagedGui setRightButtonText (String text , String hoverText ) {
198+ rightButton .setTexture (text );
199+ rightButton .setHoverTexture (hoverText );
200+ return this ;
167201 }
168202}
0 commit comments