Skip to content

Commit

Permalink
Add Overlay settings
Browse files Browse the repository at this point in the history
  • Loading branch information
shinkuan committed Apr 8, 2024
1 parent 863ffcd commit ce5c7f8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
23 changes: 22 additions & 1 deletion client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
submission = 'players/bot.zip'
PORT_NUM = 28680
AUTOPLAY = False
OVERLAY = False
ENABLE_PLAYWRIGHT = False
with open("settings.json", "r") as f:
settings = json.load(f)
PORT_NUM = settings["Port"]["MJAI"]
AUTOPLAY = settings["Autoplay"]
OVERLAY = settings["Overlay"]
ENABLE_PLAYWRIGHT = settings["Playwright"]["enable"]


Expand Down Expand Up @@ -194,7 +196,7 @@ def compose(self) -> ComposeResult:
loading_indicator = LoadingIndicator(id="loading_indicator")
loading_indicator.styles.height = "3"
checkbox_autoplay = Checkbox("Autoplay", id="checkbox_autoplay", classes="short", value=AUTOPLAY)
checkbox_overlay = Checkbox("Overlay ", id="checkbox_overlay", classes="short")
checkbox_overlay = Checkbox("Overlay ", id="checkbox_overlay", classes="short", value=OVERLAY)
checkbox_test_one = Checkbox("test_one", id="checkbox_test_one", classes="short")
checkbox_container = Vertical(checkbox_autoplay, checkbox_overlay, id="checkbox_container")
checkbox_container.border_title = "Options"
Expand Down Expand Up @@ -242,6 +244,9 @@ def on_mount(self) -> None:
except IndexError:
self.akagi_action.label = "Akagi"

if OVERLAY:
self.app.rpc_server.start_overlay_action()

def refresh_log(self) -> None:
try:
if self.flow_id not in self.app.liqi_msg_dict:
Expand Down Expand Up @@ -375,6 +380,8 @@ def checkbox_autoplay_changed(self, event: Checkbox.Changed) -> None:

@on(Checkbox.Changed, "#checkbox_overlay")
def checkbox_overlay_changed(self, event: Checkbox.Changed) -> None:
global OVERLAY
OVERLAY = event.value
if event.value:
self.app.rpc_server.start_overlay_action()
else:
Expand Down Expand Up @@ -445,6 +452,7 @@ def __init__(self, *args, **kwargs) -> None:
self.value_port_setting_xmlrpc_input = settings["Port"]["XMLRPC"]
self.value_unlocker_setting_enable_checkbox = settings["Unlocker"]
self.value_helper_setting_checkbox = settings["Helper"]
self.value_overlay_setting_enable_checkbox = settings["Overlay"]
self.value_autoplay_setting_enable_checkbox = settings["Autoplay"]
self.value_autoplay_setting_random_time_new_min_input = settings["RandomTime"]["new_min"]
self.value_autoplay_setting_random_time_new_max_input = settings["RandomTime"]["new_max"]
Expand Down Expand Up @@ -474,6 +482,11 @@ def compose(self) -> ComposeResult:
self.helper_setting_container = Horizontal(self.helper_setting_label, self.helper_setting_checkbox, id="helper_setting_container")
self.helper_setting_container.border_title = "Helper"

self.overlay_setting_label = Label("Overlay", id="overlay_setting_label")
self.overlay_setting_checkbox = Checkbox("Enable", id="overlay_setting_checkbox", classes="short", value=self.value_overlay_setting_enable_checkbox)
self.overlay_setting_container = Horizontal(self.overlay_setting_label, self.overlay_setting_checkbox, id="overlay_setting_container")
self.overlay_setting_container.border_title = "Overlay"

self.autoplay_setting_enable_label = Label("Enable", id="autoplay_setting_enable_label")
self.autoplay_setting_enable_checkbox = Checkbox("Enable", id="autoplay_setting_enable_checkbox", classes="short", value=self.value_autoplay_setting_enable_checkbox)
self.autoplay_setting_enable_container = Horizontal(self.autoplay_setting_enable_label, self.autoplay_setting_enable_checkbox, id="autoplay_setting_enable_container")
Expand Down Expand Up @@ -506,6 +519,7 @@ def compose(self) -> ComposeResult:
self.port_setting_container,
self.unlocker_setting_container,
self.helper_setting_container,
self.overlay_setting_container,
self.autoplay_setting_container,
self.playwright_setting_container,
self.setting_save_button,
Expand Down Expand Up @@ -537,6 +551,12 @@ def unlocker_setting_enable_checkbox_changed(self, event: Checkbox.Changed) -> N
def helper_setting_checkbox_changed(self, event: Checkbox.Changed) -> None:
self.value_helper_setting_checkbox = event.value

@on(Checkbox.Changed, "#overlay_setting_checkbox")
def overlay_setting_checkbox_changed(self, event: Checkbox.Changed) -> None:
global OVERLAY
OVERLAY = event.value
self.value_overlay_setting_enable_checkbox = event.value

@on(Checkbox.Changed, "#autoplay_setting_enable_checkbox")
def autoplay_setting_enable_checkbox_changed(self, event: Checkbox.Changed) -> None:
global AUTOPLAY
Expand Down Expand Up @@ -597,6 +617,7 @@ def setting_save_button_pressed(self) -> None:
settings["Port"]["XMLRPC"] = self.value_port_setting_xmlrpc_input
settings["Unlocker"] = self.value_unlocker_setting_enable_checkbox
settings["Helper"] = self.value_helper_setting_checkbox
settings["Overlay"] = self.value_overlay_setting_enable_checkbox
settings["Autoplay"] = self.value_autoplay_setting_enable_checkbox
settings["RandomTime"]["new_min"] = self.value_autoplay_setting_random_time_new_min_input
settings["RandomTime"]["new_max"] = self.value_autoplay_setting_random_time_new_max_input
Expand Down
23 changes: 23 additions & 0 deletions client.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,29 @@ Button.action_nukidora.-active {
border-title-align: center;
}

#overlay_setting_label {
padding: 1 0;
width: 11;
height: 3;
align: center middle;
margin: 0 1;
}

#overlay_setting_checkbox {
width: 1fr;
align: center top;
margin: 0 1;
}

#overlay_setting_container {
width: 1fr;
height: auto;
align: center top;
margin: 0;
border: round $accent;
border-title-align: center;
}

#port_setting_mitm_label {
padding: 1 0;
width: 11;
Expand Down
5 changes: 4 additions & 1 deletion mitm.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ def page_clicker(self, xy):
return True

def do_autohu(self):
return self.evaluate("() => view.DesktopMgr.Inst.setAutoHule(true)")
global do_autohu
if do_autohu:
return self.evaluate("() => view.DesktopMgr.Inst.setAutoHule(true)")
return False

def evaluate(self, script):
global enable_playwright, playwright_controller
Expand Down
3 changes: 2 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"enable": true,
"width": 1280,
"height": 720
}
},
"Overlay": true
}

0 comments on commit ce5c7f8

Please sign in to comment.