-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
210 lines (189 loc) · 7.82 KB
/
main.py
File metadata and controls
210 lines (189 loc) · 7.82 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import pygame
import pygame_gui
import pyperclip
from MatchUpGenerator import MatchUpGenerator
from Rules import Rules
COLOR_BIEGE = (242, 240, 221)
COLOR_BROWN = (105, 70, 53)
WINDOW_SIZE = (1440, 810)
PLAYER_OPTIONS = [str(i) for i in range(1, 11)]
MODE_OPTIONS = ["NG", "AR"]
SPY_OPTIONS = ["ON", "OFF", "ONLY SPY"]
COMPONENT_X_INIT_POSITION = 50
COMPONENT_Y_INIT_POSITION = 50
COMPONENT_Y_DISTANCE = 50
LABEL_WIDTH = 150
DROPDOWN_WIDTH = 200
BUTTON_WIDTH = LABEL_WIDTH + DROPDOWN_WIDTH
LABEL_HEIGHT = DROPDOWN_HEIGHT = BUTTON_HEIGHT = 30
pygame.init()
window = pygame.display.set_mode(WINDOW_SIZE)
pygame.display.set_caption("LOL Random Selector")
manager = pygame_gui.UIManager(WINDOW_SIZE, "./theme/theme.json")
### UI Elements
# player label, "Players"
playerLabelPositionX = COMPONENT_X_INIT_POSITION
playerLabelPositionY = COMPONENT_Y_INIT_POSITION
playerLabelWidth = LABEL_WIDTH
playerLabelHeight = LABEL_HEIGHT
playerLabel = pygame_gui.elements.UILabel(
relative_rect = pygame.Rect((playerLabelPositionX, playerLabelPositionY), (playerLabelWidth, playerLabelHeight)),
text = "Players",
manager = manager
)
# player dropdown
playerDropdownPositionX = playerLabelPositionX + playerLabelWidth
playerDropdownPositionY = playerLabelPositionY
playerDropdownWidth = DROPDOWN_WIDTH
playerDropdownHeight = DROPDOWN_HEIGHT
playerDropdown = pygame_gui.elements.UIDropDownMenu(
options_list = PLAYER_OPTIONS,
starting_option = PLAYER_OPTIONS[0],
relative_rect = pygame.Rect((playerDropdownPositionX, playerDropdownPositionY), (playerDropdownWidth, playerDropdownHeight)),
manager = manager
)
# mode label, "LOL Mode"
modeLabelPositionX = COMPONENT_X_INIT_POSITION
modeLabelPositionY = playerLabelPositionY + COMPONENT_Y_DISTANCE
modeLabelWidth = LABEL_WIDTH
modeLabelHeight = LABEL_HEIGHT
modeLabel = pygame_gui.elements.UILabel(
relative_rect = pygame.Rect((modeLabelPositionX, modeLabelPositionY), (modeLabelWidth, modeLabelHeight)),
text = "LOL Mode",
manager = manager
)
# mode dropdown
modeDropdownPositionX = modeLabelPositionX + modeLabelWidth
modeDropdownPositionY = modeLabelPositionY
modeDropdownWidth = DROPDOWN_WIDTH
modeDropdownHeight = DROPDOWN_HEIGHT
modeDropdown = pygame_gui.elements.UIDropDownMenu(
options_list = MODE_OPTIONS,
starting_option = MODE_OPTIONS[0],
relative_rect = pygame.Rect((modeDropdownPositionX, modeDropdownPositionY), (modeDropdownWidth, modeDropdownHeight)),
manager = manager
)
# spy mode label, "Spy Mode"
spyModeLabelPositionX = COMPONENT_X_INIT_POSITION
spyModeLabelPositionY = modeLabelPositionY + COMPONENT_Y_DISTANCE
spyModeLabelWidth = LABEL_WIDTH
spyModeLabelHeight = LABEL_HEIGHT
spyModeLabel = pygame_gui.elements.UILabel(
relative_rect = pygame.Rect((spyModeLabelPositionX, spyModeLabelPositionY), (spyModeLabelWidth, spyModeLabelHeight)),
text = "Spy Mode",
manager = manager
)
# spy mode dropdown
spyModeDropdownPositionX = spyModeLabelPositionX + spyModeLabelWidth
spyModeDropdownPositionY = spyModeLabelPositionY
spyModeDropdownWidth = DROPDOWN_WIDTH
spyModeDropdownHeight = DROPDOWN_HEIGHT
spyModeDropdown = pygame_gui.elements.UIDropDownMenu(
options_list = SPY_OPTIONS,
starting_option = SPY_OPTIONS[0],
relative_rect = pygame.Rect((spyModeDropdownPositionX, spyModeDropdownPositionY), (spyModeDropdownWidth, spyModeDropdownHeight)),
manager = manager
)
# clear textbox button
clearButtonPositionX = COMPONENT_X_INIT_POSITION
clearButtonPositionY = spyModeLabelPositionY + COMPONENT_Y_DISTANCE
clearButtonWidth = BUTTON_WIDTH
clearButtonHeight = BUTTON_HEIGHT
clearButton = pygame_gui.elements.UIButton(
relative_rect = pygame.Rect((clearButtonPositionX, clearButtonPositionY), (clearButtonWidth, clearButtonHeight)),
text = "Clear MatchUp Information",
manager = manager
)
# generate matchup button
generateButtonPositionX = COMPONENT_X_INIT_POSITION
generateButtonPositionY = clearButtonPositionY + COMPONENT_Y_DISTANCE
generateButtonWidth = BUTTON_WIDTH
generateButtonHeight = BUTTON_HEIGHT
generateButton = pygame_gui.elements.UIButton(
relative_rect = pygame.Rect((generateButtonPositionX, generateButtonPositionY), (generateButtonWidth, generateButtonHeight)),
text = "Generate MatchUp",
manager = manager
)
# copy matchup button
copyButtonPositionX = COMPONENT_X_INIT_POSITION
copyButtonPositionY = generateButtonPositionY + COMPONENT_Y_DISTANCE
copyButtonWidth = BUTTON_WIDTH
copyButtonHeight = BUTTON_HEIGHT
copyButton = pygame_gui.elements.UIButton(
relative_rect = pygame.Rect((copyButtonPositionX, copyButtonPositionY), (copyButtonWidth, copyButtonHeight)),
text = "Copy MatchUp Information",
manager = manager
)
# export matchup button
exportButtonPositionX = COMPONENT_X_INIT_POSITION
exportButtonPositionY = copyButtonPositionY + COMPONENT_Y_DISTANCE
exportButtonWidth = BUTTON_WIDTH
exportButtonHeight = BUTTON_HEIGHT
exportButton = pygame_gui.elements.UIButton(
relative_rect = pygame.Rect((exportButtonPositionX, exportButtonPositionY), (exportButtonWidth, exportButtonHeight)),
text = "Export files to matchup.txt",
manager = manager
)
# show rules button
showRulesButtonPositionX = COMPONENT_X_INIT_POSITION
showRulesButtonPositionY = WINDOW_SIZE[1] - 60
showRulesButtonWidth = BUTTON_WIDTH
showRulesButtonHeight = BUTTON_HEIGHT
showRulesButton = pygame_gui.elements.UIButton(
relative_rect = pygame.Rect((showRulesButtonPositionX, showRulesButtonPositionY), (showRulesButtonWidth, showRulesButtonHeight)),
text = "Show Rules",
manager = manager
)
# close button
# closeButtonPositionX = 50
# closeButtonPositionY = WINDOW_SIZE[1] - 60
# closeButtonWidth = modeLabelWidth + modeDropdownWidth
# closeButtonHeight = 30
# closeButton = pygame_gui.elements.UIButton(relative_rect = pygame.Rect((closeButtonPositionX, closeButtonPositionY), (closeButtonWidth, closeButtonHeight)),
# text = "Close Application",
# manager = manager)
# generate textbox
padding = 30
textBoxPositionX = playerDropdownPositionX + playerDropdownWidth + padding
textBoxPositionY = playerDropdownPositionY
textBoxWidth = WINDOW_SIZE[0] - textBoxPositionX - padding
textBoxHeight = WINDOW_SIZE[1] - textBoxPositionY - padding
textBox = pygame_gui.elements.UITextEntryBox(
initial_text = "MatchUp Information Here :D",
relative_rect = pygame.Rect((textBoxPositionX, textBoxPositionY), (textBoxWidth, textBoxHeight)),
manager = manager
)
clock = pygame.time.Clock()
isRunning = True
while isRunning:
time_delta = clock.tick(60) / 1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
isRunning = False
if event.type == pygame_gui.UI_BUTTON_PRESSED:
if event.ui_element == clearButton:
textBox.set_text("")
if event.ui_element == generateButton:
totalPlayer = int(playerDropdown.selected_option)
gameMode = modeDropdown.selected_option
spyMode = spyModeDropdown.selected_option
matchupGenerator = MatchUpGenerator(totalPlayer, gameMode, spyMode)
matchupInformation = matchupGenerator.GenerateMatchUp()
textBox.set_text(matchupInformation)
if event.ui_element == copyButton:
pyperclip.copy(textBox.get_text())
if event.ui_element == exportButton:
with open("matchup.txt", "w") as file:
file.write(textBox.get_text())
if event.ui_element == showRulesButton:
textBox.set_text(Rules().GetRules())
if spyModeDropdown.selected_option == "ONLY SPY":
modeDropdown.disable()
else:
modeDropdown.enable()
manager.process_events(event)
manager.update(time_delta)
window.fill(COLOR_BIEGE)
manager.draw_ui(window)
pygame.display.flip()
pygame.quit()