mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-25 00:13:27 +08:00
PB-ID Copy Button
This commit is contained in:
parent
266f39e260
commit
cb4d0ee809
@ -36,9 +36,9 @@ class PopupText(ba.Actor):
|
||||
if len(color) == 3:
|
||||
color = (color[0], color[1], color[2], 1.0)
|
||||
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] +
|
||||
offset[0] + random_offset * (0.5 - random.random()))
|
||||
offset[2] + random_offset * (0.5 - random.random()))
|
||||
|
||||
self.node = ba.newnode('text',
|
||||
attrs={
|
||||
|
||||
@ -20,9 +20,9 @@ class ServerDialogWindow(ba.Window):
|
||||
self._dialog_id = data['dialogID']
|
||||
txt = ba.Lstr(translate=('serverResponses', data['text']),
|
||||
subs=data.get('subs', [])).evaluate()
|
||||
txt = txt.strip()
|
||||
self.txt = txt.strip()
|
||||
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)
|
||||
self._width = 500
|
||||
self._height = 130 + min(200, txt_height)
|
||||
@ -43,11 +43,13 @@ class ServerDialogWindow(ba.Window):
|
||||
scale=txt_scale,
|
||||
h_align='center',
|
||||
v_align='center',
|
||||
text=txt,
|
||||
text=self.txt,
|
||||
maxwidth=self._width * 0.85,
|
||||
max_height=(self._height - 110))
|
||||
show_cancel = data.get('showCancel', True)
|
||||
show_copy = ba.clipboard_is_supported()
|
||||
self._cancel_button: ba.Widget | None
|
||||
self._copy_button: ba.Widget | None
|
||||
if show_cancel:
|
||||
self._cancel_button = ba.buttonwidget(
|
||||
parent=self._root_widget,
|
||||
@ -56,11 +58,22 @@ class ServerDialogWindow(ba.Window):
|
||||
autoselect=True,
|
||||
label=ba.Lstr(resource='cancelText'),
|
||||
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:
|
||||
self._cancel_button = None
|
||||
self._copy_button = None
|
||||
self._ok_button = ba.buttonwidget(
|
||||
parent=self._root_widget,
|
||||
position=((self._width - 182) if show_cancel else
|
||||
(self._width - 182) if show_copy else
|
||||
(self._width * 0.5 - 80), 30),
|
||||
size=(160, 60),
|
||||
autoselect=True,
|
||||
@ -71,6 +84,10 @@ class ServerDialogWindow(ba.Window):
|
||||
start_button=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:
|
||||
if ba.time(ba.TimeType.REAL,
|
||||
ba.TimeFormat.MILLISECONDS) - self._starttime < 1000:
|
||||
@ -93,4 +110,4 @@ class ServerDialogWindow(ba.Window):
|
||||
'dialogID': self._dialog_id,
|
||||
'response': 0
|
||||
})
|
||||
ba.containerwidget(edit=self._root_widget, transition='out_scale')
|
||||
ba.containerwidget(edit=self._root_widget, transition='out_scale')
|
||||
Loading…
x
Reference in New Issue
Block a user