Skip to content

Commit

Permalink
Refactor stage select nearly completely, refs #8
Browse files Browse the repository at this point in the history
  • Loading branch information
bojidar-bg committed May 25, 2016
1 parent d275471 commit 88a9b35
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 93 deletions.
4 changes: 2 additions & 2 deletions engine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ icon="res://art/intro_alpaca.png"

[autoload]

main="res://main.gd"
game_data="res://shared/game_data.gd"
main="*res://main.gd"
game_data="*res://shared/game_data.gd"
progress="res://shared/progress.tscn"

[debug]
Expand Down
109 changes: 49 additions & 60 deletions menu/stage_select.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,62 @@
# Copyright (c) 2009-2016 Juan Linietsky, Ariel Manzur
# Distributed under the terms of the MIT license (cf. LICENSE.md file)

extends TextureFrame
extends Control

# member variables here, example:
# var a=2
# var b="textvar"
export var column_count = 3
onready var tabs = get_node("items/worlds")

func _ready():
add_levels()

func _on_load_world(world):
get_tree().get_root().get_node("game_data").current_world=world
# get_tree().get_root().get_node("game_data").current_checkpoint=null
get_tree().get_root().get_node("main").goto_scene(world.path)


const LEVEL_COLUMNS = 3

func _on_back_pressed():
print("goback")
get_tree().get_root().get_node("main").goto_scene("res://menu/main_menu.tscn")

func add_levels():
# Initalization here
var gd = get_tree().get_root().get_node("game_data");
var tab_world={}
var tabs=get_node("vbox/tabs")
print("ENTER SCENE!")
var focus = false
var world_tabs = {}
print("Adding levels...")
var gave_focus = false

for l in gd.levels:
printt("adding level", l.enabled, l.path)
if (not l.enabled):
for level in game_data.levels:
if !level.enabled:
continue
if (!(l.id[0] in tab_world)):
var tabdata = {}
var t = CenterContainer.new()
t.set_name("World "+str(l.id[0]))
tabs.add_child(t)
var vb = VBoxContainer.new()
t.add_child(vb)
tabdata.vb=vb
tab_world[l.id[0]]=tabdata
tabdata.current_hb=null


var td = tab_world[l.id[0]]
if (td.current_hb==null or td.current_hb.get_child_count()==LEVEL_COLUMNS):

var hb = HBoxContainer.new()
td.current_hb=hb
td.vb.add_child(hb)

printt("Adding level", level.enabled, level.path)

if !(level.id.x in world_tabs):
var tab_center_container = CenterContainer.new()
tab_center_container.set_name(str("World ", level.id[0]))
tabs.add_child(tab_center_container)

var vb2 = VBoxContainer.new()
td.current_hb.add_child(vb2)
var b = Button.new()
#b.set_flat(true)
vb2.add_child(b)
b.set_button_icon(ResourceLoader.load(l.preview_path))
var lb = Label.new()
lb.add_font_override("font",preload("res://art/font.xfnt"))
lb.set_align(Label.ALIGN_CENTER)
vb2.add_child(lb)
lb.set_text(str(l.id[0],"-",l.id[1]))
b.connect("pressed",self,"_on_load_world",[l])
if !focus:
b.call_deferred("grab_focus")
focus = true
var tab_levels_grid = GridContainer.new()
tab_levels_grid.set_columns(column_count)
tab_center_container.add_child(tab_levels_grid)
world_tabs[level.id.x] = tab_levels_grid

var tab_levels_grid = world_tabs[level.id.x]

var level_vbox = VBoxContainer.new()

func _enter_tree():
printt("stage select enter scene!")
call_deferred("add_levels")
var level_button = Button.new()
level_button.set_button_icon(load(level.preview_path))
level_button.connect("pressed",self,"select_stage",[level])
level_vbox.add_child(level_button)

var level_name = Label.new()
level_name.set_align(Label.ALIGN_CENTER)
level_name.set_text(level.name)
level_name.add_font_override("font", preload("res://art/font.xfnt"))
level_vbox.add_child(level_name)

if !gave_focus:
level_button.call_deferred("grab_focus")
gave_focus = true

tab_levels_grid.add_child(level_vbox)

func select_stage(stage):
game_data.current_world = stage
# get_tree().get_root().get_node("game_data").current_checkpoint=null
get_tree().get_root().get_node("main").goto_scene(stage.path)


