From afa3ce30cdca620b7b0e16d19b50ff804962027f Mon Sep 17 00:00:00 2001 From: rainlizard <15337628+rainlizard@users.noreply.github.com> Date: Tue, 9 Apr 2024 08:47:34 +1000 Subject: [PATCH] Disable the ownership icons for collectibles when placing. --- Autoload/Things.gd | 11 ++++++++--- Scenes/Instances.gd | 11 +++-------- Scenes/Main.tscn | 9 +++++++++ Scenes/OwnerSelection.gd | 34 ++++++++++++++++++++++++++++++---- Scenes/Selection.gd | 7 +++++++ Scenes/SlabOwnerCheckBox.gd | 9 +++------ Scenes/WriteData.gd | 14 +++++++------- 7 files changed, 67 insertions(+), 28 deletions(-) diff --git a/Autoload/Things.gd b/Autoload/Things.gd index 4486efb6..bd252b88 100644 --- a/Autoload/Things.gd +++ b/Autoload/Things.gd @@ -23,7 +23,6 @@ enum TYPE { EXTRA = 696969 } - var data_structure_name = { TYPE.NONE: "Empty", TYPE.OBJECT: "Object", @@ -41,6 +40,7 @@ var data_structure_name = { TYPE.CAVEIN: "CaveIn", TYPE.EXTRA: "Extra" } + var reverse_data_structure_name = { "Empty": TYPE.NONE, "Object":TYPE.OBJECT, @@ -59,8 +59,6 @@ var reverse_data_structure_name = { "Extra":TYPE.EXTRA, } - - enum { NAME = 0 KEEPERFX_NAME = 1 @@ -400,6 +398,13 @@ enum SPELLBOOK { DESTROY_WALLS = 47 } +var genre_belonging = { + TAB_GOLD : Slabs.TREASURE_ROOM, + TAB_SPELL : Slabs.LIBRARY, + TAB_SPECIAL : Slabs.LIBRARY, + TAB_BOX : Slabs.WORKSHOP, +} + #OBJECT = 1 #CREATURE = 5 #EFFECT = 7 diff --git a/Scenes/Instances.gd b/Scenes/Instances.gd index 6ac38b63..6c84c917 100644 --- a/Scenes/Instances.gd +++ b/Scenes/Instances.gd @@ -433,17 +433,12 @@ func manage_things_on_slab(xSlab, ySlab, slabID, ownership): on_slab_delete_stray_door_thing_and_key(id, slabID) on_slab_set_belongings_ownership(id, slabID, ownership) -var genre_belonging = { - Things.TAB_GOLD : Slabs.TREASURE_ROOM, - Things.TAB_SPELL : Slabs.LIBRARY, - Things.TAB_SPECIAL : Slabs.LIBRARY, - Things.TAB_BOX : Slabs.WORKSHOP, -} + func on_slab_set_belongings_ownership(id, slabID, ownership): if id.thingType == Things.TYPE.OBJECT: var genre = Things.DATA_OBJECT[id.subtype][Things.EDITOR_TAB] - if genre_belonging.has(genre): - if slabID == genre_belonging[genre]: + if Things.genre_belonging.has(genre): + if slabID == Things.genre_belonging[genre]: id.ownership = ownership else: id.ownership = 5 diff --git a/Scenes/Main.tscn b/Scenes/Main.tscn index 2e473046..1b915381 100644 --- a/Scenes/Main.tscn +++ b/Scenes/Main.tscn @@ -1385,6 +1385,15 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="CollectibleLabel" type="Label" parent="Ui/UiTools/PropertiesWindow/VBoxContainer/PropertiesTabs/PlacingSettings/OwnerSelection"] +visible = false +margin_top = 9.0 +margin_right = 40.0 +margin_bottom = 30.0 +hint_tooltip = "Collectibles have their ownership set to Neutral unless placed in their specified room: Gold in Treasury, Boxes in Workshop, Specials/Spells in Library." +mouse_filter = 1 +text = "Collectible" + [node name="Control" type="Control" parent="Ui/UiTools/PropertiesWindow/VBoxContainer/PropertiesTabs/PlacingSettings/OwnerSelection"] margin_top = 42.0 margin_right = 276.0 diff --git a/Scenes/OwnerSelection.gd b/Scenes/OwnerSelection.gd index 7ba2f49f..7a488186 100644 --- a/Scenes/OwnerSelection.gd +++ b/Scenes/OwnerSelection.gd @@ -4,6 +4,7 @@ onready var oOnlyOwnership = Nodelist.list["oOnlyOwnership"] onready var oUseSlabOwnerCheckBox = Nodelist.list["oUseSlabOwnerCheckBox"] onready var oOwnershipGridContainer = Nodelist.list["oOwnershipGridContainer"] onready var oMirrorOptions = Nodelist.list["oMirrorOptions"] +onready var oCollectibleLabel = Nodelist.list["oCollectibleLabel"] #onready var oEditor = Nodelist.list["oEditor"] onready var gridItemScene = preload("res://Scenes/GenericGridItem.tscn") @@ -15,6 +16,8 @@ onready var oCenteredLabel = $Control/CenteredLabel # var owner_order = [0,1,2,3,4,5] +var ownership_available = true + func _ready(): for i in owner_order: var id = gridItemScene.instance() @@ -46,8 +49,9 @@ func add_child_to_grid(id, set_text): func pressed(id): var setValue = id.get_meta("grid_value") - if oUseSlabOwnerCheckBox.pressed == true and oUseSlabOwnerCheckBox.visible == true: - #setValue = 5 + if oCollectibleLabel.visible == true: + return + elif oUseSlabOwnerCheckBox.pressed == true and oUseSlabOwnerCheckBox.visible == true: oUseSlabOwnerCheckBox.pressed = false oSelection.paintOwnership = setValue set_selection(setValue) @@ -59,10 +63,12 @@ func _process(delta): # It's necessary to use _process to update selection, beca func update_selection(): if oSelectedRect == null: return if is_instance_valid(oSelectedRect.boundToItem) == false: return - # If checkbox is checked then don't do anything - if oUseSlabOwnerCheckBox.pressed == true and oUseSlabOwnerCheckBox.visible == true: + + # If greyed out then don't do anything + if ownership_available == false: oSelectedRect.visible = false return + oSelectedRect.visible = true oSelectedRect.rect_global_position = oSelectedRect.boundToItem.rect_global_position oSelectedRect.rect_size = oSelectedRect.boundToItem.rect_size @@ -87,6 +93,26 @@ func set_selection(value): if id.get_meta("grid_value") == value: oSelectedRect.boundToItem = id +func collectible_ownership_mode(collMode): + if collMode == true: + oCollectibleLabel.visible = true + oUseSlabOwnerCheckBox.visible = false + else: + oCollectibleLabel.visible = false + oUseSlabOwnerCheckBox.visible = true + update_ownership_available() + +func update_ownership_available(): + ownership_available = true + oOwnershipGridContainer.modulate.a = 1.00 + + if oCollectibleLabel.visible == true: + ownership_available = false + oOwnershipGridContainer.modulate.a = 0.25 + elif oUseSlabOwnerCheckBox.visible == true and oUseSlabOwnerCheckBox.pressed == true: + ownership_available = false + oOwnershipGridContainer.modulate.a = 0.25 + # #func clear_grid(): diff --git a/Scenes/Selection.gd b/Scenes/Selection.gd index 2ad51ffd..c2842d9f 100644 --- a/Scenes/Selection.gd +++ b/Scenes/Selection.gd @@ -81,6 +81,13 @@ func newPaintSubtype(value): oSelector.change_mode(oSelector.MODE_SUBTILE) oPickSlabWindow.set_selection(null) # Deselect anything in slab window paintSubtype = value + + oOwnerSelection.collectible_ownership_mode(false) + if paintThingType == Things.TYPE.OBJECT: + var genre = Things.DATA_OBJECT[paintSubtype][Things.EDITOR_TAB] + if Things.genre_belonging.has(genre): + oOwnerSelection.collectible_ownership_mode(true) + func newOwnership(value): oUi.update_theme_colour(value) diff --git a/Scenes/SlabOwnerCheckBox.gd b/Scenes/SlabOwnerCheckBox.gd index 66bfef28..308a3d62 100644 --- a/Scenes/SlabOwnerCheckBox.gd +++ b/Scenes/SlabOwnerCheckBox.gd @@ -1,13 +1,10 @@ extends CheckBox +onready var oOwnerSelection = Nodelist.list["oOwnerSelection"] onready var oOwnershipGridContainer = Nodelist.list["oOwnershipGridContainer"] func _on_UseSlabOwnerCheckBox_toggled(button_pressed): - if button_pressed == true and visible == true: - oOwnershipGridContainer.modulate = Color(1,1,1,0.25) - else: - oOwnershipGridContainer.modulate = Color(1,1,1,1.00) - + oOwnerSelection.update_ownership_available() func _on_UseSlabOwnerCheckBox_visibility_changed(): yield(get_tree(),'idle_frame') - _on_UseSlabOwnerCheckBox_toggled(pressed) + oOwnerSelection.update_ownership_available() diff --git a/Scenes/WriteData.gd b/Scenes/WriteData.gd index fdb06ef7..a20fad25 100644 --- a/Scenes/WriteData.gd +++ b/Scenes/WriteData.gd @@ -89,13 +89,13 @@ func write_slb(buffer): buffer.put_8(0) func write_own(buffer): - var dataHeight = (M.ySize*3)+1 - var dataWidth = (M.xSize*3)+1 - for subtileY in dataHeight: - for subtileX in dataWidth: - buffer.seek(subtileX + (subtileY*dataWidth)) - value = oDataOwnership.get_cell(subtileX/3,subtileY/3) - buffer.put_8(value) + var dataHeight = (M.ySize * 3) + 1 + var dataWidth = (M.xSize * 3) + 1 + var size = dataHeight * dataWidth + for i in size: + var subtileX = i % dataWidth + var subtileY = i / dataWidth + buffer.put_8(oDataOwnership.get_cell(subtileX / 3, subtileY / 3)) func write_tng(buffer): var numberOfTngEntries = get_tree().get_nodes_in_group("Thing").size()