|
| 1 | +import wx |
| 2 | +import wx.lib.agw.hyperlink |
| 3 | + |
| 4 | +from amulet_map_editor import lang |
| 5 | + |
| 6 | + |
| 7 | +class SupportDialog(wx.Dialog): |
| 8 | + def __init__(self, parent: wx.Window, wait_time: int, is_first: bool): |
| 9 | + super().__init__(parent, style=wx.CAPTION) |
| 10 | + self.SetTitle(lang.get("support_dialog.title")) |
| 11 | + |
| 12 | + self._wait_time = wait_time |
| 13 | + |
| 14 | + main_sizer = wx.BoxSizer(wx.VERTICAL) |
| 15 | + |
| 16 | + title = wx.StaticText( |
| 17 | + self, |
| 18 | + wx.ID_ANY, |
| 19 | + lang.get("support_dialog.title"), |
| 20 | + style=wx.ALIGN_CENTER_HORIZONTAL, |
| 21 | + ) |
| 22 | + font = title.GetFont() |
| 23 | + font.SetPointSize(50) |
| 24 | + title.SetFont(font) |
| 25 | + main_sizer.Add(title, 0, wx.ALL | wx.EXPAND, 5) |
| 26 | + |
| 27 | + content_1 = wx.StaticText( |
| 28 | + self, |
| 29 | + wx.ID_ANY, |
| 30 | + lang.get("support_dialog.content_1"), |
| 31 | + style=wx.ALIGN_CENTER_HORIZONTAL, |
| 32 | + ) |
| 33 | + font = content_1.GetFont() |
| 34 | + font.SetPointSize(12) |
| 35 | + content_1.SetFont(font) |
| 36 | + content_1.Wrap(750) |
| 37 | + main_sizer.Add(content_1, 0, wx.EXPAND) |
| 38 | + |
| 39 | + main_sizer.AddSpacer(20) |
| 40 | + |
| 41 | + content_2 = wx.StaticText( |
| 42 | + self, |
| 43 | + wx.ID_ANY, |
| 44 | + lang.get("support_dialog.content_2"), |
| 45 | + style=wx.ALIGN_CENTER_HORIZONTAL, |
| 46 | + ) |
| 47 | + font = content_2.GetFont() |
| 48 | + font.SetPointSize(12) |
| 49 | + content_2.SetFont(font) |
| 50 | + content_2.Wrap(750) |
| 51 | + main_sizer.Add(content_2, 0, wx.EXPAND) |
| 52 | + |
| 53 | + main_sizer.AddSpacer(20) |
| 54 | + |
| 55 | + github_sponsor_link = wx.lib.agw.hyperlink.HyperLinkCtrl( |
| 56 | + self, |
| 57 | + wx.ID_ANY, |
| 58 | + lang.get("support_dialog.github_sponsor"), |
| 59 | + URL="https://github.com/sponsors/Amulet-Team", |
| 60 | + ) |
| 61 | + font = github_sponsor_link.GetFont() |
| 62 | + font.SetPointSize(12) |
| 63 | + github_sponsor_link.SetFont(font) |
| 64 | + main_sizer.Add(github_sponsor_link, 0, wx.ALIGN_CENTER) |
| 65 | + |
| 66 | + main_sizer.AddSpacer(10) |
| 67 | + |
| 68 | + paypal_sponsor_link = wx.lib.agw.hyperlink.HyperLinkCtrl( |
| 69 | + self, |
| 70 | + wx.ID_ANY, |
| 71 | + lang.get("support_dialog.paypal_sponsor"), |
| 72 | + URL="https://www.paypal.com/donate/?hosted_button_id=6G7P8K36W7TX2", |
| 73 | + ) |
| 74 | + font = paypal_sponsor_link.GetFont() |
| 75 | + font.SetPointSize(12) |
| 76 | + paypal_sponsor_link.SetFont(font) |
| 77 | + main_sizer.Add(paypal_sponsor_link, 0, wx.ALIGN_CENTER) |
| 78 | + |
| 79 | + main_sizer.AddSpacer(20) |
| 80 | + |
| 81 | + content_3 = wx.StaticText( |
| 82 | + self, |
| 83 | + wx.ID_ANY, |
| 84 | + lang.get("support_dialog.content_3"), |
| 85 | + style=wx.ALIGN_CENTER_HORIZONTAL, |
| 86 | + ) |
| 87 | + font = content_3.GetFont() |
| 88 | + font.SetPointSize(12) |
| 89 | + content_3.SetFont(font) |
| 90 | + content_3.Wrap(750) |
| 91 | + main_sizer.Add(content_3, 0, wx.EXPAND) |
| 92 | + |
| 93 | + main_sizer.AddSpacer(10) |
| 94 | + |
| 95 | + button_sizer = wx.StdDialogButtonSizer() |
| 96 | + main_sizer.Add(button_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 4) |
| 97 | + |
| 98 | + self._ignore_button = wx.Button(self, wx.ID_CANCEL) |
| 99 | + self._ignore_button.SetDefault() |
| 100 | + self.SetEscapeId(self._ignore_button.GetId()) |
| 101 | + button_sizer.Add(self._ignore_button) |
| 102 | + |
| 103 | + self._support_button = wx.Button( |
| 104 | + self, wx.ID_OK, lang.get("support_dialog.support_button") |
| 105 | + ) |
| 106 | + if is_first: |
| 107 | + self._support_button.Disable() |
| 108 | + button_sizer.Add(self._support_button) |
| 109 | + self.SetAffirmativeId(self._support_button.GetId()) |
| 110 | + |
| 111 | + self._set_ignore_text() |
| 112 | + |
| 113 | + button_sizer.Realize() |
| 114 | + |
| 115 | + self.SetSizer(main_sizer) |
| 116 | + main_sizer.Fit(self) |
| 117 | + |
| 118 | + self._timer = wx.Timer(self) |
| 119 | + if 0 < self._wait_time: |
| 120 | + self.Bind(wx.EVT_TIMER, self._on_timer, self._timer) |
| 121 | + self._timer.Start(1000) |
| 122 | + |
| 123 | + self.Layout() |
| 124 | + |
| 125 | + def _set_ignore_text(self) -> None: |
| 126 | + if 0 < self._wait_time: |
| 127 | + self._ignore_button.Disable() |
| 128 | + self._ignore_button.SetLabel( |
| 129 | + lang.get("support_dialog.ignore_button_wait").format(t=self._wait_time) |
| 130 | + ) |
| 131 | + else: |
| 132 | + self._support_button.Enable() |
| 133 | + self._ignore_button.Enable() |
| 134 | + self._ignore_button.SetLabel(lang.get("support_dialog.ignore_button")) |
| 135 | + self.Layout() |
| 136 | + |
| 137 | + def _on_timer(self, evt) -> None: |
| 138 | + if 0 < self._wait_time: |
| 139 | + self._wait_time -= 1 |
| 140 | + if self._wait_time <= 0: |
| 141 | + self._timer.Stop() |
| 142 | + self._set_ignore_text() |
0 commit comments