Skip to content

Commit

Permalink
Make it easier to use background_area.gd
Browse files Browse the repository at this point in the history
  • Loading branch information
fleskesvor committed Apr 29, 2017
1 parent c5945b8 commit ddfd7fa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
23 changes: 17 additions & 6 deletions globals/background_area.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,34 @@ var rectangleshape
func input(viewport, event, shape_idx):
if event.type == InputEvent.MOUSE_BUTTON && event.pressed:
if (event.button_index == 1):
get_tree().call_group(0, "game", "clicked", self, get_pos() + Vector2(event.x, event.y))
get_tree().call_group(0, "game", "clicked", self, get_pos() + Vector2(event.x, event.y), BUTTON_LEFT)
elif (event.button_index == 2):
emit_right_click()



func get_action():
return action

func _init():
add_user_signal("right_click_on_bg")

func _enter_tree():
# Use size of background texture to calculate collision shape
var background = get_parent().get_node("background")
if background:
printt("GET SIZE", background.get_size())

var size = background.get_size()
var extents = Vector2(size.x / 2, size.y / 2)
var transform = Matrix32(Vector2(1, 0), Vector2(0, 1), extents)

var shape = RectangleShape2D.new()
shape.set_extents(extents)
add_shape(shape)
set_shape_transform(0, transform)

func _ready():
connect("input_event", self, "input")
add_to_group("background")




func emit_right_click():
emit_signal("right_click_on_bg")
6 changes: 5 additions & 1 deletion globals/item_background.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends "res://globals/interactive.gd"

export var tooltip = ""
export var action = ""
export var secondary_action = ""
export(String,FILE) var events_path = ""
export var global_id = ""
export var use_combine = false
Expand Down Expand Up @@ -78,6 +79,9 @@ func activate(p_action, p_param = null):
func get_action():
return action

func get_secondary_action():
return secondary_action

func mouse_enter():
get_tree().call_group(0, "game", "mouse_enter", self)
_check_focus(true, false)
Expand All @@ -89,7 +93,7 @@ func mouse_exit():
func input(viewport, event, shape_idx):
if event.type == InputEvent.MOUSE_BUTTON || event.is_action("ui_accept"):
if event.is_pressed():
get_tree().call_group(0, "game", "clicked", self, get_pos())
get_tree().call_group(0, "game", "clicked", self, get_pos(), event.button_index)
_check_focus(true, true)
else:
_check_focus(true, false)
Expand Down
7 changes: 7 additions & 0 deletions rooms/test/mountain.esc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:look

say player "A mountain"

:climb

say player "I don't want to climb it"
Binary file modified rooms/test/test.scn
Binary file not shown.

0 comments on commit ddfd7fa

Please sign in to comment.