Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved the tiling feature #378

Merged
merged 5 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Translations/Translations.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1464,3 +1464,12 @@ msgstr ""

msgid "Frame duration"
msgstr ""

msgid "Tiled In Both Axis"
msgstr ""

msgid "Tiled In X Axis"
msgstr ""

msgid "Tiled In Y Axis"
msgstr ""
5 changes: 0 additions & 5 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,6 @@ redo={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":89,"unicode":0,"echo":false,"script":null)
]
}
tile_mode={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":84,"unicode":0,"echo":false,"script":null)
]
}
show_grid={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":71,"unicode":0,"echo":false,"script":null)
Expand Down
15 changes: 12 additions & 3 deletions src/Autoload/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ enum Grid_Types {CARTESIAN, ISOMETRIC, ALL}
enum Pressure_Sensitivity {NONE, ALPHA, SIZE, ALPHA_AND_SIZE}
enum Direction {UP, DOWN, LEFT, RIGHT}
enum Theme_Types {DARK, BLUE, CARAMEL, LIGHT}

enum Tile_Mode {NONE, BOTH, XAXIS, YAXIS}
# Stuff for arrowkey-based canvas movements nyaa ^.^
const low_speed_move_rate := 150.0
const medium_speed_move_rate := 750.0
Expand Down Expand Up @@ -74,7 +74,7 @@ var left_square_indicator_visible := true
var right_square_indicator_visible := false

# View menu options
var tile_mode := false
var tile_mode : int = Tile_Mode.NONE
var draw_grid := false
var show_rulers := true
var show_guides := true
Expand Down Expand Up @@ -116,6 +116,7 @@ var cursor_position_label : Label
var zoom_level_label : Label

var recent_projects_submenu : PopupMenu
var tile_mode_submenu : PopupMenu

var new_image_dialog : ConfirmationDialog
var open_sprites_dialog : FileDialog
Expand Down Expand Up @@ -157,7 +158,6 @@ var layer_opacity_slider : HSlider
var layer_opacity_spinbox : SpinBox

var preview_zoom_slider : VSlider

var add_palette_button : BaseButton
var edit_palette_button : BaseButton
var palette_option_button : OptionButton
Expand Down Expand Up @@ -219,6 +219,15 @@ func _ready() -> void:
recent_projects_submenu = PopupMenu.new()
recent_projects_submenu.set_name("recent_projects_submenu")

tile_mode_submenu = PopupMenu.new()
tile_mode_submenu.set_name("tile_mode_submenu")
tile_mode_submenu.add_check_item("None", 0)
tile_mode_submenu.set_item_checked(0, true)
tile_mode_submenu.add_check_item("Tiled In Both Axis", 1)
tile_mode_submenu.add_check_item("Tiled In X Axis", 2)
tile_mode_submenu.add_check_item("Tiled In Y Axis", 3)
tile_mode_submenu.hide_on_checkable_item_selection = false

new_image_dialog = find_node_by_name(root, "CreateNewImage")
open_sprites_dialog = find_node_by_name(root, "OpenSprite")
save_sprites_dialog = find_node_by_name(root, "SaveSprite")
Expand Down
2 changes: 1 addition & 1 deletion src/UI/Canvas/Grid.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func _draw() -> void:


func draw_grid(grid_type : int) -> void:
var size : Vector2 = Global.current_project.size
var size : Vector2 = Global.transparent_checker.rect_size
if grid_type == Global.Grid_Types.CARTESIAN || grid_type == Global.Grid_Types.ALL:
for x in range(Global.grid_width, size.x, Global.grid_width):
draw_line(Vector2(x, location.y), Vector2(x, size.y), Global.grid_color, true)
Expand Down
44 changes: 28 additions & 16 deletions src/UI/Canvas/TileMode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,7 @@ var location := Vector2.ZERO
func _draw() -> void:
var current_cels : Array = Global.current_project.frames[Global.current_project.current_frame].cels
var size : Vector2 = Global.current_project.size
var positions := [
Vector2(location.x, location.y + size.y), # Down
Vector2(location.x - size.x, location.y + size.y), # Down left
Vector2(location.x - size.x, location.y), # Left
location - size, # Up left
Vector2(location.x, location.y - size.y), # Up
Vector2(location.x + size.x, location.y - size.y), # Up right
Vector2(location.x + size.x, location.y), # Right
location + size # Down right
]

for pos in positions:
# Draw a blank rectangle behind the textures
# Mostly used to hide the grid if it goes outside the canvas boundaries
draw_rect(Rect2(pos, size), Global.default_clear_color)

var positions : Array = get_tile_positions(size)
var tilemode_opacity = 1.0 - Global.tilemode_opacity

for i in range(Global.current_project.layers.size()):
Expand All @@ -31,3 +16,30 @@ func _draw() -> void:
if Global.tile_mode:
for pos in positions:
draw_texture(current_cels[i].image_texture, pos, modulate_color)


func get_tile_positions(size):
match Global.tile_mode:
1:
return [
Vector2(location.x, location.y + size.y), # Down
Vector2(location.x - size.x, location.y + size.y), # Down left
Vector2(location.x - size.x, location.y), # Left
location - size, # Up left
Vector2(location.x, location.y - size.y), # Up
Vector2(location.x + size.x, location.y - size.y), # Up right
Vector2(location.x + size.x, location.y), # Right
location + size # Down right
]
2:
return [
Vector2(location.x + size.x, location.y), # Right
Vector2(location.x - size.x, location.y), # Left
]
3:
return [
Vector2(location.x, location.y + size.y), # Down
Vector2(location.x, location.y - size.y), # Up
]
_:
return []
30 changes: 21 additions & 9 deletions src/UI/TopMenuContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func setup_edit_menu() -> void:

func setup_view_menu() -> void:
var view_menu_items := {
"Tile Mode" : InputMap.get_action_list("tile_mode")[0].get_scancode_with_modifiers(),
"Tile Mode" : 0,
OverloadedOrama marked this conversation as resolved.
Show resolved Hide resolved
"Show Grid" : InputMap.get_action_list("show_grid")[0].get_scancode_with_modifiers(),
"Show Rulers" : InputMap.get_action_list("show_rulers")[0].get_scancode_with_modifiers(),
"Show Guides" : InputMap.get_action_list("show_guides")[0].get_scancode_with_modifiers(),
Expand All @@ -86,16 +86,24 @@ func setup_view_menu() -> void:

var i := 0
for item in view_menu_items.keys():
view_menu.add_check_item(item, i, view_menu_items[item])
if item == "Tile Mode":
setup_tile_mode_submenu(item)
else:
view_menu.add_check_item(item, i, view_menu_items[item])
i += 1

view_menu.set_item_checked(2, true) # Show Rulers
view_menu.set_item_checked(3, true) # Show Guides
view_menu.set_item_checked(4, true) # Show Animation Timeline
view_menu.hide_on_checkable_item_selection = false
view_menu.connect("id_pressed", self, "view_menu_id_pressed")


func setup_tile_mode_submenu(item : String):
Global.tile_mode_submenu.connect("id_pressed", self, "tile_mode_submenu_id_pressed")
view_menu.add_child(Global.tile_mode_submenu)
view_menu.add_submenu_item(item, Global.tile_mode_submenu.get_name())


func setup_image_menu() -> void:
var image_menu_items := {
"Scale Image" : 0,
Expand Down Expand Up @@ -245,8 +253,6 @@ func edit_menu_id_pressed(id : int) -> void:

func view_menu_id_pressed(id : int) -> void:
match id:
0: # Tile mode
toggle_tile_mode()
1: # Show grid
toggle_show_grid()
2: # Show rulers
Expand All @@ -259,13 +265,19 @@ func view_menu_id_pressed(id : int) -> void:
toggle_zen_mode()
6: # Fullscreen mode
toggle_fullscreen()

Global.canvas.update()


func toggle_tile_mode() -> void:
Global.tile_mode = !Global.tile_mode
view_menu.set_item_checked(0, Global.tile_mode)
func tile_mode_submenu_id_pressed(id : int):
Global.transparent_checker._init_position(id)
for i in range(len(Global.Tile_Mode)):
if i != id:
Global.tile_mode_submenu.set_item_checked(i, false)
else:
Global.tile_mode_submenu.set_item_checked(i, true)
Global.canvas.tile_mode.update()
IsotoxalDev marked this conversation as resolved.
Show resolved Hide resolved
Global.canvas.grid.update()
Global.canvas.grid.set_position(Global.transparent_checker.get_position())


func toggle_show_grid() -> void:
Expand Down
21 changes: 21 additions & 0 deletions src/UI/TransparentChecker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func _ready() -> void:
material.set_shader_param("color2", Global.checker_color_2)
material.set_shader_param("follow_movement", Global.checker_follow_movement)
material.set_shader_param("follow_scale", Global.checker_follow_scale)
_init_position(Global.tile_mode)


func update_offset(offset : Vector2, scale : Vector2) -> void:
Expand All @@ -20,3 +21,23 @@ func update_offset(offset : Vector2, scale : Vector2) -> void:

func _on_TransparentChecker_resized():
material.set_shader_param("rect_size", rect_size)


func _init_position(id : int):
match id:
0:
Global.tile_mode = Global.Tile_Mode.NONE
Global.transparent_checker.set_size(Global.current_project.size)
Global.transparent_checker.set_position(Vector2.ZERO)
1:
Global.tile_mode = Global.Tile_Mode.BOTH
Global.transparent_checker.set_size(Global.current_project.size*3)
Global.transparent_checker.set_position(-Global.current_project.size)
2:
Global.tile_mode = Global.Tile_Mode.XAXIS
Global.transparent_checker.set_size(Vector2(Global.current_project.size.x*3, Global.current_project.size.y*1))
Global.transparent_checker.set_position(Vector2(-Global.current_project.size.x, 0))
3:
Global.tile_mode = Global.Tile_Mode.YAXIS
Global.transparent_checker.set_size(Vector2(Global.current_project.size.x*1, Global.current_project.size.y*3))
Global.transparent_checker.set_position(Vector2(0, -Global.current_project.size.y))