Skip to content

Commit

Permalink
通用鼠标支持
Browse files Browse the repository at this point in the history
  • Loading branch information
ahao committed Feb 14, 2023
1 parent 0a2c371 commit 6446754
Show file tree
Hide file tree
Showing 40 changed files with 10,477 additions and 145 deletions.
30 changes: 21 additions & 9 deletions controller/ApexMacroConfigController.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MacroMode(Enum):

LGS = "LGS"
GHUB = "GHUB"
GHUB2 = "GHUB-通用鼠标"

class MacroConfigController():

Expand Down Expand Up @@ -56,7 +57,6 @@ def init_ui_data(self) -> None:

for macroMode in MacroMode:
self.view.driversoft.addItem(macroMode.value, userData=macroMode)
self.driver_changed()

for aimMode in AimMode:
self.view.modes.addItem(aimMode.value, userData=aimMode)
Expand Down Expand Up @@ -95,6 +95,8 @@ def init_ui_with_config(self):
keyBindings = []
for key in self.config["keybinds"]:
modifiers = key.split("+")[0].split(",")
if len(modifiers) == 1 and modifiers[0] == "":
modifiers = []
mouseBtn = key.split("+")[-1]
try:
scriptFunc = self.macroFunctions[self.config["keybinds"][key]]
Expand All @@ -121,7 +123,10 @@ def save_config(self):

keyBinding_data = self.tablemodel.data.copy()
keyBinding_data.append(KeyBinding(1,self.macroFunctions["leftbutton"]))
keyBinding_data.append(KeyBinding(2,self.macroFunctions["rightbutton"]))
rightkey = 2
if self.view.driversoft.currentData() == MacroMode.GHUB2:
rightkey = 3
keyBinding_data.append(KeyBinding(rightkey,self.macroFunctions["rightbutton"]))

## render config.lua
result = ""
Expand Down Expand Up @@ -195,13 +200,6 @@ def save_config(self):

Settings().save_config_to_json()

def load_configs(self,configpath):
config = None
with open(configpath, "r") as f:
config = json.load(f)
if config:
self.config = config

def load_functions(self, script_file_path: str) -> str:
with open(script_file_path, "r") as f:
scripts = json.load(f)
Expand Down Expand Up @@ -245,6 +243,16 @@ def download_driverscript(self):
tempfile.tempdir.replace("\\", "/")+"/config.lua")
with open(save_path, "w") as f:
f.write(result)
elif self.view.driversoft.currentData() == MacroMode.GHUB2:
try:
mainscript = self.macroFunctions["script"]
except:
traceback.print_exc()
return
result = mainscript.openContent.format(
tempfile.tempdir.replace("\\", "/")+"/config.lua")
with open(save_path, "w") as f:
f.write(result)

def mode_changed(self):
self.config["adsmode"] = self.view.modes.currentData().value
Expand Down Expand Up @@ -304,6 +312,8 @@ def driver_changed(self):
self.macroFunctions = self.parse_functions_to_model(self.load_functions(Settings().resource_dir+"lgsscripts.json"))
if macro == MacroMode.GHUB:
self.macroFunctions = self.parse_functions_to_model(self.load_functions(Settings().resource_dir+"ghubscripts.json"))
if macro == MacroMode.GHUB2:
self.macroFunctions = self.parse_functions_to_model(self.load_functions(Settings().resource_dir+"ghub2scripts.json"))
self.load_macro_functions()

