godot-platform-desktop
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlatform: Desktop
平台:桌面端
Settings flexibility, window management, and kb/mouse precision define desktop gaming.
设置灵活性、窗口管理以及键鼠操作精度是桌面端游戏的核心特性。
Available Scripts
可用脚本
desktop_integration_manager.gd
desktop_integration_manager.gd
Expert desktop integration (Steam achievements, settings persistence, window management).
专业的桌面端集成功能(Steam成就、设置持久化、窗口管理)。
NEVER Do in Desktop Development
桌面端开发绝对禁忌
- NEVER hardcode resolution/fullscreen — 1920x1080 fullscreen on 4K monitor? Blurry mess. ALWAYS provide settings menu with resolution dropdown + fullscreen toggle.
- NEVER save settings to —
res://is read-only in exported builds. Useres://for persistent config via ConfigFile.user://settings.cfg - NEVER ignore Alt+F4 or Cmd+Q — Player presses Alt+F4, nothing happens = frustration. Handle to quit gracefully.
NOTIFICATION_WM_CLOSE_REQUEST - NEVER lock rebinding — Fixed WASD movement ignores AZERTY/Dvorak keyboards. MUST allow InputMap rebinding via settings.
- NEVER use wrong — Volume slider 0-1 directly to AudioServer? Perceptually wrong curve. Use
linear_to_db().AudioServer.set_bus_volume_db(0, linear_to_db(slider.value)) - NEVER skip borderless fullscreen option — Exclusive fullscreen breaks Alt+Tab on Windows. Offer +
WINDOW_MODE_EXCLUSIVE_FULLSCREEN(borderless).WINDOW_MODE_FULLSCREEN
gdscript
undefined- 绝对不要硬编码分辨率/全屏设置 —— 在4K显示器上强制1920x1080全屏?画面会模糊不堪。务必提供包含分辨率下拉菜单和全屏切换按钮的设置界面。
- 绝对不要将设置保存到目录 —— 导出后的构建包中
res://是只读的。请使用res://通过ConfigFile实现配置持久化。user://settings.cfg - 绝对不要忽略Alt+F4或Cmd+Q快捷键 —— 玩家按下Alt+F4却毫无反应?这会引发不满。请处理事件以实现优雅退出。
NOTIFICATION_WM_CLOSE_REQUEST - 绝对不要锁定按键绑定 —— 固定的WASD移动方式无法适配AZERTY/Dvorak键盘。必须允许通过设置界面修改InputMap的按键绑定。
- 绝对不要错误使用—— 将音量滑块的0-1值直接传给AudioServer?这不符合人类的听觉感知曲线。请使用
linear_to_db()。AudioServer.set_bus_volume_db(0, linear_to_db(slider.value)) - 绝对不要跳过无边框全屏选项 —— 独占全屏模式会导致Windows系统下Alt+Tab失效。请同时提供(独占全屏)和
WINDOW_MODE_EXCLUSIVE_FULLSCREEN(无边框全屏)选项。WINDOW_MODE_FULLSCREEN
gdscript
undefinedsettings.gd
settings.gd
extends Control
func _ready() -> void:
load_settings()
apply_settings()
func load_settings() -> void:
var config := ConfigFile.new()
config.load("user://settings.cfg")
$Graphics/ResolutionDropdown.selected = config.get_value("graphics", "resolution", 0)
$Graphics/FullscreenCheck.button_pressed = config.get_value("graphics", "fullscreen", false)
$Audio/MasterSlider.value = config.get_value("audio", "master_volume", 1.0)func save_settings() -> void:
var config := ConfigFile.new()
config.set_value("graphics", "resolution", $Graphics/ResolutionDropdown.selected)
config.set_value("graphics", "fullscreen", $Graphics/FullscreenCheck.button_pressed)
config.set_value("audio", "master_volume", $Audio/MasterSlider.value)
config.save("user://settings.cfg")
func apply_settings() -> void:
# Resolution
var resolutions := [Vector2i(1920, 1080), Vector2i(2560, 1440), Vector2i(3840, 2160)]
var resolution := resolutions[$Graphics/ResolutionDropdown.selected]
get_window().size = resolution
# Fullscreen
if $Graphics/FullscreenCheck.button_pressed:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
# Audio
AudioServer.set_bus_volume_db(0, linear_to_db($Audio/MasterSlider.value))undefinedextends Control
func _ready() -> void:
load_settings()
apply_settings()
func load_settings() -> void:
var config := ConfigFile.new()
config.load("user://settings.cfg")
$Graphics/ResolutionDropdown.selected = config.get_value("graphics", "resolution", 0)
$Graphics/FullscreenCheck.button_pressed = config.get_value("graphics", "fullscreen", false)
$Audio/MasterSlider.value = config.get_value("audio", "master_volume", 1.0)func save_settings() -> void:
var config := ConfigFile.new()
config.set_value("graphics", "resolution", $Graphics/ResolutionDropdown.selected)
config.set_value("graphics", "fullscreen", $Graphics/FullscreenCheck.button_pressed)
config.set_value("audio", "master_volume", $Audio/MasterSlider.value)
config.save("user://settings.cfg")
func apply_settings() -> void:
# Resolution
var resolutions := [Vector2i(1920, 1080), Vector2i(2560, 1440), Vector2i(3840, 2160)]
var resolution := resolutions[$Graphics/ResolutionDropdown.selected]
get_window().size = resolution
# Fullscreen
if $Graphics/FullscreenCheck.button_pressed:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
# Audio
AudioServer.set_bus_volume_db(0, linear_to_db($Audio/MasterSlider.value))undefinedKeyboard Remapping
键盘绑定重映射
gdscript
undefinedgdscript
undefinedAllow players to rebind keys
Allow players to rebind keys
func rebind_action(action: String, new_key: Key) -> void:
# Remove existing
InputMap.action_erase_events(action)
# Add new
var event := InputEventKey.new()
event.keycode = new_key
InputMap.action_add_event(action, event)
# Save
save_input_map()undefinedfunc rebind_action(action: String, new_key: Key) -> void:
# Remove existing
InputMap.action_erase_events(action)
# Add new
var event := InputEventKey.new()
event.keycode = new_key
InputMap.action_add_event(action, event)
# Save
save_input_map()undefinedWindow Management
窗口管理
gdscript
undefinedgdscript
undefinedToggle fullscreen
Toggle fullscreen
func toggle_fullscreen() -> void:
if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
undefinedfunc toggle_fullscreen() -> void:
if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
undefinedSteam Integration (if using)
Steam Integration (if using)
gdscript
undefinedgdscript
undefinedUsing GodotSteam plugin
Using GodotSteam plugin
var steam_id: int
func _ready() -> void:
if Steam.isSteamRunning():
steam_id = Steam.getSteamID()
Steam.achievement_progress.connect(_on_achievement_progress)
func unlock_achievement(name: String) -> void:
Steam.setAchievement(name)
Steam.storeStats()
undefinedvar steam_id: int
func _ready() -> void:
if Steam.isSteamRunning():
steam_id = Steam.getSteamID()
Steam.achievement_progress.connect(_on_achievement_progress)
func unlock_achievement(name: String) -> void:
Steam.setAchievement(name)
Steam.storeStats()
undefinedBest Practices
最佳实践
- Settings - Extensive graphics/audio options
- Keybinds - Allow remapping
- Alt+F4 - Support quit shortcuts
- Save Location - Use directory
user://
- 设置 - 提供丰富的图形/音频选项
- 按键绑定 - 允许用户重映射
- Alt+F4支持 - 适配退出快捷键
- 保存路径 - 使用目录
user://
Reference
参考
- Related: ,
godot-export-buildsgodot-save-load-systems
- 相关内容:,
godot-export-buildsgodot-save-load-systems
Related
相关
- Master Skill: godot-master
- 核心技能:godot-master