diff --git a/src/data/GuiData.java b/src/data/GuiData.java index 16fc3a7..58612c8 100644 --- a/src/data/GuiData.java +++ b/src/data/GuiData.java @@ -22,6 +22,7 @@ public class GuiData { private ArrayList ytlink = new ArrayList(); private ArrayList creators = new ArrayList(); private ArrayList victors = new ArrayList(); + private ArrayList attempts = new ArrayList(); public ArrayList completed = new ArrayList(); private FetchData data = new FetchData(); @@ -60,6 +61,10 @@ public class GuiData { return creators; } + public ArrayList getAttempts() { + return attempts; + } + public ArrayList getVictors() { return victors; } @@ -95,6 +100,7 @@ public class GuiData { ytlink.add(obj.getString("verification") + ""); creators.add(obj.getJSONArray("creators") + ""); victors.add(obj.getJSONArray("records") + ""); + attempts.add(0); } diff --git a/src/database/DatabaseManager.java b/src/database/DatabaseManager.java index 9ccc59b..1226d20 100644 --- a/src/database/DatabaseManager.java +++ b/src/database/DatabaseManager.java @@ -76,6 +76,7 @@ public class DatabaseManager { database.insertData( "levels", // Tabellenname + data.getAttempts().get(i), fetch.allLevels().indexOf(levels.get(i).replace(".json", "")) + 1, data.getLocalLevels().get(i), // Level-Name levels.get(i).replace(".json", ""), // Level-Name-Raw (oder entsprechender Wert aus fetch.allLevels()) diff --git a/src/database/Sqlite.java b/src/database/Sqlite.java index e5318e8..6265d13 100644 --- a/src/database/Sqlite.java +++ b/src/database/Sqlite.java @@ -28,6 +28,7 @@ public class Sqlite { private ArrayList records = new ArrayList(); private ArrayList completed = new ArrayList(); private ArrayList rawLevelNames = new ArrayList(); + private ArrayList attempts = new ArrayList(); public ArrayList getLevelname() { @@ -69,6 +70,10 @@ public class Sqlite { public ArrayList getRawLevelNames() { return rawLevelNames; } + + public ArrayList getAttempts() { + return attempts; + } public Sqlite(String dbname) { // setzt variablen url = "jdbc:sqlite:C:\\ExtremeDemonList\\database\\sqlite\\"; @@ -112,6 +117,7 @@ public class Sqlite { + " verificationLink TEXT NOT NULL,\n" + " percentToQualify INTEGER NOT NULL,\n" + " records TEXT NOT NULL,\n" + + " attempts INTEGER 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) { - String sql = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + 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, attempts, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; System.out.println("tablename: " + levelname); @@ -143,7 +149,8 @@ public class Sqlite { pstmt.setString(8, verificationLink); pstmt.setInt(9, percenttoqualify); pstmt.setString(10, records); - pstmt.setBoolean(11, completed); + pstmt.setInt(11, attempts); + pstmt.setBoolean(12, completed); pstmt.executeUpdate(); } catch (SQLException e) { @@ -155,7 +162,7 @@ public class Sqlite { 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); Statement stmt = conn.createStatement(); @@ -173,6 +180,7 @@ public class Sqlite { completed.add(rs.getBoolean("completed") + ""); records.add(rs.getString("records")); rawLevelNames.add(rs.getString("levelNameRaw")); + attempts.add(rs.getInt("attempts")); } @@ -195,6 +203,7 @@ public class Sqlite { ArrayList recordslocal = new ArrayList(); ArrayList completedlocal = new ArrayList(); ArrayList rawLevelNameslocal = new ArrayList(); + ArrayList attemptsLocal = new ArrayList(); try (Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement()) { @@ -226,6 +235,7 @@ public class Sqlite { completedlocal.add(rs.getBoolean("completed") + ""); recordslocal.add(rs.getString("records")); rawLevelNameslocal.add(rs.getString("levelNameRaw")); + attemptsLocal.add(rs.getInt("attempts")); } } @@ -236,7 +246,7 @@ public class Sqlite { createNewTable(tablename); // 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)) { for (int i = 0; i < levelnamelocal.size(); i++) { pstmt.setInt(1, i + 1); @@ -249,7 +259,8 @@ public class Sqlite { pstmt.setString(8, verificationLinklocal.get(i)); pstmt.setInt(9, Integer.parseInt(percenttoqualifylocal.get(i))); pstmt.setString(10, recordslocal.get(i)); - pstmt.setBoolean(11, false); + pstmt.setInt(11, attemptsLocal.get(i)); + pstmt.setBoolean(12, false); pstmt.executeUpdate(); } } @@ -258,13 +269,14 @@ public class Sqlite { } } - public void modifyData(String levelname, boolean completedStatus) { - String sql = "UPDATE levels SET completed = ? WHERE levelname = ?"; + public void modifyData(String levelname, boolean completedStatus, int attempts) { + String sql = "UPDATE levels SET completed = ?, attempts = ? WHERE levelname = ?"; try (Connection conn = DriverManager.getConnection(url); PreparedStatement pstmt = conn.prepareStatement(sql)) { pstmt.setBoolean(1, completedStatus); - pstmt.setString(2, levelname); + pstmt.setInt(2, attempts); + pstmt.setString(3, levelname); int rowsUpdated = pstmt.executeUpdate(); if (rowsUpdated > 0) { @@ -278,4 +290,5 @@ public class Sqlite { } + } diff --git a/src/gui/MainGUI.java b/src/gui/MainGUI.java index 9a4c4a5..e88fe78 100644 --- a/src/gui/MainGUI.java +++ b/src/gui/MainGUI.java @@ -71,6 +71,7 @@ public class MainGUI { private Elements elements = new Elements(); private int completedcount = 0; + public void build() throws IOException { LoadSettings load = new LoadSettings(); @@ -141,12 +142,15 @@ public class MainGUI { show.setBounds(500, 1, 200, 60); recordspanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + + Thread thread = new Thread(new Runnable() { @Override 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++) { + final int index = i; progress.setValue(i + 1); @@ -159,41 +163,106 @@ public class MainGUI { contents.setLayout(null); 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.setVisible(false); 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.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() { @Override public void actionPerformed(ActionEvent e) { - contents.setBackground(Color.decode("#cbffbf")); + completed.setVisible(false); uncompleted.setVisible(true); + comp[index] = true; - data.modifyData(data.getLevelname().get(index), true); } }); uncompleted.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - contents.setBackground(Color.WHITE); + uncompleted.setVisible(false); 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))) { contents.setBackground(Color.decode("#cbffbf")); - uncompleted.setVisible(true); - completed.setVisible(false); + comp[index] = true; completedcount++; + } else { + comp[index] = false; } contents.addMouseListener(new MouseListener() { @@ -386,6 +455,9 @@ public class MainGUI { contents.add(rank); contents.add(completed); contents.add(uncompleted); + contents.add(anpassen); + contents.add(confirm); + contents.add(attempts); levelpanel.add(contents); }