def load_macro_functions(self):
Expand Down Expand Up @@ -352,6 +362,8 @@ def save_macro_script(self,func:MacroFunction,openContent: str,closeContent:str,
save_file = Settings().resource_dir+"lgsscripts.json"
elif self.view.driversoft.currentData() == MacroMode.GHUB:
save_file = Settings().resource_dir+"ghubscripts.json"
elif self.view.driversoft.currentData() == MacroMode.GHUB2:
save_file = Settings().resource_dir+"ghub2scripts.json"

with open(save_file,"w") as file:
json.dump(result, file, indent=4)
Expand Down
13 changes: 9 additions & 4 deletions controller/ApexRecognizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def check_resolution(self):
point = self.boxs[k]
newpoint = [point[0]+monitor["left"],point[1]+monitor["top"]]
self.boxs[k] = newpoint
self.boxs[k].extend(point[2:])
self.resize_rate = float(height/1080)
except FileNotFoundError as e:
raise FileNotFoundError("不支持的分辨率{}x{}".format(width,height))
Expand Down Expand Up @@ -84,8 +85,10 @@ def isweapon_icon(self, cvimg):
return round(np.sum(cvimg)/6311250*100)>=8

def recognize(self):
icon_scale = 180/45
icon_height = round(45 * self.resize_rate)
icon_width = self.boxs["weapon1"][2]
icon_height = self.boxs["weapon1"][3]
icon_scale = icon_width/icon_height
icon_height = round(icon_height * self.resize_rate)
icon_width = round(icon_height * icon_scale)

box1 = (self.boxs["weapon1"][0],
Expand Down Expand Up @@ -119,8 +122,10 @@ def recognize(self):
self.qt_comunicate.update.emit(d) if self.qt_comunicate else None

def screenshot(self):
icon_scale = 180/45
icon_height = round(45 * self.resize_rate)
icon_width = self.boxs["weapon1"][2]
icon_height = self.boxs["weapon1"][3]
icon_scale = icon_width/icon_height
icon_height = round(icon_height * self.resize_rate)
icon_width = round(icon_height * icon_scale)

box1 = (self.boxs["weapon1"][0],
Expand Down
23 changes: 15 additions & 8 deletions controller/ApexWeaponConfigController.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def load_datas(self):
self.datas = {
"loading": 0,
"dq": ["true"],
"dqrate": 2,
"dqrate": [2],
"debug": ["false"],
"weapons": {}
}
Expand All @@ -78,7 +78,7 @@ def load_datas(self):
is_weapon_data = True
# global sensitive
for k in self.datas.keys():
if f.find(k)>=0:
if f.find(k+"=")>=0:
leftquote = f.split("=")[-1].find("{")
rightquote = f.split("=")[-1].find("}")
self.datas[k] = f.split("=")[-1][leftquote+1:rightquote].split(",")
Expand Down Expand Up @@ -135,6 +135,8 @@ def generate_config(self):
def block_ui_event(self,block:bool):
for widget in [self.view.loading,
self.view.dq,
self.view.debug,
self.view.dqrate,
self.view.speed,
self.view.yrate,
self.view.xrate,
Expand Down Expand Up @@ -199,11 +201,13 @@ def cal_data_result(self):
movex = (offsetx) * xrate
movey = (base + offsety) * yrate

countx = countx + movex
county = county + movey
# countx = countx + movex
# county = county + movey

countdatax.append("{:.2f}".format(countx))
countdatay.append("{:.2f}".format(county))
# countdatax.append("{:.2f}".format(countx))
# countdatay.append("{:.2f}".format(county))
countdatax.append("{:.2f}".format(movex))
countdatay.append("{:.2f}".format(movey))
# self.view.weapon_data_result.append(f"{{{i},{movey},0}}")

countdatax = str(countdatax).replace("[","{").replace("]","}")
Expand Down Expand Up @@ -259,8 +263,11 @@ def fill_ui_data(self):

def delteweapon(self):
weapon_name = self.view.weapons.currentText()
del self.datas["weapons"][weapon_name]
self.fill_ui_data()
try:
del self.datas["weapons"][weapon_name]
self.fill_ui_data()
except:
pass

def apply(self):
result = ""
Expand Down
26 changes: 23 additions & 3 deletions controller/PubgMacroConfigController.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MacroMode(Enum):

LGS = "LGS"
GHUB = "GHUB"
GHUB2 = "GHUB-通用鼠标"

class MacroConfigController():

Expand Down Expand Up @@ -55,8 +56,8 @@ def init_ui_data(self) -> None:

for macroMode in MacroMode:
self.view.driversoft.addItem(macroMode.value, userData=macroMode)
self.view.driversoft.setCurrentIndex( self.view.driversoft.findData(MacroMode(self.config["driver"])) )
self.driver_changed()
# self.view.driversoft.setCurrentIndex( self.view.driversoft.findData(MacroMode(self.config["driver"])) )
# self.driver_changed()

for aimMode in AimMode:
self.view.modes.addItem(aimMode.value, userData=aimMode)
Expand Down Expand Up @@ -111,6 +112,8 @@ def init_ui_with_config(self):
keyBindings = []
for key in self.config["keybinds"]:
modifiers = key.split("+")[0].split(",")
if len(modifiers) == 1 and modifiers[0] == "":
modifiers = []
mouseBtn = key.split("+")[-1]
try:
scriptFunc = self.macroFunctions[self.config["keybinds"][key]]
Expand Down Expand Up @@ -141,7 +144,10 @@ def save_config(self):

keyBinding_data = self.tablemodel.data.copy()
keyBinding_data.append(KeyBinding(1,self.macroFunctions["leftbutton"]))
keyBinding_data.append(KeyBinding(2,self.macroFunctions["rightbutton"]))
rightkey = 2
if self.view.driversoft.currentData() == MacroMode.GHUB2:
rightkey = 3
keyBinding_data.append(KeyBinding(rightkey,self.macroFunctions["rightbutton"]))

if self.config["adsmode"] == AimMode.HOLD_MOUSE_BTN_2.value:
keyBinding_data.append(KeyBinding(self.config["aimbutton"],self.macroFunctions["aimbutton"]))
Expand Down Expand Up @@ -278,6 +284,16 @@ def download_driverscript(self):
tempfile.tempdir.replace("\\", "/")+"/config.lua")
with open(save_path, "w") as f:
f.write(result)
elif self.view.driversoft.currentData() == MacroMode.GHUB2:
try:
mainscript = self.macroFunctions["script"]
except:
print("配置文件损坏")
return
result = mainscript.openContent.format(
tempfile.tempdir.replace("\\", "/")+"/config.lua")
with open(save_path, "w") as f:
f.write(result)

def mode_changed(self):
self.view.toggle_aimMode_display(False) if self.view.modes.currentData() == AimMode.CLICK_MOUSE_BTN_2 else self.view.toggle_aimMode_display(True)
Expand Down Expand Up @@ -356,6 +372,8 @@ def driver_changed(self):
self.macroFunctions = self.parse_functions_to_model(self.load_functions(Settings().resource_dir+"lgsscripts.json"))
if macro == MacroMode.GHUB:
self.macroFunctions = self.parse_functions_to_model(self.load_functions(Settings().resource_dir+"ghubscripts.json"))
if macro == MacroMode.GHUB2:
self.macroFunctions = self.parse_functions_to_model(self.load_functions(Settings().resource_dir+"ghub2scripts.json"))
self.load_macro_functions()

def load_macro_functions(self):
Expand Down Expand Up @@ -404,6 +422,8 @@ def save_macro_script(self,func:MacroFunction,openContent: str,closeContent:str,
save_file = Settings().resource_dir+"lgsscripts.json"
elif self.view.driversoft.currentData() == MacroMode.GHUB:
save_file = Settings().resource_dir+"ghubscripts.json"
elif self.view.driversoft.currentData() == MacroMode.GHUB2:
save_file = Settings().resource_dir+"ghub2scripts.json"

with open(save_file,"w") as file:
json.dump(result, file, indent=4)
Expand Down
10 changes: 6 additions & 4 deletions controller/PubgWeaponConfigController.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ def cal_data_result(self):
movex = round(offsetx * rate )
movey = round((base + offsety) * rate )

countx = countx + movex
county = county + movey
# countx = countx + movex
# county = county + movey

countdatax.append(countx)
countdatay.append(county)
# countdatax.append(countx)
# countdatay.append(county)
countdatax.append(movex)
countdatay.append(movey)
# self.view.weapon_data_result.append(f"{{{i},{movey},0}}")

countdatax = str(countdatax).replace("[","{").replace("]","}")
Expand Down
4 changes: 2 additions & 2 deletions resource/APEX/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"macro_config": {
"driver": "LGS",
"driver": "GHUB-\u901a\u7528\u9f20\u6807",
"adsmode": "HOLD",
"keybinds": {
"lctrl,lshift,lalt+5": "reloadconfig"
"+2": "reloadconfig"
}
},
"pose": {
Expand Down
Loading

0 comments on commit 6446754

Please sign in to comment.