diff --git a/Translations/Translations.pot b/Translations/Translations.pot index 0320444d0..9c5c7288a 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -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 "" diff --git a/project.godot b/project.godot index f19a351d3..80039b17a 100644 --- a/project.godot +++ b/project.godot @@ -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) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index a6d574564..c011a69c4 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -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 @@ -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 @@ -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 @@ -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 @@ -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") diff --git a/src/UI/Canvas/Grid.gd b/src/UI/Canvas/Grid.gd index 9c6c51e29..f5db478e8 100644 --- a/src/UI/Canvas/Grid.gd +++ b/src/UI/Canvas/Grid.gd @@ -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) diff --git a/src/UI/Canvas/TileMode.gd b/src/UI/Canvas/TileMode.gd index 6b47acbec..0fd61e9a9 100644 --- a/src/UI/Canvas/TileMode.gd +++ b/src/UI/Canvas/TileMode.gd @@ -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()): @@ -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 [] diff --git a/src/UI/TopMenuContainer.gd b/src/UI/TopMenuContainer.gd index af997518d..82a06d595 100644 --- a/src/UI/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer.gd @@ -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, "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(), @@ -86,9 +86,11 @@ 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 @@ -96,6 +98,12 @@ func setup_view_menu() -> void: 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, @@ -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 @@ -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() + Global.canvas.grid.update() + Global.canvas.grid.set_position(Global.transparent_checker.get_position()) func toggle_show_grid() -> void: diff --git a/src/UI/TransparentChecker.gd b/src/UI/TransparentChecker.gd index 158233c49..972179543 100644 --- a/src/UI/TransparentChecker.gd +++ b/src/UI/TransparentChecker.gd @@ -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: @@ -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))