-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
299 lines (242 loc) · 10.3 KB
/
main.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
from base64 import b64decode
import sys,os
import webbrowser
import pyperclip
from PySide6 import QtWidgets
from PySide6.QtWidgets import *
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtCore import Qt
from qtgui_ui import Ui_MainWindow
from set_ui import Ui_Dialog
import LocatorLib,time,json,plt
import requests
from memory_pic import *
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton
from PySide6.QtGui import QKeySequence, QShortcut
if not os.path.exists('icon.ico'): # 释放图标
def get_pic(pic_code, pic_name):
image = open(pic_name, 'wb')
image.write(b64decode(pic_code))
image.close()
get_pic(icon_ico, 'icon.ico')
# 检查文件是否存在
if not os.path.exists('set.json'):
# 如果文件不存在,则创建并写入初始内容
data = {"debug": False, "debug_version": False, "map": True, "tpy": 100, "osj": False,"sjy":32}
with open('set.json', 'w') as f:
json.dump(data, f)
tp = ""
version = "v3.1.0"
vc = vd = 0
with open("set.json","r") as f:
set_json=json.loads(f.read())
def LogTxt(xyt_1, xyt_2 ,xyt_3,out):
with open("log.txt", "a",encoding = 'utf-8') as f:
if type(out)==str:
f.write(f"""
时间:{time.ctime()}
位置1:{xyt_1}
位置2:{xyt_2}
位置3:{xyt_3}
错误信息:{out}
""")
else:
f.write(f"""
时间:{time.ctime()}
位置1:{xyt_1}
位置2:{xyt_2}
位置3:{xyt_3}
结果:x={out[0]},y={out[1]}
TP指令:{f"/tp {out[0]} {set_json['tpy']} {out[1]}"}
""")
class Dialog(QDialog): #设置界面
def __init__(self, parent = None) :
with open("set.json","r") as f:
out=json.loads(f.read())
super().__init__(parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
if not bool(out["debug"]):
self.ui.tabWidget.removeTab(1)
self.ui.debug_ver.setChecked(set_json["debug_version"])
self.ui.open_map.setChecked(set_json["map"])
self.ui.open_sj.setChecked(set_json["osj"])
self.ui.tp_y.setValue(set_json["tpy"])
self.ui.sj_y.setValue(set_json["sjy"])
self.ui.off_debug.clicked.connect(self.off_debug)
self.ui.enter.clicked.connect(self.enter)
self.ui.debug_ver.clicked.connect(self.debug_ver)
self.ui.open_map.clicked.connect(self.open_map)
self.ui.open_sj.clicked.connect(self.open_sj)
def enter(self):
set_json["tpy"] = int(self.ui.tp_y.text())
set_json["sjy"] = int(self.ui.sj_y.text())
with open("set.json","w") as f:
f.write(json.dumps(set_json))
QMessageBox.about(self,"重启应用程序","请重启本应用,以应用设置。")
app.exit(app.exec())
def off_debug(self):
global set_json
set_json["debug"]=False
QMessageBox.about(self,"关闭调试模式","已关闭。")
def debug_ver(self):
global set_json
set_json["debug_version"]=self.ui.debug_ver.isChecked()
def open_map(self):
global set_json
set_json["map"]=self.ui.open_map.isChecked()
def open_sj(self):
global set_json
set_json["osj"]=self.ui.open_sj.isChecked()
class MainWindow(QMainWindow): #主界面
def __init__(self, parent = None) :
super().__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
#主界面
if not set_json["osj"]:
self.ui.dx_sj.setEnabled(False)
self.ui.dx_jd.clicked.connect(self.dx_jd)
self.ui.dx_sj.clicked.connect(self.dx_sj)
self.ui.dx_gs.clicked.connect(self.dx_gs)
self.ui.copy_1.clicked.connect(self.copy_1)
self.ui.copy_2.clicked.connect(self.copy_2)
self.ui.copy_3.clicked.connect(self.copy_3)
self.ui.copy_tp.clicked.connect(self.copy_tp)
self.ui.ck_y.triggered.connect(self.ck_y)
self.ui.bh_y.triggered.connect(self.bh_y)
self.ui.bh_g.triggered.connect(self.bh_g)
self.ui.jc_gx.triggered.connect(self.jc_gx)
self.ui.open_log.triggered.connect(self.open_log)
self.ui.open_set.triggered.connect(self.open_set)
self.ui.win_top.clicked.connect(self.win_top)
shortcut = QShortcut(QKeySequence("Ctrl+R"), QApplication.instance())
shortcut.activated.connect(self.crp)
def crp(self):
print("crp")
def dx_jd(self):
global tp
xyt_1=str(self.ui.xyt_1.text())
xyt_2=str(self.ui.xyt_2.text())
out=LocatorLib.Calculate(xyt_1,xyt_2)
if type(out)==str:
self.ui.print_err.showMessage("错误:"+out,5000)
self.ui.out_x.setText("")
self.ui.out_z.setText("")
self.ui.out_tp.setText("")
LogTxt(xyt_1,xyt_2,"交点法",out)
else:
tp = f"/tp {out[0]} {set_json['tpy']} {out[1]}"
self.ui.out_x.setText(out[0])
self.ui.out_z.setText(out[1])
self.ui.out_tp.setText(f"/tp {out[0]} {set_json['tpy']} {out[1]}")
LogTxt(xyt_1,xyt_2,"交点法",out)
if set_json['map']:
inxyt_1 = (float(str(self.ui.xyt_1.text()).split()[6]),float(str(self.ui.xyt_1.text()).split()[8]))
inxyt_2 = (float(str(self.ui.xyt_2.text()).split()[6]),float(str(self.ui.xyt_2.text()).split()[8]))
plt.plot_points_s(inxyt_1,inxyt_2,(int(out[0]),int(out[1])))
def dx_sj(self):
global tp
xyt_1=str(self.ui.xyt_1.text())
xyt_2=str(self.ui.xyt_2.text())
xyt_3=str(self.ui.xyt_3.text())
out=LocatorLib.CalculateT(xyt_1,xyt_2,xyt_3,set_json["sjy"])
if type(out)==str:
self.ui.print_err.showMessage("错误:"+out,5000)
self.ui.out_x.setText("")
self.ui.out_z.setText("")
self.ui.out_tp.setText("")
LogTxt(xyt_1,xyt_2,xyt_3,out)
else:
tp = f"/tp {out[0]} {set_json['tpy']} {out[1]}"
self.ui.out_x.setText(out[0])
self.ui.out_z.setText(out[1])
self.ui.out_tp.setText(f"/tp {out[0]} {set_json['tpy']} {out[1]}")
LogTxt(xyt_1,xyt_2,xyt_3,out)
def dx_gs(self):
global tp
xyt_1=str(self.ui.xyt_1.text())
out=LocatorLib.Estimate(xyt_1)
if type(out)==str:
self.ui.print_err.showMessage("错误:"+out,5000)
self.ui.out_x.setText("")
self.ui.out_z.setText("")
self.ui.out_tp.setText("")
LogTxt(xyt_1,"估算法","估算法",out)
else:
tp = f"/tp {out[0]} {set_json['tpy']} {out[1]}"
self.ui.out_x.setText(out[0])
self.ui.out_z.setText(out[1])
self.ui.out_tp.setText(f"/tp {out[0]} {set_json['tpy']} {out[1]}")
LogTxt(xyt_1,"估算法","估算法",out)
if set_json['map']:
inxyt = (float(str(self.ui.xyt_1.text()).split()[6]),float(str(self.ui.xyt_1.text()).split()[8]))
plt.plot_points_t(inxyt,(int(out[0]),int(out[1])))
def copy_tp(self):
global tp
pyperclip.copy(tp)
def copy_1(self):
self.ui.xyt_1.setText(pyperclip.paste())
def copy_2(self):
self.ui.xyt_2.setText(pyperclip.paste())
def copy_3(self):
self.ui.xyt_3.setText(pyperclip.paste())
def ck_y(self):
global vd
if vd < 3:
webbrowser.open("https://github.com/Shrans/Stronghold-Locator")
vd+=1
else:
with open("set.json","r") as f:
set=json.loads(f.read())
set["debug"] = True
with open("set.json","w") as f:
f.write(json.dumps(set))
webbrowser.open("https://github.com/Shrans/Stronghold-Locator")
QMessageBox.information(self, "调试模式", "已开启调试模式。\n请重启该程序")
app.exit(app.exec())
def bh_y(self):
webbrowser.open("https://space.bilibili.com/228828764")
def bh_g(self):
webbrowser.open("https://space.bilibili.com/502594227")
def open_log(self):
os.system("start log.txt")
# QMessageBox.information(self, "关于", "这是一个关于对话框",QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
def open_set(self):
with open("set.json","r") as f:
global set_json
set_json=json.loads(f.read())
set.show()
def jc_gx(self):
global vc
if not set_json["debug_version"]:
response = requests.get("https://api.github.com/repos/Shrans/Stronghold-Locator/releases/latest")
data = response.json()
else:
response = requests.get("https://api.github.com/repos/Shrans/Stronghold-Locator/releases")
data = response.json()[0]
tag_name = data["tag_name"]
if version == tag_name:
if vc < 2:
QMessageBox.information(self, "检查更新", "你正在使用最新版")
vc+=1
else:
QMessageBox.information(self, "检查更新", "你正在使用最新版\n不要频繁使用该功能!如使用频率过高,您将会被GitHub拒绝访问一段时间!")
else:
if QMessageBox.information(self, "发现新版本", f"你的版本:{version},新的版本{data['tag_name']}\n新版本介绍:\n{data['body']}",QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) == QMessageBox.Yes:
webbrowser.open(data["html_url"])
def win_top(self):
if not self.ui.win_top.isChecked():
self.setWindowFlags(self.windowFlags() & ~Qt.WindowStaysOnTopHint)
else:
self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)
self.show()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
win = MainWindow()
win.setWindowTitle("Stronghold-Locator-GUI")
win.show()
set = Dialog()
set.setWindowTitle("Stronghold-Locator-GUI-SET")
win.ui.print_err.showMessage("欢迎使用Stronghold-Locator-GUI应用程序")
app.exit(app.exec())