Skip to content

Commit

Permalink
Merge branch 'feature/system-overlay' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aussig committed Aug 31, 2023
2 parents f22637a + 1c5c285 commit 1eb5741
Show file tree
Hide file tree
Showing 7 changed files with 436 additions and 362 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New Features:

* In-game overlay now briefly displays a BGS summary for the current system when doing BGS work.
* Space Conflict Zones are now tracked automatically. As with Ground CZs, the game doesn't give us enough information to detect whether you've actually **won** the CZ, so if you drop in and log a kill within 5 minutes, this is tallied as a win. Manual controls are still available to adjust if you need.
* Thargoid War system progress is now displayed as a progress bar on the in-game overlay when in a TW active system.
* An activity indicator now briefly flashes green on the overlay when BGS-Tally logs BGS or TW activity.
Expand Down
343 changes: 293 additions & 50 deletions bgstally/activity.py

Large diffs are not rendered by default.

90 changes: 66 additions & 24 deletions bgstally/overlay.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from bgstally.debug import Debug
import textwrap

from bgstally.constants import CheckStates
from bgstally.debug import Debug

try:
from EDMCOverlay import edmcoverlay
except ImportError:
edmcoverlay = None

HEIGHT_CHARACTER_NORMAL = 14
HEIGHT_CHARACTER_LARGE = 20
WIDTH_CHARACTER_NORMAL = 4
WIDTH_CHARACTER_LARGE = 6
MAX_LINES_PER_PANEL = 30


