|
1 | 1 | import math
|
2 | 2 |
|
3 | 3 | from collections import deque
|
4 |
| -from typing import Dict, List, Union, Tuple, Optional |
| 4 | +from typing import Dict, List, Union, Tuple, Optional, Deque |
5 | 5 |
|
6 | 6 | import pygame
|
7 | 7 |
|
@@ -247,7 +247,7 @@ def __init__(
|
247 | 247 | self.ui_manager = manager
|
248 | 248 | self.shape_cache = self.ui_manager.get_theme().shape_cache
|
249 | 249 |
|
250 |
| - self.states_to_redraw_queue = deque([]) |
| 250 | + self.states_to_redraw_queue: Deque[str] = deque([]) |
251 | 251 | self.need_to_clean_up = True
|
252 | 252 |
|
253 | 253 | self.should_trigger_full_rebuild = True
|
@@ -772,29 +772,27 @@ def finalise_text(
|
772 | 772 | flags=pygame.SRCALPHA,
|
773 | 773 | depth=32,
|
774 | 774 | )
|
775 |
| - self.states[state_str].text_surface.fill("#00000000") |
| 775 | + text_surface = self.states[state_str].text_surface |
| 776 | + if text_surface is not None: |
| 777 | + text_surface.fill("#00000000") |
| 778 | + |
| 779 | + if only_text_changed: |
| 780 | + self.text_box_layout.blit_finalised_text_to_surf(text_surface) |
| 781 | + else: |
| 782 | + self.text_box_layout.set_default_text_colour( |
| 783 | + self.theming[text_colour_state_str] |
| 784 | + ) |
| 785 | + self.text_box_layout.set_default_text_shadow_colour( |
| 786 | + self.theming[text_shadow_colour_state_str] |
| 787 | + ) |
| 788 | + self.text_box_layout.finalise_to_surf(text_surface) |
776 | 789 |
|
777 |
| - if only_text_changed: |
778 |
| - self.text_box_layout.blit_finalised_text_to_surf( |
779 |
| - self.states[state_str].text_surface |
780 |
| - ) |
781 |
| - else: |
782 |
| - self.text_box_layout.set_default_text_colour( |
783 |
| - self.theming[text_colour_state_str] |
784 |
| - ) |
785 |
| - self.text_box_layout.set_default_text_shadow_colour( |
786 |
| - self.theming[text_shadow_colour_state_str] |
787 |
| - ) |
788 |
| - self.text_box_layout.finalise_to_surf( |
789 |
| - self.states[state_str].text_surface |
| 790 | + basic_blit( |
| 791 | + self.states[state_str].surface, |
| 792 | + text_surface, |
| 793 | + (0, 0), |
790 | 794 | )
|
791 | 795 |
|
792 |
| - basic_blit( |
793 |
| - self.states[state_str].surface, |
794 |
| - self.states[state_str].text_surface, |
795 |
| - (0, 0), |
796 |
| - ) |
797 |
| - |
798 | 796 | def apply_active_text_changes(self):
|
799 | 797 | """
|
800 | 798 | Updates the shape surface with any changes to the text surface. Useful when we've made
|
@@ -832,14 +830,15 @@ def set_text_alpha(self, alpha: int):
|
832 | 830 |
|
833 | 831 | :param alpha: the alpha to set.
|
834 | 832 | """
|
835 |
| - self.text_box_layout.set_alpha(alpha) |
836 |
| - self.redraw_state(self.active_state.state_id, add_text=False) |
837 |
| - self.finalise_text( |
838 |
| - self.active_state.state_id, |
839 |
| - f"{self.active_state.state_id}_text", |
840 |
| - f"{self.active_state.state_id}_text_shadow", |
841 |
| - only_text_changed=False, |
842 |
| - ) |
| 833 | + if self.text_box_layout is not None: |
| 834 | + self.text_box_layout.set_alpha(alpha) |
| 835 | + self.redraw_state(self.active_state.state_id, add_text=False) |
| 836 | + self.finalise_text( |
| 837 | + self.active_state.state_id, |
| 838 | + f"{self.active_state.state_id}_text", |
| 839 | + f"{self.active_state.state_id}_text_shadow", |
| 840 | + only_text_changed=False, |
| 841 | + ) |
843 | 842 |
|
844 | 843 | def redraw_active_state_no_text(self):
|
845 | 844 | """
|
@@ -877,7 +876,8 @@ def insert_text(
|
877 | 876 | + text
|
878 | 877 | + self.theming["text"][layout_index:]
|
879 | 878 | )
|
880 |
| - self.text_box_layout.insert_text(text, layout_index, parser) |
| 879 | + if self.text_box_layout is not None: |
| 880 | + self.text_box_layout.insert_text(text, layout_index, parser) |
881 | 881 |
|
882 | 882 | def toggle_text_cursor(self):
|
883 | 883 | """
|
|
0 commit comments