forked from WAZAAAAA0/TekkenBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI_Overlay.py
125 lines (103 loc) · 4.55 KB
/
GUI_Overlay.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
"""
Our abstract overlay class provides shared tools for our overlays
"""
from ConfigReader import ConfigReader, ReloadableConfig
from enum import Enum
import platform
from tkinter import *
from tkinter.ttk import *
class DisplaySettings(Enum):
overlay_on_bottom = -1
overlay_as_draggable_window = 0
only_appears_when_Tekken_7_has_focus = 1
transparent_background = 2
tiny_live_frame_data_numbers = 3
def config_name():
return "DisplaySettings"
class ColorSchemeEnum(Enum):
background = 0
transparent = 1
p1_text = 2
p2_text = 3
system_text = 4
advantage_plus = 5
advantage_slight_minus = 6
advantage_safe_minus = 7
advantage_punishible = 8
advantage_very_punishible = 9
advantage_text = 10
class CurrentColorScheme:
dict = {
ColorSchemeEnum.background : 'gray10',
ColorSchemeEnum.transparent: 'white',
ColorSchemeEnum.p1_text: '#93A1A1',
ColorSchemeEnum.p2_text: '#586E75',
ColorSchemeEnum.system_text: 'lawn green',
ColorSchemeEnum.advantage_plus: 'DodgerBlue2',
ColorSchemeEnum.advantage_slight_minus: 'ivory2',
ColorSchemeEnum.advantage_safe_minus: 'ivory2',
ColorSchemeEnum.advantage_punishible: 'orchid2',
ColorSchemeEnum.advantage_very_punishible: 'deep pink',
ColorSchemeEnum.advantage_text: 'black',
}
class Overlay:
def __init__(self, master, xy_size, window_name):
print("Launching {}".format(window_name))
config_filename = "frame_data_overlay"
self.tekken_config = ConfigReader(config_filename)
is_windows_7 = 'Windows-7' in platform.platform()
self.is_draggable_window = self.tekken_config.get_property(DisplaySettings.config_name(), DisplaySettings.overlay_as_draggable_window.name, False)
self.is_minimize_on_lost_focus = self.tekken_config.get_property(DisplaySettings.config_name(), DisplaySettings.only_appears_when_Tekken_7_has_focus.name, True)
self.is_transparency = self.tekken_config.get_property(DisplaySettings.config_name(), DisplaySettings.transparent_background.name, not is_windows_7)
self.is_overlay_on_top = not self.tekken_config.get_property(DisplaySettings.config_name(), DisplaySettings.overlay_on_bottom.name, False)
self.overlay_visible = False
if master == None:
self.toplevel = Tk()
else:
self.toplevel = Toplevel()
self.toplevel.wm_title(window_name)
self.toplevel.attributes("-topmost", True)
self.background_color = CurrentColorScheme.dict[ColorSchemeEnum.background]
if self.is_transparency:
self.tranparency_color = CurrentColorScheme.dict[ColorSchemeEnum.transparent]
self.toplevel.wm_attributes("-transparentcolor", self.tranparency_color)
self.toplevel.attributes("-alpha", "0.75")
else:
if is_windows_7:
print("Windows 7 detected. Disabling transparency.")
self.tranparency_color = self.background_color
self.toplevel.configure(background=self.tranparency_color)
self.toplevel.iconbitmap('TekkenData/tekken_bot_close.ico')
if not self.is_draggable_window:
self.toplevel.overrideredirect(True)
self.w = xy_size[0]
self.h = xy_size[1]
self.toplevel.geometry(str(self.w) + 'x' + str(self.h))
def update_location(self):
if not self.is_draggable_window:
tekken_rect = self.launcher.gameState.gameReader.GetWindowRect()
if tekken_rect != None:
x = (tekken_rect.right + tekken_rect.left) / 2 - self.w / 2
if self.is_overlay_on_top:
y = tekken_rect.top
else:
y = tekken_rect.bottom - self.h - 10
self.toplevel.geometry('%dx%d+%d+%d' % (self.w, self.h, x, y))
if not self.overlay_visible:
self.show()
else:
if self.overlay_visible:
self.hide()
def update_state(self):
pass
def hide(self):
if self.is_minimize_on_lost_focus and not self.is_draggable_window:
self.toplevel.withdraw()
self.overlay_visible = False
def show(self):
# print("Reloading configs...")
ReloadableConfig.reload()
self.toplevel.deiconify()
self.overlay_visible = True
def write_config_file(self):
self.tekken_config.write()