class Overlay:
"""
Expand All @@ -20,7 +26,7 @@ def __init__(self, bgstally):
self._check_overlay()


def display_message(self, frame_name: str, message: str, fit_to_width: bool = False, ttl_override: int = None, text_colour_override: str = None):
def display_message(self, frame_name: str, message: str, fit_to_text: bool = False, ttl_override: int = None, text_colour_override: str = None, title_colour_override: str = None, has_title: bool = False):
"""
Display a message in the overlay
"""
Expand All @@ -29,13 +35,48 @@ def display_message(self, frame_name: str, message: str, fit_to_width: bool = Fa

try:
fi:dict = self._get_frame_info(frame_name)
message_width:int = len(message) * WIDTH_CHARACTER_NORMAL if fi["text_size"] == "normal" else len(message) * WIDTH_CHARACTER_LARGE
ttl:int = ttl_override if ttl_override else fi["ttl"]
text_colour:str = text_colour_override if text_colour_override else fi["text_colour"]

if fi["border_colour"] and fi["fill_colour"]:
self.edmcoverlay.send_shape(f"bgstally-frame-{frame_name}", "rect", fi["border_colour"], fi["fill_colour"], fi["x"], fi["y"], message_width + 30 if fit_to_width else fi["w"], fi["h"], ttl=ttl)
self.edmcoverlay.send_message(f"bgstally-msg-{frame_name}", message, text_colour, fi["x"] + 10, fi["y"] + 5, ttl=ttl, size=fi["text_size"])
# Split text on line breaks, then limit length of each line
lines:list = message.splitlines()
segments:list = []
for line in lines:
segments += textwrap.wrap(line, width = 70, subsequent_indent = ' ')

message_width:int = len(max(segments, key = len)) * WIDTH_CHARACTER_NORMAL if fi['text_size'] == "normal" else len(max(segments, key = len)) * WIDTH_CHARACTER_LARGE
message_height:int = len(segments) * HEIGHT_CHARACTER_NORMAL if fi['text_size'] == "normal" else len(max(segments, key = len)) * HEIGHT_CHARACTER_LARGE
ttl:int = ttl_override if ttl_override else fi['ttl']
title_colour:str = title_colour_override if title_colour_override else fi['title_colour']
text_colour:str = text_colour_override if text_colour_override else fi['text_colour']

# Border
if fi['border_colour'] and fi['fill_colour']:
self.edmcoverlay.send_shape(f"bgstally-frame-{frame_name}", "rect", fi['border_colour'], fi['fill_colour'], fi['x'], fi['y'], message_width + 30 if fit_to_text else fi['w'], message_height + 10 if fit_to_text else fi['h'], ttl=ttl)

yoffset:int = 0
index:int = 0

# Title
if has_title:
self.edmcoverlay.send_message(f"bgstally-msg-{frame_name}-{index}", segments[index], title_colour, fi['x'] + 10, fi['y'] + 5 + yoffset, ttl=ttl, size="large")
yoffset += HEIGHT_CHARACTER_LARGE
index += 1

# Text
while index <= MAX_LINES_PER_PANEL:
if index < len(segments):
if index < MAX_LINES_PER_PANEL:
# Line has content
self.edmcoverlay.send_message(f"bgstally-msg-{frame_name}-{index}", segments[index], text_colour, fi['x'] + 10, fi['y'] + 5 + yoffset, ttl=ttl, size=fi['text_size'])
else:
# Last line
self.edmcoverlay.send_message(f"bgstally-msg-{frame_name}-{index}", "[...]", text_colour, fi['x'] + 10, fi['y'] + 5 + yoffset, ttl=ttl, size=fi['text_size'])
else:
# Unused line, clear
self.edmcoverlay.send_message(f"bgstally-msg-{frame_name}-{index}", "", text_colour, fi['x'] + 10, fi['y'] + 5 + yoffset, ttl=ttl, size=fi['text_size'])

yoffset += HEIGHT_CHARACTER_NORMAL if fi['text_size'] == "normal" else HEIGHT_CHARACTER_LARGE
index += 1

self.problem_displaying = False

except Exception as e:
Expand All @@ -54,10 +95,10 @@ def display_indicator(self, frame_name: str, ttl_override: int = None, fill_colo

try:
fi = self._get_frame_info(frame_name)
ttl = ttl_override if ttl_override else fi["ttl"]
fill_colour = fill_colour_override if fill_colour_override else fi["fill_colour"]
border_colour = border_colour_override if border_colour_override else fi["border_colour"]
self.edmcoverlay.send_shape(f"bgstally-frame-{frame_name}", "rect", border_colour, fill_colour, fi["x"], fi["y"], fi["w"], fi["h"], ttl=ttl)
ttl = ttl_override if ttl_override else fi['ttl']
fill_colour = fill_colour_override if fill_colour_override else fi['fill_colour']
border_colour = border_colour_override if border_colour_override else fi['border_colour']
self.edmcoverlay.send_shape(f"bgstally-frame-{frame_name}", "rect", border_colour, fill_colour, fi['x'], fi['y'], fi['w'], fi['h'], ttl=ttl)

except Exception as e:
if not self.problem_displaying:
Expand All @@ -75,15 +116,15 @@ def display_progress_bar(self, frame_name: str, message: str, progress: float =

try:
fi:dict = self._get_frame_info(frame_name)
ttl:int = ttl_override if ttl_override else fi["ttl"]
bar_width:int = int(fi["w"] * progress)
ttl:int = ttl_override if ttl_override else fi['ttl']
bar_width:int = int(fi['w'] * progress)
bar_height:int = 10

#vect:list = [{"x":int(cx+(coords["x"]*hw)), "y":int(cy-(coords["y"]*hh))]
#vect:list = [{'x':int(cx+(coords['x']*hw)), 'y':int(cy-(coords['y']*hh))]

self.edmcoverlay.send_message(f"bgstally-msg-{frame_name}", message, fi["text_colour"], fi["x"] + 10, fi["y"] + 5, ttl=ttl, size=fi["text_size"])
self.edmcoverlay.send_shape(f"bgstally-bar-{frame_name}", "rect", "#ffffff", fi["fill_colour"], fi["x"] + 10, fi["y"] + 20, bar_width, bar_height, ttl=ttl)
self.edmcoverlay.send_shape(f"bgstally-frame-{frame_name}", "rect", "#ffffff", fi["border_colour"], fi["x"] + 10 + bar_width, fi["y"] + 20, fi["w"] - bar_width, bar_height, ttl=ttl)
self.edmcoverlay.send_message(f"bgstally-msg-{frame_name}", message, fi['text_colour'], fi['x'] + 10, fi['y'] + 5, ttl=ttl, size=fi['text_size'])
self.edmcoverlay.send_shape(f"bgstally-bar-{frame_name}", "rect", "#ffffff", fi['fill_colour'], fi['x'] + 10, fi['y'] + 20, bar_width, bar_height, ttl=ttl)
self.edmcoverlay.send_shape(f"bgstally-frame-{frame_name}", "rect", "#ffffff", fi['border_colour'], fi['x'] + 10 + bar_width, fi['y'] + 20, fi['w'] - bar_width, bar_height, ttl=ttl)

self.problem_displaying = False

Expand Down Expand Up @@ -116,13 +157,14 @@ def _get_frame_info(self, frame: str) -> dict:
Get the properties of the type of message frame we are displaying
"""
if frame == "info":
return {"border_colour": "green", "fill_colour": "green", "text_colour": "#ffffff", "x": 900, "y": 5, "w": 100, "h": 25, "ttl": 30, "text_size": "normal"}
return {'border_colour': "green", 'fill_colour': "green", 'text_colour': "#ffffff", 'title_colour': "#ffffff", 'x': 900, 'y': 5, 'w': 100, 'h': 25, 'ttl': 30, 'text_size': "normal"}
elif frame == "indicator":
return {"border_colour": "#ffffff", "fill_colour": "#00cc00", "text_colour": "red", "x": 970, "y": 10, "w": 10, "h": 15, "ttl": 1, "text_size": "normal"}
return {'border_colour': "#ffffff", 'fill_colour': "#00cc00", 'text_colour': "red", 'title_colour': "red", 'x': 970, 'y': 10, 'w': 10, 'h': 15, 'ttl': 1, 'text_size': "normal"}
elif frame == "tick":
return {"border_colour": None, "fill_colour": None, "text_colour": "#ffffff", "x": 1000, "y": 0, "w": 100, "h": 25, "ttl": 3, "text_size": "large"}
return {'border_colour': None, 'fill_colour': None, 'text_colour': "#ffffff", 'title_colour': "#ffffff", 'x': 1000, 'y': 0, 'w': 100, 'h': 25, 'ttl': 3, 'text_size': "large"}
elif frame == "tickwarn":
return {"border_colour": None, "fill_colour": None, "text_colour": "red", "x": 1000, "y": 20, "w": 100, "h": 25, "ttl": 1, "text_size": "normal"}
return {'border_colour': None, 'fill_colour': None, 'text_colour': "red", 'title_colour': "red", 'x': 1000, 'y': 20, 'w': 100, 'h': 25, 'ttl': 1, 'text_size': "normal"}
elif frame == "tw":
return {"border_colour": "#1a4f09", "fill_colour": "#63029c", "text_colour": "#ffffff", "x": 1000, "y": 60, "w": 100, "h": 25, "ttl": 3, "text_size": "normal"}

