Improve chat presentation and draft handling

This commit is contained in:
Alexander Sellite 2026-07-30 15:05:18 -04:00
parent 985fe1c28f
commit 4985cc3374
7 changed files with 354 additions and 59 deletions

View file

@ -13,6 +13,7 @@ const DEFAULT_WORLD_PIXEL_SIZE: int = 3
const MIN_UI_PIXEL_SIZE: int = 1
const MAX_UI_PIXEL_SIZE: int = 5
const DEFAULT_UI_PIXEL_SIZE: int = 3
const MAX_CHAT_DRAFT_CHARACTERS: int = 280
const COMPACT_DISPLAY_HEIGHT: int = 560
const WORLD_DESKTOP_GRID_HEIGHTS: Array[int] = [0, 540, 360, 216, 96]
const WORLD_COMPACT_GRID_HEIGHTS: Array[int] = [0, 360, 240, 144, 72]
@ -25,6 +26,8 @@ const UI_COMPACT_RENDER_HEIGHTS: Array[int] = [0, 408, 336, 264, 192]
@export_range(0.001, 0.012, 0.0005) var mouse_camera_sensitivity: float = 0.005
@export_range(0.5, 5.0, 0.1) var controller_camera_sensitivity: float = 2.5
@export var invert_camera_y: bool = false
@export var chat_draft: String = ""
@export var chat_collapsed: bool = false
@export_range(1, 5, 1) var world_pixel_size: int = DEFAULT_WORLD_PIXEL_SIZE
@export_range(1, 5, 1) var ui_pixel_size: int = DEFAULT_UI_PIXEL_SIZE
@ -40,6 +43,7 @@ func is_valid() -> bool:
and is_finite(controller_camera_sensitivity)
and controller_camera_sensitivity >= MIN_CONTROLLER_SENSITIVITY
and controller_camera_sensitivity <= MAX_CONTROLLER_SENSITIVITY
and chat_draft.length() <= MAX_CHAT_DRAFT_CHARACTERS
and world_pixel_size >= MIN_WORLD_PIXEL_SIZE
and world_pixel_size <= MAX_WORLD_PIXEL_SIZE
and ui_pixel_size >= MIN_UI_PIXEL_SIZE
@ -55,6 +59,8 @@ func copy() -> PlayerSettings:
result.mouse_camera_sensitivity = mouse_camera_sensitivity
result.controller_camera_sensitivity = controller_camera_sensitivity
result.invert_camera_y = invert_camera_y
result.chat_draft = chat_draft
result.chat_collapsed = chat_collapsed
result.world_pixel_size = world_pixel_size
result.ui_pixel_size = ui_pixel_size
return result

View file

@ -49,6 +49,14 @@ func load_settings() -> bool:
accessibility.has("use_readable_interface_font")
and typeof(accessibility["use_readable_interface_font"]) != TYPE_BOOL
)
or (
presentation.has("chat_draft")
and typeof(presentation["chat_draft"]) != TYPE_STRING
)
or (
presentation.has("chat_collapsed")
and typeof(presentation["chat_collapsed"]) != TYPE_BOOL
)
):
return _use_defaults_after_corruption("Player settings values are invalid.")
var loaded := PlayerSettings.new()
@ -87,6 +95,10 @@ func load_settings() -> bool:
PlayerSettings.MAX_UI_PIXEL_SIZE,
PlayerSettings.DEFAULT_UI_PIXEL_SIZE
)
loaded.chat_draft = str(presentation.get("chat_draft", "")).left(
PlayerSettings.MAX_CHAT_DRAFT_CHARACTERS
)
loaded.chat_collapsed = bool(presentation.get("chat_collapsed", false))
if not loaded.is_valid():
return _use_defaults_after_corruption("Player settings values are invalid.")
current_settings = loaded
@ -123,6 +135,22 @@ func apply_pixelation(world_pixel_size: int, ui_pixel_size: int) -> bool:
return apply_settings(edited)
func update_chat_preferences(draft: String, collapsed: bool) -> void:
var clean_draft := draft.left(PlayerSettings.MAX_CHAT_DRAFT_CHARACTERS)
if (
current_settings.chat_draft == clean_draft
and current_settings.chat_collapsed == collapsed
):
return
current_settings.chat_draft = clean_draft
current_settings.chat_collapsed = collapsed
_is_dirty = true
func save_chat_preferences() -> bool:
return save_if_dirty()
func save_now() -> bool:
if current_settings == null or not current_settings.is_valid():
return false
@ -143,8 +171,12 @@ func save_now() -> bool:
"presentation": {
"world_pixel_size": current_settings.world_pixel_size,
"ui_pixel_size": current_settings.ui_pixel_size,
"chat_draft": current_settings.chat_draft,
"chat_collapsed": current_settings.chat_collapsed,
},
}
if current_settings.chat_draft.is_empty():
(data["presentation"] as Dictionary).erase("chat_draft")
var file := FileAccess.open(TEMP_PATH, FileAccess.WRITE)
if file == null:
return false