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

Improved the tiling feature (#378)

* Improved tiling feature

* Removed some unwanted code

* Fixed the bug mentioned by overloaded

* Added the requests by overload

* changed the y value which was given x value before
This commit is contained in:
AbhinavKDev 2020-11-13 23:42:20 +05:30 committed by GitHub
parent 4be0740170
commit de4634e22d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 92 additions and 34 deletions

View file

@ -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 ""

View file

@ -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)

View file

@ -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")

View file

@ -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)

View file

@ -7,7 +7,21 @@ 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 := [
var positions : Array = get_tile_positions(size)
var tilemode_opacity = 1.0 - Global.tilemode_opacity
for i in range(Global.current_project.layers.size()):
var modulate_color := Color(1, 1, 1, current_cels[i].opacity - tilemode_opacity)
if Global.current_project.layers[i].visible: # if it's visible
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
@ -17,17 +31,15 @@ func _draw() -> void:
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 tilemode_opacity = 1.0 - Global.tilemode_opacity
for i in range(Global.current_project.layers.size()):
var modulate_color := Color(1, 1, 1, current_cels[i].opacity - tilemode_opacity)
if Global.current_project.layers[i].visible: # if it's visible
if Global.tile_mode:
for pos in positions:
draw_texture(current_cels[i].image_texture, pos, modulate_color)
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 []

View file

@ -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():
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:

View file

@ -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))