return {'border_colour': "#1a4f09", 'fill_colour': "#63029c", 'text_colour': "#ffffff", 'title_colour': "#ffffff", 'x': 1000, 'y': 60, 'w': 100, 'h': 25, 'ttl': 3, 'text_size': "normal"}
elif frame == "system_info":
return {'border_colour': None, 'fill_colour': None, 'text_colour': "#ffffff", 'title_colour': "green", 'x': 1000, 'y': 95, 'w': 100, 'h': 100, 'ttl': 30, 'text_size': "normal"}
16 changes: 15 additions & 1 deletion bgstally/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing import List, Optional

import myNotebook as nb
import semantic_version
from ttkHyperlinkLabel import HyperlinkLabel

from bgstally.activity import Activity
Expand Down Expand Up @@ -46,6 +45,7 @@ def __init__(self, bgstally):
self.image_button_carrier = PhotoImage(file = path.join(self.bgstally.plugin_dir, FOLDER_ASSETS, "button_carrier.png"))

self.indicate_activity:bool = False
self.report_system_address:str = None

# Single-instance windows
self.window_cmdrs:WindowCMDRs = WindowCMDRs(self.bgstally)
Expand Down Expand Up @@ -175,6 +175,14 @@ def get_prefs_frame(self, parent_frame: tk.Frame):
return frame


def show_system_report(self, system_address:int):
"""
Show the system report overlay
"""
self.indicate_activity = True
self.report_system_address = str(system_address)


def _worker(self) -> None:
"""
Handle thread work for overlay
Expand Down Expand Up @@ -214,6 +222,12 @@ def _worker(self) -> None:

self.bgstally.overlay.display_progress_bar("tw", f"TW War Progress in {current_system.get('System', 'Unknown')}: {percent}%", progress)

if self.report_system_address is not None and current_activity is not None:
report_system:dict = current_activity.get_system_by_address(self.report_system_address)
if report_system is not None:
self.bgstally.overlay.display_message("system_info", current_activity.generate_text(DiscordActivity.BOTH, False, report_system['System']), fit_to_text=True, has_title=True)
self.report_system_address = None

sleep(TIME_WORKER_PERIOD_S)


Expand Down
12 changes: 12 additions & 0 deletions bgstally/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ def get_by_path(dic:dict, keys:list, default:any = None):
return default

return dic


def human_format(num):
"""
Format a BGS value into shortened human-readable text
"""
num = float('{:.3g}'.format(num))
magnitude = 0
while abs(num) >= 1000:
magnitude += 1
num /= 1000.0
return '{}{}'.format('{:f}'.format(num).rstrip('0').rstrip('.'), ['', 'K', 'M', 'B', 'T'][magnitude])
Loading

0 comments on commit 1eb5741

Please sign in to comment.