PB-ID Copy Button

This commit is contained in:
Vishal 2022-09-05 20:33:47 +05:30 committed by GitHub
parent 266f39e260
commit cb4d0ee809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -36,9 +36,9 @@ class PopupText(ba.Actor):
if len(color) == 3: if len(color) == 3:
color = (color[0], color[1], color[2], 1.0) color = (color[0], color[1], color[2], 1.0)
pos = (position[0] + offset[0] + random_offset * pos = (position[0] + offset[0] + random_offset *
(0.5 - random.random()), position[1] + offset[0] + (0.5 - random.random()), position[1] + offset[1] +
random_offset * (0.5 - random.random()), position[2] + random_offset * (0.5 - random.random()), position[2] +
offset[0] + random_offset * (0.5 - random.random())) offset[2] + random_offset * (0.5 - random.random()))
self.node = ba.newnode('text', self.node = ba.newnode('text',
attrs={ attrs={

View File

@ -20,9 +20,9 @@ class ServerDialogWindow(ba.Window):
self._dialog_id = data['dialogID'] self._dialog_id = data['dialogID']
txt = ba.Lstr(translate=('serverResponses', data['text']), txt = ba.Lstr(translate=('serverResponses', data['text']),
subs=data.get('subs', [])).evaluate() subs=data.get('subs', [])).evaluate()
txt = txt.strip() self.txt = txt.strip()
txt_scale = 1.5 txt_scale = 1.5
txt_height = (_ba.get_string_height(txt, suppress_warning=True) * txt_height = (_ba.get_string_height(self.txt, suppress_warning=True) *
txt_scale) txt_scale)
self._width = 500 self._width = 500
self._height = 130 + min(200, txt_height) self._height = 130 + min(200, txt_height)
@ -43,11 +43,13 @@ class ServerDialogWindow(ba.Window):
scale=txt_scale, scale=txt_scale,
h_align='center', h_align='center',
v_align='center', v_align='center',
text=txt, text=self.txt,
maxwidth=self._width * 0.85, maxwidth=self._width * 0.85,
max_height=(self._height - 110)) max_height=(self._height - 110))
show_cancel = data.get('showCancel', True) show_cancel = data.get('showCancel', True)
show_copy = ba.clipboard_is_supported()
self._cancel_button: ba.Widget | None self._cancel_button: ba.Widget | None
self._copy_button: ba.Widget | None
if show_cancel: if show_cancel:
self._cancel_button = ba.buttonwidget( self._cancel_button = ba.buttonwidget(
parent=self._root_widget, parent=self._root_widget,
@ -56,11 +58,22 @@ class ServerDialogWindow(ba.Window):
autoselect=True, autoselect=True,
label=ba.Lstr(resource='cancelText'), label=ba.Lstr(resource='cancelText'),
on_activate_call=self._cancel_press) on_activate_call=self._cancel_press)
elif show_copy:
self._cancel_button = None
self._copy_button = ba.buttonwidget(
parent=self._root_widget,
position=(30, 30),
size=(160, 60),
autoselect=True,
label=ba.Lstr(resource='copyText'),
on_activate_call=self._copy_press)
else: else:
self._cancel_button = None self._cancel_button = None
self._copy_button = None
self._ok_button = ba.buttonwidget( self._ok_button = ba.buttonwidget(
parent=self._root_widget, parent=self._root_widget,
position=((self._width - 182) if show_cancel else position=((self._width - 182) if show_cancel else
(self._width - 182) if show_copy else
(self._width * 0.5 - 80), 30), (self._width * 0.5 - 80), 30),
size=(160, 60), size=(160, 60),
autoselect=True, autoselect=True,
@ -71,6 +84,10 @@ class ServerDialogWindow(ba.Window):
start_button=self._ok_button, start_button=self._ok_button,
selected_child=self._ok_button) selected_child=self._ok_button)
def _copy_press(self) -> None:
ba.clipboard_set_text(self.txt)
ba.screenmessage("Copied To Clipboard", color = (0, 1, 0))
def _ok_press(self) -> None: def _ok_press(self) -> None:
if ba.time(ba.TimeType.REAL, if ba.time(ba.TimeType.REAL,
ba.TimeFormat.MILLISECONDS) - self._starttime < 1000: ba.TimeFormat.MILLISECONDS) - self._starttime < 1000: