Refactor code structure for improved readability and maintainability
This commit is contained in:
+27
-38
@@ -37,13 +37,13 @@ const SWIPE_DELAY = 2000 # msec
|
||||
@onready var date_time: Label = $StageRows/TopMenu/InfoPanel/DateTime
|
||||
|
||||
@onready var g_speed_icons: Array = [
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed1,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed2,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed3,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed4,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed5,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed6,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed7,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed1,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed2,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed3,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed4,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed5,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed6,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed7,
|
||||
$StageRows/TopMenu/InfoPanel/Speed/Speed8
|
||||
]
|
||||
|
||||
@@ -51,7 +51,6 @@ const SWIPE_DELAY = 2000 # msec
|
||||
@onready var g_time_plus: TextureButton = $StageRows/TopMenu/TimePlus
|
||||
|
||||
|
||||
|
||||
var g_tween: Tween = null
|
||||
var g_dragged_start: Vector2 = Vector2.ZERO
|
||||
var g_scroll_start: int = 0
|
||||
@@ -73,37 +72,38 @@ var owniverse = Owniverse.new()
|
||||
func set_datetime(value: String):
|
||||
date_time.text = value
|
||||
|
||||
func on_putton_pressed(button_name: String):
|
||||
#emit_signal("button_pressed", button_name)
|
||||
print(button_name)
|
||||
#SaveManager.save_settings()
|
||||
#SaveManager.ch()
|
||||
#print(Global.filename)
|
||||
|
||||
|
||||
#func _on_speed_change(delta: int) -> void:
|
||||
#print(delta)
|
||||
func _on_indicator_pressed(indicator_name: String, page: int = 0):
|
||||
_set_description(indicator_name, page)
|
||||
|
||||
|
||||
func entity_activated(entity: OwniverseEntity) -> void:
|
||||
_control_page(entity)
|
||||
_set_description(entity)
|
||||
_set_entity_description(entity)
|
||||
|
||||
func _set_description(entity: OwniverseEntity) -> void:
|
||||
|
||||
func _set_entity_description(entity: OwniverseEntity) -> void:
|
||||
var description: String = "[b]" \
|
||||
+ Global.get_localized_item_description(entity.entity_name, "label") \
|
||||
+ "[/b]" \
|
||||
+ "\n" \
|
||||
+"[/b]" \
|
||||
+"\n" \
|
||||
+ Global.get_localized_item_description(entity.entity_name, "description")
|
||||
var desc_page = clamp(entity.entity_page, 0, 4)
|
||||
g_entity_descriptions[desc_page].text = description
|
||||
pass
|
||||
|
||||
|
||||
func _set_description(item_name: String, page: int) -> void:
|
||||
var description = Global.get_description(item_name + ".Name")
|
||||
description += "\n"
|
||||
description += Global.get_description(item_name + ".Description")
|
||||
g_entity_descriptions[page].text = description
|
||||
|
||||
|
||||
func _control_page(entity: OwniverseEntity) -> void:
|
||||
if !ActiveEntities.has(entity.entity_page):
|
||||
ActiveEntities[entity.entity_page] = null
|
||||
|
||||
var current_entity:OwniverseEntity = ActiveEntities[entity.entity_page]
|
||||
var current_entity: OwniverseEntity = ActiveEntities[entity.entity_page]
|
||||
if current_entity == entity:
|
||||
return
|
||||
|
||||
@@ -159,7 +159,7 @@ func _check_counters(delta: float) -> Array:
|
||||
func _do_actions(actions: Array) -> void:
|
||||
for action: String in actions:
|
||||
match action:
|
||||
"swipe":
|
||||
"swipe":
|
||||
_swipe_to_nearest_page()
|
||||
|
||||
|
||||
@@ -176,12 +176,11 @@ func _swipe_to_nearest_page() -> void:
|
||||
return
|
||||
|
||||
g_tween = stage_page_scroller.get_tree().create_tween()
|
||||
g_tween.tween_property(stage_page_scroller, "scroll_horizontal",
|
||||
g_tween.tween_property(stage_page_scroller, "scroll_horizontal",
|
||||
new_page * PAGE_WIDTH, SWIPE_DURATION).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
|
||||
if event is InputEventScreenDrag:
|
||||
stage_page_scroller.scroll_horizontal = clamp(
|
||||
stage_page_scroller.scroll_horizontal - PAGE_COUNT * event.screen_relative.x,
|
||||
@@ -199,9 +198,6 @@ func _input(event: InputEvent) -> void:
|
||||
func _ready() -> void:
|
||||
_init_entities()
|
||||
|
||||
func _on_button_pressed(extra_param): # теперь 1 параметр
|
||||
print("Кнопка нажата! Параметр:", extra_param)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# Update date
|
||||
@@ -221,15 +217,6 @@ func _on_report_button_pressed() -> void:
|
||||
print("r")
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func _on_time_minus_pressed() -> void:
|
||||
_change_speed(-1)
|
||||
|
||||
|
||||
func _on_time_plus_pressed() -> void:
|
||||
_change_speed(+1)
|
||||
|
||||
|
||||
func _change_speed(delta: int) -> void:
|
||||
var speed: int = owniverse.change_speed(delta)
|
||||
var ind: int = 1
|
||||
@@ -249,3 +236,5 @@ func _change_speed(delta: int) -> void:
|
||||
g_time_minus.texture_normal = load(SPEED_TEXTURE_NAME_TEMPLATE % str(speed - 1))
|
||||
g_time_plus.texture_normal = load(SPEED_TEXTURE_NAME_TEMPLATE % str(speed + 1))
|
||||
|
||||
func _on_topmenu_button_pressed(ButtonName) -> void:
|
||||
print(ButtonName)
|
||||
|
||||
Reference in New Issue
Block a user