- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShopPanel.java
More file actions
Latest commit
75 lines (58 loc) · 2.67 KB
/
Copy pathShopPanel.java
File metadata and controls
75 lines (58 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
packageGrafica.JavaClashOfClans;
importjavax.swing.*;
importjava.awt.*;
importjava.io.File;
importjava.util.ArrayList;
publicclassShopPanelextendsJPanel {
privateCardLayoutcardLayout;
privateJPanelitemsPanel;
ShopPanel(MainWindowmainWindow) {
//? shop top panel
setLayout(newBorderLayout());
JPaneltopPanel = newJPanel(null);
topPanel.setPreferredSize(newDimension(0,100)); //? set 100 px of height
topPanel.add(newShopBackButton(mainWindow)); //? add back button
//? shop main panel =>
//? section panel and items panel
JPanelmainPanel = newJPanel(newBorderLayout());
JPanelsectionPanel = newJPanel(newGridLayout(1 ,5));
sectionPanel.setPreferredSize(newDimension(0,100)); //? set 100 px of height
cardLayout = newCardLayout();
itemsPanel = newJPanel(cardLayout);
FilebuildFolder = newFile(MainWindow.assetsPath + "/../builds");
ArrayList<String> sections = sectionCounter(buildFolder);
for (Stringsection : sections) {
sectionPanel.add(newShopSectionButton(this, capitalize(section)));
itemsPanel.add(newShopContainerItemsPanel(section, mainWindow.getBounds().width, mainWindow.getBounds().height, 2, 5, mainWindow), capitalize(section));
}
mainPanel.add(sectionPanel, BorderLayout.NORTH);
mainPanel.add(itemsPanel, BorderLayout.CENTER);
add(topPanel, BorderLayout.NORTH);
add(mainPanel, BorderLayout.CENTER);
}
voidswitchSection(Stringsection) {
cardLayout.show(itemsPanel, section);
}
Stringcapitalize(Strings){
returns.substring(0, 1).toUpperCase() + s.substring(1);
}
privateArrayList<String> sectionCounter(FilebuildFolder){
//? ritorna l'ArrayList dei nomi delle cartelle che ci sono al suo interno
ArrayList<String> sections = newArrayList<>();
try {
if (buildFolder.listFiles().length != 0) {
for (inti = 0; i < buildFolder.listFiles().length; i++) {
//? se il file non contiene il punto nel nome significa che è una cartella, cioè una sezione nello shop
if (!buildFolder.listFiles()[i].getName().contains(".")) {
sections.add(buildFolder.listFiles()[i].getName());
}
}
} else {
System.out.println("non ci sono sezioni dello shop");
}
} catch (Exceptione){
System.out.println("errore nel conteggio delle sezioni dello shop!\n" + e + ", path="+buildFolder.getPath());
}
returnsections;
}
}