cleaner settings menu for levels
This commit is contained in:
parent
a7187b7f8e
commit
cf48a1e73f
4 changed files with 113 additions and 21 deletions
|
@ -22,6 +22,7 @@ public class GuiData {
|
||||||
private ArrayList<String> ytlink = new ArrayList<String>();
|
private ArrayList<String> ytlink = new ArrayList<String>();
|
||||||
private ArrayList<String> creators = new ArrayList<String>();
|
private ArrayList<String> creators = new ArrayList<String>();
|
||||||
private ArrayList<String> victors = new ArrayList<String>();
|
private ArrayList<String> victors = new ArrayList<String>();
|
||||||
|
private ArrayList<Integer> attempts = new ArrayList<Integer>();
|
||||||
public ArrayList<String> completed = new ArrayList<String>();
|
public ArrayList<String> completed = new ArrayList<String>();
|
||||||
|
|
||||||
private FetchData data = new FetchData();
|
private FetchData data = new FetchData();
|
||||||
|
@ -60,6 +61,10 @@ public class GuiData {
|
||||||
return creators;
|
return creators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<Integer> getAttempts() {
|
||||||
|
return attempts;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<String> getVictors() {
|
public ArrayList<String> getVictors() {
|
||||||
return victors;
|
return victors;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +100,7 @@ public class GuiData {
|
||||||
ytlink.add(obj.getString("verification") + "");
|
ytlink.add(obj.getString("verification") + "");
|
||||||
creators.add(obj.getJSONArray("creators") + "");
|
creators.add(obj.getJSONArray("creators") + "");
|
||||||
victors.add(obj.getJSONArray("records") + "");
|
victors.add(obj.getJSONArray("records") + "");
|
||||||
|
attempts.add(0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ public class DatabaseManager {
|
||||||
|
|
||||||
database.insertData(
|
database.insertData(
|
||||||
"levels", // Tabellenname
|
"levels", // Tabellenname
|
||||||
|
data.getAttempts().get(i),
|
||||||
fetch.allLevels().indexOf(levels.get(i).replace(".json", "")) + 1,
|
fetch.allLevels().indexOf(levels.get(i).replace(".json", "")) + 1,
|
||||||
data.getLocalLevels().get(i), // Level-Name
|
data.getLocalLevels().get(i), // Level-Name
|
||||||
levels.get(i).replace(".json", ""), // Level-Name-Raw (oder entsprechender Wert aus fetch.allLevels())
|
levels.get(i).replace(".json", ""), // Level-Name-Raw (oder entsprechender Wert aus fetch.allLevels())
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class Sqlite {
|
||||||
private ArrayList<String> records = new ArrayList<String>();
|
private ArrayList<String> records = new ArrayList<String>();
|
||||||
private ArrayList<String> completed = new ArrayList<String>();
|
private ArrayList<String> completed = new ArrayList<String>();
|
||||||
private ArrayList<String> rawLevelNames = new ArrayList<String>();
|
private ArrayList<String> rawLevelNames = new ArrayList<String>();
|
||||||
|
private ArrayList<Integer> attempts = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<String> getLevelname() {
|
public ArrayList<String> getLevelname() {
|
||||||
|
@ -69,6 +70,10 @@ public class Sqlite {
|
||||||
public ArrayList<String> getRawLevelNames() {
|
public ArrayList<String> getRawLevelNames() {
|
||||||
return rawLevelNames;
|
return rawLevelNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<Integer> getAttempts() {
|
||||||
|
return attempts;
|
||||||
|
}
|
||||||
|
|
||||||
public Sqlite(String dbname) { // setzt variablen
|
public Sqlite(String dbname) { // setzt variablen
|
||||||
url = "jdbc:sqlite:C:\\ExtremeDemonList\\database\\sqlite\\";
|
url = "jdbc:sqlite:C:\\ExtremeDemonList\\database\\sqlite\\";
|
||||||
|
@ -112,6 +117,7 @@ public class Sqlite {
|
||||||
+ " verificationLink TEXT NOT NULL,\n"
|
+ " verificationLink TEXT NOT NULL,\n"
|
||||||
+ " percentToQualify INTEGER NOT NULL,\n"
|
+ " percentToQualify INTEGER NOT NULL,\n"
|
||||||
+ " records TEXT NOT NULL,\n"
|
+ " records TEXT NOT NULL,\n"
|
||||||
|
+ " attempts INTEGER NOT NULL,\n"
|
||||||
+ " completed BOOLEAN NOT NULL\n"
|
+ " completed BOOLEAN NOT NULL\n"
|
||||||
+ ");";
|
+ ");";
|
||||||
|
|
||||||
|
@ -126,8 +132,8 @@ public class Sqlite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertData(String tablename, int placement, String levelname, String levelnameRaw, int levelid, String author, String creators, String verifier, String verificationLink, int percenttoqualify, String records, boolean completed) {
|
public void insertData(String tablename, Integer attempts, int placement, String levelname, String levelnameRaw, int levelid, String author, String creators, String verifier, String verificationLink, int percenttoqualify, String records, boolean completed) {
|
||||||
String sql = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
String sql = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, attempts, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
System.out.println("tablename: " + levelname);
|
System.out.println("tablename: " + levelname);
|
||||||
|
|
||||||
|
@ -143,7 +149,8 @@ public class Sqlite {
|
||||||
pstmt.setString(8, verificationLink);
|
pstmt.setString(8, verificationLink);
|
||||||
pstmt.setInt(9, percenttoqualify);
|
pstmt.setInt(9, percenttoqualify);
|
||||||
pstmt.setString(10, records);
|
pstmt.setString(10, records);
|
||||||
pstmt.setBoolean(11, completed);
|
pstmt.setInt(11, attempts);
|
||||||
|
pstmt.setBoolean(12, completed);
|
||||||
pstmt.executeUpdate();
|
pstmt.executeUpdate();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -155,7 +162,7 @@ public class Sqlite {
|
||||||
|
|
||||||
public void queryData(String tablename) {
|
public void queryData(String tablename) {
|
||||||
|
|
||||||
String sql = "SELECT levelname, levelNameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, completed, records FROM " + tablename;
|
String sql = "SELECT levelname, levelNameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, attempts, completed, records FROM " + tablename;
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url);
|
try (Connection conn = DriverManager.getConnection(url);
|
||||||
Statement stmt = conn.createStatement();
|
Statement stmt = conn.createStatement();
|
||||||
|
@ -173,6 +180,7 @@ public class Sqlite {
|
||||||
completed.add(rs.getBoolean("completed") + "");
|
completed.add(rs.getBoolean("completed") + "");
|
||||||
records.add(rs.getString("records"));
|
records.add(rs.getString("records"));
|
||||||
rawLevelNames.add(rs.getString("levelNameRaw"));
|
rawLevelNames.add(rs.getString("levelNameRaw"));
|
||||||
|
attempts.add(rs.getInt("attempts"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,6 +203,7 @@ public class Sqlite {
|
||||||
ArrayList<String> recordslocal = new ArrayList<String>();
|
ArrayList<String> recordslocal = new ArrayList<String>();
|
||||||
ArrayList<String> completedlocal = new ArrayList<String>();
|
ArrayList<String> completedlocal = new ArrayList<String>();
|
||||||
ArrayList<String> rawLevelNameslocal = new ArrayList<String>();
|
ArrayList<String> rawLevelNameslocal = new ArrayList<String>();
|
||||||
|
ArrayList<Integer> attemptsLocal = new ArrayList<Integer>();
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url);
|
try (Connection conn = DriverManager.getConnection(url);
|
||||||
Statement stmt = conn.createStatement()) {
|
Statement stmt = conn.createStatement()) {
|
||||||
|
@ -226,6 +235,7 @@ public class Sqlite {
|
||||||
completedlocal.add(rs.getBoolean("completed") + "");
|
completedlocal.add(rs.getBoolean("completed") + "");
|
||||||
recordslocal.add(rs.getString("records"));
|
recordslocal.add(rs.getString("records"));
|
||||||
rawLevelNameslocal.add(rs.getString("levelNameRaw"));
|
rawLevelNameslocal.add(rs.getString("levelNameRaw"));
|
||||||
|
attemptsLocal.add(rs.getInt("attempts"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +246,7 @@ public class Sqlite {
|
||||||
createNewTable(tablename);
|
createNewTable(tablename);
|
||||||
|
|
||||||
// Füge Daten in die neue Tabelle ein
|
// Füge Daten in die neue Tabelle ein
|
||||||
String insert = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
String insert = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, attempts, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
try (PreparedStatement pstmt = conn.prepareStatement(insert)) {
|
try (PreparedStatement pstmt = conn.prepareStatement(insert)) {
|
||||||
for (int i = 0; i < levelnamelocal.size(); i++) {
|
for (int i = 0; i < levelnamelocal.size(); i++) {
|
||||||
pstmt.setInt(1, i + 1);
|
pstmt.setInt(1, i + 1);
|
||||||
|
@ -249,7 +259,8 @@ public class Sqlite {
|
||||||
pstmt.setString(8, verificationLinklocal.get(i));
|
pstmt.setString(8, verificationLinklocal.get(i));
|
||||||
pstmt.setInt(9, Integer.parseInt(percenttoqualifylocal.get(i)));
|
pstmt.setInt(9, Integer.parseInt(percenttoqualifylocal.get(i)));
|
||||||
pstmt.setString(10, recordslocal.get(i));
|
pstmt.setString(10, recordslocal.get(i));
|
||||||
pstmt.setBoolean(11, false);
|
pstmt.setInt(11, attemptsLocal.get(i));
|
||||||
|
pstmt.setBoolean(12, false);
|
||||||
pstmt.executeUpdate();
|
pstmt.executeUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,13 +269,14 @@ public class Sqlite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void modifyData(String levelname, boolean completedStatus) {
|
public void modifyData(String levelname, boolean completedStatus, int attempts) {
|
||||||
String sql = "UPDATE levels SET completed = ? WHERE levelname = ?";
|
String sql = "UPDATE levels SET completed = ?, attempts = ? WHERE levelname = ?";
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url);
|
try (Connection conn = DriverManager.getConnection(url);
|
||||||
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||||
pstmt.setBoolean(1, completedStatus);
|
pstmt.setBoolean(1, completedStatus);
|
||||||
pstmt.setString(2, levelname);
|
pstmt.setInt(2, attempts);
|
||||||
|
pstmt.setString(3, levelname);
|
||||||
|
|
||||||
int rowsUpdated = pstmt.executeUpdate();
|
int rowsUpdated = pstmt.executeUpdate();
|
||||||
if (rowsUpdated > 0) {
|
if (rowsUpdated > 0) {
|
||||||
|
@ -278,4 +290,5 @@ public class Sqlite {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ public class MainGUI {
|
||||||
private Elements elements = new Elements();
|
private Elements elements = new Elements();
|
||||||
|
|
||||||
private int completedcount = 0;
|
private int completedcount = 0;
|
||||||
|
|
||||||
|
|
||||||
public void build() throws IOException {
|
public void build() throws IOException {
|
||||||
LoadSettings load = new LoadSettings();
|
LoadSettings load = new LoadSettings();
|
||||||
|
@ -141,12 +142,15 @@ public class MainGUI {
|
||||||
show.setBounds(500, 1, 200, 60);
|
show.setBounds(500, 1, 200, 60);
|
||||||
|
|
||||||
recordspanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
recordspanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Thread thread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println(data.getLevelname().size() + " ======== size");
|
boolean[] comp = new boolean[data.getLevelname().size()];
|
||||||
for(int i = 0; i < data.getLevelname().size(); i++) {
|
for(int i = 0; i < data.getLevelname().size(); i++) {
|
||||||
|
|
||||||
final int index = i;
|
final int index = i;
|
||||||
progress.setValue(i + 1);
|
progress.setValue(i + 1);
|
||||||
|
|
||||||
|
@ -159,41 +163,106 @@ public class MainGUI {
|
||||||
contents.setLayout(null);
|
contents.setLayout(null);
|
||||||
|
|
||||||
JButton completed = new JButton("x");
|
JButton completed = new JButton("x");
|
||||||
completed.setBounds(640, 17, 17, 17);
|
completed.setBounds(610, 17, 17, 17);
|
||||||
completed.setMargin(new Insets(0,0,0,0));
|
completed.setMargin(new Insets(0,0,0,0));
|
||||||
|
completed.setVisible(false);
|
||||||
|
|
||||||
JButton uncompleted = new JButton("\u2713");
|
JButton uncompleted = new JButton("\u2713");
|
||||||
uncompleted.setBounds(640, 17, 17, 17);
|
uncompleted.setBounds(610, 17, 17, 17);
|
||||||
uncompleted.setMargin(new Insets(0,0,0,0));
|
uncompleted.setMargin(new Insets(0,0,0,0));
|
||||||
|
uncompleted.setVisible(false);
|
||||||
|
|
||||||
|
JTextField attempts = new JTextField("0");
|
||||||
|
attempts.setBounds(535, 17, 70, 18);
|
||||||
|
attempts.setVisible(false);
|
||||||
|
|
||||||
|
if(data.getAttempts().get(i) != null) {
|
||||||
|
attempts.setText(data.getAttempts().get(i) + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
JButton confirm = new JButton("\uD83D\uDDAB");
|
||||||
|
confirm.setBounds(640, 17, 17, 17);
|
||||||
|
confirm.setMargin(new Insets(0, 0, 0, 0));
|
||||||
|
|
||||||
|
JButton anpassen = new JButton("⚙");
|
||||||
|
anpassen.setBounds(640, 17, 17, 17);
|
||||||
|
anpassen.setMargin(new Insets(0, 0, 0, 0));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
completed.addActionListener(new ActionListener() {
|
completed.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
contents.setBackground(Color.decode("#cbffbf"));
|
|
||||||
completed.setVisible(false);
|
completed.setVisible(false);
|
||||||
uncompleted.setVisible(true);
|
uncompleted.setVisible(true);
|
||||||
|
comp[index] = true;
|
||||||
|
|
||||||
data.modifyData(data.getLevelname().get(index), true);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
uncompleted.addActionListener(new ActionListener() {
|
uncompleted.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
contents.setBackground(Color.WHITE);
|
|
||||||
uncompleted.setVisible(false);
|
uncompleted.setVisible(false);
|
||||||
completed.setVisible(true);
|
completed.setVisible(true);
|
||||||
data.modifyData(data.getLevelname().get(index), false);
|
comp[index] = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
anpassen.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
anpassen.setVisible(false);
|
||||||
|
confirm.setVisible(true);
|
||||||
|
attempts.setVisible(true);
|
||||||
|
if(Boolean.parseBoolean(data.getCompleted().get(index))) {
|
||||||
|
uncompleted.setVisible(true);
|
||||||
|
completed.setVisible(false);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
uncompleted.setVisible(false);
|
||||||
|
completed.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
confirm.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
data.modifyData(data.getLevelname().get(index), comp[index], Integer.parseInt(attempts.getText()));
|
||||||
|
|
||||||
|
if(!comp[index]) {
|
||||||
|
contents.setBackground(Color.WHITE);
|
||||||
|
} else {
|
||||||
|
contents.setBackground(Color.decode("#cbffbf"));
|
||||||
|
}
|
||||||
|
|
||||||
|
anpassen.setVisible(true);
|
||||||
|
confirm.setVisible(false);
|
||||||
|
uncompleted.setVisible(false);
|
||||||
|
completed.setVisible(false);
|
||||||
|
attempts.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(Boolean.parseBoolean(data.getCompleted().get(index))) {
|
if(Boolean.parseBoolean(data.getCompleted().get(index))) {
|
||||||
contents.setBackground(Color.decode("#cbffbf"));
|
contents.setBackground(Color.decode("#cbffbf"));
|
||||||
uncompleted.setVisible(true);
|
comp[index] = true;
|
||||||
completed.setVisible(false);
|
|
||||||
completedcount++;
|
completedcount++;
|
||||||
|
} else {
|
||||||
|
comp[index] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
contents.addMouseListener(new MouseListener() {
|
contents.addMouseListener(new MouseListener() {
|
||||||
|
@ -386,6 +455,9 @@ public class MainGUI {
|
||||||
contents.add(rank);
|
contents.add(rank);
|
||||||
contents.add(completed);
|
contents.add(completed);
|
||||||
contents.add(uncompleted);
|
contents.add(uncompleted);
|
||||||
|
contents.add(anpassen);
|
||||||
|
contents.add(confirm);
|
||||||
|
contents.add(attempts);
|
||||||
levelpanel.add(contents);
|
levelpanel.add(contents);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue