From 96454a2d57507a1f026768b2d97597225ef7986b Mon Sep 17 00:00:00 2001 From: AbhinavKDev <62714538+abhinav3967@users.noreply.github.com> Date: Tue, 24 Nov 2020 22:23:18 +0530 Subject: [PATCH] Handiling tile modes in each project (#388) * Handiling tile modes in each project Co-authored-by: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> --- src/Autoload/Global.gd | 1 - src/Classes/Project.gd | 1 + src/Tools/Base.gd | 2 +- src/Tools/Draw.gd | 5 ++--- src/UI/Canvas/TileMode.gd | 4 ++-- src/UI/TransparentChecker.gd | 10 +++++----- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 845a7f7a9..84d8909dc 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -74,7 +74,6 @@ var left_square_indicator_visible := true var right_square_indicator_visible := false # View menu options -var tile_mode : int = Tile_Mode.NONE var mirror_view := false var draw_grid := false var show_rulers := true diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 546945b78..15a53fdcb 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -5,6 +5,7 @@ class_name Project extends Reference var name := "" setget name_changed var size : Vector2 setget size_changed var undo_redo : UndoRedo +var tile_mode : int = Global.Tile_Mode.NONE var undos := 0 # The number of times we added undo properties var has_changed := false setget has_changed_changed var frames := [] setget frames_changed # Array of Frames (that contain Cels) diff --git a/src/Tools/Base.gd b/src/Tools/Base.gd index 3bd0f63cd..4363df40b 100644 --- a/src/Tools/Base.gd +++ b/src/Tools/Base.gd @@ -82,7 +82,7 @@ func _get_draw_rect() -> Rect2: func _get_tile_mode_rect() -> Rect2: - match Global.tile_mode: + match Global.current_project.tile_mode: Global.Tile_Mode.XAXIS: return Rect2(Vector2(-Global.current_project.size.x,0), Vector2(Global.current_project.size.x * 3,Global.current_project.size.y)) Global.Tile_Mode.YAXIS: diff --git a/src/Tools/Draw.gd b/src/Tools/Draw.gd index 31adf1aa9..9e9db92e7 100644 --- a/src/Tools/Draw.gd +++ b/src/Tools/Draw.gd @@ -305,7 +305,7 @@ func draw_tool_brush(position : Vector2) -> void: func draw_indicator() -> void: draw_indicator_at(_cursor, Vector2.ZERO, Color.blue) - if Global.tile_mode and _get_tile_mode_rect().has_point(_cursor): + if Global.current_project.tile_mode and _get_tile_mode_rect().has_point(_cursor): var tile := _line_start if _draw_line else _cursor if not tile in Global.current_project.selected_pixels: var offset := tile - tile.posmodv(Global.current_project.size) @@ -336,8 +336,7 @@ func _set_pixel(position : Vector2) -> void: var project : Project = Global.current_project if Global.mirror_view: position.x = project.size.x - position.x - 1 - - if Global.tile_mode and _get_tile_mode_rect().has_point(position): + if Global.current_project.tile_mode and _get_tile_mode_rect().has_point(position): position = position.posmodv(project.size) var entire_image_selected : bool = project.selected_pixels.size() == project.size.x * project.size.y diff --git a/src/UI/Canvas/TileMode.gd b/src/UI/Canvas/TileMode.gd index 8a640457d..d630f385c 100644 --- a/src/UI/Canvas/TileMode.gd +++ b/src/UI/Canvas/TileMode.gd @@ -20,7 +20,7 @@ func _draw() -> void: 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: + if Global.current_project.tile_mode: for pos in positions: draw_texture(current_cels[i].image_texture, pos, modulate_color) @@ -28,7 +28,7 @@ func _draw() -> void: func get_tile_positions(size): - match Global.tile_mode: + match Global.current_project.tile_mode: 1: return [ Vector2(location.x, location.y + size.y), # Down diff --git a/src/UI/TransparentChecker.gd b/src/UI/TransparentChecker.gd index 972179543..1e74149fd 100644 --- a/src/UI/TransparentChecker.gd +++ b/src/UI/TransparentChecker.gd @@ -11,7 +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) + _init_position(Global.current_project.tile_mode) func update_offset(offset : Vector2, scale : Vector2) -> void: @@ -26,18 +26,18 @@ func _on_TransparentChecker_resized(): func _init_position(id : int): match id: 0: - Global.tile_mode = Global.Tile_Mode.NONE + Global.current_project.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.current_project.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.current_project.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.current_project.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))