diff --git a/scenes/game.tscn b/scenes/game.tscn index 62451a7..9cb03ff 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=5 format=3 uid="uid://c0b5w48jk67qd"] +[gd_scene load_steps=6 format=3 uid="uid://c0b5w48jk67qd"] [ext_resource type="Script" uid="uid://c0uvlwmkm3r8o" path="res://scripts/game/game_screen.gd" id="1_uwrxv"] [ext_resource type="Script" uid="uid://dcqqr8b42tn0x" path="res://scripts/game/CommandProcessor.gd" id="2_lbhrr"] [ext_resource type="Texture2D" uid="uid://ccxs3ctob15es" path="res://gfx/ui/main_frame.png" id="2_lnu2h"] [ext_resource type="FontFile" uid="uid://1u28cjgctsn7" path="res://fonts/alagard_by_pix3m-d6awiwp.ttf" id="3_lbhrr"] +[ext_resource type="Script" uid="uid://dv3fd112uj8o1" path="res://scripts/ui/Message Console.gd" id="5_iywne"] [node name="Game" type="Node" node_paths=PackedStringArray("map")] script = ExtResource("1_uwrxv") @@ -24,7 +25,7 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -[node name="TextureRect" type="TextureRect" parent="UI"] +[node name="Background Frame" type="TextureRect" parent="UI"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -33,20 +34,50 @@ grow_horizontal = 2 grow_vertical = 2 texture = ExtResource("2_lnu2h") -[node name="Left Panel" type="VBoxContainer" parent="UI"] +[node name="Left Display" type="MarginContainer" parent="UI"] layout_mode = 0 offset_left = 13.0 offset_top = 15.0 -offset_right = 166.0 +offset_right = 167.0 offset_bottom = 216.0 -[node name="Command Menu" type="VBoxContainer" parent="UI/Left Panel"] +[node name="Background" type="ColorRect" parent="UI/Left Display"] +layout_mode = 2 +color = Color(0, 0, 0, 1) + +[node name="Contents" type="VBoxContainer" parent="UI/Left Display"] layout_mode = 2 -[node name="Pass Button" type="Button" parent="UI/Left Panel/Command Menu"] +[node name="Command Menu" type="VBoxContainer" parent="UI/Left Display/Contents"] +layout_mode = 2 + +[node name="Pass Button" type="Button" parent="UI/Left Display/Contents/Command Menu"] layout_mode = 2 theme_override_fonts/font = ExtResource("3_lbhrr") text = "Pass" +[node name="Message Console" type="MarginContainer" parent="UI" node_paths=PackedStringArray("scrollContainer", "messages")] +layout_mode = 0 +offset_left = 13.0 +offset_top = 231.0 +offset_right = 627.0 +offset_bottom = 345.0 +script = ExtResource("5_iywne") +scrollContainer = NodePath("ScrollContainer") +messages = NodePath("ScrollContainer/Messages") + +[node name="Background" type="ColorRect" parent="UI/Message Console"] +layout_mode = 2 +color = Color(0, 0, 0, 1) + +[node name="ScrollContainer" type="ScrollContainer" parent="UI/Message Console"] +layout_mode = 2 +horizontal_scroll_mode = 0 + +[node name="Messages" type="VBoxContainer" parent="UI/Message Console/ScrollContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[connection signal="BROADCAST_COMMAND" from="Command Processor" to="UI/Message Console" method="_on_command"] [connection signal="timeout" from="Command Processor" to="Command Processor" method="_on_timeout"] -[connection signal="pressed" from="UI/Left Panel/Command Menu/Pass Button" to="." method="_on_pass_button_pressed"] +[connection signal="pressed" from="UI/Left Display/Contents/Command Menu/Pass Button" to="." method="_on_pass_button_pressed"] diff --git a/scenes/ui/MessageLine.tscn b/scenes/ui/MessageLine.tscn new file mode 100644 index 0000000..bdb93e1 --- /dev/null +++ b/scenes/ui/MessageLine.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=2 format=3 uid="uid://wbh5uji0cktb"] + +[ext_resource type="Theme" uid="uid://dnxny0n7ti7eq" path="res://themes/default_theme.tres" id="1_re2k6"] + +[node name="MessageLine" type="RichTextLabel"] +theme = ExtResource("1_re2k6") +text = "Enter Command: + +" +fit_content = true +scroll_active = false diff --git a/scripts/game/CommandProcessor.gd b/scripts/game/CommandProcessor.gd index 353b17e..e3c7f30 100644 --- a/scripts/game/CommandProcessor.gd +++ b/scripts/game/CommandProcessor.gd @@ -1,6 +1,5 @@ extends Timer -class_name CommandProcessor signal BROADCAST_COMMAND(label) var resumeWaiting:bool = true @@ -16,17 +15,15 @@ func processCommand(command:Command): return stop() - command.COMMAND_PROCESSED.connect(onCommandProcessed) - - BROADCAST_COMMAND.emit(command.getCommandText()) - + emit_signal("BROADCAST_COMMAND", command.getCommandText()) command.execute() func waitForCommand(): resumeWaiting = true start() + CommandDispatcher.DISPLAY_COMMAND_PROMPT.emit() func pauseProcessor(): diff --git a/scripts/game/GameManager.gd b/scripts/game/GameManager.gd index cfeec11..c817f28 100644 --- a/scripts/game/GameManager.gd +++ b/scripts/game/GameManager.gd @@ -1,7 +1,8 @@ extends Node -var defaultMapPath: String = "res://scenes/game/maps/world_map.tscn" -var currentMapPath: String = "" +var defaultMapPath:String = "res://scenes/game/maps/world_map.tscn" + +var currentMapPath func startNewGame(): currentMapPath = defaultMapPath diff --git a/scripts/game/commands/Command.gd b/scripts/game/commands/Command.gd index cafac40..f36e208 100644 --- a/scripts/game/commands/Command.gd +++ b/scripts/game/commands/Command.gd @@ -4,7 +4,6 @@ signal COMMAND_PROCESSED(label) var commandLabel - func execute(): COMMAND_PROCESSED.emit(commandLabel) diff --git a/scripts/game/commands/CommandDispatcher.gd b/scripts/game/commands/CommandDispatcher.gd index 49a28b7..eba3eb8 100644 --- a/scripts/game/commands/CommandDispatcher.gd +++ b/scripts/game/commands/CommandDispatcher.gd @@ -3,3 +3,9 @@ extends Node signal PROCESS_COMMAND(command) signal WAIT_FOR_COMMAND signal PAUSE_PROCESSOR + +signal PLAYER_MOVE(direction) + +signal DISPLAY_MESSAGE(message) +signal DISPLAY_COMMAND_PROMPT +signal DISPLAY_CLEAR diff --git a/scripts/game/commands/MoveCommand.gd b/scripts/game/commands/MoveCommand.gd new file mode 100644 index 0000000..c51c2fb --- /dev/null +++ b/scripts/game/commands/MoveCommand.gd @@ -0,0 +1,22 @@ +extends Command + +class_name MoveCommand + +var direction + +func _init(dir): + commandLabel = "Move" + direction = dir + + +func execute(): + CommandDispatcher.PLAYER_MOVE.emit(direction) + emit_signal("COMMAND_PROCESSED", getCommandText()) + + +func getDirectionString() -> String: + return Map.Direction.keys()[direction] + + +func getCommandText(): + return "%s %s" % [commandLabel, getDirectionString()] diff --git a/scripts/game/commands/MoveCommand.gd.uid b/scripts/game/commands/MoveCommand.gd.uid new file mode 100644 index 0000000..38c0573 --- /dev/null +++ b/scripts/game/commands/MoveCommand.gd.uid @@ -0,0 +1 @@ +uid://c136g73lrccts diff --git a/scripts/game/commands/PassCommand.gd b/scripts/game/commands/PassCommand.gd index ef2e81c..a7b5d30 100644 --- a/scripts/game/commands/PassCommand.gd +++ b/scripts/game/commands/PassCommand.gd @@ -2,9 +2,10 @@ extends Command class_name PassCommand -func _init() -> void: +func _init(): commandLabel = "Pass" + func execute(): print("Player passed.") COMMAND_PROCESSED.emit(commandLabel) diff --git a/scripts/game/game_screen.gd b/scripts/game/game_screen.gd index 4577e5f..123b2c5 100644 --- a/scripts/game/game_screen.gd +++ b/scripts/game/game_screen.gd @@ -1,12 +1,13 @@ extends Node -class_name GameScreen +class_name GameScreen -@export var map: Node +@export var map:Node -# Called when the node enters the scene tree for the first time. -func _ready() -> void: +func _ready(): map.add_child(load(GameManager.currentMapPath).instantiate()) + CommandDispatcher.WAIT_FOR_COMMAND.emit() -func _on_pass_button_pressed() -> void: + +func _on_pass_button_pressed(): CommandDispatcher.PROCESS_COMMAND.emit(PassCommand.new()) diff --git a/scripts/game/maps/map.gd b/scripts/game/maps/map.gd new file mode 100644 index 0000000..d688516 --- /dev/null +++ b/scripts/game/maps/map.gd @@ -0,0 +1,5 @@ +extends TileMap + +class_name Map + +enum Direction { North, East, South, West } diff --git a/scripts/game/maps/map.gd.uid b/scripts/game/maps/map.gd.uid new file mode 100644 index 0000000..d6f5d01 --- /dev/null +++ b/scripts/game/maps/map.gd.uid @@ -0,0 +1 @@ +uid://dg5n82oyi536p diff --git a/scripts/game/maps/map2d.gd b/scripts/game/maps/map2d.gd index e8401c7..b7dd7e9 100644 --- a/scripts/game/maps/map2d.gd +++ b/scripts/game/maps/map2d.gd @@ -1,27 +1,26 @@ -extends TileMap +extends Map class_name Map2d enum TerrainDataTypes { TerrainType } - func getTerrainDataForTile(layer, data, x, y): - var tile: TileData = get_cell_tile_data(layer, Vector2i(x, y)) - if tile != null: + var tile:TileData = get_cell_tile_data(layer, Vector2i(x, y)) + + if (tile != null): return tile.get_custom_data(TerrainDataTypes.keys()[data]) else: return null - # Called when the node enters the scene tree for the first time. -func _ready() -> void: - print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 39, 17)) - print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 0, 0)) - print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 11, 11)) - print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 6, 9)) - print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 22, 22)) - - +#func _ready() -> void: +# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 39, 17)) +# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 0, 0)) +# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 11, 11)) +# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 6, 9)) +# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 22, 22)) +# +# # Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass +#func _process(delta: float) -> void: +# pass diff --git a/scripts/game/maps/world_map.gd b/scripts/game/maps/world_map.gd index ce3d745..cc6ab35 100644 --- a/scripts/game/maps/world_map.gd +++ b/scripts/game/maps/world_map.gd @@ -1,6 +1,4 @@ extends Map2d - -func _ready() -> void: - super._ready() - +#func _ready() -> void: +# super._ready() diff --git a/scripts/loader.gd b/scripts/loader.gd index e00e76c..e8b19e8 100644 --- a/scripts/loader.gd +++ b/scripts/loader.gd @@ -1,36 +1,32 @@ extends Node -signal LOADING_PROGRESS_UPDATED -@export var loadingScene: Node = preload("res://scenes/ui/loading_screen.tscn").instantiate() +signal LOADING_PROGRESS_UPDATED(percentage) -var scenePath: String +@export var loadingScene = preload("res://scenes/ui/loading_screen.tscn").instantiate() -func loadScene(caller: Node, path: String): +var scenePath + +func loadScene(caller, path): scenePath = path get_tree().root.add_child(loadingScene) - + ResourceLoader.load_threaded_request(scenePath) - #print(scenePath) + caller.queue_free() +func _process(delta): + + if (scenePath != null): + var progress = [] + var loaderStatus = ResourceLoader.load_threaded_get_status(scenePath, progress) -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(_delta: float) -> void: - if scenePath: - var progress: Array = [] - var loaderStatus: ResourceLoader.ThreadLoadStatus = ResourceLoader.load_threaded_get_status(scenePath, progress) - - if loaderStatus == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_LOADED: + LOADING_PROGRESS_UPDATED.emit(progress[0]) + + if (loaderStatus == ResourceLoader.THREAD_LOAD_LOADED): var loadedScene = ResourceLoader.load_threaded_get(scenePath).instantiate() + get_tree().root.remove_child(loadingScene) get_tree().root.add_child(loadedScene) - scenePath = "" - - elif loaderStatus == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_IN_PROGRESS: - LOADING_PROGRESS_UPDATED.emit(progress[0]) - else: - pass - - - + + scenePath = null diff --git a/scripts/title/title_screen.gd b/scripts/title/title_screen.gd index de834ad..60c6069 100644 --- a/scripts/title/title_screen.gd +++ b/scripts/title/title_screen.gd @@ -1,7 +1,7 @@ extends Control -func _on_new_game_button_pressed() -> void: +func _on_new_game_button_pressed(): GameManager.startNewGame() Loader.loadScene(self, "res://scenes/game.tscn") diff --git a/scripts/title/version_number.gd b/scripts/title/version_number.gd index 9c876fc..abe0f78 100644 --- a/scripts/title/version_number.gd +++ b/scripts/title/version_number.gd @@ -1,6 +1,4 @@ extends Label - -# Called when the node enters the scene tree for the first time. -func _ready() -> void: +func _ready(): text += ProjectSettings.get_setting("application/config/version") diff --git a/scripts/ui/Message Console.gd b/scripts/ui/Message Console.gd new file mode 100644 index 0000000..066aff0 --- /dev/null +++ b/scripts/ui/Message Console.gd @@ -0,0 +1,63 @@ +extends MarginContainer + +@export var scrollContainer:ScrollContainer +@export var messages:VBoxContainer +@export var messageHistory := 10 + +var messageLinePrefab = preload("res://scenes/ui/MessageLine.tscn") + +func _ready(): + CommandDispatcher.DISPLAY_MESSAGE.connect(_onMessageReceived) + CommandDispatcher.DISPLAY_COMMAND_PROMPT.connect(displayCommandPrompt) + CommandDispatcher.DISPLAY_CLEAR.connect(clearWindow) + +func _on_command(text): + displayCommand(text) + + +func _onMessageReceived(message): + displayMessage(message) + + +func displayCommandPrompt(): + messages.add_child(messageLinePrefab.instantiate()) + + +func clearWindow(): + for item in messages.get_children(): + messages.remove_child(item) + item.queue_free() + + +func scrollToEnd(): + await scrollContainer.get_v_scroll_bar().changed + + if (messages.get_child_count() > messageHistory): + messages.get_child(0).queue_free() + + scrollContainer.scroll_vertical = scrollContainer.get_v_scroll_bar().max_value + + +func displayMessage(message): + + var messageLine = messageLinePrefab.instantiate() + + messageLine.text = "%s\n" % message + + messages.add_child(messageLine) + + scrollToEnd() + + +func displayCommand(message): + + var currentMessageLine:RichTextLabel + + if (messages.get_child_count() == 0): + displayCommandPrompt() + + currentMessageLine = messages.get_children()[messages.get_children().size() - 1] + + currentMessageLine.text = currentMessageLine.text.insert(currentMessageLine.text.length() - 2, message) + + scrollToEnd() diff --git a/scripts/ui/Message Console.gd.uid b/scripts/ui/Message Console.gd.uid new file mode 100644 index 0000000..4df0251 --- /dev/null +++ b/scripts/ui/Message Console.gd.uid @@ -0,0 +1 @@ +uid://dv3fd112uj8o1 diff --git a/scripts/ui/loading_screen.gd b/scripts/ui/loading_screen.gd index 5c15c32..11656ec 100644 --- a/scripts/ui/loading_screen.gd +++ b/scripts/ui/loading_screen.gd @@ -1,11 +1,11 @@ extends Control -@export var loadingBar: TextureProgressBar +@export var loadingBar:TextureProgressBar # Called when the node enters the scene tree for the first time. -func _ready() -> void: +func _ready(): Loader.LOADING_PROGRESS_UPDATED.connect(_on_progress_updated) -func _on_progress_updated(percentage: float) -> void: - loadingBar.value = percentage +func _on_progress_updated(percentage): + loadingBar.value = percentage * 100 diff --git a/themes/default_theme.tres b/themes/default_theme.tres index 81ef0b8..dd5e2f0 100644 --- a/themes/default_theme.tres +++ b/themes/default_theme.tres @@ -40,3 +40,4 @@ Button/styles/hover = SubResource("StyleBoxTexture_r3xux") Button/styles/normal = SubResource("StyleBoxTexture_oxkhk") Button/styles/pressed = SubResource("StyleBoxTexture_pvobe") Label/fonts/font = ExtResource("1_lkf7m") +RichTextLabel/fonts/normal_font = ExtResource("1_lkf7m")