mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-12 16:53:07 +00:00
Fixed more stuff
This commit is contained in:
parent
8b12eac231
commit
6a60050bd3
|
@ -53,16 +53,24 @@ class GridPreference:
|
||||||
value_type = _value_type
|
value_type = _value_type
|
||||||
if _default_value != null:
|
if _default_value != null:
|
||||||
default_value = _default_value
|
default_value = _default_value
|
||||||
else:
|
|
||||||
default_value = Global.get(prop_name)
|
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
var grids = Global.config_cache.get_value(
|
||||||
|
"preferences", "grids", {0: create_default_properties()}
|
||||||
|
)
|
||||||
|
Global.config_cache.set_value("preferences", "grids", grids)
|
||||||
|
$GridsCount.value = grids.size()
|
||||||
for pref in grid_preferences:
|
for pref in grid_preferences:
|
||||||
if not has_node(pref.node_path):
|
if not has_node(pref.node_path):
|
||||||
continue
|
continue
|
||||||
var node := get_node(pref.node_path)
|
var node := get_node(pref.node_path)
|
||||||
var restore_default_button := RestoreDefaultButton.new()
|
var restore_default_button := RestoreDefaultButton.new()
|
||||||
|
restore_default_button.pressed.connect(
|
||||||
|
_on_Grid_Pref_value_changed.bind(
|
||||||
|
pref.default_value, pref, restore_default_button
|
||||||
|
)
|
||||||
|
)
|
||||||
restore_default_button.setting_name = pref.prop_name
|
restore_default_button.setting_name = pref.prop_name
|
||||||
restore_default_button.value_type = pref.value_type
|
restore_default_button.value_type = pref.value_type
|
||||||
restore_default_button.default_value = pref.default_value
|
restore_default_button.default_value = pref.default_value
|
||||||
|
@ -71,11 +79,6 @@ func _ready() -> void:
|
||||||
var node_position := node.get_index()
|
var node_position := node.get_index()
|
||||||
node.get_parent().add_child(restore_default_button)
|
node.get_parent().add_child(restore_default_button)
|
||||||
node.get_parent().move_child(restore_default_button, node_position)
|
node.get_parent().move_child(restore_default_button, node_position)
|
||||||
var grids = Global.config_cache.get_value(
|
|
||||||
"preferences", "grids", {0: create_default_properties()}
|
|
||||||
)
|
|
||||||
Global.config_cache.set_value("preferences", "grids", grids)
|
|
||||||
$GridsCount.value = grids.size()
|
|
||||||
|
|
||||||
match pref.value_type:
|
match pref.value_type:
|
||||||
"button_pressed":
|
"button_pressed":
|
||||||
|
@ -108,12 +111,12 @@ func _on_Grid_Pref_value_changed(value, pref: GridPreference, button: RestoreDef
|
||||||
var prop := pref.prop_name
|
var prop := pref.prop_name
|
||||||
grid_info[prop] = value
|
grid_info[prop] = value
|
||||||
grids[grid_selected] = grid_info
|
grids[grid_selected] = grid_info
|
||||||
|
Global.update_grids(grids)
|
||||||
var default_value = pref.default_value
|
var default_value = pref.default_value
|
||||||
var disable: bool = Global.get(prop) == default_value
|
var disable: bool = Global.grids[grid_selected].get(prop) == default_value
|
||||||
if typeof(value) == TYPE_COLOR:
|
if typeof(value) == TYPE_COLOR:
|
||||||
disable = value.is_equal_approx(default_value)
|
disable = value.is_equal_approx(default_value)
|
||||||
disable_restore_default_button(button, disable)
|
disable_restore_default_button(button, disable)
|
||||||
Global.update_grids(grids)
|
|
||||||
Global.config_cache.set_value(
|
Global.config_cache.set_value(
|
||||||
"preferences", "grids", grids
|
"preferences", "grids", grids
|
||||||
)
|
)
|
||||||
|
@ -133,6 +136,7 @@ func _on_grids_count_value_changed(value: float) -> void:
|
||||||
for key: int in range(grid_idx + 1, grids.size()):
|
for key: int in range(grid_idx + 1, grids.size()):
|
||||||
grids.erase(key)
|
grids.erase(key)
|
||||||
add_remove_select_button(key, true)
|
add_remove_select_button(key, true)
|
||||||
|
Global.update_grids(grids)
|
||||||
Global.config_cache.set_value("preferences", "grids", grids)
|
Global.config_cache.set_value("preferences", "grids", grids)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
|
var unique_rect_lines := PackedVector2Array()
|
||||||
|
var unique_iso_lines := PackedVector2Array()
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
Global.project_switched.connect(queue_redraw)
|
Global.project_switched.connect(queue_redraw)
|
||||||
|
@ -10,7 +12,9 @@ func _draw() -> void:
|
||||||
return
|
return
|
||||||
|
|
||||||
var target_rect: Rect2i
|
var target_rect: Rect2i
|
||||||
for grid_idx in Global.grids.size():
|
unique_rect_lines.clear()
|
||||||
|
unique_iso_lines.clear()
|
||||||
|
for grid_idx in range(Global.grids.size() - 1, -1, -1):
|
||||||
if Global.grids[grid_idx].grid_draw_over_tile_mode:
|
if Global.grids[grid_idx].grid_draw_over_tile_mode:
|
||||||
target_rect = Global.current_project.tiles.get_bounding_rect()
|
target_rect = Global.current_project.tiles.get_bounding_rect()
|
||||||
else:
|
else:
|
||||||
|
@ -35,8 +39,10 @@ func _draw_cartesian_grid(grid_index: int, target_rect: Rect2i) -> void:
|
||||||
+ fposmod(grid.grid_offset.x - target_rect.position.x, grid.grid_size.x)
|
+ fposmod(grid.grid_offset.x - target_rect.position.x, grid.grid_size.x)
|
||||||
)
|
)
|
||||||
while x <= target_rect.end.x:
|
while x <= target_rect.end.x:
|
||||||
grid_multiline_points.push_back(Vector2(x, target_rect.position.y))
|
# Check if the exact line has been added before
|
||||||
grid_multiline_points.push_back(Vector2(x, target_rect.end.y))
|
if not Vector2(x, target_rect.position.y) in unique_rect_lines:
|
||||||
|
grid_multiline_points.push_back(Vector2(x, target_rect.position.y))
|
||||||
|
grid_multiline_points.push_back(Vector2(x, target_rect.end.y))
|
||||||
x += grid.grid_size.x
|
x += grid.grid_size.x
|
||||||
|
|
||||||
var y: float = (
|
var y: float = (
|
||||||
|
@ -44,10 +50,13 @@ func _draw_cartesian_grid(grid_index: int, target_rect: Rect2i) -> void:
|
||||||
+ fposmod(grid.grid_offset.y - target_rect.position.y, grid.grid_size.y)
|
+ fposmod(grid.grid_offset.y - target_rect.position.y, grid.grid_size.y)
|
||||||
)
|
)
|
||||||
while y <= target_rect.end.y:
|
while y <= target_rect.end.y:
|
||||||
grid_multiline_points.push_back(Vector2(target_rect.position.x, y))
|
# Check if the exact line has been added before
|
||||||
grid_multiline_points.push_back(Vector2(target_rect.end.x, y))
|
if not Vector2(target_rect.position.x, y) in unique_rect_lines:
|
||||||
|
grid_multiline_points.push_back(Vector2(target_rect.position.x, y))
|
||||||
|
grid_multiline_points.push_back(Vector2(target_rect.end.x, y))
|
||||||
y += grid.grid_size.y
|
y += grid.grid_size.y
|
||||||
|
|
||||||
|
unique_rect_lines.append_array(grid_multiline_points)
|
||||||
if not grid_multiline_points.is_empty():
|
if not grid_multiline_points.is_empty():
|
||||||
draw_multiline(grid_multiline_points, grid.grid_color)
|
draw_multiline(grid_multiline_points, grid.grid_color)
|
||||||
|
|
||||||
|
@ -73,8 +82,9 @@ func _draw_isometric_grid(grid_index: int, target_rect: Rect2i) -> void:
|
||||||
var start: Vector2 = Vector2(target_rect.position) + Vector2(0, y)
|
var start: Vector2 = Vector2(target_rect.position) + Vector2(0, y)
|
||||||
var cells_to_rect_bounds: float = minf(max_cell_count.x, y / cell_size.y)
|
var cells_to_rect_bounds: float = minf(max_cell_count.x, y / cell_size.y)
|
||||||
var end := start + cells_to_rect_bounds * per_cell_offset
|
var end := start + cells_to_rect_bounds * per_cell_offset
|
||||||
grid_multiline_points.push_back(start)
|
if not start in unique_iso_lines:
|
||||||
grid_multiline_points.push_back(end)
|
grid_multiline_points.push_back(start)
|
||||||
|
grid_multiline_points.push_back(end)
|
||||||
y += cell_size.y
|
y += cell_size.y
|
||||||
|
|
||||||
# lines ↗↗↗ starting from the rect's bottom side (left to right):
|
# lines ↗↗↗ starting from the rect's bottom side (left to right):
|
||||||
|
@ -83,8 +93,9 @@ func _draw_isometric_grid(grid_index: int, target_rect: Rect2i) -> void:
|
||||||
var start: Vector2 = Vector2(target_rect.position) + Vector2(x, target_rect.size.y)
|
var start: Vector2 = Vector2(target_rect.position) + Vector2(x, target_rect.size.y)
|
||||||
var cells_to_rect_bounds: float = minf(max_cell_count.y, max_cell_count.x - x / cell_size.x)
|
var cells_to_rect_bounds: float = minf(max_cell_count.y, max_cell_count.x - x / cell_size.x)
|
||||||
var end: Vector2 = start + cells_to_rect_bounds * per_cell_offset
|
var end: Vector2 = start + cells_to_rect_bounds * per_cell_offset
|
||||||
grid_multiline_points.push_back(start)
|
if not start in unique_iso_lines:
|
||||||
grid_multiline_points.push_back(end)
|
grid_multiline_points.push_back(start)
|
||||||
|
grid_multiline_points.push_back(end)
|
||||||
x += cell_size.x
|
x += cell_size.x
|
||||||
|
|
||||||
# lines ↘↘↘ (from top-left to bottom-right)
|
# lines ↘↘↘ (from top-left to bottom-right)
|
||||||
|
@ -96,8 +107,9 @@ func _draw_isometric_grid(grid_index: int, target_rect: Rect2i) -> void:
|
||||||
var start: Vector2 = Vector2(target_rect.position) + Vector2(0, y)
|
var start: Vector2 = Vector2(target_rect.position) + Vector2(0, y)
|
||||||
var cells_to_rect_bounds: float = minf(max_cell_count.x, max_cell_count.y - y / cell_size.y)
|
var cells_to_rect_bounds: float = minf(max_cell_count.x, max_cell_count.y - y / cell_size.y)
|
||||||
var end: Vector2 = start + cells_to_rect_bounds * per_cell_offset
|
var end: Vector2 = start + cells_to_rect_bounds * per_cell_offset
|
||||||
grid_multiline_points.push_back(start)
|
if not start in unique_iso_lines:
|
||||||
grid_multiline_points.push_back(end)
|
grid_multiline_points.push_back(start)
|
||||||
|
grid_multiline_points.push_back(end)
|
||||||
y += cell_size.y
|
y += cell_size.y
|
||||||
|
|
||||||
# lines ↘↘↘ starting from the rect's top side (left to right):
|
# lines ↘↘↘ starting from the rect's top side (left to right):
|
||||||
|
@ -106,9 +118,11 @@ func _draw_isometric_grid(grid_index: int, target_rect: Rect2i) -> void:
|
||||||
var start: Vector2 = Vector2(target_rect.position) + Vector2(x, 0)
|
var start: Vector2 = Vector2(target_rect.position) + Vector2(x, 0)
|
||||||
var cells_to_rect_bounds: float = minf(max_cell_count.y, max_cell_count.x - x / cell_size.x)
|
var cells_to_rect_bounds: float = minf(max_cell_count.y, max_cell_count.x - x / cell_size.x)
|
||||||
var end: Vector2 = start + cells_to_rect_bounds * per_cell_offset
|
var end: Vector2 = start + cells_to_rect_bounds * per_cell_offset
|
||||||
grid_multiline_points.push_back(start)
|
if not start in unique_iso_lines:
|
||||||
grid_multiline_points.push_back(end)
|
grid_multiline_points.push_back(start)
|
||||||
|
grid_multiline_points.push_back(end)
|
||||||
x += cell_size.x
|
x += cell_size.x
|
||||||
|
grid_multiline_points.append_array(grid_multiline_points)
|
||||||
|
|
||||||
if not grid_multiline_points.is_empty():
|
if not grid_multiline_points.is_empty():
|
||||||
draw_multiline(grid_multiline_points, grid.grid_color)
|
draw_multiline(grid_multiline_points, grid.grid_color)
|
||||||
|
|
Loading…
Reference in a new issue