From 0fc903c6deb9b639c4a81a81bedb99162f49e8d0 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 18 Jun 2025 10:57:58 +0200 Subject: [PATCH] higlight should now correctly takes tile if one is on top --- ...metric_map_layer_holder.tscn1727497572.tmp | 146 ++++++++++++++++++ scripts/isometric_map_data.gd | 3 + scripts/isometric_map_renderer.gd | 14 +- scripts/isometric_map_system.gd | 4 +- scripts/player.gd | 10 +- 5 files changed, 172 insertions(+), 5 deletions(-) create mode 100644 scenes/isometric_map_layer_holder.tscn1727497572.tmp diff --git a/scenes/isometric_map_layer_holder.tscn1727497572.tmp b/scenes/isometric_map_layer_holder.tscn1727497572.tmp new file mode 100644 index 0000000..544aeeb --- /dev/null +++ b/scenes/isometric_map_layer_holder.tscn1727497572.tmp @@ -0,0 +1,146 @@ +[gd_scene load_steps=7 format=3 uid="uid://dg0qxdwe2rlcn"] + +[ext_resource type="Script" uid="uid://dxcfy8xypdde6" path="res://scripts/isometric_map_layer_holder.gd" id="1_4o54u"] +[ext_resource type="Texture2D" uid="uid://p8iyle6kr3nf" path="res://assets/sprites/tiles/iso_tileset.png" id="1_fme3d"] +[ext_resource type="Texture2D" uid="uid://bsox4y2fftlh8" path="res://assets/sprites/tiles/iso_tileset_with_select.png" id="3_s16iq"] + +[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_4o54u"] +texture = ExtResource("1_fme3d") +texture_region_size = Vector2i(32, 32) +0:0/0 = 0 +0:0/0/texture_origin = Vector2i(0, -8) +1:0/0 = 0 +1:0/0/texture_origin = Vector2i(0, -8) +2:0/0 = 0 +2:0/0/texture_origin = Vector2i(0, -8) +3:0/0 = 0 +3:0/0/texture_origin = Vector2i(0, -8) +4:0/0 = 0 +4:0/0/texture_origin = Vector2i(0, -8) +5:0/0 = 0 +5:0/0/texture_origin = Vector2i(0, -8) +6:0/0 = 0 +6:0/0/texture_origin = Vector2i(0, -8) + +[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_wvhlo"] +texture = ExtResource("3_s16iq") +texture_region_size = Vector2i(32, 32) +0:0/0 = 0 +0:0/0/texture_origin = Vector2i(0, -8) +1:0/0 = 0 +1:0/0/texture_origin = Vector2i(0, -8) +2:0/0 = 0 +2:0/0/texture_origin = Vector2i(0, -8) +3:0/0 = 0 +3:0/0/texture_origin = Vector2i(0, -8) +4:0/0 = 0 +4:0/0/texture_origin = Vector2i(0, -8) +5:0/0 = 0 +5:0/0/texture_origin = Vector2i(0, -8) +6:0/0 = 0 +6:0/0/texture_origin = Vector2i(0, -8) +7:0/0 = 0 +7:0/0/texture_origin = Vector2i(0, -8) +0:1/0 = 0 +0:1/0/texture_origin = Vector2i(0, -8) +1:1/0 = 0 +1:1/0/texture_origin = Vector2i(0, -8) +2:1/0 = 0 +2:1/0/texture_origin = Vector2i(0, -8) +3:1/0 = 0 +3:1/0/texture_origin = Vector2i(0, -8) +4:1/0 = 0 +4:1/0/texture_origin = Vector2i(0, -8) +5:1/0 = 0 +5:1/0/texture_origin = Vector2i(0, -8) +6:1/0 = 0 +6:1/0/texture_origin = Vector2i(0, -8) + +[sub_resource type="TileSet" id="TileSet_s16iq"] +tile_shape = 1 +tile_layout = 5 +tile_offset_axis = 1 +tile_size = Vector2i(32, 16) +sources/0 = SubResource("TileSetAtlasSource_4o54u") +sources/1 = SubResource("TileSetAtlasSource_wvhlo") + +[node name="IsometricMapLayerHolder" type="Node2D"] +script = ExtResource("1_4o54u") + +[node name="Camera2D" type="Camera2D" parent="."] +zoom = Vector2(0.5, 0.5) + +[node name="TileMapLayer" type="TileMapLayer" parent="."] +tile_set = SubResource("TileSet_s16iq") + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="ResetButton" type="Button" parent="CanvasLayer"] +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -25.5 +offset_top = -31.0 +offset_right = 25.5 +grow_horizontal = 2 +grow_vertical = 0 +size_flags_horizontal = 4 +size_flags_vertical = 4 +text = "Reset" + +[node name="RotationVBoxContainer" type="VBoxContainer" parent="CanvasLayer"] +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="Z_CW" type="Button" parent="CanvasLayer/RotationVBoxContainer"] +layout_mode = 2 +text = "Rotate CW Z-Axis" + +[node name="Z_CCW" type="Button" parent="CanvasLayer/RotationVBoxContainer"] +layout_mode = 2 +text = "Rotate CCW Z-Axis" + +[node name="X_CW" type="Button" parent="CanvasLayer/RotationVBoxContainer"] +layout_mode = 2 +text = "Rotate CW X-Axis" + +[node name="X_CCW" type="Button" parent="CanvasLayer/RotationVBoxContainer"] +layout_mode = 2 +text = "Rotate CCW X-Axis" + +[node name="Y_CW" type="Button" parent="CanvasLayer/RotationVBoxContainer"] +layout_mode = 2 +text = "Rotate CW Y-Axis" + +[node name="Y_CCW" type="Button" parent="CanvasLayer/RotationVBoxContainer"] +layout_mode = 2 +text = "Rotate CCW Y-Axis" + +[node name="DebugPlayerStuff" type="VBoxContainer" parent="CanvasLayer"] +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -37.5 +offset_right = 37.5 +offset_bottom = 70.0 +grow_horizontal = 2 + +[node name="PlayerZLayerChangeUp" type="Button" parent="CanvasLayer/DebugPlayerStuff"] +layout_mode = 2 +text = "Z-layer +" + +[node name="PlayerZLayerChangeDown" type="Button" parent="CanvasLayer/DebugPlayerStuff"] +layout_mode = 2 +text = "Z-layer -" + +[connection signal="pressed" from="CanvasLayer/ResetButton" to="." method="_on_reset_button_pressed"] +[connection signal="pressed" from="CanvasLayer/RotationVBoxContainer/Z_CW" to="." method="_on_cw_pressed"] +[connection signal="pressed" from="CanvasLayer/RotationVBoxContainer/Z_CCW" to="." method="_on_ccw_pressed"] +[connection signal="pressed" from="CanvasLayer/RotationVBoxContainer/X_CW" to="." method="_on_x_cw_pressed"] +[connection signal="pressed" from="CanvasLayer/RotationVBoxContainer/X_CCW" to="." method="_on_x_ccw_pressed"] +[connection signal="pressed" from="CanvasLayer/RotationVBoxContainer/Y_CW" to="." method="_on_y_cw_pressed"] +[connection signal="pressed" from="CanvasLayer/RotationVBoxContainer/Y_CCW" to="." method="_on_y_ccw_pressed"] +[connection signal="pressed" from="CanvasLayer/DebugPlayerStuff/PlayerZLayerChangeUp" to="." method="_on_player_z_layer_change_pressed"] +[connection signal="pressed" from="CanvasLayer/DebugPlayerStuff/PlayerZLayerChangeDown" to="." method="_on_player_z_layer_change_down_pressed"] diff --git a/scripts/isometric_map_data.gd b/scripts/isometric_map_data.gd index c09a3bd..61fe7e5 100644 --- a/scripts/isometric_map_data.gd +++ b/scripts/isometric_map_data.gd @@ -210,6 +210,7 @@ func rotate_around_x_axis(rotation_steps = 1): temp_map[x][new_y][new_z]["x"] = new_coord_x temp_map[x][new_y][new_z]["y"] = new_coord_y temp_map[x][new_y][new_z]["z"] = new_z + temp_map[x][new_y][new_z]["highlighted"] = false # Update the grid dimensions GRID_SIZE_HEIGHT = new_height @@ -276,6 +277,7 @@ func rotate_around_y_axis(rotation_steps = 1): temp_map[new_x][y][new_z]["x"] = new_coord_x temp_map[new_x][y][new_z]["y"] = new_coord_y temp_map[new_x][y][new_z]["z"] = new_z + temp_map[new_x][y][new_z]["highlighted"] = false # Update the grid dimensions GRID_SIZE_WIDTH = new_width @@ -342,6 +344,7 @@ func rotate_around_z_axis(rotation_steps = 1): temp_map[new_x][new_y][z]["x"] = new_coord_x temp_map[new_x][new_y][z]["y"] = new_coord_y temp_map[new_x][new_y][z]["z"] = z + temp_map[new_x][new_y][z]["highlighted"] = false # Update the grid dimensions GRID_SIZE_WIDTH = new_width diff --git a/scripts/isometric_map_renderer.gd b/scripts/isometric_map_renderer.gd index 9aaf172..edd8fbc 100644 --- a/scripts/isometric_map_renderer.gd +++ b/scripts/isometric_map_renderer.gd @@ -114,8 +114,18 @@ func handle_hover(mouse_position): for x in map_data.GRID_SIZE_WIDTH: for y in map_data.GRID_SIZE_LENGTH: var tile = map_data.get_tile(x, y, z) - - if tile != null and tile["visibility"] and not tile["unit"]: + var tile_above = map_data.get_tile(x, y, z + 1) + if tile_above != null and tile_above["visibility"] and not tile_above["unit"]: + if tile["x"] == hover_tile_position.x and tile["y"] == hover_tile_position.y: + # Store this tile for highlighting + var tile_key = str(x) + "_" + str(y) + "_" + str(z) + + new_highlighted_tiles[tile_key] = { + "x": x, + "y": y, + "z": z + 1 + } + elif tile != null and tile["visibility"] and not tile["unit"]: if tile["x"] == hover_tile_position.x and tile["y"] == hover_tile_position.y: # Store this tile for highlighting var tile_key = str(x) + "_" + str(y) + "_" + str(z) diff --git a/scripts/isometric_map_system.gd b/scripts/isometric_map_system.gd index 32a56de..9717a52 100644 --- a/scripts/isometric_map_system.gd +++ b/scripts/isometric_map_system.gd @@ -48,8 +48,8 @@ func world_to_iso(world_pos, player_z_layer = 0, tile_width = 32, tile_height = # Create a new tile data structure with default values func create_tile_data(coord_x, coord_y, z, atlas_base_position = null, atlas_highlight_position = null): # Ensure we have valid default positions to avoid null reference errors - var base_pos = atlas_base_position if atlas_base_position != null else BLUE_ISOMETRICTILE_ATLAS_POSITION - var highlight_pos = atlas_highlight_position if atlas_highlight_position != null else WHITE_ISOMETRICTILE_ATLAS_POSITION + var _base_pos = atlas_base_position if atlas_base_position != null else BLUE_ISOMETRICTILE_ATLAS_POSITION + var _highlight_pos = atlas_highlight_position if atlas_highlight_position != null else WHITE_ISOMETRICTILE_ATLAS_POSITION return { "x": coord_x, diff --git a/scripts/player.gd b/scripts/player.gd index 0d658e9..76e02d7 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -75,6 +75,14 @@ var player_data = { func _input(event): if event is InputEventMouseMotion: check_hover() + + if event is InputEventKey and event.pressed: + if event.keycode == KEY_H: + debug_detection_at_mouse() + +func debug_detection_at_mouse(): + var mouse_pos = get_viewport().get_mouse_position() + print(mouse_pos) func _unhandled_input(event): if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed: @@ -139,7 +147,7 @@ func _process(delta: float): play_player_animation("idle") #process_combat_movement(delta) -func process_free_movement(delta): +func process_free_movement(_delta): # Get input direction var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")