Skip to content

Commit 5007258

Browse files
committed
Dark theme + twitch extension
1 parent 8639e05 commit 5007258

4 files changed

Lines changed: 197 additions & 46 deletions

File tree

‎main.py‎

Lines changed: 186 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,55 @@
11
from tkinter import *
22
import pygame
33
import os
4-
from threading import Thread
4+
import threading
5+
from twitchio.ext import commands
56
import subprocess
67

8+
env = {}
9+
file = open("settings.txt", mode="r")
10+
the_settings = file.readlines()
11+
for i in the_settings:
12+
if i[0] == "#":
13+
pass
14+
else:
15+
setting = i.split("=")
16+
setting[1] = setting[1].replace("\n", "")
17+
env[setting[0]] = setting[1]
18+
file.close()
19+
20+
class Bot(commands.Bot):
21+
22+
def __init__(self):
23+
super().__init__(token=str(env["TWITCH_TOKEN"]), prefix="!", initial_channels=[str(env["TWITCH_USERNAME"])])
24+
25+
async def event_ready(self):
26+
print(f'Logged in as {self.nick}')
27+
print((f'User id is {self.nick}'))
28+
29+
@commands.command()
30+
async def switch(self, ctx: commands.Context):
31+
if ctx.author.is_mod:
32+
structure = ctx.message.content.split(" ")[1]
33+
if structure in add_n_sup_functions.keys():
34+
add_n_sup_functions[structure]()
35+
await ctx.send(f"The structure has been checked by {ctx.author.name}.")
36+
print(f"The structure has been checked by {ctx.author.name}.")
37+
else:
38+
await ctx.send(f"@{ctx.author.name}, this structure don't exist.")
39+
else:
40+
await ctx.send(f"You can't check a structure as you're not mod.")
41+
42+
@commands.command()
43+
async def clear(self, ctx: commands.Context):
44+
if ctx.author.is_mod:
45+
add_n_sup_functions["clear"]()
46+
await ctx.send(f"The grid has been cleared by {ctx.author.name}.")
47+
print(f"The grid has been cleared by {ctx.author.name}.")
48+
else:
49+
await ctx.send(f"You can't clear the grid as you're not mod.")
50+
51+
bot = Bot()
52+
753
window_buttons = Tk()
854
size = (393, 400)
955
window_buttons.title("All Structures Tracker by DraquoDrass")
@@ -12,14 +58,18 @@
1258
window_buttons.minsize(size[0], size[1])
1359
window_buttons.maxsize(size[0], size[1])
1460

15-
file = open("settings.txt", mode="r")
16-
the_settings = file.readlines()
17-
file.close()
18-
1961
font = ("Arial, 15")
20-
bg = "#ffffff"
21-
fg = "#000000"
22-
changed_bg = str(the_settings[2].replace("CLICKED_BUTTONS=", "").replace("\n", ""))
62+
if str(env["DARK_MODE"]) == "True":
63+
bg = "#32393d"
64+
fg = "#ffffff"
65+
bgs = "#1a1e21"
66+
fgs = "#ffffff"
67+
else:
68+
bg = "#ffffff"
69+
fg = "#000000"
70+
bgs = "#cccccc"
71+
fgs = "#000000"
72+
changed_bg = str(env["CLICKED_BUTTONS"])
2373
width = 17
2474

2575
global structures
@@ -31,98 +81,152 @@
3181
structures_copy = list(structures)
3282

3383
def buttons_function():
34-
def bastion():
35-
button_bastion.configure(bg=changed_bg, fg=fg)
36-
if "bastion.png" in structures_copy:
37-
structures_copy.pop(structures_copy.index("bastion.png"))
84+
def bastion_remnant():
85+
if "bastion_remnant.png" in structures_copy:
86+
button_bastion_remnant.configure(bg=changed_bg, fg=fg)
87+
structures_copy.pop(structures_copy.index("bastion_remnant.png"))
88+
else:
89+
button_bastion_remnant.configure(bg=bg, fg=fg)
90+
structures_copy.append("bastion_remnant.png")
3891

3992
def burried_treasure():
40-
button_burried_treasure.configure(bg=changed_bg, fg=fg)
4193
if "burried_treasure.png" in structures_copy:
94+
button_burried_treasure.configure(bg=changed_bg, fg=fg)
4295
structures_copy.pop(structures_copy.index("burried_treasure.png"))
96+
else:
97+
button_burried_treasure.configure(bg=bg, fg=fg)
98+
structures_copy.append("burried_treasure.png")
4399

44100
def desert_pyramid():
45-
button_desert_pyramid.configure(bg=changed_bg, fg=fg)
46101
if "desert_pyramid.png" in structures_copy:
102+
button_desert_pyramid.configure(bg=changed_bg, fg=fg)
47103
structures_copy.pop(structures_copy.index("desert_pyramid.png"))
104+
else:
105+
button_desert_pyramid.configure(bg=bg, fg=fg)
106+
structures_copy.append("desert_pyramid.png")
48107

49108
def end_city():
50-
button_end_city.configure(bg=changed_bg, fg=fg)
51109
if "end_city.png" in structures_copy:
110+
button_end_city.configure(bg=changed_bg, fg=fg)
52111
structures_copy.pop(structures_copy.index("end_city.png"))
112+
else:
113+
button_end_city.configure(bg=bg, fg=fg)
114+
structures_copy.append("end_city.png")
53115

54116
def igloo():
55-
button_igloo.configure(bg=changed_bg, fg=fg)
56117
if "igloo.png" in structures_copy:
118+
button_igloo.configure(bg=changed_bg, fg=fg)
57119
structures_copy.pop(structures_copy.index("igloo.png"))
120+
else:
121+
button_igloo.configure(bg=bg, fg=fg)
122+
structures_copy.append("igloo.png")
58123

59124
def jungle_temple():
60-
button_jungle_temple.configure(bg=changed_bg, fg=fg)
61125
if "jungle_temple.png" in structures_copy:
126+
button_jungle_temple.configure(bg=changed_bg, fg=fg)
62127
structures_copy.pop(structures_copy.index("jungle_temple.png"))
128+
else:
129+
button_jungle_temple.configure(bg=bg, fg=fg)
130+
structures_copy.append("jungle_temple.png")
63131

64132
def mineshaft():
65-
button_mineshaft.configure(bg=changed_bg, fg=fg)
66133
if "mineshaft.png" in structures_copy:
134+
button_mineshaft.configure(bg=changed_bg, fg=fg)
67135
structures_copy.pop(structures_copy.index("mineshaft.png"))
136+
else:
137+
button_mineshaft.configure(bg=bg, fg=fg)
138+
structures_copy.append("mineshaft.png")
68139

69140
def nether_fortress():
70-
button_nether_fortress.configure(bg=changed_bg, fg=fg)
71141
if "nether_fortress.png" in structures_copy:
142+
button_nether_fortress.configure(bg=changed_bg, fg=fg)
72143
structures_copy.pop(structures_copy.index("nether_fortress.png"))
144+
else:
145+
button_nether_fortress.configure(bg=bg, fg=fg)
146+
structures_copy.append("nether_fortress.png")
73147

74148
def nether_fossil():
75-
button_nether_fossil.configure(bg=changed_bg, fg=fg)
76149
if "nether_fossil.png" in structures_copy:
150+
button_nether_fossil.configure(bg=changed_bg, fg=fg)
77151
structures_copy.pop(structures_copy.index("nether_fossil.png"))
152+
else:
153+
button_nether_fossil.configure(bg=bg, fg=fg)
154+
structures_copy.append("nether_fossil.png")
78155

79156
def ocean_monument():
80-
button_ocean_monument.configure(bg=changed_bg, fg=fg)
81157
if "ocean_monument.png" in structures_copy:
158+
button_ocean_monument.configure(bg=changed_bg, fg=fg)
82159
structures_copy.pop(structures_copy.index("ocean_monument.png"))
160+
else:
161+
button_ocean_monument.configure(bg=bg, fg=fg)
162+
structures_copy.append("ocean_monument.png")
83163

84164
def ocean_ruins():
85-
button_ocean_ruins.configure(bg=changed_bg, fg=fg)
86165
if "ocean_ruins.png" in structures_copy:
166+
button_ocean_ruins.configure(bg=changed_bg, fg=fg)
87167
structures_copy.pop(structures_copy.index("ocean_ruins.png"))
168+
else:
169+
button_ocean_ruins.configure(bg=bg, fg=fg)
170+
structures_copy.append("ocean_ruins.png")
88171

89172
def pillager_outpost():
90-
button_pillager_outpost.configure(bg=changed_bg, fg=fg)
91173
if "pillager_outpost.png" in structures_copy:
174+
button_pillager_outpost.configure(bg=changed_bg, fg=fg)
92175
structures_copy.pop(structures_copy.index("pillager_outpost.png"))
176+
else:
177+
button_pillager_outpost.configure(bg=bg, fg=fg)
178+
structures_copy.append("pillager_outpost.png")
93179

94180
def ruined_portal():
95-
button_ruined_portal.configure(bg=changed_bg, fg=fg)
96181
if "ruined_portal.png" in structures_copy:
182+
button_ruined_portal.configure(bg=changed_bg, fg=fg)
97183
structures_copy.pop(structures_copy.index("ruined_portal.png"))
184+
else:
185+
button_ruined_portal.configure(bg=bg, fg=fg)
186+
structures_copy.append("ruined_portal.png")
98187

