use super::*;
pub fn mount_game3d_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
let host: GameEngineHost = state.get_game3d_host().clone();
let quality_sig: Signal<RenderQualityConfig> = state.get_engine3d_quality();
let preset_idx: Signal<usize> = state.get_engine3d_preset_idx();
let rt_idx: Signal<usize> = state.get_engine3d_rt_idx();
let res_scale: Signal<f32> = state.get_engine3d_res_scale();
let status_sig: Signal<String> = state.get_engine3d_import_status();
let tsr_idx: Signal<usize> = state.get_engine3d_tsr_idx();
let fs_3d_open: Signal<bool> = state.get_engine3d_fullscreen_open();
let viewport: NodeId = host.mount_viewport(style! {
Width(Length::Percent(100.0))
Height(Length::Percent(100.0))
});
let fs_enter_btn: NodeId =
mount_game_fullscreen_enter_button(BTN_GAME3D_FULLSCREEN, fs_3d_open, tokens);
let vp_sig: Signal<Size> = use_viewport_size();
let vp_frame_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
let height_val: f32 = adaptive_viewport_height(vp_sig.get().get_height());
style! {
FlexDirection::Column
Width(Length::Percent(100.0))
Height(Length::Px(height_val))
Overflow::Hidden
Border::new(live.get_geometry().get_border_width(), live.get_palette().get_border())
Radius(live.get_geometry().get_radius_md())
}
};
let viewport_frame: NodeId = view! {
column {
bind_style: vp_frame_style
{ viewport }
{ fs_enter_btn }
}
};
let fs_3d_portal: NodeId = mount_game_fullscreen_portal(fs_3d_open, &host, viewport, tokens);
let ctx: Context = current_context();
let (sync_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
Effect::new(move || {
let p_idx: usize = preset_idx.get();
let preset: QualityPreset = match p_idx {
0 => QualityPreset::Low,
1 => QualityPreset::Medium,
2 => QualityPreset::High,
3 => QualityPreset::Ultra,
_ => QualityPreset::Cinematic,
};
let runtime_ref: RayTracingMode = match rt_idx.get() {
0 => RayTracingMode::Off,
1 => RayTracingMode::ShadowsOnly,
2 => RayTracingMode::ShadowsAndReflections,
_ => RayTracingMode::FullPathTracedGi,
};
let scale_pct: f32 = res_scale.get();
let t_idx: usize = tsr_idx.get();
let mut config_spec: RenderQualityConfig = if preset == QualityPreset::Cinematic {
Engine3dSignals::max_quality_config()
} else {
RenderQualityConfig::from_preset(preset)
};
config_spec.set_ray_tracing(runtime_ref);
match t_idx {
1 => {
config_spec.set_anti_aliasing(AntiAliasingMode::Tsr);
config_spec.set_resolution_scale(0.67);
}
2 => {
config_spec.set_anti_aliasing(AntiAliasingMode::Tsr);
config_spec.set_resolution_scale(0.50);
}
_ => {
config_spec.set_resolution_scale((scale_pct / 100.0).clamp(0.40, 1.25));
}
}
let _: bool = quality_sig.set_if_changed(config_spec);
})
});
let status_text = move || -> String { status_sig.get() };
let hint_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
style! {
Width(Length::Percent(100.0))
FontSize(12.0)
FontFamily::Monospace
TextColor(live.get_palette().get_muted_foreground())
}
};
let mut sync_host_id: NodeId = NodeId::default();
let column_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_SM)
};
let main_card: NodeId = view! {
EuvCard {
title: GAME3D_CARD_TITLE.to_string()
tokens: tokens
subtitle: GAME3D_CARD_SUB
column {
node_ref: sync_host_id
style: column_style
{ viewport_frame }
text {
bind_style: hint_style
{ GAME3D_CONTROLS_HINT }
}
text {
bind_style: hint_style
{ status_text }
}
}
}
};
let page: NodeId = view! {
EuvPage {
title: GAME3D_TITLE.to_string()
subtitle: GAME3D_SUBTITLE.to_string()
tokens: tokens
{ main_card }
{ fs_3d_portal }
}
};
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(sync_host_id, sync_scope);
},
(),
);
page
}