Skip to content

Commit

Permalink
Removes extra variants, uses enums, new constant
Browse files Browse the repository at this point in the history
  • Loading branch information
DoomTas3r committed Nov 5, 2024
1 parent 7be00b6 commit ec01653
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func _ready():

if not definition == null and definition.variant_type == Variant.Type.TYPE_BOOL:
_background.visible = true
_background.variant = 3
_background.background_variant = _background.POINTED
_background.color = color
_panel.visible = false
else:
Expand Down
111 changes: 36 additions & 75 deletions addons/block_code/ui/blocks/utilities/background/background.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ var parent_block: Block
@export var shift_bottom: float = 0.0:
set = _set_shift_bottom

enum { BODY, HEADER }

## Style of the top knob
@export var top_variant: int = 0:
@export var top_variant := BODY:
set = _set_top_variant

## |0|, \1/, /2/, <3>, >4>, v5v, v6^, \7y, /8y
@export var variant: int = 0:
set = _set_variant
enum { FLAT, POINTED }

## Style of the background |FLAT|, <POINTED>
@export var background_variant := FLAT:
set = _set_background_variant


func _set_color(new_color):
Expand Down Expand Up @@ -68,12 +72,12 @@ func _set_shift_bottom(new_shift_bottom):


func _set_top_variant(new_variant):
top_variant = clamp(new_variant, 0, 1)
top_variant = clamp(new_variant, BODY, HEADER)
queue_redraw()


func _set_variant(new_variant):
variant = clamp(new_variant, 0, 8)
func _set_background_variant(new_variant):
background_variant = clamp(new_variant, FLAT, POINTED)
queue_redraw()


Expand All @@ -87,14 +91,14 @@ func _ready():


func _draw():
var top_left_align = Constants.KNOB_X + shift_top
var bottom_left_align = Constants.KNOB_X + shift_bottom
var top_left_align := Constants.KNOB_X + shift_top
var bottom_left_align := Constants.KNOB_X + shift_bottom
var top_knob: PackedVector2Array
var fill_polygon: PackedVector2Array
fill_polygon.append(Vector2(0.0, 0.0))

if show_top:
if top_variant == 1:
if top_variant == HEADER:
top_knob.append_array(
[
Vector2(5, -4.012612),
Expand Down Expand Up @@ -123,23 +127,15 @@ func _draw():
fill_polygon.append_array(top_knob)

# Right side
if variant > 0:
if background_variant == POINTED:
# Top
if variant == 3 or variant == 4:
fill_polygon.append(Vector2(size.x - 5.0, 0.0))
else:
fill_polygon.append(Vector2(size.x, 0.0))
fill_polygon.append(Vector2(size.x - Constants.POINT_WIDTH, 0.0))

# Middle
if variant == 3 or variant == 4:
fill_polygon.append(Vector2(size.x, size.y / 2.0))
elif variant == 5 or variant == 6:
fill_polygon.append(Vector2(size.x, size.y * 2.0 / 3.0))
elif variant == 7 or variant == 8:
fill_polygon.append(Vector2(size.x, size.y / 3.0))
fill_polygon.append(Vector2(size.x, size.y / 2.0))

# Bottom
fill_polygon.append(Vector2(size.x - 5.0, size.y))
fill_polygon.append(Vector2(size.x - Constants.POINT_WIDTH, size.y))
else:
fill_polygon.append(Vector2(size.x, 0.0))
fill_polygon.append(Vector2(size.x, size.y))
Expand All @@ -151,28 +147,15 @@ func _draw():
fill_polygon.append(Vector2(bottom_left_align, size.y))

# Left side
if variant > 0:
if background_variant == POINTED:
# Bottom
if variant == 2 or variant == 4 or variant == 6 or variant == 8:
fill_polygon.append(Vector2(0.0, size.y))
else:
fill_polygon.append(Vector2(5.0, size.y))
fill_polygon.append(Vector2(Constants.POINT_WIDTH, size.y))

# Middle
if variant == 4:
fill_polygon.append(Vector2(5.0, size.y / 2.0))
elif variant == 3:
fill_polygon.append(Vector2(0.0, size.y / 2.0))
elif variant == 5 or variant == 8:
fill_polygon.append(Vector2(0.0, size.y * 2 / 3.0))
elif variant == 6 or variant == 7:
fill_polygon.append(Vector2(0.0, size.y / 3.0))
fill_polygon.append(Vector2(0.0, size.y / 2.0))

# Top
if variant == 2 or variant == 3 or variant == 6 or variant == 8:
fill_polygon.append(Vector2(5.0, 0.0))
else:
fill_polygon.append(Vector2(0.0, 0.0))
fill_polygon.append(Vector2(Constants.POINT_WIDTH, 0.0))
else:
fill_polygon.append(Vector2(0.0, size.y))
fill_polygon.append(Vector2(0.0, 0.0))
Expand All @@ -182,35 +165,27 @@ func _draw():
if draw_outline:
var stroke_polygon: PackedVector2Array
var edge_polygon: PackedVector2Array
var outline_middle = Constants.OUTLINE_WIDTH / 2
var outline_middle := Constants.OUTLINE_WIDTH / 2

# Top line
if variant > 0:
stroke_polygon.append(Vector2(shift_top - (0.0 if not shift_top > 0 else outline_middle) + 5.0, 0.0))
if background_variant == POINTED:
stroke_polygon.append(Vector2(shift_top - (0.0 if not shift_top > 0 else outline_middle) + Constants.POINT_WIDTH, 0.0))
else:
stroke_polygon.append(Vector2(shift_top - (0.0 if not shift_top > 0 else outline_middle), 0.0))

if show_top:
stroke_polygon.append_array(top_knob)

# Right line
if variant > 0:
if background_variant == POINTED:
# Top
if variant == 3 or variant == 4:
stroke_polygon.append(Vector2(size.x - 5.0, 0.0))
else:
stroke_polygon.append(Vector2(size.x, 0.0))
stroke_polygon.append(Vector2(size.x - Constants.POINT_WIDTH, 0.0))

# Middle
if variant == 3 or variant == 4:
stroke_polygon.append(Vector2(size.x, size.y / 2.0))
elif variant == 5 or variant == 6:
stroke_polygon.append(Vector2(size.x, size.y * 2.0 / 3.0))
elif variant == 7 or variant == 8:
stroke_polygon.append(Vector2(size.x, size.y / 3.0))
stroke_polygon.append(Vector2(size.x, size.y / 2.0))

# Bottom
stroke_polygon.append(Vector2(size.x - 5.0, size.y))
stroke_polygon.append(Vector2(size.x - Constants.POINT_WIDTH, size.y))
else:
stroke_polygon.append(Vector2(size.x, 0.0))
stroke_polygon.append(Vector2(size.x, size.y))
Expand All @@ -222,33 +197,19 @@ func _draw():
stroke_polygon.append(Vector2(bottom_left_align, size.y))

# Left line
if variant > 0:
stroke_polygon.append(Vector2(shift_bottom - (outline_middle if shift_bottom > 0 else 0.0) + 5.0, size.y))
edge_polygon.append(Vector2(5.0 + outline_middle, 0.0))
if background_variant == POINTED:
stroke_polygon.append(Vector2(shift_bottom - (outline_middle if shift_bottom > 0 else 0.0) + Constants.POINT_WIDTH, size.y))
edge_polygon.append(Vector2(Constants.POINT_WIDTH + outline_middle, 0.0))

# Top
if variant == 2 or variant == 3 or variant == 6 or variant == 8:
edge_polygon.append(Vector2(5.0, 0.0))
else:
edge_polygon.append(Vector2(0.0, 0.0))
edge_polygon.append(Vector2(Constants.POINT_WIDTH, 0.0))

# Middle
if variant == 4:
edge_polygon.append(Vector2(5.0, size.y / 2.0))
elif variant == 3:
edge_polygon.append(Vector2(0.0, size.y / 2.0))
elif variant == 5 or variant == 8:
edge_polygon.append(Vector2(0.0, size.y * 2.0 / 3.0))
elif variant == 6 or variant == 7:
edge_polygon.append(Vector2(0.0, size.y / 3.0))
edge_polygon.append(Vector2(0.0, size.y / 2.0))

# Bottom
if variant == 2 or variant == 4 or variant == 6 or variant == 8:
edge_polygon.append(Vector2(0.0, size.y))
edge_polygon.append(Vector2(5.0 + outline_middle, size.y))
else:
edge_polygon.append(Vector2(5.0, size.y))
edge_polygon.append(Vector2(5.0 + outline_middle, size.y))
edge_polygon.append(Vector2(Constants.POINT_WIDTH, size.y))
edge_polygon.append(Vector2(Constants.POINT_WIDTH + outline_middle, size.y))
else:
stroke_polygon.append(Vector2(shift_bottom - (outline_middle if shift_bottom > 0 else 0.0), size.y))
edge_polygon.append(Vector2(0.0, 0.0 - (0.0 if shift_top > 0 else outline_middle)))
Expand Down
26 changes: 13 additions & 13 deletions addons/block_code/ui/blocks/utilities/background/gutter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var parent_block: Block
set = _set_color

## Variant
@export var variant: bool = 0:
set = _set_variant
@export var background_variant := false:
set = _set_background_variant


func _set_color(new_color):
Expand All @@ -21,8 +21,8 @@ func _set_color(new_color):
queue_redraw()


func _set_variant(new_variant):
variant = new_variant
func _set_background_variant(new_variant):
background_variant = new_variant
queue_redraw()


Expand All @@ -34,20 +34,20 @@ func _ready():

func _draw():
var fill_polygon: PackedVector2Array
fill_polygon.append(Vector2(5.0 if variant else 0.0, 0.0))
fill_polygon.append(Vector2(size.x + (5.0 if variant else 0.0), 0.0))
fill_polygon.append(Vector2(size.x + (5.0 if variant else 0.0), size.y))
fill_polygon.append(Vector2(5.0 if variant else 0.0, size.y))
fill_polygon.append(Vector2(5.0 if variant else 0.0, 0.0))
fill_polygon.append(Vector2(Constants.POINT_WIDTH if background_variant else 0.0, 0.0))
fill_polygon.append(Vector2(size.x + (Constants.POINT_WIDTH if background_variant else 0.0), 0.0))
fill_polygon.append(Vector2(size.x + (Constants.POINT_WIDTH if background_variant else 0.0), size.y))
fill_polygon.append(Vector2(Constants.POINT_WIDTH if background_variant else 0.0, size.y))
fill_polygon.append(Vector2(Constants.POINT_WIDTH if background_variant else 0.0, 0.0))

var left_polygon: PackedVector2Array
var right_polygon: PackedVector2Array

left_polygon.append(Vector2(5.0 if variant else 0.0, 0.0))
left_polygon.append(Vector2(5.0 if variant else 0.0, size.y))
left_polygon.append(Vector2(Constants.POINT_WIDTH if background_variant else 0.0, 0.0))
left_polygon.append(Vector2(Constants.POINT_WIDTH if background_variant else 0.0, size.y))

right_polygon.append(Vector2(size.x + (5.0 if variant else 0.0), 0.0))
right_polygon.append(Vector2(size.x + (5.0 if variant else 0.0), size.y))
right_polygon.append(Vector2(size.x + (Constants.POINT_WIDTH if background_variant else 0.0), 0.0))
right_polygon.append(Vector2(size.x + (Constants.POINT_WIDTH if background_variant else 0.0), size.y))

draw_colored_polygon(fill_polygon, color)
draw_polyline(left_polygon, Constants.FOCUS_BORDER_COLOR if parent_block.has_focus() else outline_color, Constants.OUTLINE_WIDTH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func _update_visible_input():
TYPE_VECTOR2:
_switch_input(_vector2_input)
TYPE_BOOL:
_background.variant = 3
_background.background_variant = _background.POINTED
_switch_input(_bool_input)
_:
_switch_input(_text_input)
Expand Down
1 change: 1 addition & 0 deletions addons/block_code/ui/constants.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const KNOB_X = 10.0
const KNOB_W = 20.0
const KNOB_H = 5.0
const KNOB_Z = 5.0
const POINT_WIDTH = 5.0
const CONTROL_MARGIN = 20.0
const OUTLINE_WIDTH = 3.0
const MINIMUM_SNAP_DISTANCE = 80.0
Expand Down

0 comments on commit ec01653

Please sign in to comment.