-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_old.py
More file actions
186 lines (157 loc) · 5.36 KB
/
Copy pathmain_old.py
File metadata and controls
186 lines (157 loc) · 5.36 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
# init
import time
from Utils.Controls import Controls
from Utils.GameTasks import GameTasks
from Utils.MapNavigation import MapNavigation
from Utils.params import *
import multiprocessing
ADBADRESS = "127.0.0.1:5555"
ADB = "\"C:\Program Files\BlueStacks_nxt\.\HD-Adb.exe\""
SCREEN = "Screen/screen.png"
# init
controls = Controls(ADB,
ADBADRESS,
SCREEN,
device=navigationEvent["device"],
pressSteps=navigationEvent["pressSteps"],
releaseSteps=navigationEvent["releaseSteps"],
sendEventSize=navigationEvent["sendEventSize"])
controls.connectADB()
task = GameTasks(controls)
map = MapNavigation(controls, posDict["mapOffset"], debugMode=True)
def start():
task.start()
def doTask(TaskName, TaskIndex):
task.backToMain()
task.doTask(TaskName, TaskIndex)
task.backToMain()
def navigate(bigMap, route):
# ts = time.time()
map.setBigMap(dict[bigMap])
map.getInitPos()
map.setRoute(route, posDict["center"],
[posDict["rad"][0], posDict["rad"][1]])
while (1):
# te = time.time()
# print(te - ts)
# ts = te
map.update()
if (map.goRoute()):
break
def tryFunc(func, *args):
try:
exitProcess()
process = multiprocessing.Process(target=func, args=args)
process.daemon = True
process.start()
except Exception as e:
print(e)
def exitProcess():
print(multiprocessing.active_children())
for p in multiprocessing.active_children():
p.terminate()
controls.release()
controls.release()
task.backToMain()
# gui part using tkinter
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
def gui():
window = tk.Tk()
window.title("AutoGame")
window.geometry("500x300")
window.resizable(False, False)
# tab control
tabControl = ttk.Notebook(window)
tab1 = ttk.Frame(tabControl)
tabControl.add(tab1, text="Main")
tabControl.pack(expand=1, fill="both")
tab2 = ttk.Frame(tabControl)
tabControl.add(tab2, text="Task")
tabControl.pack(expand=1, fill="both")
tab3 = ttk.Frame(tabControl)
tabControl.add(tab3, text="Map")
tabControl.pack(expand=1, fill="both")
# tab1 main
# start button
startButton = tk.Button(tab1, text="Start", command=lambda: tryFunc(start))
startButton.place(x=100, y=50, width=100, height=50)
# exit button
exitButton = tk.Button(tab1, text="Terminate", command=exitProcess)
exitButton.place(x=300, y=50, width=100, height=50)
# tab2 task
# add a place to input the task name
taskName = tk.StringVar()
taskName.set("taskSub5")
taskNameEntry = tk.Entry(tab2, textvariable=taskName)
taskNameEntry.place(x=100, y=50, width=100, height=50)
# add a place to input the task index
taskIndex = tk.StringVar()
taskIndex.set("taskSub5d")
taskIndexEntry = tk.Entry(tab2, textvariable=taskIndex)
taskIndexEntry.place(x=300, y=50, width=100, height=50)
# get the task name and index
TaskName = taskName.get()
TaskIndex = taskIndex.get()
# set taskName and taskIndex
def setTaskName():
TaskName = taskName.get()
TaskIndex = taskIndex.get()
doTaskButton = tk.Button(
tab2,
text="DoTask",
command=lambda: tryFunc(doTask, TaskName, TaskIndex))
doTaskButton.place(x=300, y=150, width=100, height=50)
print(TaskName, TaskIndex)
# setTaskName button
setTaskNameButton = tk.Button(tab2,
text="SetTaskName",
command=setTaskName)
setTaskNameButton.place(x=100, y=150, width=100, height=50)
# doTask button
doTaskButton = tk.Button(
tab2,
text="DoTask",
command=lambda: tryFunc(doTask, TaskName, TaskIndex))
doTaskButton.place(x=300, y=150, width=100, height=50)
# tab3 map
# add a place to input the map name
mapName = tk.StringVar()
mapName.set("map21")
mapNameEntry = tk.Entry(tab3, textvariable=mapName)
mapNameEntry.place(x=100, y=50, width=100, height=50)
# add a place to input the route
routeName = tk.StringVar()
routeName.set("route1")
routeEntry = tk.Entry(tab3, textvariable=routeName)
routeEntry.place(x=300, y=50, width=100, height=50)
# get the map name and route
MapName = mapName.get()
RouteName = routeName.get()
route = dictRoute[RouteName]
# set mapName
def setMapAndRoute():
MapName = mapName.get()
RouteName = routeName.get()
route = dictRoute[RouteName]
navigateButton = tk.Button(
tab3,
text="Navigate",
command=lambda: tryFunc(navigate, MapName, route))
navigateButton.place(x=300, y=150, width=100, height=50)
print(MapName, RouteName)
# setMapName button
setMapNameButton = tk.Button(tab3,
text="SetMapAndRoute",
command=setMapAndRoute)
setMapNameButton.place(x=100, y=150, width=100, height=50)
# navigate button
navigateButton = tk.Button(
tab3,
text="Navigate",
command=lambda: tryFunc(navigate, MapName, route))
navigateButton.place(x=300, y=150, width=100, height=50)
window.mainloop()
if __name__ == "__main__":
gui()