Tractor beam
This commit is contained in:
@@ -85,8 +85,15 @@ func _process(delta):
|
||||
cursor = current_selected_item.get_pointer()
|
||||
Input.set_custom_mouse_cursor(cursor)
|
||||
|
||||
if player and dragging_inspected:
|
||||
inspected.global_position = player.get_global_mouse_position()
|
||||
if player:
|
||||
if dragging_inspected:
|
||||
inspected.global_position = player.get_global_mouse_position()
|
||||
if inspected is ItemObject:
|
||||
var global_dir: Vector2 = (inspected.global_position - player.global_position).normalized()
|
||||
inspected.object_sprite.tractor_beam.position = 30 * global_dir
|
||||
inspected.object_sprite.tractor_beam.rotation = Vector2.RIGHT.angle_to(global_dir)
|
||||
if not inspected.object_sprite.tractor_beam.emitting:
|
||||
inspected.object_sprite.tractor_beam.emitting = true
|
||||
|
||||
func process_player_actions(delta: float):
|
||||
can_interact = (
|
||||
@@ -146,43 +153,12 @@ func process_player_actions(delta: float):
|
||||
press_action_done = false
|
||||
%ActionProgressPlayer.playing = false
|
||||
%ActionProgressBar.value = 0.
|
||||
|
||||
if (
|
||||
inspected and
|
||||
(inspected is ItemObject
|
||||
or (inspected is InventoryGuiItemMouseDetector
|
||||
and GameInfo.game_data.player_data.inventory.get_item(inspected.index)
|
||||
and press_time > PRESS_TIME_DRAG))
|
||||
):
|
||||
if Input.is_action_pressed("action"):
|
||||
all_inspected.clear()
|
||||
all_inspected.append(inspected)
|
||||
dragging_inspected = true
|
||||
can_interact = false
|
||||
if inspected is ItemObject:
|
||||
inspected.mouse_over = false
|
||||
elif inspected is InventoryGuiItemMouseDetector:
|
||||
var item_to_drop: Item = GameInfo.game_data.player_data.inventory.pop_item(inspected.index)
|
||||
if item_to_drop and item_to_drop.type != Item.ItemType.TOOL_ITEM:
|
||||
var dropped_item_object := player.terrain.drop_item(item_to_drop, player.get_global_mouse_position())
|
||||
inspected = dropped_item_object
|
||||
all_inspected.clear()
|
||||
all_inspected.append(inspected)
|
||||
player.region.save()
|
||||
else:
|
||||
dragging_inspected = false
|
||||
else:
|
||||
dragging_inspected = false
|
||||
if inspected is ItemObject and inspected_inventory_slot is InventoryGuiItemMouseDetector:
|
||||
# GameInfo.game_data.player_data.inventory.add_seed(inspected.item)
|
||||
if GameInfo.game_data.player_data.inventory.add_item_at(inspected.item, inspected_inventory_slot.index):
|
||||
all_inspected.clear()
|
||||
inspected.queue_free()
|
||||
inspected = null
|
||||
|
||||
if Input.is_action_just_released("action") and press_time < PRESS_TIME_DRAG:
|
||||
if Input.is_action_just_pressed("action"):
|
||||
if inspected is InventoryGuiItemMouseDetector:
|
||||
GameInfo.game_data.player_data.inventory.set_current_item(inspected.index)
|
||||
elif can_use_item and not current_selected_item.is_action_need_press_time() and current_selected_item.get_action_is_hold():
|
||||
player.try_use_item(current_selected_item, player.get_global_mouse_position())
|
||||
elif can_interact:
|
||||
var interactable = inspected as Interactable
|
||||
player.try_interact(interactable)
|
||||
@@ -191,6 +167,16 @@ func process_player_actions(delta: float):
|
||||
current_selected_item,
|
||||
player.get_global_mouse_position()
|
||||
)
|
||||
|
||||
if (
|
||||
Input.is_action_just_released("action")
|
||||
and can_use_item
|
||||
and current_selected_item.get_action_is_hold()
|
||||
):
|
||||
if dragging_inspected:
|
||||
player.try_use_item(current_selected_item, player.get_global_mouse_position())
|
||||
else:
|
||||
player.instruction = null
|
||||
|
||||
func inspect(node: Node):
|
||||
if (
|
||||
@@ -237,7 +223,6 @@ func update_inspector(current_inspected):
|
||||
if current_inspected:
|
||||
if inspected != current_inspected:
|
||||
if inspected and inspected.has_method("inspect"):
|
||||
print("Stop inspect")
|
||||
inspected.inspect(false)
|
||||
inspected = current_inspected
|
||||
if inspected.has_method("card_info"):
|
||||
@@ -252,12 +237,7 @@ func update_inspector(current_inspected):
|
||||
inspected = null
|
||||
|
||||
if player and not action_disabled and (get_tree() and not get_tree().paused):
|
||||
if can_interact and inspected and inspected is Interactable:
|
||||
%Action.visible = true
|
||||
%ActionText.text = inspected.interact_text()
|
||||
%Action.modulate = DEFAULT_ACTION_COLOR if inspected.interaction_cost(player) == 0 else ENERGY_ACTION_COLOR
|
||||
%ActionEnergyImage.visible = inspected.interaction_cost(player) != 0
|
||||
elif dragging_inspected:
|
||||
if dragging_inspected:
|
||||
%Action.visible = true
|
||||
if inspected is ItemObject:
|
||||
%ActionText.text = inspected.item.name
|
||||
@@ -267,6 +247,15 @@ func update_inspector(current_inspected):
|
||||
%ActionText.text = item.name
|
||||
else:
|
||||
%Action.visible = false
|
||||
elif current_selected_item and current_selected_item.use_text() != "" and current_selected_item.get_action_is_hold():
|
||||
%Action.visible = true
|
||||
%ActionText.text = current_selected_item.use_text()
|
||||
%Action.modulate = DEFAULT_ACTION_COLOR
|
||||
elif can_interact and inspected and inspected is Interactable:
|
||||
%Action.visible = true
|
||||
%ActionText.text = inspected.interact_text()
|
||||
%Action.modulate = DEFAULT_ACTION_COLOR if inspected.interaction_cost(player) == 0 else ENERGY_ACTION_COLOR
|
||||
%ActionEnergyImage.visible = inspected.interaction_cost(player) != 0
|
||||
elif current_selected_item and current_selected_item.use_text() != "":
|
||||
%Action.visible = true
|
||||
%ActionText.text = current_selected_item.use_text() + (tr("NO_ENERGY_LEFT") if not have_energy_to_use_item else "")
|
||||
@@ -280,8 +269,41 @@ func update_inspector(current_inspected):
|
||||
else:
|
||||
%Action.visible = false
|
||||
|
||||
func stop_inspect(node: Node = get_current_inspected()):
|
||||
func stop_inspect(node: Node):
|
||||
if not dragging_inspected:
|
||||
all_inspected.erase(node)
|
||||
if node is InventoryGuiItemMouseDetector:
|
||||
inspected_inventory_slot = null
|
||||
|
||||
func start_dragging():
|
||||
if not dragging_inspected:
|
||||
dragging_inspected = true
|
||||
if inspected is ItemObject:
|
||||
inspected.mouse_over = false
|
||||
elif inspected is InventoryGuiItemMouseDetector:
|
||||
var item_to_drop: Item = GameInfo.game_data.player_data.inventory.get_item(inspected.index)
|
||||
if item_to_drop and item_to_drop.type != Item.ItemType.TOOL_ITEM:
|
||||
GameInfo.game_data.player_data.inventory.remove_item_at(inspected.index)
|
||||
var dropped_item_object := player.terrain.drop_item(item_to_drop, player.get_global_mouse_position())
|
||||
inspected_inventory_slot = inspected
|
||||
inspected = dropped_item_object
|
||||
player.region.save()
|
||||
else:
|
||||
dragging_inspected = false
|
||||
if dragging_inspected:
|
||||
all_inspected.clear()
|
||||
all_inspected.append(inspected)
|
||||
can_interact = false
|
||||
|
||||
func stop_dragging():
|
||||
if dragging_inspected:
|
||||
dragging_inspected = false
|
||||
if inspected is ItemObject:
|
||||
inspected.object_sprite.tractor_beam.emitting = false
|
||||
if (
|
||||
inspected_inventory_slot is InventoryGuiItemMouseDetector
|
||||
and GameInfo.game_data.player_data.inventory.add_item_at(inspected.item, inspected_inventory_slot.index)
|
||||
):
|
||||
all_inspected.clear()
|
||||
inspected.queue_free()
|
||||
inspected = null
|
||||
|
||||
Reference in New Issue
Block a user