CustomLevelContainer.gd 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. class_name CustomLevelContainer
  2. extends Control
  3. signal selected(this: CustomLevelContainer)
  4. var level_name := ""
  5. var level_author := ""
  6. var level_desc := ""
  7. var level_theme := "Overworld"
  8. var level_time := 0
  9. var game_style := "SMBLL"
  10. var difficulty := 0
  11. var file_path := ""
  12. var idx := 0
  13. const CAMPAIGN_RECTS := {
  14. "SMB1": Rect2(0, 0, 42, 16),
  15. "SMBLL": Rect2(0, 16, 42, 16),
  16. "SMBS": Rect2(0, 32, 42, 16),
  17. "SMBANN": Rect2(0, 0, 42, 16)
  18. }
  19. const ICON_TEXTURES := [
  20. preload("uid://chtjq1vr0rpso"),
  21. preload("uid://cn8bcncfmdikq")
  22. ]
  23. const THEME_RECTS := {
  24. "Overworld": Rect2(0, 0, 32, 32),
  25. "Underground": Rect2(32, 0, 32, 32),
  26. "Desert": Rect2(64, 0, 32, 32),
  27. "Snow": Rect2(96, 0, 32, 32),
  28. "Jungle": Rect2(128, 0, 32, 32),
  29. "Beach": Rect2(0, 32, 32, 32),
  30. "Garden": Rect2(32, 32, 32, 32),
  31. "Mountain": Rect2(64, 32, 32, 32),
  32. "Skyland": Rect2(96, 32, 32, 32),
  33. "Autumn": Rect2(128, 32, 32, 32),
  34. "Pipeland": Rect2(0, 64, 32, 32),
  35. "Space": Rect2(32, 64, 32, 32),
  36. "Underwater": Rect2(64, 64, 32, 32),
  37. "Volcano": Rect2(96, 64, 32, 32),
  38. "GhostHouse": Rect2(128, 64, 32, 32),
  39. "Castle": Rect2(0, 96, 32, 32),
  40. "CastleWater": Rect2(32, 96, 32, 32),
  41. "Mystery": Rect2(96, 96, 32, 32),
  42. "Airship": Rect2(128, 96, 32, 32),
  43. "Bonus": Rect2(0, 128, 32, 32)
  44. }
  45. func _ready() -> void:
  46. set_process(false)
  47. update_visuals()
  48. func update_visuals() -> void:
  49. %LevelIcon.texture = ResourceSetter.get_resource(ICON_TEXTURES[level_time])
  50. %LevelIcon.region_rect = THEME_RECTS[level_theme]
  51. %LevelName.text = level_name if level_name != "" else "(Unnamed Level)"
  52. %LevelAuthor.text = "By " + (level_author if level_author != "" else "Player")
  53. %CampaignIcon.region_rect = CAMPAIGN_RECTS[game_style]
  54. var idx := 0
  55. for i in %DifficultyStars.get_children():
  56. i.region_rect.position.x = 24 if idx > difficulty else [0, 0, 8, 8, 16][difficulty]
  57. idx += 1
  58. func _process(_delta: float) -> void:
  59. if Input.is_action_just_pressed("ui_accept") and visible:
  60. selected.emit(self)