Skip to content

Commit

Permalink
[CtrlInventoryGrid] Custom styles
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-kish committed May 18, 2024
1 parent 648abe0 commit 56a7ea2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
19 changes: 15 additions & 4 deletions addons/gloot/ui/ctrl_inventory_grid.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PriorityPanel extends Panel:
add_theme_stylebox_override("panel", style)


class SelectionPanel extends Panel:
class CustomizablePanel extends Panel:
func set_style(style: StyleBox) -> void:
remove_theme_stylebox_override("panel")
if style != null:
Expand Down Expand Up @@ -107,7 +107,7 @@ class SelectionPanel extends Panel:
_ctrl_inventory_grid_basic.select_mode = select_mode

@export_group("Custom Styles")
@export var field_style: StyleBox :
@export var field_style: StyleBox = preload("res://addons/gloot/ui/ctrl_inventory_grid_field_style_normal.tres") :
set(new_field_style):
field_style = new_field_style
_queue_refresh()
Expand All @@ -119,16 +119,21 @@ class SelectionPanel extends Panel:
set(new_field_selected_style):
field_selected_style = new_field_selected_style
_queue_refresh()
@export var selection_style: StyleBox :
@export var selection_style: StyleBox = preload("res://addons/gloot/ui/ctrl_inventory_grid_style_selection.tres"):
set(new_selection_style):
selection_style = new_selection_style
_queue_refresh()
@export var background_style: StyleBox = preload("res://addons/gloot/ui/ctrl_inventory_grid_style_background.tres"):
set(new_background_style):
background_style = new_background_style
_queue_refresh()

var _ctrl_inventory_grid_basic: CtrlInventoryGridBasic = null
var _field_background_grid: Control = null
var _field_backgrounds: Array = []
var _selection_panels: Control = null
var _refresh_queued: bool = false
var _background: CustomizablePanel = null


func _connect_inventory_signals() -> void:
Expand Down Expand Up @@ -184,7 +189,7 @@ func _refresh_selection_panel() -> void:
return

for selected_item in selected_items:
var selection_panel := SelectionPanel.new()
var selection_panel := CustomizablePanel.new()
var rect := _ctrl_inventory_grid_basic.get_item_rect(selected_item)
selection_panel.position = rect.position
selection_panel.size = rect.size
Expand Down Expand Up @@ -227,6 +232,11 @@ func _ready() -> void:
_ctrl_inventory_grid_basic.queue_free()
_field_background_grid.queue_free()

_background = CustomizablePanel.new()
_background.name = "Background"
_background.set_style(background_style)
add_child(_background)

_field_background_grid = Control.new()
_field_background_grid.name = "FieldBackgrounds"
add_child(_field_background_grid)
Expand Down Expand Up @@ -275,6 +285,7 @@ func _notification(what: int) -> void:
func _update_size() -> void:
custom_minimum_size = _ctrl_inventory_grid_basic.size
size = _ctrl_inventory_grid_basic.size
_background.size = _ctrl_inventory_grid_basic.size


func _on_item_mouse_entered(item: InventoryItem) -> void:
Expand Down
6 changes: 6 additions & 0 deletions addons/gloot/ui/ctrl_inventory_grid_field_style_normal.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_resource type="StyleBoxFlat" format=3 uid="uid://bab5l46oddme5"]

[resource]
bg_color = Color(0.6, 0.6, 0.6, 0)
border_width_right = 1
border_width_bottom = 1
6 changes: 6 additions & 0 deletions addons/gloot/ui/ctrl_inventory_grid_style_background.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_resource type="StyleBoxFlat" format=3 uid="uid://dnk4u11b38rr6"]

[resource]
bg_color = Color(0.6, 0.6, 0.6, 0)
border_width_left = 1
border_width_top = 1
9 changes: 9 additions & 0 deletions addons/gloot/ui/ctrl_inventory_grid_style_selection.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_resource type="StyleBoxFlat" format=3 uid="uid://c2h2ygy48r1cr"]

[resource]
bg_color = Color(0.6, 0.6, 0.6, 0)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(1, 1, 1, 1)

0 comments on commit 56a7ea2

Please sign in to comment.