This repository has been archived by the owner on Jul 31, 2021. It is now read-only.
forked from roguelike2d/TekkenBot
-
Notifications
You must be signed in to change notification settings - Fork 4
/
GUI_FrameDataOverlay.py
250 lines (203 loc) · 10.4 KB
/
GUI_FrameDataOverlay.py
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
"""
A transparent frame data display that sits on top of Tekken.exe in windowed or borderless mode.
"""
from tkinter import *
from tkinter.ttk import *
import sys
from enum import Enum
import GUI_Overlay
from GUI_Overlay import CurrentColorScheme, ColorSchemeEnum
class DataColumns(Enum):
XcommX = 0
XidX = 1
name = 3
XtypeXX = 4
XstX = 5
bloX = 6
hitX = 7
XchXX = 8
act = 9
T = 10
tot = 11
rec = 12
opp = 13
notes = 14
def config_name():
return "DataColumns"
DataColumnsToMenuNames = {
DataColumns.XcommX : 'input command',
DataColumns.XidX : 'internal move id number',
DataColumns.name: 'internal move name',
DataColumns.XtypeXX: 'attack type',
DataColumns.XstX: 'startup frames',
DataColumns.bloX: 'frame advantage on block',
DataColumns.hitX: 'frame advantage on hit',
DataColumns.XchXX: 'frame advantage on counter hit',
DataColumns.act: 'active frame connected on / total active frames',
DataColumns.T: 'how well move tracks during startup',
DataColumns.tot: 'total number of frames in move',
DataColumns.rec: 'frames before attacker can act',
DataColumns.opp: 'frames before defender can act',
DataColumns.notes: 'additional move properties',
}
class TextRedirector(object):
def __init__(self, stdout, widget, style, fa_p1_var, fa_p2_var):
self.stdout = stdout
self.widget = widget
self.fa_p1_var = fa_p1_var
self.fa_p2_var = fa_p2_var
self.style = style
self.widget.tag_config("p1", foreground=CurrentColorScheme.dict[ColorSchemeEnum.p1_text])
self.widget.tag_config("p2", foreground=CurrentColorScheme.dict[ColorSchemeEnum.p2_text])
self.columns_to_print = [True] * len(DataColumns)
self.style.configure('.', background=CurrentColorScheme.dict[ColorSchemeEnum.advantage_slight_minus])
def set_columns_to_print(self, booleans_for_columns):
self.columns_to_print = booleans_for_columns
self.populate_column_names(booleans_for_columns)
def populate_column_names(self, booleans_for_columns):
column_names = ""
for i, enum in enumerate(DataColumns):
if booleans_for_columns[i]:
column_names += "|{}".format(enum.name.replace('X', ' '))
self.set_first_column(column_names)
def set_first_column(self, first_column_string):
self.widget.configure(state="normal")
self.widget.delete("1.0", "2.0")
self.widget.insert("1.0", first_column_string + '\n')
self.widget.configure(state="disabled")
def write(self, output_str):
#self.stdout.write(output_str)
lines = int(self.widget.index('end-1c').split('.')[0])
max_lines = 5
if lines > max_lines:
r = lines - max_lines
for _ in range(r):
self.widget.configure(state="normal")
self.widget.delete('2.0', '3.0')
self.widget.configure(state="disabled")
if 'NOW:' in output_str:
data = output_str.split('NOW:')[0]
fa = output_str.split('NOW:')[1][:3]
if '?' not in fa:
if int(fa) <= -14:
self.style.configure('.', background=CurrentColorScheme.dict[ColorSchemeEnum.advantage_very_punishible])
elif int(fa) <= -10:
self.style.configure('.', background=CurrentColorScheme.dict[ColorSchemeEnum.advantage_punishible])
elif int(fa) <= -5:
self.style.configure('.', background=CurrentColorScheme.dict[ColorSchemeEnum.advantage_safe_minus])
elif int(fa) < 0:
self.style.configure('.', background=CurrentColorScheme.dict[ColorSchemeEnum.advantage_slight_minus])
else:
self.style.configure('.', background=CurrentColorScheme.dict[ColorSchemeEnum.advantage_plus])
text_tag = None
if "p1:" in output_str:
self.fa_p1_var.set(fa)
data = data.replace('p1:', '')
text_tag = 'p1'
else:
self.fa_p2_var.set(fa)
data = data.replace('p2:', '')
text_tag = 'p2'
if '|' in output_str:
out = ""
for i, col in enumerate(data.split('|')):
if self.columns_to_print[i]:
out += '|' + col
out += "\n"
self.widget.configure(state="normal")
self.widget.insert("end", out, text_tag)
self.widget.configure(state="disabled")
self.widget.see('0.0')
self.widget.yview('moveto', '.02')
class GUI_FrameDataOverlay(GUI_Overlay.Overlay):
def __init__(self, master, launcher):
GUI_Overlay.Overlay.__init__(self, master, (1000, 86), "Tekken Bot: Frame Data Overlay")
self.show_live_framedata = self.tekken_config.get_property(GUI_Overlay.DisplaySettings.config_name(), GUI_Overlay.DisplaySettings.tiny_live_frame_data_numbers.name, True)
#self.launcher = FrameDataLauncher(self.enable_nerd_data)
self.launcher = launcher
self.s = Style()
self.s.theme_use('alt')
self.s.configure('.', background=self.background_color)
self.s.configure('.', foreground=CurrentColorScheme.dict[ColorSchemeEnum.advantage_text])
Grid.columnconfigure(self.toplevel, 0, weight=0)
Grid.columnconfigure(self.toplevel, 1, weight=0)
Grid.columnconfigure(self.toplevel, 2, weight=0)
Grid.columnconfigure(self.toplevel, 3, weight=1)
Grid.columnconfigure(self.toplevel, 4, weight=0)
Grid.columnconfigure(self.toplevel, 5, weight=0)
Grid.columnconfigure(self.toplevel, 6, weight=0)
Grid.rowconfigure(self.toplevel, 0, weight=1)
Grid.rowconfigure(self.toplevel, 1, weight=0)
self.s.configure('TFrame', background=self.tranparency_color)
self.fa_p1_var, fa_p1_label = self.create_frame_advantage_label(1)
self.fa_p2_var, fa_p2_label = self.create_frame_advantage_label(5)
self.l_margin = self.create_padding_frame(0)
self.r_margin = self.create_padding_frame(6)
self.l_seperator = self.create_padding_frame(2)
self.r_seperator = self.create_padding_frame(4)
if self.show_live_framedata:
self.l_live_recovery = self.create_live_recovery(fa_p1_label, 0)
self.r_live_recovery = self.create_live_recovery(fa_p2_label, 0)
self.text = self.create_textbox(3)
self.stdout = sys.stdout
self.redirector = TextRedirector(self.stdout, self.text, self.s, self.fa_p1_var, self.fa_p2_var)
self.text.configure(state="normal")
self.text.delete("1.0", "end")
#self.text.insert("1.0", "{:^5}|{:^8}|{:^9}|{:^7}|{:^5}|{:^5}|{:^8}|{:^5}|{:^5}|{:^7}|{:^5}|{}\n".format(" input ", "type", "startup", "block", "hit", "CH", "active", "track", "tot", "rec", "stun", "notes"))
#self.redirector.populate_column_names(self.get_data_columns())
self.redirector.set_columns_to_print(self.get_data_columns())
self.text.configure(state="disabled")
def get_data_columns(self):
booleans_for_columns = []
for enum in DataColumns:
bool = self.tekken_config.get_property(DataColumns.config_name(), enum.name, True)
booleans_for_columns.append(bool)
return booleans_for_columns
def create_padding_frame(self, col):
padding = Frame(self.toplevel, width=10)
padding.grid(row=0, column=col, rowspan=2, sticky=N + S + W + E)
return padding
def create_live_recovery(self, parent, col):
live_recovery_var = StringVar()
live_recovery_var.set('??')
live_recovery_label = Label(parent, textvariable=live_recovery_var, font=("Segoe UI", 12), width=5, anchor='c')
#live_recovery_label.grid(row=0, column=col, sticky =S+W)
live_recovery_label.place(rely=0.0, relx=0.0, x=4, y=4, anchor=NW)
return live_recovery_var
def create_frame_advantage_label(self, col):
frame_advantage_var = StringVar()
frame_advantage_var.set('?')
frame_advantage_label = Label(self.toplevel, textvariable=frame_advantage_var, font=("Consolas", 44), width=4, anchor='c',
borderwidth=4, relief='ridge')
frame_advantage_label.grid(row=0, column=col)
return frame_advantage_var, frame_advantage_label
def create_attack_type_label(self, col):
attack_type_var = StringVar()
attack_type_var.set('?')
attack_type_label = Label(self.toplevel, textvariable=attack_type_var, font=("Verdana", 12), width=10, anchor='c',
borderwidth=4, relief='ridge')
attack_type_label.grid(row=1, column=col)
return attack_type_var
def create_textbox(self, col):
textbox = Text(self.toplevel, font=("Consolas", 14), wrap=NONE, highlightthickness=0, pady=0, relief='flat')
textbox.grid(row=0, column=col, rowspan=2, sticky=N + S + W + E)
textbox.configure(background=self.background_color)
textbox.configure(foreground=CurrentColorScheme.dict[ColorSchemeEnum.system_text])
return textbox
def update_state(self):
#GUI_Overlay.Overlay.update_state(self)
if self.show_live_framedata:
if len(self.launcher.gameState.stateLog) > 1:
l_recovery = str(self.launcher.gameState.GetOppFramesTillNextMove() - self.launcher.gameState.GetBotFramesTillNextMove())
r_recovery = str(self.launcher.gameState.GetBotFramesTillNextMove() - self.launcher.gameState.GetOppFramesTillNextMove())
if not '-' in l_recovery:
l_recovery = '+' + l_recovery
if not '-' in r_recovery:
r_recovery = '+' + r_recovery
self.l_live_recovery.set(l_recovery)
self.r_live_recovery.set(r_recovery)
def set_columns_to_print(self, columns_to_print):
self.redirector.set_columns_to_print(columns_to_print)
def update_column_to_print(self, enum, value):
self.tekken_config.set_property(DataColumns.config_name(), enum.name, value)
self.write_config_file()