Skillpedia
برمجة عامة6.6k · #13831

godot-ui-control

ما الذي تفعله

تشرح هذه المهارة كيفية بناء قوائم الألعاب ولوحات المعلومات وشاشات الإعدادات في Godot باستخدام عُقد Control. وهي مناسبة للمطوّرين الذين يريدون واجهات تناسب أحجام شاشات كثيرة.

متى تستخدمها

  • ✓عندما ترتّب قائمة أو لوحة معلومات أو مخزونًا أو شاشة إعدادات في Godot.
  • ✓عندما تريد أن تتكيف الواجهة مع تغيّر حجم النافذة.
  • ✓عندما يحتاج اللاعبون إلى التنقل في القوائم بلوحة المفاتيح أو يد التحكم.

رابط المهارة

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/godot/godot-ui-control/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/godot/godot-ui-control/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“ابنِ لي قائمة إيقاف مؤقت في Godot فيها زرّا الاستمرار والخروج، وتعمل أيضًا بيد التحكم.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تشرح المهارة المراسي لتغيير الحجم، والحاويات التي ترتب العناصر تلقائيًا، والسمات لتنسيق موحّد، وإعدادات التركيز للتنقل بيد التحكم.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Godot UI / Control nodes (4.x)

Lay out responsive UI with Control anchors and Container nodes, style it with a Theme, and make it navigable by keyboard and gamepad. Targets Godot 4.7.

When to use

  • Use when building HUDs, menus, inventories, dialog boxes, or settings screens with Control-derived nodes; arranging UI that adapts to window size; theming; or wiring focus navigation for controller/keyboard.

When not to use: in-world 2D nodes (Node2D/sprites) → godot-nodes-scenes; animating UI transitions → godot-animation (Tween); genre UIs like card hands → card-game/visual-novel. For full input rebinding → input-systems.

Core workflow

  1. Use Control nodes for UI, not Node2D. Controls have a rect (position + size), anchors, and participate in focus/theming.
  2. Anchor for responsiveness. Anchors are fractions (0–1) of the parent rect that the Control's edges stick to. Use the editor's Layout presets (Top-Left, Full Rect, Center, etc.) instead of hand-placing pixels.
  3. Let Containers position children. Put children in a VBoxContainer, HBoxContainer, GridContainer, MarginContainer, etc. — the container sets their position/size; you control flow with size_flags. Don't set child anchors inside a container (it overrides them).
  4. Style with a Theme. Assign a Theme resource on a top Control; children inherit it. Override per-node with theme overrides only when necessary.
  5. Wire focus so gamepad/keyboard can move between buttons; set a default focused control and define neighbors or rely on auto-neighbor.
  6. Connect signals (pressed, toggled, text_submitted, value_changed).

Patterns

1. Responsive layout with anchors (code form)

extends Control

func _ready() -> void:
    # Stretch this panel to fill its parent (the editor's "Full Rect" preset).
    # Setting only anchors (or `anchors_preset`) keeps the current offsets, so the
    # control keeps its old rect; this call moves anchors AND resets offsets.
    set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
    # Manual equivalent: anchor_left = 0; anchor_top = 0; anchor_right = 1;
    # anchor_bottom = 1, then set all four offset_* to 0.

2. A menu built from containers + button signals

extends VBoxContainer    # children stack vertically, auto-sized

func _ready() -> void:
    for child in get_children():
        if child is Button:
            child.pressed.connect(_on_button_pressed.bind(child.name))
    # Give the first button focus so a gamepad can navigate immediately.
    if get_child_count() > 0:
        (get_child(0) as Control).grab_focus()

func _on_button_pressed(which: StringName) -> void:
    match which:
        "PlayButton":  get_tree().change_scene_to_file("res://game.tscn")
        "QuitButton":  get_tree().quit()

3. Size flags: make one child expand to fill leftover space

# In a HBoxContainer: a label on the left, a spacer that eats remaining width.
func _ready() -> void:
    $Label.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
    $Spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL   # grows to fill

4. Theme override for one node (without a full Theme resource)

func _ready() -> void:
    # Per-node overrides: use add_theme_* (type-specific setters).
    $Title.add_theme_font_size_override("font_size", 32)
    $Title.add_theme_color_override("font_color", Color.GOLD)
    $Panel.add_theme_stylebox_override("panel", preload("res://ui/panel.stylebox.tres"))

Pitfalls

  • Mixing manual position with Containers. A child of a Container cannot set its own position/anchors — the container owns layout. To free-place, take the node out of the container or use a plain Control/PanelContainer wrapper. To nudge, rotate or scale a container child (e.g. a hover pop) in 4.7+, set offset_transform_enabled = true and use offset_transform_position/_rotation/_scale; the container leaves those alone.
  • Anchors vs offsets. Anchors are fractions of the parent; offsets are pixel deltas from the anchored point. Set anchors via presets, then nudge with offsets. Setting only position while anchors are at 0 makes UI not scale with the window.
  • Node2D for UI. Buttons/labels parented under a Node2D won't theme or take focus correctly. Keep UI under a CanvasLayer/Control subtree.
  • Focus lost on gamepad. If
الأسئلة الشائعة

ما هي عقدة Control؟

هي النوع المستخدم في Godot لعناصر الواجهة، وتختلف عن الكائنات في عالم اللعبة.

ما هي Theme في Godot؟

هي مجموعة محفوظة من قواعد التنسيق تُطبّق على واجهة كاملة.

هل تغطي إعادة تعيين الأزرار؟

ليس بالكامل. تغطي إعادة تعيين مفاتيح التحكم كاملةً مهارة إدخال منفصلة.

التفاصيل

الوصف الأصلي من المؤلف

Build Godot 4.7 user interfaces with Control nodes: anchors and offsets for responsive layout, Container nodes (VBox/HBox/Grid/Margin) for automatic arrangement, Theme resources for consistent styling, and keyboard/gamepad focus navigation. Use when laying out a HUD, menu, or UI in a Godot project, working with Control/Container nodes, anchors, themes, or focus in a .tscn.

repo: gamedev-skills/awesome-gamedev-agent-skills

الشعبية

نجوم GitHub
6.6k
الترتيب
#13831
الترخيص
Apache-2.0
آخر تحديث
28‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة