Skip to content

Commit

Permalink
Merge pull request #38 from OpMonTeam/30-in-game-menu
Browse files Browse the repository at this point in the history
Added game menu
  • Loading branch information
milkyroute authored Mar 4, 2022
2 parents 2241866 + 1295e00 commit 92ff785
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 17 deletions.
2 changes: 1 addition & 1 deletion OpMon-Data
6 changes: 3 additions & 3 deletions Scenes/Events/Interactable/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const InteractableClass = preload("Interactable.gd")

func _input(event):
if not Engine.editor_hint:
if event.is_action_pressed("ui_accept") and not _paused:
if event.is_action_pressed("interact") and not _paused:
_interact()

func _process(_delta):
Expand All @@ -22,8 +22,8 @@ func _check_move():
move(input_direction) # Move in this direction

func _get_input_direction():
var horizontal_input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
var vertical_input = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
var horizontal_input = Input.get_action_strength("right") - Input.get_action_strength("left")
var vertical_input = Input.get_action_strength("down") - Input.get_action_strength("up")

if abs(horizontal_input) > abs(vertical_input):
return Vector2(horizontal_input, 0)
Expand Down
37 changes: 37 additions & 0 deletions Scenes/GameMenu/GameMenu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
extends Interface

var labels := []

var selection := 0

signal choice(id)

func _ready():
labels.append($OpMonLabel)
labels.append($BagLabel)
labels.append($OpDexLabel)
labels.append($IDLabel)
labels.append($SaveLabel)
labels.append($SettingsLabel)
self.rect_position = (Vector2(960,640) / 2) - (self.rect_size / 2)

func _input(event):
# Conditions on selection are here to avoid warping
if event.is_action_pressed("ui_accept"):
emit_signal("choice", selection)
emit_signal("closed")
elif event.is_action_pressed("menu"):
emit_signal("closed")
elif event.is_action_pressed("ui_down") and selection != 4:
selection += 2
elif event.is_action_pressed("ui_up") and selection != 1:
selection -= 2
elif event.is_action_pressed("ui_left") and selection % 2 == 1:
selection -= 1
elif event.is_action_pressed("ui_right") and selection % 2 == 0:
selection += 1
if selection < 0:
selection = 0
elif selection > 5:
selection = 5
$ChoiceRect.rect_position = labels[selection].rect_position
119 changes: 119 additions & 0 deletions Scenes/GameMenu/GameMenu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Scenes/GameMenu/GameMenu.gd" type="Script" id=1]

[sub_resource type="DynamicFontData" id=1]
font_path = "res://OpMon-Data/Fonts/main_font.ttf"

[sub_resource type="DynamicFont" id=2]
size = 23
font_data = SubResource( 1 )

[node name="GameMenu" type="Control"]
anchor_right = 0.417
anchor_bottom = 0.625
margin_right = -0.320038
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Background" type="ColorRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.533333, 0.533333, 0.533333, 1 )
__meta__ = {
"_edit_use_anchors_": false,
"_editor_description_": ""
}

[node name="OpMonLabel" type="Label" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 192.0
margin_bottom = 136.0
custom_fonts/font = SubResource( 2 )
text = "GAMEMENU_OPMON"
align = 1
valign = 1
clip_text = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="BagLabel" type="Label" parent="."]
margin_left = 208.0
margin_top = 8.0
margin_right = 392.0
margin_bottom = 136.0
custom_fonts/font = SubResource( 2 )
text = "GAMEMENU_BAG"
align = 1
valign = 1
clip_text = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="OpDexLabel" type="Label" parent="."]
margin_left = 8.0
margin_top = 144.0
margin_right = 192.0
margin_bottom = 269.0
custom_fonts/font = SubResource( 2 )
text = "GAMEMENU_ENCYCLOPEDIA"
align = 1
valign = 1
clip_text = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="IDLabel" type="Label" parent="."]
margin_left = 208.0
margin_top = 144.0
margin_right = 392.0
margin_bottom = 269.0
custom_fonts/font = SubResource( 2 )
text = "GAMEMENU_ID"
align = 1
valign = 1
clip_text = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="SaveLabel" type="Label" parent="."]
margin_left = 8.0
margin_top = 269.0
margin_right = 192.0
margin_bottom = 394.0
custom_fonts/font = SubResource( 2 )
text = "GAMEMENU_SAVE"
align = 1
valign = 1
clip_text = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="SettingsLabel" type="Label" parent="."]
margin_left = 208.0
margin_top = 269.0
margin_right = 392.0
margin_bottom = 394.0
custom_fonts/font = SubResource( 2 )
text = "GAMEMENU_SETTINGS"
align = 1
valign = 1
clip_text = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="ChoiceRect" type="ColorRect" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 192.0
margin_bottom = 136.0
color = Color( 1, 1, 1, 0.45098 )
2 changes: 1 addition & 1 deletion Scenes/Interface/DialogBox.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func _finish_current_line():
$NinePatchRect/Text.visible_characters = -1 # Sets all characters visible