99188
def shipwreck():
100-
button_shipwreck.configure(bg=changed_bg, fg=fg)
101189
if "shipwreck.png" in structures_copy:
190+
button_shipwreck.configure(bg=changed_bg, fg=fg)
102191
structures_copy.pop(structures_copy.index("shipwreck.png"))
192+
else:
193+
button_shipwreck.configure(bg=bg, fg=fg)
194+
structures_copy.append("shipwreck.png")
103195

104196
def stronghold():
105-
button_stronghold.configure(bg=changed_bg, fg=fg)
106197
if "stronghold.png" in structures_copy:
198+
button_stronghold.configure(bg=changed_bg, fg=fg)
107199
structures_copy.pop(structures_copy.index("stronghold.png"))
200+
else:
201+
button_stronghold.configure(bg=bg, fg=fg)
202+
structures_copy.append("stronghold.png")
108203

109204
def swamp_hut():
110-
button_swamp_hut.configure(bg=changed_bg, fg=fg)
111205
if "swamp_hut.png" in structures_copy:
206+
button_swamp_hut.configure(bg=changed_bg, fg=fg)
112207
structures_copy.pop(structures_copy.index("swamp_hut.png"))
208+
else:
209+
button_swamp_hut.configure(bg=bg, fg=fg)
210+
structures_copy.append("swamp_hut.png")
113211

114212
def village():
115-
button_village.configure(bg=changed_bg, fg=fg)
116213
if "village.png" in structures_copy:
214+
button_village.configure(bg=changed_bg, fg=fg)
117215
structures_copy.pop(structures_copy.index("village.png"))
216+
else:
217+
button_village.configure(bg=bg, fg=fg)
218+
structures_copy.append("village.png")
118219

119220
def wooden_mansion():
120-
button_wooden_mansion.configure(bg=changed_bg, fg=fg)
121221
if "wooden_mansion.png" in structures_copy:
222+
button_wooden_mansion.configure(bg=changed_bg, fg=fg)
122223
structures_copy.pop(structures_copy.index("wooden_mansion.png"))
224+
else:
225+
button_wooden_mansion.configure(bg=bg, fg=fg)
226+
structures_copy.append("wooden_mansion.png")
123227

124228
def clear():
125-
button_bastion.configure(bg=bg, fg=fg)
229+
button_bastion_remnant.configure(bg=bg, fg=fg)
126230
button_burried_treasure.configure(bg=bg, fg=fg)
127231
button_desert_pyramid.configure(bg=bg, fg=fg)
128232
button_end_city.configure(bg=bg, fg=fg)
@@ -145,10 +249,33 @@ def clear():
145249
for i in structures:
146250
structures_copy.append(i)
147251

252+
global add_n_sup_functions
253+
add_n_sup_functions = {
254+
"bastion_remnant": bastion_remnant,
255+
"burried_treasure": burried_treasure,
256+
"desert_pyramid": desert_pyramid,
257+
"end_city": end_city,
258+
"igloo": igloo,
259+
"jungle_temple": jungle_temple,
260+
"mineshaft": mineshaft,
261+
"nether_fortress": nether_fortress,
262+
"nether_fossil": nether_fossil,
263+
"ocean_monument": ocean_monument,
264+
"ocean_ruins": ocean_ruins,
265+
"pillager_outpost": pillager_outpost,
266+
"ruined_portal": ruined_portal,
267+
"shipwreck": shipwreck,
268+
"stronghold": stronghold,
269+
"swamp_hut": swamp_hut,
270+
"village": village,
271+
"wooden_mansion": wooden_mansion,
272+
"clear": clear
273+
}
274+
148275
def settings():
149276
subprocess.Popen('explorer "settings.txt"')
150277

151-
button_bastion = Button(text="Bastion Remnant", font=font, bg=bg, fg=fg, width=width, command=bastion)
278+
button_bastion_remnant = Button(text="Bastion Remnant", font=font, bg=bg, fg=fg, width=width, command=bastion_remnant)
152279
button_burried_treasure = Button(text="Burried Treasure", font=font, bg=bg, fg=fg, width=width, command=burried_treasure)
153280
button_desert_pyramid = Button(text="Desert Pyramid", font=font, bg=bg, fg=fg, width=width, command=desert_pyramid)
154281
button_end_city = Button(text="End City", font=font, bg=bg, fg=fg, width=width, command=end_city)
@@ -166,10 +293,10 @@ def settings():
166293
button_swamp_hut = Button(text="Swamp Hut", font=font, bg=bg, fg=fg, width=width, command=swamp_hut)
167294
button_village = Button(text="Village", font=font, bg=bg, fg=fg, width=width, command=village)
168295
button_wooden_mansion = Button(text="Woodland Mansion", font=font, bg=bg, fg=fg, width=width, command=wooden_mansion)
169-
button_clear = Button(text="Clear", font=font, bg="#cccccc", fg=fg, width=width, command=clear)
170-
button_settings = Button(text="Settings", font=font, bg="#cccccc", fg=fg, width=width, command=settings)
296+
button_clear = Button(text="Clear", font=font, bg=bgs, fg=fgs, width=width, command=clear)
297+
button_settings = Button(text="Settings", font=font, bg=bgs, fg=fgs, width=width, command=settings)
171298

