|
8 | 8 | from tkinter import ttk, messagebox |
9 | 9 | from addDiag import AddDiag |
10 | 10 |
|
| 11 | +from updaterUpdate import * |
11 | 12 | from datetime import * |
12 | 13 |
|
13 | 14 | import matplotlib |
|
17 | 18 | from matplotlib.patches import Rectangle |
18 | 19 |
|
19 | 20 | windowSize = vars.WINDOW_GEOMETRY.split("x") |
| 21 | +checkNewUpdaterVersion() |
20 | 22 |
|
21 | 23 | with open(vars.VERSION_PATH, 'r') as f: |
22 | | - versionString = f.read() |
| 24 | + versionString = f.readlines()[0] |
23 | 25 |
|
24 | 26 | root = tk.Tk() |
25 | 27 | root.title(vars.WINDOW_TITLE + " " + versionString) |
|
244 | 246 | # History |
245 | 247 | # -------------------------------- |
246 | 248 |
|
| 249 | +historyListContainer = tk.Frame(historyTab) |
| 250 | +historyListContainer.pack(fill="both", expand=True) |
| 251 | + |
247 | 252 | historyStyle = ttk.Style() |
248 | 253 | historyStyle.configure("history.Treeview", highlightthickness=0, bd=0, font=('TkDefaultFont', 10)) |
249 | 254 | historyStyle.configure("history.Treeview.Heading", font=('TkDefaultFont', 10,'bold')) |
250 | 255 | historyStyle.layout("history.Treeview", [('history.Treeview.treearea', {'sticky': 'nswe'})]) |
251 | 256 |
|
252 | | -history = ttk.Treeview(historyTab, columns=(1, 2, 3), show="headings", height="16", style="history.Treeview") |
| 257 | +history = ttk.Treeview(historyListContainer, columns=(1, 2, 3), show="headings", height="16", style="history.Treeview") |
253 | 258 | history.pack(side=tk.LEFT, fill="both", expand=True) |
254 | 259 |
|
255 | 260 | history.heading(1, text="Description", anchor="w") |
|
261 | 266 | history.column(3, anchor="e") |
262 | 267 |
|
263 | 268 | # Create history Scrollbar |
264 | | -historyScrollbar = Scrollbar(historyTab, orient=VERTICAL, command=history.yview) |
| 269 | +historyScrollbar = Scrollbar(historyListContainer, orient=VERTICAL, command=history.yview) |
265 | 270 | historyScrollbar.pack(side=tk.LEFT, fill="y") |
266 | 271 |
|
267 | 272 | history.configure(yscrollcommand=historyScrollbar.set) |
268 | 273 |
|
| 274 | +historyBtnContainer = tk.Frame(historyTab) |
| 275 | +historyBtnContainer.pack(fill="x") |
| 276 | + |
269 | 277 | # ================================ |
270 | 278 | # Daily XP Container |
271 | 279 | # ================================ |
@@ -353,6 +361,30 @@ def resetCallback(): |
353 | 361 | return |
354 | 362 | return |
355 | 363 |
|
| 364 | +def editElementCallback(): |
| 365 | + currElementFocus = history.focus() |
| 366 | + currElement = history.item(currElementFocus) |
| 367 | + currElementID = history.index(currElementFocus) |
| 368 | + |
| 369 | + if len(currElement["values"]) == 0: |
| 370 | + return |
| 371 | + |
| 372 | + editDiag = AddDiag(root, "Edit Element", currElement["values"][0], currElement["values"][1].strip(" XP")) |
| 373 | + if editDiag.description != currElement["values"][0] or editDiag.xpAmount != currElement["values"][1].strip(" XP"): |
| 374 | + editElement(currElementID, editDiag.description, int(editDiag.xpAmount)) |
| 375 | + |
| 376 | +def deleteElementCallback(): |
| 377 | + currElementFocus = history.focus() |
| 378 | + currElement = history.item(currElementFocus) |
| 379 | + currElementID = history.index(currElementFocus) |
| 380 | + |
| 381 | + if len(currElement["values"]) == 0: |
| 382 | + return |
| 383 | + |
| 384 | + res = messagebox.askquestion("Delete Element", "Are you sure, that you want to delete the selected element?\nDescription: " + currElement["values"][0] + "\nAmount: " + currElement["values"][1]) |
| 385 | + if res == "yes": |
| 386 | + deleteElement(currElementID) |
| 387 | + |
356 | 388 | # -------------------------------- |
357 | 389 | # Init |
358 | 390 | # -------------------------------- |
@@ -407,6 +439,51 @@ def addXP(description, amount): |
407 | 439 |
|
408 | 440 | writeConfig(vars.CONFIG_PATH, config) |
409 | 441 |
|
| 442 | +def editElement(index, description, amount): |
| 443 | + config = readConfig(vars.CONFIG_PATH) |
| 444 | + historyLen = len(config["history"]) |
| 445 | + |
| 446 | + prevBPLevel = config["activeBPLevel"] |
| 447 | + |
| 448 | + index = historyLen - 1 - index |
| 449 | + config["history"][index]["description"] = description |
| 450 | + config["history"][index]["amount"] = amount |
| 451 | + |
| 452 | + config = recalcXP(config) |
| 453 | + deltaBP = prevBPLevel - config["activeBPLevel"] |
| 454 | + |
| 455 | + if deltaBP > 0: |
| 456 | + for i in range(0, deltaBP, 1): |
| 457 | + messagebox.showinfo("Sorry", "You have lost Battlepass Level " + str(prevBPLevel - i - 1)) |
| 458 | + elif deltaBP < 0: |
| 459 | + for i in range(0, deltaBP, -1): |
| 460 | + messagebox.showinfo("Congratulations", "Congratulations! You have unlocked Battlepass Level " + str(-1 * i + prevBPLevel)) |
| 461 | + |
| 462 | + writeConfig(vars.CONFIG_PATH, config) |
| 463 | + updateValues() |
| 464 | + |
| 465 | +def deleteElement(index): |
| 466 | + config = readConfig(vars.CONFIG_PATH) |
| 467 | + historyLen = len(config["history"]) |
| 468 | + |
| 469 | + prevBPLevel = config["activeBPLevel"] |
| 470 | + |
| 471 | + index = historyLen - 1 - index |
| 472 | + config["history"].pop(index) |
| 473 | + |
| 474 | + config = recalcXP(config) |
| 475 | + deltaBP = prevBPLevel - config["activeBPLevel"] |
| 476 | + |
| 477 | + if deltaBP > 0: |
| 478 | + for i in range(0, deltaBP, 1): |
| 479 | + messagebox.showinfo("Sorry", "You have lost Battlepass Level " + str(prevBPLevel - i - 1)) |
| 480 | + elif deltaBP < 0: |
| 481 | + for i in range(0, deltaBP, -1): |
| 482 | + messagebox.showinfo("Congratulations", "Congratulations! You have unlocked Battlepass Level " + str(-1 * i + prevBPLevel)) |
| 483 | + |
| 484 | + writeConfig(vars.CONFIG_PATH, config) |
| 485 | + updateValues() |
| 486 | + |
410 | 487 | def updateGraph(config, epilogue, plot): |
411 | 488 | plot.clear() |
412 | 489 | timeAxis = [] |
@@ -463,10 +540,13 @@ def updateGraph(config, epilogue, plot): |
463 | 540 | remainingDays = dateDelta.days |
464 | 541 | dayDelta = duration - remainingDays |
465 | 542 |
|
466 | | - dailyProgress, dailyCollected, dailyRemaining, dailyTotal = calcDailyValues(config, epilogue) |
| 543 | + if date.fromtimestamp(config["history"][len(config["history"]) - 1]["time"]) == date.today(): offset = 1 |
| 544 | + else: offset = 0 |
| 545 | + |
467 | 546 | totalXPProgress, totalXPCollected, totalXPRemaining, totalXPTotal = calcTotalValues(config, epilogue) |
| 547 | + dailyTotal = round((totalXPTotal - yAxisYou[index - offset]) / (remainingDays - vars.BUFFER_DAYS)) |
468 | 548 |
|
469 | | - yAxisDailyIdeal.append(totalXPCollected) |
| 549 | + yAxisDailyIdeal.append(yAxisYou[index - offset]) |
470 | 550 |
|
471 | 551 | for i in range(1, remainingDays + 1): |
472 | 552 | yAxisDailyIdeal.append(yAxisDailyIdeal[i - 1] + dailyTotal) |
@@ -562,12 +642,17 @@ def updateValues(): |
562 | 642 | epilogueCheck = ttk.Checkbutton(buttonContainer, text="Epilogue", onvalue=1, offvalue=0, variable=epilogueVar, command=updateValues) |
563 | 643 | epilogueCheck.pack(padx=8, pady=0, side=tk.RIGHT) |
564 | 644 |
|
| 645 | +editBTN = ttk.Button(historyBtnContainer, text="Edit Element", command=editElementCallback) |
| 646 | +editBTN.pack(side=tk.RIGHT, fill="both", expand=True) |
| 647 | + |
| 648 | +delBTN = ttk.Button(historyBtnContainer, text="Delete Element", command=deleteElementCallback) |
| 649 | +delBTN.pack(side=tk.LEFT, fill="both", expand=True) |
| 650 | + |
565 | 651 | # ================================ |
566 | 652 | # Main Loop |
567 | 653 | # ================================ |
568 | 654 |
|
569 | 655 | os.startfile(vars.UPDATER_PATH) |
570 | | - |
571 | 656 | init() |
572 | 657 |
|
573 | 658 | while dailyBar == None: |
|
0 commit comments