Skip to content

Commit

Permalink
feat: 添加调试用解锁关卡 / 重置存档按钮
Browse files Browse the repository at this point in the history
fix: 修复下一章节按钮逻辑问题
  • Loading branch information
cutekibry committed Sep 25, 2024
1 parent 9be92b0 commit 030a4a1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
34 changes: 25 additions & 9 deletions scenes/level_menu/level_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ func init(chap_id: int) -> void:
$UI/Title.text = tr("CHAPTER_PATTERN") % [chap_id + 1, tr("CHAPTER_NAME_%d" % chap_id)]
$LevelMenuCamera.init_position(Vector2(WIDTH * chap_id, 0))

$UI/PreviousChapterButton.set_disabled(chapter_id == 0)
$UI/NextChapterButton.set_disabled(chapter_id == LevelData.get_chapter_count() - 1 or not LevelData.is_chapter_unlocked(chapter_id + 1))
$UI/PreviousChapterButton.visible = (chapter_id != 0)
$UI/NextChapterButton.disabled = (chapter_id == LevelData.get_chapter_count() - 1 or not LevelData.is_chapter_unlocked(chapter_id + 1))
$UI/NextChapterButton.visible = (chapter_id != LevelData.get_chapter_count() - 1)

func _ready():
for cid in range(LevelData.get_chapter_count()):
Expand All @@ -31,7 +32,7 @@ func _ready():
var y := button_heigth * (lid / 7) + 100
button.init(cid, lid, Vector2(x, y), 1)
button.enter_level.connect(_on_button_enter_level)
button.set_disabled(lid >= 1 and not SaveLib.is_level_cleared(cid, lid - 1))
button.disabled = (lid >= 1 and not SaveLib.is_level_cleared(cid, lid - 1))


func _on_button_enter_level(chap_id: int, lvl_id: int) -> void:
Expand All @@ -46,17 +47,32 @@ func _on_previous_chapter_button_pressed():
self.chapter_id -= 1
$UI/Title.text = tr("CHAPTER_PATTERN") % [self.chapter_id + 1, tr("CHAPTER_NAME_%d" % self.chapter_id)]
ImageLib.change_theme(ImageLib.COLOR_THEMES[ImageLib.COLOR_THEMES.find(ImageLib.theme_to) - 1], LevelMenuCamera.MOVE_TIME)
$UI/PreviousChapterButton.set_disabled(true)
$UI/NextChapterButton.set_disabled(true)
$UI/PreviousChapterButton.disabled = true
$UI/PreviousChapterButton.visible = (chapter_id != 0)
$UI/NextChapterButton.disabled = true
$UI/NextChapterButton.visible = (chapter_id != LevelData.get_chapter_count() - 1)


func _on_next_chapter_button_pressed():
self.chapter_id += 1
ImageLib.change_theme(ImageLib.COLOR_THEMES[ImageLib.COLOR_THEMES.find(ImageLib.theme_to) + 1], LevelMenuCamera.MOVE_TIME)
$UI/Title.text = tr("CHAPTER_PATTERN") % [self.chapter_id + 1, tr("CHAPTER_NAME_%d" % self.chapter_id)]
$UI/PreviousChapterButton.set_disabled(true)
$UI/NextChapterButton.set_disabled(true)
$UI/PreviousChapterButton.disabled = true
$UI/PreviousChapterButton.visible = (chapter_id != 0)
$UI/NextChapterButton.disabled = true
$UI/NextChapterButton.visible = (chapter_id != LevelData.get_chapter_count() - 1)

func _on_smooth_movement_timeout():
$UI/PreviousChapterButton.set_disabled(chapter_id == 0)
$UI/NextChapterButton.set_disabled(chapter_id == LevelData.get_chapter_count() - 1)
$UI/PreviousChapterButton.disabled = false
$UI/NextChapterButton.disabled = (chapter_id == LevelData.get_chapter_count() - 1 or not LevelData.is_chapter_unlocked(chapter_id + 1))


func _on_debug_unlock_button_pressed() -> void:
for i in range(LevelData.get_chapter_count()):
for j in range(LevelData.get_chapter_level_count(i)):
SaveLib.set_level_cleared(i, j, true)

func _on_debug_reset_button_pressed() -> void:
for i in range(LevelData.get_chapter_count()):
for j in range(LevelData.get_chapter_level_count(i)):
SaveLib.set_level_cleared(i, j, false)
18 changes: 17 additions & 1 deletion scenes/level_menu/level_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource type="Script" path="res://scenes/level_menu/level_menu.gd" id="1_sd65g"]
[ext_resource type="Script" path="res://scenes/level_menu/level_menu_camera.gd" id="2_4o5wo"]
[ext_resource type="PackedScene" uid="uid://drl1xe103umpi" path="res://ui/styled_button/styled_button.tscn" id="2_66j1c"]
[ext_resource type="PackedScene" uid="uid://byqwkmuk64h73" path="res://ui/styled_button/styled_button.tscn" id="2_66j1c"]
[ext_resource type="PackedScene" uid="uid://fxcs5dmb21q2" path="res://scripts/smooth_movement/smooth_movement.tscn" id="3_1jj52"]
[ext_resource type="Theme" path="res://themes/default_theme_big.tres" id="5_y07je"]
[ext_resource type="FontFile" uid="uid://dkcus8d34pbhm" path="res://fonts/fusion-pixel-10px-proportional-zh_hans.otf" id="6_o20ik"]
Expand Down Expand Up @@ -42,8 +42,24 @@ text = "Title"
horizontal_alignment = 1
vertical_alignment = 1

[node name="DebugUnlockButton" type="Button" parent="UI"]
offset_left = 10.0
offset_top = 325.0
offset_right = 90.0
offset_bottom = 354.0
text = "解锁全部关卡"

[node name="DebugResetButton" type="Button" parent="UI"]
offset_left = 97.0
offset_top = 325.0
offset_right = 242.0
offset_bottom = 354.0
text = "重置存档(需要退出重进)"

[connection signal="timeout" from="LevelMenuCamera/SmoothMovement" to="." method="_on_smooth_movement_timeout"]
[connection signal="pressed" from="UI/PreviousChapterButton" to="." method="_on_previous_chapter_button_pressed"]
[connection signal="pressed" from="UI/PreviousChapterButton" to="LevelMenuCamera" method="_on_previous_chapter_button_pressed"]
[connection signal="pressed" from="UI/NextChapterButton" to="." method="_on_next_chapter_button_pressed"]
[connection signal="pressed" from="UI/NextChapterButton" to="LevelMenuCamera" method="_on_next_chapter_button_pressed"]
[connection signal="pressed" from="UI/DebugUnlockButton" to="." method="_on_debug_unlock_button_pressed"]
[connection signal="pressed" from="UI/DebugResetButton" to="." method="_on_debug_reset_button_pressed"]

0 comments on commit 030a4a1

Please sign in to comment.