Skip to content

Commit

Permalink
ProjectSetting for RMB opening the action menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Törnqvist committed Feb 21, 2018
1 parent 7cbc7de commit cc22835
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
6 changes: 3 additions & 3 deletions device/globals/background.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export var action = "walk"

func input(event):
if event is InputEventMouseButton && event.pressed:
if (event.button_index == 1):
get_tree().call_group_flags(SceneTree.GROUP_CALL_DEFAULT, "game", "clicked", self, get_position() + Vector2(event.position.x, event.position.y))
elif (event.button_index == 2):
if (event.button_index == BUTTON_LEFT):
get_tree().call_group_flags(SceneTree.GROUP_CALL_DEFAULT, "game", "clicked", self, get_position() + event.position, event)
elif (event.button_index == BUTTON_RIGHT):
emit_right_click()

func get_action():
Expand Down
6 changes: 3 additions & 3 deletions device/globals/background_area.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ 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_flags(SceneTree.GROUP_CALL_DEFAULT, "game", "clicked", self, get_position() + Vector2(event.x, event.y))
elif (event.button_index == 2):
if (event.button_index == BUTTON_LEFT):
get_tree().call_group_flags(SceneTree.GROUP_CALL_DEFAULT, "game", "clicked", self, get_position() + event.position, event)
elif (event.button_index == BUTTON_RIGHT):
emit_right_click()

func get_action():
Expand Down
21 changes: 17 additions & 4 deletions device/globals/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func set_current_action(p_act):
func set_current_tool(p_tool):
current_tool = p_tool

func clicked(obj, pos):
func clicked(obj, pos, input_event = null):
# If multiple areas are clicked at once, an item_background "wins"
if obj is Area2D:
for area in obj.get_overlapping_areas():
Expand All @@ -78,8 +78,9 @@ func clicked(obj, pos):
player = self
if mode == "default":
var action = obj.get_action()
# Hide the action menu when performing actions, so it's not eg. open while walking
action_menu.stop()
# Hide the action menu (where available) when performing actions, so it's not eg. open while walking
if action_menu:
action_menu.stop()
if action == "walk":

#click.set_position(pos)
Expand Down Expand Up @@ -108,7 +109,19 @@ func clicked(obj, pos):
get_tree().call_group_flags(SceneTree.GROUP_CALL_DEFAULT, "hud", "set_tooltip", "")

elif obj.use_action_menu && action_menu != null:
spawn_action_menu(obj)
if ProjectSettings.get_setting("escoria/ui/right_mouse_button_action_menu"):
if input_event.button_index == BUTTON_RIGHT:
spawn_action_menu(obj)
else:
# Left-clicking in this context causes `player` to move to `obj`
if obj.has_node("interact_pos"):
pos = obj.get_node("interact_pos").get_global_position()
else:
pos = obj.get_global_position()
player.walk_to(pos)
# Have to verify left button because `clicked` reacts to any click
elif input_event.button_index == BUTTON_LEFT:
spawn_action_menu(obj)


func spawn_action_menu(obj):
Expand Down
2 changes: 1 addition & 1 deletion device/globals/item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func input(event):
if event is InputEventMouseButton || event.is_action("ui_accept"):
if event.is_pressed():
clicked = true
get_tree().call_group_flags(SceneTree.GROUP_CALL_DEFAULT, "game", "clicked", self, event.get_global_position())
get_tree().call_group_flags(SceneTree.GROUP_CALL_DEFAULT, "game", "clicked", self, event.get_global_position(), event)
_check_focus(true, true)
else:
clicked = false
Expand Down
3 changes: 2 additions & 1 deletion device/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ platform/screen_resizable=true
platform/show_ingame_buttons=false
platform/telon="res://globals/telon.tscn"
platform/window_title_height=32
platform/use_custom_camera=true
ui/credits=""
ui/in_game_menu="res://ui/in_game_menu.tscn"
ui/main_menu="res://ui/main_menu.tscn"
ui/confirm_popup="res://ui/confirm_popup.tscn"
ui/savegames=""
platform/use_custom_camera=true
ui/right_mouse_button_action_menu=false

[gdnative]

Expand Down

0 comments on commit cc22835

Please sign in to comment.