Skip to content

Commit

Permalink
fix(level_menu.gd): 修复 CHAP_NAMES 和按钮初始化
Browse files Browse the repository at this point in the history
- 修复 CHAP_NAMES 后面没有加上 ["name-en"] 导致的错误
- 修复初始化:将左右选章按钮的初始化从 _ready 转移到 init 函数中,否则会
  导致按钮 disabled 属性设置错误(因为 _ready 时还没确定 chapter_id)
  • Loading branch information
cutekibry committed Feb 19, 2024
1 parent 56a9dc2 commit 3a1f52c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions levels/chapter_menu/level_menu/level_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ const button_heigth : int = 50

func init(chap_id: int) -> void:
self.chapter_id = chap_id
$UI/Title.text = LevelData.CHAP_NAMES[chapter_id]
$UI/Title.text = LevelData.CHAP_NAMES[chapter_id]["name-en"]
$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)

func _ready():
for cid in range(LevelData.get_chapter_count()):
for lid in range(LevelData.get_chapter_level_count(cid)):
Expand All @@ -28,9 +31,6 @@ func _ready():
button.init(cid, lid, Vector2(x, y), 1)
button.enter_level.connect(_on_button_enter_level)
$LevelButtons.add_child(button)

$UI/PreviousChapterButton.set_disabled(chapter_id == 0)
$UI/NextChapterButton.set_disabled(chapter_id == LevelData.get_chapter_count() - 1)


func _on_button_enter_level(chap_id: int, lvl_id: int) -> void:
Expand All @@ -43,17 +43,17 @@ func _on_button_enter_level(chap_id: int, lvl_id: int) -> void:

func _on_previous_chapter_button_pressed():
self.chapter_id -= 1
$UI/Title.text = LevelData.CHAP_NAMES[chapter_id]
$UI/Title.text = LevelData.CHAP_NAMES[chapter_id]["name-en"]
$UI/PreviousChapterButton.set_disabled(true)
$UI/NextChapterButton.set_disabled(true)


func _on_next_chapter_button_pressed():
self.chapter_id += 1
$UI/Title.text = LevelData.CHAP_NAMES[chapter_id]
$UI/Title.text = LevelData.CHAP_NAMES[chapter_id]["name-en"]
$UI/PreviousChapterButton.set_disabled(true)
$UI/NextChapterButton.set_disabled(true)

func _on_smooth_movement_timeout():
$UI/PreviousChapterButton.set_disabled(chapter_id == 0)
$UI/NextChapterButton.set_disabled(chapter_id == LevelData.get_chapter_count() - 1)
$UI/NextChapterButton.set_disabled(chapter_id == LevelData.get_chapter_count() - 1)

0 comments on commit 3a1f52c

Please sign in to comment.