func back_pressed():
get_tree().change_scene("res://menu/main_menu.tscn")
85 changes: 54 additions & 31 deletions menu/stage_select.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=7 format=1]

[ext_resource path="res://art/intro_sky_bg.png" type="Texture" id=1]
[ext_resource path="res://menu/stage_select.gd" type="Script" id=2]
[ext_resource path="res://menu/stage_select.gd" type="Script" id=1]
[ext_resource path="res://art/intro_sky_bg.png" type="Texture" id=2]
[ext_resource path="res://art/world1.png" type="Texture" id=3]
[ext_resource path="res://art/intro_menu_back.png" type="Texture" id=4]
[ext_resource path="res://art/intro_menu_back_focus.png" type="Texture" id=5]
Expand All @@ -13,90 +13,113 @@ content_margin/right = -1.0
content_margin/top = -1.0
content_margin/bottom = -1.0

[node name="TextureFrame" type="TextureFrame"]
[node name="stage_select" type="Control"]

anchor/right = 1
anchor/bottom = 1
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
texture = ExtResource( 1 )
expand = true
script/script = ExtResource( 2 )
margin/left = 0.0
margin/top = 0.0
margin/right = 0.0
margin/bottom = 0.0
script/script = ExtResource( 1 )
__meta__ = { "__editor_plugin_screen__":"2D" }
column_count = 3

[node name="vbox" type="VBoxContainer" parent="."]
[node name="background" type="TextureFrame" parent="."]

anchor/right = 1
anchor/bottom = 1
margin/left = 20.0
margin/top = 20.0
margin/right = 20.0
margin/bottom = 20.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 0.0
margin/top = 0.0
margin/right = 0.0
margin/bottom = 0.0
texture = ExtResource( 2 )
expand = true

[node name="items" type="VBoxContainer" parent="."]

anchor/right = 1
anchor/bottom = 1
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 20.0
margin/top = 20.0
margin/right = 20.0
margin/bottom = 20.0
alignment = 0

[node name="center" type="CenterContainer" parent="vbox"]
[node name="world_name" type="CenterContainer" parent="items"]

margin/right = 1240.0
margin/bottom = 64.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 0.0
margin/top = 0.0
margin/right = 1240.0
margin/bottom = 64.0
use_top_left = false

[node name="world" type="TextureFrame" parent="vbox/center"]
[node name="texture" type="TextureFrame" parent="items/world_name"]

margin/left = 364.0
margin/right = 876.0
margin/bottom = 64.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 364.0
margin/top = 0.0
margin/right = 876.0
margin/bottom = 64.0
texture = ExtResource( 3 )

[node name="tabs" type="TabContainer" parent="vbox"]
[node name="worlds" type="TabContainer" parent="items"]

margin/top = 68.0
margin/right = 1240.0
margin/bottom = 612.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 3
margin/left = 0.0
margin/top = 68.0
margin/right = 1240.0
margin/bottom = 612.0
custom_styles/panel = SubResource( 1 )
tab_align = 1
tabs_visible = false

[node name="hbox" type="HBoxContainer" parent="vbox"]
[node name="buttons" type="HBoxContainer" parent="items"]

margin/top = 616.0
margin/right = 1240.0
margin/bottom = 680.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 0.0
margin/top = 616.0
margin/right = 1240.0
margin/bottom = 680.0
alignment = 0

[node name="back" type="TextureButton" parent="vbox/hbox"]
[node name="back" type="TextureButton" parent="items/buttons"]

margin/right = 64.0
margin/bottom = 64.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
margin/left = 0.0
margin/top = 0.0
margin/right = 64.0
margin/bottom = 64.0
toggle_mode = false
textures/normal = ExtResource( 4 )
textures/focused = ExtResource( 5 )

[connection signal="pressed" from="vbox/hbox/back" to="." method="_on_back_pressed"]


2 changes: 2 additions & 0 deletions shared/game_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class LevelInfo:
var max_fruit = 0
var preview_path = ""
var path = ""
var name = ""
var enabled = true

var last_level = 0
Expand All @@ -30,6 +31,7 @@ func _init():
level.path = stage.path + ".tscn"
level.preview_path= stage.path + ".png"
level.enabled = true
level.name = str(stage.id.x, "-", stage.id.y)
levels.push_back(level)
prints("Level:", level.id, "path:", level.path)

Expand Down

0 comments on commit 88a9b35

Please sign in to comment.