From bfc063cd14b8c8ae09c3969ba18f9d73db82424b Mon Sep 17 00:00:00 2001 From: rainlizard <15337628+rainlizard@users.noreply.github.com> Date: Fri, 17 May 2024 01:07:04 +1000 Subject: [PATCH] Added extra ID/Name entry to Properties window, adjust font size based on largest word --- Autoload/Things.gd | 13 ++++++++ Scenes/CfgLoader.gd | 2 ++ Scenes/CurrentTextures.gd | 4 +-- Scenes/OpenMap.gd | 4 +-- Scenes/PlacingSettings.gd | 39 +++++++++++------------ Scenes/ThingDetails.gd | 65 +++++++++++++++++---------------------- Scenes/TwoColumnData.gd | 31 +++++++++++++------ Theme/StokeSmaller.tres | 11 +++++++ Theme/StokeTiny.tres | 11 +++++++ project.godot | 1 - 10 files changed, 111 insertions(+), 70 deletions(-) create mode 100644 Theme/StokeSmaller.tres create mode 100644 Theme/StokeTiny.tres diff --git a/Autoload/Things.gd b/Autoload/Things.gd index b121589c..ebbaa814 100644 --- a/Autoload/Things.gd +++ b/Autoload/Things.gd @@ -88,6 +88,19 @@ func fetch_name(thing_type, sub_type): else: return "Unknown Thingtype " + str(thing_type) + ", Subtype: " + str(sub_type) +func fetch_id_string(thing_type, sub_type): + var data_structure = data_structure(thing_type) + var sub_type_data = data_structure.get(sub_type) + if sub_type_data: + var nameId = sub_type_data[NAME_ID] + if nameId is String: + return nameId + elif nameId is Array: # This is to take into considersation someone accidentally using two words with spaces as an object name. (otherwise we get a crash) + return nameId[0].capitalize() + return "Error1337" + else: + return "Unknown " + data_structure_name[thing_type] + " Subtype: " + str(sub_type) + var data_structure_name = { TYPE.NONE: "Empty", diff --git a/Scenes/CfgLoader.gd b/Scenes/CfgLoader.gd index e8987aa2..b8a1943e 100644 --- a/Scenes/CfgLoader.gd +++ b/Scenes/CfgLoader.gd @@ -21,12 +21,14 @@ enum { } func start(mapPath): + if Cube.tex.empty(): Cube.read_cubes_cfg() var CODETIME_LOADCFG_START = OS.get_ticks_msec() Things.reset_thing_data_to_default() + var campaign_cfg = load_campaign_data(mapPath) var config_dirs = { diff --git a/Scenes/CurrentTextures.gd b/Scenes/CurrentTextures.gd index 25272ee7..12170f13 100644 --- a/Scenes/CurrentTextures.gd +++ b/Scenes/CurrentTextures.gd @@ -222,12 +222,12 @@ func convert_img_to_two_texture_arrays(img): func set_current_texture_pack(): - var value = oDataLevelStyle.data + var value = oDataLevelStyle.data if cachedTextures.empty() == true: oMessage.big("Error", "One or more tilesets failed to load. Try pressing the [Reload tileset cache] button in File->Preferences and then reopen the map.") return - if cachedTextures[value] == null or cachedTextures[value][0] == null or cachedTextures[value][1] == null: + if value < cachedTextures.size() == false or cachedTextures[value] == null or cachedTextures[value][0] == null or cachedTextures[value][1] == null: oMessage.big("Error", "Unable to load tileset number " + str(value) + ". Try pressing the [Reload tileset cache] button in File->Preferences.") return diff --git a/Scenes/OpenMap.gd b/Scenes/OpenMap.gd index e82bfbc3..0b14a25f 100644 --- a/Scenes/OpenMap.gd +++ b/Scenes/OpenMap.gd @@ -194,7 +194,7 @@ func continue_load(map): oScriptEditor.initialize_for_new_map() oOverheadOwnership.start() oScriptHelpers.start() - + # update_editor_data if Slabset.dat.empty() == true: Slabset.load_default_slabset() @@ -204,7 +204,7 @@ func continue_load(map): oOverheadGraphics.update_full_overhead_map(oOverheadGraphics.MULTI_THREADED) oDataClm.count_filled_clm_entries() - + oTextureCache.set_current_texture_pack() # finalize_map_opening diff --git a/Scenes/PlacingSettings.gd b/Scenes/PlacingSettings.gd index bf09c58a..65ead983 100644 --- a/Scenes/PlacingSettings.gd +++ b/Scenes/PlacingSettings.gd @@ -26,8 +26,9 @@ var orientation = 0 var goldValue = 0 enum FIELDS { - ID - TYPE + SUBTYPE + NAME_ID + THINGTYPE OWNERSHIP EFFECT_RANGE CREATURE_LEVEL @@ -68,51 +69,51 @@ func update_placing_tab(): var availableFields = [] match thingType: Things.TYPE.NONE: - availableFields = [FIELDS.ID] + availableFields = [FIELDS.SUBTYPE] Things.TYPE.OBJECT: - availableFields = [FIELDS.ID, FIELDS.TYPE] + availableFields = [FIELDS.SUBTYPE, FIELDS.NAME_ID, FIELDS.THINGTYPE] if subtype == 133: #Mysterious Box - availableFields = [FIELDS.ID, FIELDS.TYPE, FIELDS.CUSTOM_BOX_ID] + availableFields = [FIELDS.SUBTYPE, FIELDS.NAME_ID, FIELDS.THINGTYPE, FIELDS.CUSTOM_BOX_ID] if oCurrentFormat.selected != 0: # Classic format availableFields.append(FIELDS.ORIENTATION) Things.TYPE.CREATURE: - availableFields = [FIELDS.ID, FIELDS.TYPE, FIELDS.CREATURE_LEVEL] + availableFields = [FIELDS.SUBTYPE, FIELDS.NAME_ID, FIELDS.THINGTYPE, FIELDS.CREATURE_LEVEL] if oCurrentFormat.selected != 0: # Classic format availableFields.append(FIELDS.INITIAL_HEALTH) availableFields.append(FIELDS.CREATURE_GOLD) availableFields.append(FIELDS.CREATURE_NAME) #availableFields.append(FIELDS.ORIENTATION) Things.TYPE.EFFECTGEN: - availableFields = [FIELDS.ID, FIELDS.TYPE, FIELDS.EFFECT_RANGE, FIELDS.ORIENTATION] + availableFields = [FIELDS.SUBTYPE, FIELDS.NAME_ID, FIELDS.THINGTYPE, FIELDS.EFFECT_RANGE, FIELDS.ORIENTATION] if oCurrentFormat.selected != 0: # Classic format availableFields.append(FIELDS.ORIENTATION) Things.TYPE.TRAP: - availableFields = [FIELDS.ID, FIELDS.TYPE, FIELDS.ORIENTATION] + availableFields = [FIELDS.SUBTYPE, FIELDS.NAME_ID, FIELDS.THINGTYPE, FIELDS.ORIENTATION] if oCurrentFormat.selected != 0: # Classic format availableFields.append(FIELDS.ORIENTATION) Things.TYPE.DOOR: - availableFields = [FIELDS.ID, FIELDS.TYPE, FIELDS.DOOR_LOCKED] + availableFields = [FIELDS.SUBTYPE, FIELDS.NAME_ID, FIELDS.THINGTYPE, FIELDS.DOOR_LOCKED] Things.TYPE.EXTRA: match subtype: 1: - availableFields = [FIELDS.ID, FIELDS.TYPE, FIELDS.POINT_RANGE] # Action point + availableFields = [FIELDS.SUBTYPE, FIELDS.NAME_ID, FIELDS.THINGTYPE, FIELDS.POINT_RANGE] # Action point 2: - availableFields = [FIELDS.ID, FIELDS.TYPE, FIELDS.LIGHT_RANGE, FIELDS.LIGHT_INTENSITY] # Light + availableFields = [FIELDS.SUBTYPE, FIELDS.NAME_ID, FIELDS.THINGTYPE, FIELDS.LIGHT_RANGE, FIELDS.LIGHT_INTENSITY] # Light for i in FIELDS.size(): var description = null var value = null if i in availableFields: match i: - FIELDS.ID: - description = "ID" + FIELDS.SUBTYPE: + description = "Name" value = Things.fetch_name(thingType, subtype) - FIELDS.TYPE: + FIELDS.NAME_ID: + description = "ID" + value = Things.fetch_id_string(thingType, subtype) + FIELDS.THINGTYPE: description = "Type" - value = oThingDetails.retrieve_subtype_value(thingType, subtype) -# FIELDS.OWNERSHIP: -# description = "Ownership" -# value = Constants.ownershipNames[ownership] + value = Things.data_structure_name.get(thingType, "Unknown") + " : " + str(subtype) FIELDS.EFFECT_RANGE: description = "Effect range" # 9-10 value = effectRange @@ -135,7 +136,7 @@ func update_placing_tab(): description = "Custom box" # 14 value = boxNumber FIELDS.CREATURE_NAME: - description = "Name" #Creature name + description = "Unique name" value = creatureName FIELDS.CREATURE_GOLD: description = "Gold held" diff --git a/Scenes/ThingDetails.gd b/Scenes/ThingDetails.gd index 5629d7b7..75fb3f6c 100644 --- a/Scenes/ThingDetails.gd +++ b/Scenes/ThingDetails.gd @@ -103,26 +103,29 @@ func light_details(id): func thing_details(id): - for i in 16: + for i in 17: var description = null var value = null match i: 0: - description = "ID" + description = "Name" value = Things.fetch_name(id.thingType, id.subtype) 1: - description = "Type" - value = retrieve_subtype_value(id.thingType, id.subtype) + description = "ID" + value = Things.fetch_id_string(id.thingType, id.subtype) 2: + description = "Type" + value = Things.data_structure_name.get(id.thingType, "Unknown") + " : " + str(id.subtype) + 3: description = "Position" value = str(id.locationX)+' '+str(id.locationY)+' '+str(id.locationZ) - 3: + 4: description = "Ownership" value = Constants.ownershipNames[id.ownership] - 4: + 5: description = "Effect range" # 9-10 value = id.effectRange - 5: + 6: description = "Attached to" # 11-12 if id.parentTile != null: var parentY = int(id.parentTile/M.ySize) @@ -136,41 +139,41 @@ func thing_details(id): value += ' (' + str(parentX) + ','+str(parentY) + ')' if id.parentTile == 65535: value = "Manually placed" - 6: + 7: description = "Door orientation" # 13 match id.doorOrientation: 0: value = "E/W" 1: value = "N/S" - 7: + 8: description = "Level" # 14 value = id.creatureLevel - 8: + 9: description = "Gate #" # 14 value = id.herogateNumber - 9: + 10: description = "Custom box" # 14 value = id.boxNumber - 10: + 11: description = "Door locked" # 14 value = id.doorLocked # FX extended fields - 11: + 12: description = "Health %" value = id.creatureInitialHealth if oCurrentFormat.selected == Constants.ClassicFormat: value = null - 12: + 13: description = "Gold held" value = id.creatureGold if oCurrentFormat.selected == Constants.ClassicFormat: value = null - 13: - description = "Name" # Creature name + 14: + description = "Unique name" value = id.creatureName if oCurrentFormat.selected == Constants.ClassicFormat: value = null - 14: + 15: description = "Gold value" value = id.goldValue if oCurrentFormat.selected == Constants.ClassicFormat: value = null - 15: + 16: description = "Orientation" value = id.orientation if oCurrentFormat.selected == Constants.ClassicFormat: value = null @@ -209,27 +212,17 @@ func _on_thing_portrait_mouse_entered(nodeId): # Name value = Things.fetch_name(portraitThingType, portraitSubtype) if value != null: - oThingListData.add_item(str(value),"") + oThingListData.add_item("Name", str(value)) + + value = Things.fetch_id_string(portraitThingType, portraitSubtype) + if value != null: + oThingListData.add_item("ID", str(value)) - value = null if portraitThingType != Things.TYPE.EXTRA: - value = retrieve_subtype_value(portraitThingType, portraitSubtype) + value = Things.data_structure_name.get(portraitThingType, "Unknown") + " : " + str(portraitSubtype) if value != null: - oThingListData.add_item(str(value),"") - -func retrieve_subtype_value(t_type, s_type): - match t_type: - Things.TYPE.NONE: return "None" + " : " + str(s_type) - Things.TYPE.OBJECT: return "Object" + " : " + str(s_type) - Things.TYPE.CREATURE: return "Creature" + " : " + str(s_type) - Things.TYPE.EFFECTGEN: return "EffectGen" + " : " + str(s_type) - Things.TYPE.TRAP: return "Trap" + " : " + str(s_type) - Things.TYPE.DOOR: return "Door" + " : " + str(s_type) - Things.TYPE.EXTRA: return null -# match s_type: -# 1: return "Action point : " + str(s_type) -# 2: return "Light : " + str(s_type) - return "Unknown" + oThingListData.add_item("Type", str(value)) + # Fixes an obscure issue where it would continue to show what you've highlighted in the Thing Window inside of the Properties' Thing column. #func _on_PropertiesTabs_tab_changed(tab): diff --git a/Scenes/TwoColumnData.gd b/Scenes/TwoColumnData.gd index 0c3cab81..4a5b6c01 100644 --- a/Scenes/TwoColumnData.gd +++ b/Scenes/TwoColumnData.gd @@ -126,28 +126,42 @@ func add_item(leftString, rightString): var orientIndex = Constants.listOrientations.find(int(rightString)) if orientIndex != -1: nodeRightColumn.selected = orientIndex - "Name": #Creature name + "Unique name": #Creature name nodeRightColumn = LineEdit.new() nodeRightColumn.placeholder_text = "Default" nodeRightColumn.placeholder_alpha = 0.33 nodeRightColumn.text = rightString #Utils.strip_special_chars_from_string(rightString) nodeRightColumn.connect("text_changed", self, "_on_property_value_changed", [nodeRightColumn, leftString]) + #nodeRightColumn.add_font_override("font", preload("res://Theme/StokeSmaller.tres")) _: nodeRightColumn = Label.new() nodeRightColumn.autowrap = true nodeRightColumn.rect_min_size.x = columnRightSize - #if name == "ColumnListData": nodeRightColumn.rect_min_size.x = columnRightSize-50 - # This is for when highlighting something in the Thing Window - if rightString == "": - nodeRightColumn.rect_min_size.x = 0 - nameDesc.autowrap = false nodeRightColumn.text = rightString nodeRightColumn.size_flags_vertical = Control.SIZE_EXPAND# + Control.SIZE_SHRINK_END # To handle the other side's autowrap text nodeRightColumn.align = HALIGN_LEFT + + var largest_word_width = get_largest_word_width(nodeRightColumn.text, nodeRightColumn.get_font("font", "Label")) + if largest_word_width >= 198: # EFFECTGENERATOR_ENTRANCE_ is slightly too large + nodeRightColumn.add_font_override("font", preload("res://Theme/StokeTiny.tres")) + elif largest_word_width >= 101: # "DARK_MISTRESS" is slightly too large + nodeRightColumn.add_font_override("font", preload("res://Theme/StokeSmaller.tres")) add_child(nodeRightColumn) + +func get_largest_word_width(text: String, font: Font) -> float: + var words = text.split(" ") + var largest_word_width = 0.0 + + for word in words: + var word_width = font.get_string_size(word).x + if word_width > largest_word_width: + largest_word_width = word_width + + return largest_word_width + func _on_property_value_entered(new_val, callingNode): # When pressing Enter on LineEdit, lose focus oEditor.mapHasBeenEdited = true callingNode.release_focus() @@ -217,7 +231,7 @@ func update_property_value(callingNode, leftString): "Point range": property_name = "pointRange" value = clamp(float(value), 0, 255) - "Name": + "Unique name": property_name = "creatureName" # String, so no clamping "Gold held": @@ -329,6 +343,3 @@ func delete_children(node): for n in node.get_children(): node.remove_child(n) #important to do this otherwise the margins get messed up n.queue_free() - - - diff --git a/Theme/StokeSmaller.tres b/Theme/StokeSmaller.tres new file mode 100644 index 00000000..7b977c06 --- /dev/null +++ b/Theme/StokeSmaller.tres @@ -0,0 +1,11 @@ +[gd_resource type="DynamicFont" load_steps=2 format=2] + +[ext_resource path="res://Theme/Stoke-Light.ttf" type="DynamicFontData" id=1] + +[resource] +size = 14 +use_mipmaps = true +use_filter = true +extra_spacing_top = 2 +extra_spacing_char = -1 +font_data = ExtResource( 1 ) diff --git a/Theme/StokeTiny.tres b/Theme/StokeTiny.tres new file mode 100644 index 00000000..caecb2da --- /dev/null +++ b/Theme/StokeTiny.tres @@ -0,0 +1,11 @@ +[gd_resource type="DynamicFont" load_steps=2 format=2] + +[ext_resource path="res://Theme/Stoke-Light.ttf" type="DynamicFontData" id=1] + +[resource] +size = 12 +use_mipmaps = true +use_filter = true +extra_spacing_top = 3 +extra_spacing_char = -1 +font_data = ExtResource( 1 ) diff --git a/project.godot b/project.godot index 473f32de..24bde2cf 100644 --- a/project.godot +++ b/project.godot @@ -54,7 +54,6 @@ config/name="Unearth" run/main_scene="res://Scenes/Main.tscn" boot_splash/image="Skip-loading-screen" config/icon="res://Art/icon/UnearthIcon256x256.png" -config/windows_native_icon="res://Art/icon/UnearthIcon.ico" [autoload]