func _input(event):
if event.is_action_pressed("ui_accept") and not _dialog_over:
if event.is_action_pressed("dialog_pass") and not _dialog_over:
if _awaiting_next_dialog_line: # If the current dialog line already is fully printed
if _current_dialog_line_index < _dialog_lines.size() - 1: # If there is another
_start_new_line()
Expand Down
8 changes: 4 additions & 4 deletions Scenes/Interface/Interface.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ extends Control

class_name Interface

var _map
var _map_manager

signal closed

func set_map(map: Node):
_map = map
connect("closed", _map, "unload_interface")
func set_map(map_manager: Node):
_map_manager = map_manager
connect("closed", _map_manager, "unload_interface")
26 changes: 18 additions & 8 deletions Scenes/Maps/MapManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ var camera_instance: Camera2D

var interface = null

# Sets the number of frames to wait before unpausing the player
# -1 if the player has not to be unpaused
var unpause_player_delay := -1
# Sets a cooldown after closing the interface
# During the cooldown, the player is still paused and the menu can’t open
# Unpauses the player at the end of the cooldown
# -1 if the cooldown is over
var interface_closed_delay := -1

func init(p_first_map: String, p_first_player_pos: Vector2):
_first_map = p_first_map
Expand All @@ -35,24 +37,32 @@ func _ready():
player_instance.add_child(camera_instance)
change_map(_first_map, _first_player_pos)

func _input(event):
if event.is_action_pressed("menu") and interface_closed_delay < 0:
var menu = load("res://Scenes/GameMenu/GameMenu.tscn").instance()
pause_player()
load_interface(menu)

func _process(_delta):
if unpause_player_delay > 0:
unpause_player_delay -= 1
elif unpause_player_delay == 0:
unpause_player_delay -= 1
if interface_closed_delay > 0:
interface_closed_delay -= 1
if interface_closed_delay == 0:
interface_closed_delay -= 1
unpause_player()

func load_interface(p_interface: Node):
if interface == null and p_interface.has_method("set_map"):
interface = p_interface
p_interface.set_map(self)
$Interface.add_child(interface)
elif not p_interface.has_method("set_map"):
print("Error: the given interface doesn’t have the set_map method.")

func unload_interface():
if interface != null:
interface.call_deferred("free")
interface = null
unpause_player_delay = 5
interface_closed_delay = 5

# Loads a map at the given position in the global MapManager and erases all the current present maps
# Does not associate the map with the player yet, only shows the map on screen
Expand Down
47 changes: 47 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,53 @@ texture={
"svg/scale": 1.0
}

[input]

ui_home={
"deadzone": 0.5,
"events": [ ]
}
interact={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
dialog_pass={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":65,"unicode":0,"echo":false,"script":null)
]
}
right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":68,"unicode":0,"echo":false,"script":null)
]
}
up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":87,"unicode":0,"echo":false,"script":null)
]
}
down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":83,"unicode":0,"echo":false,"script":null)
]
}
menu={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}

[locale]

translations=PoolStringArray( "res://OpMon-Data/translations.en.translation", "res://OpMon-Data/translations.fr.translation" )

0 comments on commit 92ff785

Please sign in to comment.