Crafting tabs (tools, weapons, cooking, building...); panel fits at 1280x720; steadier smoothness test
This commit is contained in:
@@ -100,8 +100,14 @@ func bind(p: CharacterBody3D) -> void:
|
||||
crv.add_child(UITheme.label("Crafting", 20))
|
||||
_station_label = UITheme.label("", 13, UITheme.TEXT_DIM)
|
||||
crv.add_child(_station_label)
|
||||
# Categories: Tools, Weapons, Cooking... (ItemDB.CATEGORIES). Two rows
|
||||
# of tabs, so they all fit.
|
||||
_tabs = HFlowContainer.new()
|
||||
_tabs.add_theme_constant_override("h_separation", 4)
|
||||
_tabs.add_theme_constant_override("v_separation", 4)
|
||||
crv.add_child(_tabs)
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.custom_minimum_size = Vector2(320, 380)
|
||||
scroll.custom_minimum_size = Vector2(320, 330)
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
_recipe_list = VBoxContainer.new()
|
||||
_recipe_list.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
@@ -139,6 +145,7 @@ func open(chest: Node) -> void:
|
||||
visible = true
|
||||
player.ui_open = true
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
_pick_tab()
|
||||
_rebuild_chest()
|
||||
_refresh()
|
||||
|
||||
@@ -250,8 +257,59 @@ func _rebuild_recipes() -> void:
|
||||
if Actions.station_near(player, st):
|
||||
stations.append(st)
|
||||
_station_label.text = "Nearby: " + (", ".join(stations) if not stations.is_empty() else "nothing (hand crafting only)")
|
||||
_rebuild_tabs()
|
||||
for rid in ItemDB.recipes:
|
||||
_recipe_list.add_child(_recipe_row(ItemDB.recipes[rid]))
|
||||
var r: Dictionary = ItemDB.recipes[rid]
|
||||
if r.category == category:
|
||||
_recipe_list.add_child(_recipe_row(r))
|
||||
|
||||
var _tabs: HFlowContainer
|
||||
var category := "tools" ## the tab showing
|
||||
var _picked := false ## chose a tab since opening (don't jump about)
|
||||
|
||||
## Tabs for the categories that have recipes, each with how many of its
|
||||
## recipes you could make right now.
|
||||
func _rebuild_tabs() -> void:
|
||||
for c in _tabs.get_children():
|
||||
c.queue_free()
|
||||
var count := {}
|
||||
var ready := {}
|
||||
for rid in ItemDB.recipes:
|
||||
var r: Dictionary = ItemDB.recipes[rid]
|
||||
count[r.category] = int(count.get(r.category, 0)) + 1
|
||||
if Actions.can_craft(player, rid):
|
||||
ready[r.category] = int(ready.get(r.category, 0)) + 1
|
||||
if not count.has(category):
|
||||
category = count.keys()[0] if not count.is_empty() else "tools"
|
||||
for cat in ItemDB.CATEGORIES:
|
||||
if not count.has(cat):
|
||||
continue
|
||||
var b := Button.new()
|
||||
var n := int(ready.get(cat, 0))
|
||||
b.text = ItemDB.CATEGORIES[cat] + (" (%d)" % n if n > 0 else "")
|
||||
b.toggle_mode = true
|
||||
b.button_pressed = cat == category
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.add_theme_font_size_override("font_size", 13)
|
||||
if n > 0 and cat != category:
|
||||
b.add_theme_color_override("font_color", UITheme.OK)
|
||||
b.pressed.connect(func():
|
||||
category = cat
|
||||
_picked = true
|
||||
_rebuild_recipes())
|
||||
_tabs.add_child(b)
|
||||
|
||||
## On opening: Cooking if you're at a lit fire with something to cook,
|
||||
## otherwise the tab you were on last.
|
||||
func _pick_tab() -> void:
|
||||
_picked = false
|
||||
if not Actions.station_near(player, "campfire"):
|
||||
return
|
||||
for rid in ItemDB.recipes:
|
||||
var r: Dictionary = ItemDB.recipes[rid]
|
||||
if r.category == "cooking" and Actions.can_craft(player, rid):
|
||||
category = "cooking"
|
||||
return
|
||||
|
||||
func _recipe_row(r: Dictionary) -> Control:
|
||||
var ok := Actions.can_craft(player, r.id)
|
||||
@@ -275,7 +333,7 @@ func _recipe_row(r: Dictionary) -> Control:
|
||||
req.bbcode_enabled = true
|
||||
req.fit_content = true
|
||||
req.scroll_active = false
|
||||
req.autowrap_mode = TextServer.AUTOWRAP_OFF
|
||||
req.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART # (long lists wrap rather than widen the panel)
|
||||
req.add_theme_font_size_override("normal_font_size", 13)
|
||||
var parts: Array[String] = []
|
||||
for id in r.inputs:
|
||||
@@ -287,7 +345,7 @@ func _recipe_row(r: Dictionary) -> Control:
|
||||
var col := UITheme.OK if Actions.station_near(player, r.station) else UITheme.BAD
|
||||
parts.append("[color=#%s]@ %s[/color]" % [col.to_html(false), r.station])
|
||||
req.text = " ".join(parts)
|
||||
req.custom_minimum_size = Vector2(200, 0)
|
||||
req.custom_minimum_size = Vector2(170, 0)
|
||||
v.add_child(req)
|
||||
h.add_child(v)
|
||||
var b := Button.new()
|
||||
|
||||
Reference in New Issue
Block a user