-
Notifications
You must be signed in to change notification settings - Fork 10.5k
ui: refactor constant declarations #36860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ca8bc72
3b2c501
ca9f5f6
35f0590
087f3ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,11 +51,6 @@ class Colors: | |
| HEADER_GRADIENT_END = rl.BLANK | ||
|
|
||
|
|
||
| UI_CONFIG = UIConfig() | ||
| FONT_SIZES = FontSizes() | ||
| COLORS = Colors() | ||
|
|
||
|
|
||
| class HudRenderer(Widget): | ||
| def __init__(self): | ||
| super().__init__() | ||
|
|
@@ -70,7 +65,7 @@ def __init__(self): | |
| self._font_bold: rl.Font = gui_app.font(FontWeight.BOLD) | ||
| self._font_medium: rl.Font = gui_app.font(FontWeight.MEDIUM) | ||
|
|
||
| self._exp_button: ExpButton = ExpButton(UI_CONFIG.button_size, UI_CONFIG.wheel_icon_size) | ||
| self._exp_button: ExpButton = ExpButton(UIConfig.button_size, UIConfig.wheel_icon_size) | ||
|
|
||
| def _update_state(self) -> None: | ||
| """Update HUD state based on car state and controls state.""" | ||
|
|
@@ -107,74 +102,74 @@ def _render(self, rect: rl.Rectangle) -> None: | |
| int(rect.x), | ||
| int(rect.y), | ||
| int(rect.width), | ||
| UI_CONFIG.header_height, | ||
| COLORS.HEADER_GRADIENT_START, | ||
| COLORS.HEADER_GRADIENT_END, | ||
| UIConfig.header_height, | ||
| Colors.HEADER_GRADIENT_START, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename the classes to all upper case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then, shall we change the Colors of sidebar.py to capital letters as well? sidebar.py -> Color schemeclass Colors: Status colorsGOOD = rl.WHITE UI elementsMETRIC_BORDER = rl.Color(255, 255, 255, 85) |
||
| Colors.HEADER_GRADIENT_END, | ||
| ) | ||
|
|
||
| if self.is_cruise_available: | ||
| self._draw_set_speed(rect) | ||
|
|
||
| self._draw_current_speed(rect) | ||
|
|
||
| button_x = rect.x + rect.width - UI_CONFIG.border_size - UI_CONFIG.button_size | ||
| button_y = rect.y + UI_CONFIG.border_size | ||
| self._exp_button.render(rl.Rectangle(button_x, button_y, UI_CONFIG.button_size, UI_CONFIG.button_size)) | ||
| button_x = rect.x + rect.width - UIConfig.border_size - UIConfig.button_size | ||
| button_y = rect.y + UIConfig.border_size | ||
| self._exp_button.render(rl.Rectangle(button_x, button_y, UIConfig.button_size, UIConfig.button_size)) | ||
|
|
||
| def user_interacting(self) -> bool: | ||
| return self._exp_button.is_pressed | ||
|
|
||
| def _draw_set_speed(self, rect: rl.Rectangle) -> None: | ||
| """Draw the MAX speed indicator box.""" | ||
| set_speed_width = UI_CONFIG.set_speed_width_metric if ui_state.is_metric else UI_CONFIG.set_speed_width_imperial | ||
| x = rect.x + 60 + (UI_CONFIG.set_speed_width_imperial - set_speed_width) // 2 | ||
| set_speed_width = UIConfig.set_speed_width_metric if ui_state.is_metric else UIConfig.set_speed_width_imperial | ||
| x = rect.x + 60 + (UIConfig.set_speed_width_imperial - set_speed_width) // 2 | ||
| y = rect.y + 45 | ||
|
|
||
| set_speed_rect = rl.Rectangle(x, y, set_speed_width, UI_CONFIG.set_speed_height) | ||
| rl.draw_rectangle_rounded(set_speed_rect, 0.35, 10, COLORS.BLACK_TRANSLUCENT) | ||
| rl.draw_rectangle_rounded_lines_ex(set_speed_rect, 0.35, 10, 6, COLORS.BORDER_TRANSLUCENT) | ||
| set_speed_rect = rl.Rectangle(x, y, set_speed_width, UIConfig.set_speed_height) | ||
| rl.draw_rectangle_rounded(set_speed_rect, 0.35, 10, Colors.BLACK_TRANSLUCENT) | ||
| rl.draw_rectangle_rounded_lines_ex(set_speed_rect, 0.35, 10, 6, Colors.BORDER_TRANSLUCENT) | ||
|
|
||
| max_color = COLORS.GREY | ||
| set_speed_color = COLORS.DARK_GREY | ||
| max_color = Colors.GREY | ||
| set_speed_color = Colors.DARK_GREY | ||
| if self.is_cruise_set: | ||
| set_speed_color = COLORS.WHITE | ||
| set_speed_color = Colors.WHITE | ||
| if ui_state.status == UIStatus.ENGAGED: | ||
| max_color = COLORS.ENGAGED | ||
| max_color = Colors.ENGAGED | ||
| elif ui_state.status == UIStatus.DISENGAGED: | ||
| max_color = COLORS.DISENGAGED | ||
| max_color = Colors.DISENGAGED | ||
| elif ui_state.status == UIStatus.OVERRIDE: | ||
| max_color = COLORS.OVERRIDE | ||
| max_color = Colors.OVERRIDE | ||
|
|
||
| max_text = tr("MAX") | ||
| max_text_width = measure_text_cached(self._font_semi_bold, max_text, FONT_SIZES.max_speed).x | ||
| max_text_width = measure_text_cached(self._font_semi_bold, max_text, FontSizes.max_speed).x | ||
| rl.draw_text_ex( | ||
| self._font_semi_bold, | ||
| max_text, | ||
| rl.Vector2(x + (set_speed_width - max_text_width) / 2, y + 27), | ||
| FONT_SIZES.max_speed, | ||
| FontSizes.max_speed, | ||
| 0, | ||
| max_color, | ||
| ) | ||
|
|
||
| set_speed_text = CRUISE_DISABLED_CHAR if not self.is_cruise_set else str(round(self.set_speed)) | ||
| speed_text_width = measure_text_cached(self._font_bold, set_speed_text, FONT_SIZES.set_speed).x | ||
| speed_text_width = measure_text_cached(self._font_bold, set_speed_text, FontSizes.set_speed).x | ||
| rl.draw_text_ex( | ||
| self._font_bold, | ||
| set_speed_text, | ||
| rl.Vector2(x + (set_speed_width - speed_text_width) / 2, y + 77), | ||
| FONT_SIZES.set_speed, | ||
| FontSizes.set_speed, | ||
| 0, | ||
| set_speed_color, | ||
| ) | ||
|
|
||
| def _draw_current_speed(self, rect: rl.Rectangle) -> None: | ||
| """Draw the current vehicle speed and unit.""" | ||
| speed_text = str(round(self.speed)) | ||
| speed_text_size = measure_text_cached(self._font_bold, speed_text, FONT_SIZES.current_speed) | ||
| speed_text_size = measure_text_cached(self._font_bold, speed_text, FontSizes.current_speed) | ||
| speed_pos = rl.Vector2(rect.x + rect.width / 2 - speed_text_size.x / 2, 180 - speed_text_size.y / 2) | ||
| rl.draw_text_ex(self._font_bold, speed_text, speed_pos, FONT_SIZES.current_speed, 0, COLORS.WHITE) | ||
| rl.draw_text_ex(self._font_bold, speed_text, speed_pos, FontSizes.current_speed, 0, Colors.WHITE) | ||
|
|
||
| unit_text = tr("km/h") if ui_state.is_metric else tr("mph") | ||
| unit_text_size = measure_text_cached(self._font_medium, unit_text, FONT_SIZES.speed_unit) | ||
| unit_text_size = measure_text_cached(self._font_medium, unit_text, FontSizes.speed_unit) | ||
| unit_pos = rl.Vector2(rect.x + rect.width / 2 - unit_text_size.x / 2, 290 - unit_text_size.y / 2) | ||
| rl.draw_text_ex(self._font_medium, unit_text, unit_pos, FONT_SIZES.speed_unit, 0, COLORS.WHITE_TRANSLUCENT) | ||
| rl.draw_text_ex(self._font_medium, unit_text, unit_pos, FontSizes.speed_unit, 0, Colors.WHITE_TRANSLUCENT) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think they need to be dataclasses either, maybe enum if anything, but not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling in duplicate only in the hud_render.py