1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Finished implementing the isometric grid - Closes #305

Added the ability to change grid type in Preferences, and made an isometric cell size value which affects just the size of the cells of the isometric grid. Also updated translations.
This commit is contained in:
OverloadedOrama 2020-08-20 00:12:07 +03:00
parent 1ff32f2892
commit 8d1c2e96f3
5 changed files with 74 additions and 10 deletions

View file

@ -741,6 +741,21 @@ msgstr ""
msgid "Grid"
msgstr ""
msgid "Grid type:"
msgstr ""
msgid "Sets the type of the grid between rectangular, isometric or both"
msgstr ""
msgid "Rectangular"
msgstr ""
msgid "Isometric"
msgstr ""
msgid "All"
msgstr ""
msgid "Grid width:"
msgstr ""
@ -753,6 +768,12 @@ msgstr ""
msgid "Sets how far apart are horizontal lines of the grid"
msgstr ""
msgid "Isometric cell size:"
msgstr ""
msgid "Sets the size of the cells in an isometric grid"
msgstr ""
msgid "Grid color:"
msgstr ""

View file

@ -51,6 +51,7 @@ var default_fill_color := Color(0, 0, 0, 0)
var grid_type = Grid_Types.CARTESIAN
var grid_width := 1
var grid_height := 1
var grid_isometric_cell_size := 2
var grid_color := Color.black
var guide_color := Color.purple
var checker_size := 10

View file

@ -16,8 +16,10 @@ var preferences = [
["default_image_height", "Image/ImageOptions/ImageDefaultHeight", "value", Global.default_image_height],
["default_fill_color", "Image/ImageOptions/DefaultFillColor", "color", Global.default_fill_color],
["grid_type", "Canvas/GridOptions/GridType", "selected", Global.grid_type],
["grid_width", "Canvas/GridOptions/GridWidthValue", "value", Global.grid_width],
["grid_height", "Canvas/GridOptions/GridHeightValue", "value", Global.grid_height],
["grid_isometric_cell_size", "Canvas/GridOptions/IsometricCellSizeValue", "value", Global.grid_isometric_cell_size],
["grid_color", "Canvas/GridOptions/GridColor", "color", Global.grid_color],
["guide_color", "Canvas/GuideOptions/GuideColor", "color", Global.guide_color],
["checker_size", "Canvas/CheckerOptions/CheckerSizeValue", "value", Global.checker_size],
@ -76,6 +78,9 @@ func _ready() -> void:
if pref[2] == "color":
preference_update(pref[0])
disable_restore_default_button(restore_default_button, Global.get(pref[0]).is_equal_approx(pref[3]))
elif pref[2] == "selected":
preference_update(pref[0])
disable_restore_default_button(restore_default_button, Global.get(pref[0]) == pref[3])
func _on_Preference_toggled(button_pressed : bool, prop : String, default_value, restore_default_button : BaseButton) -> void:
@ -115,7 +120,7 @@ func preference_update(prop : String) -> void:
else:
autosave_interval.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
if prop in ["grid_width", "grid_height", "grid_color"]:
if prop in ["grid_type", "grid_width", "grid_height", "grid_isometric_cell_size", "grid_color"]:
Global.canvas.grid.isometric_polylines.clear()
Global.canvas.grid.update()

View file

@ -216,6 +216,25 @@ custom_constants/vseparation = 4
custom_constants/hseparation = 4
columns = 3
[node name="TypeLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_right = 40.0
margin_bottom = 14.0
hint_tooltip = "Sets the type of the grid between rectangular, isometric or both"
mouse_filter = 0
text = "Grid type:"
__meta__ = {
"_editor_description_": ""
}
[node name="GridType" type="OptionButton" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_right = 29.0
margin_bottom = 20.0
hint_tooltip = "Sets the type of the grid between rectangular, isometric or both"
mouse_default_cursor_shape = 2
text = "Rectangular"
items = [ "Rectangular", null, false, 0, null, "Isometric", null, false, 1, null, "All", null, false, 2, null ]
selected = 0
[node name="WidthLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_top = 5.0
margin_right = 110.0
@ -260,6 +279,26 @@ rounded = true
align = 2
suffix = "px"
[node name="IsometricCellSizeLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_right = 40.0
margin_bottom = 14.0
hint_tooltip = "Sets the size of the cells in an isometric grid"
mouse_filter = 0
text = "Isometric cell size:"
[node name="IsometricCellSizeValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_top = 28.0
margin_right = 110.0
margin_bottom = 52.0
hint_tooltip = "Sets the size of the cells in an isometric grid"
mouse_default_cursor_shape = 2
min_value = 2.0
max_value = 16384.0
value = 2.0
rounded = true
align = 2
suffix = "px"
[node name="GridColorLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"]
margin_left = 114.0
margin_top = 33.0

View file

@ -19,17 +19,15 @@ func draw_grid(grid_type : int) -> void:
for y in range(Global.grid_height, size.y, Global.grid_height):
draw_line(Vector2(location.x, y), Vector2(size.x, y), Global.grid_color, true)
# Doesn't work properly yet
# Has problems when the canvas isn't a square, and with some grid sizes
if grid_type == Global.Grid_Types.ISOMETRIC || grid_type == Global.Grid_Types.ALL:
var i := 0
for x in range(Global.grid_width, size.x + 2, Global.grid_width * 2):
for y in range(0, size.y + 1, Global.grid_width):
for x in range(Global.grid_isometric_cell_size, size.x + 2, Global.grid_isometric_cell_size * 2):
for y in range(0, size.y + 1, Global.grid_isometric_cell_size):
draw_isometric_tile(i, Vector2(x, y))
i += 1
func draw_isometric_tile(i : int, origin := Vector2.RIGHT) -> void:
func draw_isometric_tile(i : int, origin := Vector2.RIGHT, cell_size : int = Global.grid_isometric_cell_size) -> void:
# A random value I found by trial and error, I have no idea why it "works"
var diff = 1.11754
var approx_30_degrees = deg2rad(26.565)
@ -38,10 +36,10 @@ func draw_isometric_tile(i : int, origin := Vector2.RIGHT) -> void:
if i < isometric_polylines.size():
pool = isometric_polylines[i]
else:
var a = origin
var b = a + Vector2(cos(approx_30_degrees), sin(approx_30_degrees)) * Global.grid_width * diff
var c = a + Vector2.DOWN * Global.grid_width
var d = c - Vector2(cos(approx_30_degrees), sin(approx_30_degrees)) * Global.grid_width * diff
var a = origin - Vector2(0, 0.5)
var b = a + Vector2(cos(approx_30_degrees), sin(approx_30_degrees)) * cell_size * diff
var c = a + Vector2.DOWN * cell_size
var d = c - Vector2(cos(approx_30_degrees), sin(approx_30_degrees)) * cell_size * diff
pool.append(a)
pool.append(b)
pool.append(c)