@@ -5,20 +5,25 @@ use crate::{
55 belt:: { belt:: Belt , smart:: SmartBelt , splitter:: SPLITTER_BELT_LEN } ,
66 data:: DataStore ,
77 frontend:: {
8- action:: action_state_machine:: { ActionStateMachine , WIDTH_PER_LEVEL } ,
8+ action:: {
9+ action_state_machine:: { ActionStateMachine , WIDTH_PER_LEVEL } ,
10+ set_recipe:: SetRecipeInfo ,
11+ ActionType ,
12+ } ,
913 world:: tile:: {
1014 AssemblerID , AssemblerInfo , BeltId , BeltTileId , Dir , Entity , BELT_LEN_PER_TILE ,
1115 CHUNK_SIZE_FLOAT ,
1216 } ,
1317 } ,
14- item:: { usize_from, IdxTrait , Item } ,
18+ item:: { usize_from, IdxTrait , Item , Recipe } ,
1519} ;
1620use eframe:: {
1721 egui:: {
18- self , Align2 , CentralPanel , Color32 , Context , CornerRadius , Pos2 , ProgressBar , Rect , Shape ,
19- SidePanel , TopBottomPanel , Ui , Window ,
22+ self , Align2 , CentralPanel , Color32 , ComboBox , Context , CornerRadius , Pos2 , ProgressBar ,
23+ Rect , Shape , SidePanel , TopBottomPanel , Ui , Window ,
2024 } ,
2125 epaint:: text:: Row ,
26+ wgpu:: hal:: auxil:: db,
2227} ;
2328use egui_extras:: { Column , TableBuilder } ;
2429use log:: { info, warn} ;
@@ -547,7 +552,9 @@ pub fn render_ui<ItemIdxType: IdxTrait, RecipeIdxType: IdxTrait>(
547552 state_machine : & mut ActionStateMachine < ItemIdxType , RecipeIdxType > ,
548553 game_state : & GameState < ItemIdxType , RecipeIdxType > ,
549554 data_store : & DataStore < ItemIdxType , RecipeIdxType > ,
550- ) {
555+ ) -> impl IntoIterator < Item = ActionType < ItemIdxType , RecipeIdxType > > {
556+ let mut actions = vec ! [ ] ;
557+
551558 match & state_machine. state {
552559 crate :: frontend:: action:: action_state_machine:: ActionStateMachineState :: Idle => { } ,
553560 crate :: frontend:: action:: action_state_machine:: ActionStateMachineState :: Holding (
@@ -565,45 +572,78 @@ pub fn render_ui<ItemIdxType: IdxTrait, RecipeIdxType: IdxTrait>(
565572
566573 if let Some ( entity) = entity {
567574 match entity {
568- crate :: frontend:: world:: tile:: Entity :: Assembler { pos, info } => match info {
569- crate :: frontend:: world:: tile:: AssemblerInfo :: UnpoweredNoRecipe => {
570- ui. label ( "Assembler" ) ;
571- } ,
572- crate :: frontend:: world:: tile:: AssemblerInfo :: Unpowered ( recipe) => {
573- ui. label ( "Assembler" ) ;
574- } ,
575- crate :: frontend:: world:: tile:: AssemblerInfo :: PoweredNoRecipe ( grid) => {
576- ui. label ( "Assembler" ) ;
577- } ,
578- crate :: frontend:: world:: tile:: AssemblerInfo :: Powered {
579- id,
580- pole_position
581- } => {
582- ui. label ( "Assembler" ) ;
575+ crate :: frontend:: world:: tile:: Entity :: Assembler { pos, info } => {
576+ let mut goal_recipe: Option < Recipe < RecipeIdxType > > = match info {
577+ AssemblerInfo :: UnpoweredNoRecipe => None ,
578+ AssemblerInfo :: Unpowered ( recipe) => Some ( * recipe) ,
579+ AssemblerInfo :: PoweredNoRecipe ( position) => None ,
580+ AssemblerInfo :: Powered { id, pole_position } => Some ( id. recipe ) ,
581+ } ;
583582
584- // TODO:
585- // ui.label(data_store.recipe_names[usize_from(assembler_id.recipe.id)]);
583+ ComboBox :: new ( "Recipe list" , "Recipes" ) . selected_text ( goal_recipe. map ( |recipe| data_store. recipe_names [ usize_from ( recipe. id ) ] . as_str ( ) ) . unwrap_or ( "Choose a recipe!" ) ) . show_ui ( ui, |ui| {
584+ data_store. recipe_names . iter ( ) . enumerate ( ) . for_each ( |( i, recipe_name) | {
585+ ui. selectable_value ( & mut goal_recipe, Some ( Recipe { id : i. try_into ( ) . unwrap ( ) } ) , recipe_name) ;
586+ } ) ;
587+ } ) ;
586588
587- let assembler = game_state
588- . simulation_state
589- . factory
590- . power_grids
591- . get_assembler_info ( * id, data_store) ;
592-
593- let pb = ProgressBar :: new ( assembler. timer_percentage ) . show_percentage ( ) . corner_radius ( CornerRadius :: ZERO ) ;
594- ui. add ( pb) ;
595-
596- TableBuilder :: new ( ui) . columns ( Column :: auto ( ) . resizable ( false ) , assembler. inputs . len ( ) + assembler. outputs . len ( ) ) . body ( |mut body| {
597- body. row ( 5.0 , |mut row| {
598- for ( item, count) in assembler. inputs . iter ( ) . chain ( assembler. outputs . iter ( ) ) {
599- row. col ( |ui| {
600- ui. label ( & data_store. item_names [ usize_from ( item. id ) ] ) ;
601- ui. label ( format ! ( "{}" , * count) ) ;
602- } ) ;
589+
590+ match info {
591+ crate :: frontend:: world:: tile:: AssemblerInfo :: UnpoweredNoRecipe => {
592+ ui. label ( "Assembler" ) ;
593+ if let Some ( goal_recipe) = goal_recipe {
594+ actions. push ( ActionType :: SetRecipe ( SetRecipeInfo { pos : * pos, recipe : goal_recipe } ) ) ;
595+ }
596+ } ,
597+ crate :: frontend:: world:: tile:: AssemblerInfo :: Unpowered ( recipe) => {
598+ ui. label ( "Assembler" ) ;
599+ if let Some ( goal_recipe) = goal_recipe {
600+ if goal_recipe != * recipe {
601+ actions. push ( ActionType :: SetRecipe ( SetRecipeInfo { pos : * pos, recipe : goal_recipe } ) ) ;
603602 }
603+ }
604+ } ,
605+ crate :: frontend:: world:: tile:: AssemblerInfo :: PoweredNoRecipe ( grid) => {
606+ ui. label ( "Assembler" ) ;
607+ if let Some ( goal_recipe) = goal_recipe {
608+ actions. push ( ActionType :: SetRecipe ( SetRecipeInfo { pos : * pos, recipe : goal_recipe } ) ) ;
609+ }
610+ } ,
611+ crate :: frontend:: world:: tile:: AssemblerInfo :: Powered {
612+ id,
613+ pole_position
614+ } => {
615+ ui. label ( "Assembler" ) ;
616+
617+ if let Some ( goal_recipe) = goal_recipe {
618+ if goal_recipe != id. recipe {
619+ actions. push ( ActionType :: SetRecipe ( SetRecipeInfo { pos : * pos, recipe : goal_recipe } ) ) ;
620+ }
621+ }
622+
623+ // TODO:
624+ // ui.label(data_store.recipe_names[usize_from(assembler_id.recipe.id)]);
625+
626+ let assembler = game_state
627+ . simulation_state
628+ . factory
629+ . power_grids
630+ . get_assembler_info ( * id, data_store) ;
631+
632+ let pb = ProgressBar :: new ( assembler. timer_percentage ) . show_percentage ( ) . corner_radius ( CornerRadius :: ZERO ) ;
633+ ui. add ( pb) ;
634+
635+ TableBuilder :: new ( ui) . columns ( Column :: auto ( ) . resizable ( false ) , assembler. inputs . len ( ) + assembler. outputs . len ( ) ) . body ( |mut body| {
636+ body. row ( 5.0 , |mut row| {
637+ for ( item, count) in assembler. inputs . iter ( ) . chain ( assembler. outputs . iter ( ) ) {
638+ row. col ( |ui| {
639+ ui. label ( & data_store. item_names [ usize_from ( item. id ) ] ) ;
640+ ui. label ( format ! ( "{}" , * count) ) ;
641+ } ) ;
642+ }
643+ } ) ;
604644 } ) ;
605- } ) ;
606- } ,
645+ }
646+ }
607647 } ,
608648 crate :: frontend:: world:: tile:: Entity :: PowerPole {
609649 ty,
@@ -785,6 +825,8 @@ pub fn render_ui<ItemIdxType: IdxTrait, RecipeIdxType: IdxTrait>(
785825 } ) ;
786826 } ) ;
787827 } ) ;
828+
829+ actions
788830}
789831
790832fn render_items_straight < ItemIdxType : IdxTrait , RecipeIdxType : IdxTrait > (
0 commit comments