From 7446b4accb7b456d5ada064dab607b64e11c2895 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 28 Apr 2023 00:09:55 -0400 Subject: Item names are colored by type in messages The messages node is now a vertical box container with individual RichTextLabels for each line. --- Archipelago/client.gd | 42 +++++++++++++++++++++++------- Archipelago/messages.gd | 68 +++++++++++++++++++++++++++---------------------- 2 files changed, 70 insertions(+), 40 deletions(-) diff --git a/Archipelago/client.gd b/Archipelago/client.gd index 0531fe6..46b9ff0 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd @@ -293,13 +293,14 @@ func _on_data(): var i = 0 for item in message["items"]: if _map_loaded: - processItem(item["item"], message["index"] + i, item["player"]) + processItem(item["item"], message["index"] + i, item["player"], item["flags"]) else: _held_items.append( { "item": item["item"], "index": message["index"] + i, - "from": item["player"] + "from": item["player"], + "flags": item["flags"] } ) i += 1 @@ -324,6 +325,8 @@ func _on_data(): if _player_name_by_slot.has(message["receiving"]): player_name = _player_name_by_slot[message["receiving"]] + var item_color = colorForItemType(message["item"]["flags"]) + var messages_node = get_tree().get_root().get_node("Spatial/AP_Messages") if message["type"] == "Hint": var is_for = "" @@ -331,11 +334,16 @@ func _on_data(): is_for = " for %s" % player_name if !message.has("found") || !message["found"]: messages_node.showMessage( - "Hint: %s%s is on %s" % [item_name, is_for, location_name] + ( + "Hint: [color=%s]%s[/color]%s is on %s" + % [item_color, item_name, is_for, location_name] + ) ) else: if message["receiving"] != _slot: - messages_node.showMessage("Sent %s to %s" % [item_name, player_name]) + messages_node.showMessage( + "Sent [color=%s]%s[/color] to %s" % [item_color, item_name, player_name] + ) elif cmd == "Bounced": if ( @@ -486,7 +494,7 @@ func mapFinishedLoading(): emit_signal("evaluate_solvability") for item in _held_items: - processItem(item["item"], item["index"], item["from"]) + processItem(item["item"], item["index"], item["from"], item["flags"]) sendMessage([{"cmd": "LocationChecks", "locations": _held_locations}]) @@ -495,7 +503,7 @@ func mapFinishedLoading(): _held_locations = [] -func processItem(item, index, from): +func processItem(item, index, from, flags): global._print(item) var stringified = String(item) @@ -522,7 +530,7 @@ func processItem(item, index, from): if _item_name_to_id["Progressive Orange Tower"] == item and _tower_floors < orange_tower.size(): var subitem_name = "Orange Tower - %s Floor" % orange_tower[_tower_floors] global._print(subitem_name) - processItem(_item_name_to_id[subitem_name], null, null) + processItem(_item_name_to_id[subitem_name], null, null, null) _tower_floors += 1 if _color_shuffle and color_items.has(_item_id_to_name[item]): @@ -547,11 +555,15 @@ func processItem(item, index, from): if _player_name_by_slot.has(from): player_name = _player_name_by_slot[from] + var item_color = colorForItemType(flags) + var messages_node = get_tree().get_root().get_node("Spatial/AP_Messages") if from == _slot: - messages_node.showMessage("Found %s" % item_name) + messages_node.showMessage("Found [color=%s]%s[/color]" % [item_color, item_name]) else: - messages_node.showMessage("Received %s from %s" % [item_name, player_name]) + messages_node.showMessage( + "Received [color=%s]%s[/color] from %s" % [item_color, item_name, player_name] + ) var effects_node = get_tree().get_root().get_node("Spatial/AP_Effects") if item_name == "Slowness Trap": @@ -566,3 +578,15 @@ func doorIsVanilla(door): func paintingIsVanilla(painting): return !_mentioned_paintings.has(painting) + + +func colorForItemType(flags): + var int_flags = int(flags) + if int_flags & 1: # progression + return "#bc51e0" + elif int_flags & 2: # useful + return "#2b67ff" + elif int_flags & 4: # trap + return "#d63a22" + else: # filler + return "#14de9e" diff --git a/Archipelago/messages.gd b/Archipelago/messages.gd index 3a2b4b2..d5589ef 100644 --- a/Archipelago/messages.gd +++ b/Archipelago/messages.gd @@ -1,54 +1,60 @@ extends Node var _message_queue = [] +var _font +var _container +var _ordered_labels = [] func _ready(): - var label = Label.new() - label.set_name("label") - label.margin_right = 1920.0 - label.margin_bottom = 1080.0 - 20 - label.margin_left = 20.0 - label.align = Label.ALIGN_LEFT - label.valign = Label.VALIGN_BOTTOM - - var dynamic_font = DynamicFont.new() - dynamic_font.font_data = load("res://fonts/Lingo.ttf") - dynamic_font.size = 36 - dynamic_font.outline_color = Color(0, 0, 0, 1) - dynamic_font.outline_size = 2 - label.add_font_override("font", dynamic_font) - - add_child(label) + _container = VBoxContainer.new() + _container.set_name("Container") + _container.anchor_bottom = 1 + _container.margin_left = 20.0 + _container.margin_right = 1920.0 + _container.margin_top = 0.0 + _container.margin_bottom = -20.0 + _container.alignment = BoxContainer.ALIGN_END + _container.mouse_filter = Control.MOUSE_FILTER_IGNORE + self.add_child(_container) + + _font = DynamicFont.new() + _font.font_data = load("res://fonts/Lingo.ttf") + _font.size = 36 + _font.outline_color = Color(0, 0, 0, 1) + _font.outline_size = 2 + + +func _add_message(text): + var new_label = RichTextLabel.new() + new_label.push_font(_font) + new_label.append_bbcode(text) + new_label.fit_content_height = true + + _container.add_child(new_label) + _ordered_labels.push_back(new_label) func showMessage(text): - var label = self.get_node("label") - if label.text.count("\n") >= 9: + if _ordered_labels.size() >= 9: _message_queue.append(text) return - if !label.text == "": - label.text += "\n" - label.text += text - return + _add_message(text) - label.text = text + if _ordered_labels.size() > 1: + return var timeout = 10.0 - while label.text != "": + while !_ordered_labels.empty(): yield(get_tree().create_timer(timeout), "timeout") - var newline = label.text.find("\n") - if newline == -1: - label.text = "" - else: - label.text = label.text.substr(newline + 1) + var to_remove = _ordered_labels.pop_front() + to_remove.queue_free() if !_message_queue.empty(): var next_msg = _message_queue.pop_front() - label.text += "\n" - label.text += next_msg + _add_message(next_msg) if timeout > 4: timeout -= 3 -- cgit 1.4.1