Gestion des fragments

main
Allan POINT 3 years ago
parent 91593fca60
commit 9da930e512

@ -127,4 +127,8 @@ public class Manager implements ObserverBDJ {
public void setCellsColor(int color){ public void setCellsColor(int color){
Cellule.setLivingColor(color); Cellule.setLivingColor(color);
} }
public Boolean isJeuLance(){
return jeuLance;
}
} }

@ -13,7 +13,7 @@ public class GameActivity extends AppCompatActivity {
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.game_activity); setContentView(R.layout.fragment_plateau);
plateauView = findViewById(R.id.plateauView); plateauView = findViewById(R.id.plateauView);
} }

@ -35,7 +35,6 @@ public class LauncherActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
manager = new Manager(); manager = new Manager();
setContentView(R.layout.jeu_de_la_vie); setContentView(R.layout.jeu_de_la_vie);
FragmentPlateau fragmentPlateau = (FragmentPlateau) getSupportFragmentManager().findFragmentById(R.id.fragmentContainerViewId);
/* /*
//très moche à enlever plus tard //très moche à enlever plus tard
start = findViewById(R.id.startButton); start = findViewById(R.id.startButton);
@ -64,8 +63,12 @@ public class LauncherActivity extends AppCompatActivity {
manager.getActualiseurCellule().getArbitre().getPlateau().getCell(0, 1).setAlive(true); manager.getActualiseurCellule().getArbitre().getPlateau().getCell(0, 1).setAlive(true);
}); });
*/ */
if(manager.isJeuLance()) {
}else {
getSupportFragmentManager().beginTransaction().add(R.id.menuView,MenuFragment.class,null).commit(); getSupportFragmentManager().beginTransaction().add(R.id.menuView,MenuFragment.class,null).commit();
} }
}
public void updateGame (){ public void updateGame (){
@ -84,31 +87,14 @@ public class LauncherActivity extends AppCompatActivity {
super.onStop(); super.onStop();
} }
private void setNbColumns(){ public Manager getManager() {
EditText editText = findViewById(R.id.nbColone); return manager;
Editable text = editText.getText();
manager.setNumberOfColumns(Integer.parseInt(text.toString()));
}
private void setNbLignes(){
EditText editText = findViewById(R.id.nbLignes);
Editable text = editText.getText();
manager.setNumberOfLines(Integer.parseInt(text.toString()));
} }
private void setCellsColor(int color){ private void setCellsColor(int color){
manager.setCellsColor(color); manager.setCellsColor(color);
} }
public void startGame(View view){
setNbLignes();
setNbColumns();
Log.d("d", "" + manager.getNumberOfLines());
Log.d("d", "" + manager.getNomberOfColumns());
Log.d("d", "" + Cellule.getLivingColor());
//Intent intent = new Intent(this, GameActivity.class);
//startActivity(intent);
//setContentView(new PlateauView(this, manager.getNomberOfColumns() ,manager.getNumberOfLines()));
getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainerViewId, MenuFragment.class,null).commit();
}
public void setCellsRed(View view){ public void setCellsRed(View view){
int red = Color.RED; int red = Color.RED;
setCellsColor(red); setCellsColor(red);
@ -122,6 +108,13 @@ public class LauncherActivity extends AppCompatActivity {
setCellsColor(blue); setCellsColor(blue);
} }
public void startGame(Bundle bundle){
Log.d("d", "" + (manager.getNumberOfLines()));
Log.d("d", "" + (manager.getNomberOfColumns()));
Log.d("d", "" + Cellule.getLivingColor());
getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainerViewId, FragmentPlateau.class,bundle).commit();
}
@Override @Override
protected void onSaveInstanceState(@NonNull Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);

@ -11,7 +11,8 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import projet.iut.jeu_de_la_vie.R; import projet.iut.jeu_de_la_vie.R;
import projet.iut.jeu_de_la_vie.model.plateau.Plateau; import projet.iut.jeu_de_la_vie.model.Manager;
import projet.iut.jeu_de_la_vie.view.PlateauView;
public class FragmentPlateau extends Fragment { public class FragmentPlateau extends Fragment {
/* /*
@ -25,13 +26,25 @@ public class FragmentPlateau extends Fragment {
this.plateau = plateau; this.plateau = plateau;
} }
*/ */
private Manager manager;
public FragmentPlateau(){ public FragmentPlateau(){
super(R.layout.game_activity); //<-- lui passer la future vue du jeu super(R.layout.fragment_plateau); //<-- lui passer la future vue du jeu
manager = new Manager();
} }
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
manager.setNumberOfLines((Integer) getArguments().get("colones"));
manager.setNumberOfColumns((Integer) getArguments().get("lignes"));
}
@Override @Override
public void onViewCreated (@NonNull View view, Bundle savedInstanceState){ public void onViewCreated (@NonNull View view, Bundle savedInstanceState){
Log.d("fragment",isAdded()+""); Log.d("fragment",isAdded()+"");
PlateauView plateauView = view.findViewById(R.id.plateauView);
//plateauView.setColones();
} }
@Override @Override

@ -1,11 +1,53 @@
package projet.iut.jeu_de_la_vie.view.fragment; package projet.iut.jeu_de_la_vie.view.fragment;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import projet.iut.jeu_de_la_vie.R; import projet.iut.jeu_de_la_vie.R;
import projet.iut.jeu_de_la_vie.model.cellule.Cellule;
import projet.iut.jeu_de_la_vie.view.LauncherActivity;
public class MenuFragment extends Fragment { public class MenuFragment extends Fragment {
public MenuFragment() { public MenuFragment() {
super(R.layout.menu_principal); super(R.layout.menu_principal);
} }
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.startButton).setOnClickListener(l->{startGame(view);});
}
private int getNbColumnsFromView(View v) throws NumberFormatException{
EditText editText = v.findViewById(R.id.nbColone);
Editable text = editText.getText();
return Integer.parseInt(text.toString());
}
private int getNbLignesFromView(View v) throws NumberFormatException{
EditText editText = v.findViewById(R.id.nbLignes);
Editable text = editText.getText();
return Integer.parseInt(text.toString());
}
public void startGame(View view){
Bundle bundle = new Bundle();
int colones;
int lignes;
try {
lignes = getNbLignesFromView(view);
colones = getNbColumnsFromView(view);
}catch (NumberFormatException e){
lignes=10;
colones=10;
}
bundle.putInt("lignes", lignes);
bundle.putInt("colones", colones);
((LauncherActivity)getActivity()).startGame(bundle);
}
} }

@ -7,7 +7,7 @@
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerViewId" android:id="@+id/fragmentContainerViewId"
android:name="projet.iut.jeu_de_la_vie.view.fragment.FragmentPlateau" android:name="projet.iut.jeu_de_la_vie.view.fragment.MenuFragment"
android:layout_width="297dp" android:layout_width="297dp"
android:layout_height="572dp" android:layout_height="572dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"

@ -19,7 +19,7 @@
<EditText <EditText
android:id="@+id/nbColone" android:id="@+id/nbColone"
android:layout_width="84dp" android:layout_width="84dp"
android:layout_height="29dp" android:layout_height="50dp"
android:ems="10" android:ems="10"
android:inputType="number" android:inputType="number"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -48,7 +48,7 @@
<EditText <EditText
android:id="@+id/nbLignes" android:id="@+id/nbLignes"
android:layout_width="84dp" android:layout_width="84dp"
android:layout_height="29dp" android:layout_height="50dp"
android:ems="10" android:ems="10"
android:inputType="number" android:inputType="number"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"

Loading…
Cancel
Save