172-
button_bastion.grid(row=0, column=0)
299+
button_bastion_remnant.grid(row=0, column=0)
173300
button_burried_treasure.grid(row=0, column=1)
174301
button_desert_pyramid.grid(row=1, column=0)
175302
button_end_city.grid(row=1, column=1)
@@ -192,15 +319,23 @@ def settings():
192319

193320
def overlay_function():
194321

322+
env = {}
195323
file = open("settings.txt", mode="r")
196324
the_settings = file.readlines()
325+
for i in the_settings:
326+
if i[0] == "#":
327+
pass
328+
else:
329+
setting = i.split("=")
330+
setting[1] = setting[1].replace("\n", "")
331+
env[setting[0]] = setting[1]
197332
file.close()
198333

199334
global display_number
200-
display_number = int(the_settings[1].replace("STRUCTURES_SHOWN=", "").replace("\n", ""))
201-
background_color = str(the_settings[3].replace("OVERLAY_BACKGROUND=", "").replace("\n", ""))
202-
displayed_icon = str(the_settings[4].replace("PREVIEWS=", "").replace("\n", ""))
203-
scrolling_speed = float(the_settings[5].replace("SCROLLING_SPEED=", "").replace("\n", ""))
335+
display_number = int(env["STRUCTURES_SHOWN"])
336+
background_color = str(env["OVERLAY_BACKGROUND"])
337+
displayed_icon = str(env["PREVIEWS"])
338+
scrolling_speed = float(env["SCROLLING_SPEED"])
204339

205340
window_overlay_icon = pygame.image.load('assets/icon.png')
206341
window_overlay = pygame.display.set_mode((display_number*120, 140))
@@ -210,7 +345,7 @@ def overlay_function():
210345
opened = True
211346

212347
dict_images = {
213-
"bastion.png": pygame.image.load("assets/" + displayed_icon + "/bastion.png"),
348+
"bastion_remnant.png": pygame.image.load("assets/" + displayed_icon + "/bastion_remnant.png"),
214349
"burried_treasure.png": pygame.image.load("assets/" + displayed_icon + "/burried_treasure.png"),
215350
"desert_pyramid.png": pygame.image.load("assets/" + displayed_icon + "/desert_pyramid.png"),
216351
"end_city.png": pygame.image.load("assets/" + displayed_icon + "/end_city.png"),
@@ -264,11 +399,21 @@ def overlay_function():
264399

265400
pygame.quit()
266401

402+
def twitch_function():
403+
if str(env["USE_TWITCH_BOT"]) == "True":
404+
bot.run()
405+
window_buttons.mainloop()
406+
else:
407+
pass
408+
267409
if __name__ == "__main__":
268-
thread2 = Thread(target=buttons_function, args=())
269-
thread = Thread(target=overlay_function, args=())
410+
thread3 = threading.Thread(target=twitch_function, args=())
411+
thread2 = threading.Thread(target=buttons_function, args=())
412+
thread = threading.Thread(target=overlay_function, args=())
413+
thread3.start()
270414
thread.start()
271415
thread2.start()
272416

417+
273418
window_buttons.mainloop()
274419
opened = False

‎settings.txt‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
# You will need to restart the tracker once data changed. Previews can be "BLOCS" or "ICONS". Scrolling speed is px per loop.
2-
STRUCTURES_SHOWN=18
3-
CLICKED_BUTTONS=#00ff00
1+
# You will need to restart the tracker once data changed.
2+
# Previews can be "BLOCS" or "ICONS".
3+
# Scrolling speed is px per loop.
4+
CLICKED_BUTTONS=#51b051
5+
DARK_MODE=True
46
OVERLAY_BACKGROUND=#00ff00
5-
PREVIEWS=BLOCS
6-
SCROLLING_SPEED=0.1
7+
PREVIEWS=ICONS
8+
SCROLLING_SPEED=0.1
9+
STRUCTURES_SHOWN=18
10+
TWITCH_TOKEN=oauth:yourauth
11+
TWITCH_USERNAME=YourTwitchUsername
12+
USE_TWITCH_BOT=False

0 commit comments

Comments
 (0)