This commit is contained in:
Team3
2026-09-07 04:29:23 +02:00
parent e299f9d088
commit 6478559252
8 changed files with 708 additions and 197 deletions

View File

@@ -6,12 +6,12 @@ const BOT_NAMES_MAX := 7
var screens: Dictionary = {}
# Einzelspieler
var solo_bots: SpinBox
var solo_bots: NumberRow
# Mehrspieler
var name_edit: LineEdit
var ip_edit: LineEdit
var multi_bots: SpinBox
var multi_bots: NumberRow
var lobby_list: Label
var status: Label
var host_btn: Button
@@ -94,9 +94,46 @@ func _button(text: String, parent: Control, action: Callable) -> Button:
return b
## Eine Reihe anklickbarer Zahlen - bei so wenigen Werten schneller als eine
## Spinbox mit ihren winzigen Pfeilen.
class NumberRow extends HBoxContainer:
var value := 0
var _buttons: Array[Button] = []
var _lo := 0
func _init(lo: int, hi: int, start: int) -> void:
_lo = lo
alignment = BoxContainer.ALIGNMENT_CENTER
add_theme_constant_override("separation", 6)
for n in range(lo, hi + 1):
var b := Button.new()
b.text = str(n)
b.toggle_mode = true
b.custom_minimum_size = Vector2(40, 38)
b.pressed.connect(pick.bind(n))
add_child(b)
_buttons.append(b)
pick(start)
func pick(n: int) -> void:
value = n
for i in _buttons.size():
_buttons[i].button_pressed = _lo + i == n
## Werte oberhalb von `hi` sperren (im Mehrspieler sind die Plätze begrenzt).
func set_limit(hi: int) -> void:
for i in _buttons.size():
_buttons[i].disabled = _lo + i > hi
if value > hi:
pick(maxi(_lo, hi))
func set_enabled(on: bool) -> void:
for b in _buttons:
b.disabled = not on
func _title(box: VBoxContainer) -> void:
box.add_child(_text("LIAR'S DICE 3D", 40))
box.add_child(_text("Würfeln - Bluffen - Boostern", 16, Color(0.6, 0.63, 0.7)))
box.add_child(HSeparator.new())
@@ -113,12 +150,9 @@ func _build_single() -> Control:
var box := _box(400)
_title(box)
box.add_child(_text("Einzelspieler", 22, Color(1.0, 0.82, 0.32)))
solo_bots = SpinBox.new()
solo_bots.min_value = 1
solo_bots.max_value = BOT_NAMES_MAX
solo_bots.value = 3
box.add_child(_row("Bots", solo_bots))
box.add_child(_text("Ohne Netzwerk - du spielst allein gegen die Bots.", 13, Color(0.55, 0.58, 0.65)))
box.add_child(_text("Bots", 15))
solo_bots = NumberRow.new(1, BOT_NAMES_MAX, 3)
box.add_child(solo_bots)
box.add_child(HSeparator.new())
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 8)
@@ -142,11 +176,9 @@ func _build_multi() -> Control:
ip_edit.text = "127.0.0.1"
box.add_child(_row("Server-IP", ip_edit))
multi_bots = SpinBox.new()
multi_bots.min_value = 0
multi_bots.max_value = BOT_NAMES_MAX
multi_bots.value = 1
box.add_child(_row("Bots (nur Host)", multi_bots))
box.add_child(_text("Bots (nur Host)", 15))
multi_bots = NumberRow.new(0, BOT_NAMES_MAX, 1)
box.add_child(multi_bots)
var brow := HBoxContainer.new()
brow.add_theme_constant_override("separation", 8)
@@ -174,18 +206,26 @@ func _build_multi() -> Control:
# ------------------------------------------------------------ Aktionen
func _on_solo_start() -> void:
Net.start_singleplayer("Spieler", int(solo_bots.value))
Net.start_singleplayer("Spieler", solo_bots.value)
## Ein leeres Namensfeld ergäbe einen namenlosen Platz am Tisch.
func _spielername() -> String:
var n := name_edit.text.strip_edges()
return n if n != "" else "Spieler"
func _on_host() -> void:
status.text = ""
if Net.host_game(name_edit.text.strip_edges()):
if Net.host_game(_spielername()):
status.text = "Server läuft auf Port %d. Warte auf Mitspieler." % Net.PORT
_refresh()
func _on_join() -> void:
status.text = "Verbinde..."
Net.join_game(ip_edit.text.strip_edges(), name_edit.text.strip_edges())
Net.join_game(ip_edit.text.strip_edges(), _spielername())
_refresh()
func _on_leave() -> void:
@@ -202,7 +242,7 @@ func _on_back() -> void:
func _on_start() -> void:
var humans: int = Net.lobby.size()
var ai: int = mini(int(multi_bots.value), Net.MAX_HUMANS - humans)
var ai: int = mini(multi_bots.value, Net.MAX_HUMANS - humans)
if humans + ai < 2:
status.text = "Mindestens 2 Spieler nötig (Mitspieler oder Bots)."
return
@@ -227,7 +267,11 @@ func _refresh() -> void:
join_btn.disabled = connected
leave_btn.disabled = not connected
start_btn.disabled = not (connected and Net.is_host)
multi_bots.editable = not connected or Net.is_host
if not connected or not Net.is_host:
multi_bots.set_enabled(not connected)
else:
multi_bots.set_enabled(true)
multi_bots.set_limit(Net.MAX_HUMANS - Net.lobby.size())
if Net.lobby.is_empty():
lobby_list.text = "- nicht verbunden -"
else: