forked from SumZer0-git/EDAPGui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEDSystemMap.py
More file actions
119 lines (102 loc) · 4.98 KB
/
EDSystemMap.py
File metadata and controls
119 lines (102 loc) · 4.98 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
from __future__ import annotations
from EDAP_data import GuiFocusSystemMap
from EDlogger import logger
from OCR import OCR
from Screen_Regions import reg_scale_for_station
from StatusParser import StatusParser
from time import sleep
class EDSystemMap:
""" Handles the System Map. """
def __init__(self, ed_ap, screen, keys, cb, is_odyssey=True):
self.ap = ed_ap
self.ocr = ed_ap.ocr
self.is_odyssey = is_odyssey
self.screen = screen
self.keys = keys
self.status_parser = StatusParser()
self.ap_ckb = cb
# The rect is top left x, y, and bottom right x, y in fraction of screen resolution
self.reg = {'cartographics': {'rect': [0.0, 0.0, 0.25, 0.25]},
}
def set_sys_map_dest_bookmark(self, ap, bookmark_type: str, bookmark_position: int) -> bool:
""" Set the System Map destination using a bookmark.
@param ap: ED_AP reference.
@param bookmark_type: The bookmark type (Favorite, Body, Station, Settlement or Navigation), Favorite
being the default if no match is made with the other options. Navigation is unique in that it uses
the Nav Panel instead of the System Map.
@param bookmark_position: The position in the bookmark list, starting at 1 for the first bookmark.
@return: True if bookmark could be selected, else False
"""
if self.is_odyssey and bookmark_position != -1:
# Check if this is a nav-panel bookmark
if not bookmark_type.lower().startswith("nav"):
self.goto_system_map()
ap.keys.send('UI_Left') # Go to BOOKMARKS
sleep(.5)
ap.keys.send('UI_Select') # Select BOOKMARKS
sleep(.25)
ap.keys.send('UI_Right') # Go to FAVORITES
sleep(.25)
# If bookmark type is Fav, do nothing as this is the first item
if bookmark_type.lower().startswith("bod"):
ap.keys.send('UI_Down', repeat=1) # Go to BODIES
elif bookmark_type.lower().startswith("sta"):
ap.keys.send('UI_Down', repeat=2) # Go to STATIONS
elif bookmark_type.lower().startswith("set"):
ap.keys.send('UI_Down', repeat=3) # Go to SETTLEMENTS
sleep(.25)
ap.keys.send('UI_Select') # Select bookmark type, moves you to bookmark list
ap.keys.send('UI_Left') # Sometimes the first bookmark is not selected, so we try to force it.
ap.keys.send('UI_Right')
sleep(.25)
ap.keys.send('UI_Down', repeat=bookmark_position - 1)
sleep(.25)
ap.keys.send('UI_Select', hold=3.0)
# Close System Map
ap.keys.send('SystemMapOpen')
sleep(0.5)
return True
elif bookmark_type.lower().startswith("nav"):
# TODO - Move to, or call Nav Panel code instead?
# This is a nav-panel bookmark
# Goto cockpit view
self.ap.ship_control.goto_cockpit_view()
# get to the Left Panel menu: Navigation
ap.keys.send("HeadLookReset")
ap.keys.send("UIFocus", state=1)
ap.keys.send("UI_Left")
ap.keys.send("UIFocus", state=0) # this gets us over to the Nav panel
ap.keys.send('UI_Up', hold=4)
ap.keys.send('UI_Down', repeat=bookmark_position - 1)
sleep(1.0)
ap.keys.send('UI_Select')
sleep(0.25)
ap.keys.send('UI_Select')
ap.keys.send("UI_Back")
ap.keys.send("HeadLookReset")
return True
return False
def goto_system_map(self):
""" Open System Map if we are not there.
"""
if self.status_parser.get_gui_focus() != GuiFocusSystemMap:
logger.debug("Opening System Map")
# Goto cockpit view
self.ap.ship_control.goto_cockpit_view()
# Goto System Map
self.ap.keys.send('SystemMapOpen')
# Wait for map to load
# if not self.status_parser.wait_for_gui_focus(GuiFocusSystemMap):
# logger.debug("goto_galaxy_map: System map did not open.")
# TODO - Add OCR to check screen loaded
# Scale the regions based on the target resolution.
scl_reg = reg_scale_for_station(self.reg['cartographics'], self.screen.screen_width,
self.screen.screen_height)
# Wait for screen to appear. The text is the same, regardless of language.
res = self.ocr.wait_for_text(self.ap, ["CARTOGRAPHICS"], scl_reg)
# sleep(3.5)
else:
logger.debug("System Map is already open")
self.keys.send('UI_Left')
self.keys.send('UI_Up', hold=2)
self.keys.send('UI_Left')