- 为铁球、陶瓷球和木球制作风格化材质,归档 CC0 原始参考 - 更新方形球洞和实心滑槽,统一 90° 弯槽并兼容旧存档 - 用顺流泡沫表示水流方向,为冰块制作三种交错的裂纹 - 同步 Blender 源资产、Godot 加载、工坊和试玩预览
62 lines
3.7 KiB
GDScript
62 lines
3.7 KiB
GDScript
extends Button
|
||
|
||
# Live thumbnails use the same visible GLB as the track, without colliders.
|
||
var viewport: SubViewport
|
||
var model: Node3D
|
||
var caption: Label
|
||
var counter: Label
|
||
var artwork: TextureRect
|
||
var shown_quarter := -1
|
||
var state_key := ""
|
||
|
||
func configure(title: String, model_path: String, height: float, text_font: Font) -> void:
|
||
focus_mode=Control.FOCUS_NONE;custom_minimum_size=Vector2(112,128)
|
||
var content:=VBoxContainer.new();content.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
content.offset_left=6;content.offset_right=-6;content.offset_top=5;content.offset_bottom=-5
|
||
content.add_theme_constant_override("separation",1);content.mouse_filter=Control.MOUSE_FILTER_IGNORE;add_child(content)
|
||
artwork=TextureRect.new();artwork.custom_minimum_size=Vector2(100,76)
|
||
artwork.expand_mode=TextureRect.EXPAND_IGNORE_SIZE;artwork.stretch_mode=TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||
artwork.mouse_filter=Control.MOUSE_FILTER_IGNORE;content.add_child(artwork)
|
||
for text in [title,""]:
|
||
var line:=Label.new();line.text=text;line.horizontal_alignment=HORIZONTAL_ALIGNMENT_CENTER
|
||
line.add_theme_font_override("font",text_font);line.add_theme_font_size_override("font_size",13)
|
||
line.add_theme_color_override("font_color",Color("343143"));line.mouse_filter=Control.MOUSE_FILTER_IGNORE;content.add_child(line)
|
||
if caption==null:caption=line
|
||
else:counter=line
|
||
if model_path.is_empty():
|
||
artwork.texture=load("res://playtest/tutorial/ui/eraser.svg")
|
||
return
|
||
viewport=SubViewport.new();viewport.size=Vector2i(200,152);viewport.own_world_3d=true
|
||
viewport.transparent_bg=true;viewport.gui_disable_input=true
|
||
viewport.render_target_update_mode=SubViewport.UPDATE_ONCE;add_child(viewport)
|
||
var world:=Node3D.new();viewport.add_child(world)
|
||
var environment:=Environment.new();environment.background_mode=Environment.BG_COLOR
|
||
environment.ambient_light_source=Environment.AMBIENT_SOURCE_COLOR
|
||
environment.ambient_light_color=Color.WHITE;environment.ambient_light_energy=.65
|
||
var world_environment:=WorldEnvironment.new();world_environment.environment=environment;world.add_child(world_environment)
|
||
var light:=DirectionalLight3D.new();light.rotation_degrees=Vector3(-55,-30,0);light.light_energy=.7;world.add_child(light)
|
||
model=load(model_path).instantiate();world.add_child(model)
|
||
var camera:=Camera3D.new();camera.projection=Camera3D.PROJECTION_ORTHOGONAL
|
||
camera.size=1.95;world.add_child(camera)
|
||
var target:=Vector3(0,height*.5,0);camera.position=target+Vector3(3,4,4)
|
||
camera.look_at(target);camera.current=true
|
||
artwork.texture=viewport.get_texture()
|
||
|
||
func set_state(remaining: int, quarter: int, selected: bool, locked: bool, eraser:=false) -> void:
|
||
var signature:="%d/%d/%s/%s"%[remaining,quarter,selected,locked]
|
||
if signature==state_key:return
|
||
state_key=signature;disabled=locked
|
||
counter.text=("擦除中" if selected else "点选后回收") if eraser else ("×%d · %d°"%[remaining,quarter*90])
|
||
if model!=null and quarter!=shown_quarter:
|
||
shown_quarter=quarter;model.rotation.y=-quarter*PI/2
|
||
viewport.render_target_update_mode=SubViewport.UPDATE_ONCE
|
||
var normal:=StyleBoxFlat.new();normal.bg_color=Color("f1cf91") if selected else Color("fff4d9")
|
||
normal.border_color=Color("ad5a43") if selected else Color("6e685b")
|
||
normal.set_border_width_all(3 if selected else 1);normal.set_corner_radius_all(12)
|
||
add_theme_stylebox_override("normal",normal)
|
||
var hover:StyleBoxFlat=normal.duplicate();hover.bg_color=Color("f5dfb5")
|
||
add_theme_stylebox_override("hover",hover);add_theme_stylebox_override("pressed",normal)
|
||
var inactive:StyleBoxFlat=normal.duplicate();inactive.bg_color=Color("dcd9c8")
|
||
add_theme_stylebox_override("disabled",inactive)
|
||
artwork.modulate=Color(1,1,1,.45 if locked else 1.0)
|