J'essay de comprendre les fragments:/ (j'ai essayer de faire un fragment avec le menu

main
Allan POINT 3 years ago
parent 8510b32bc1
commit 91593fca60

@ -11,6 +11,7 @@ import projet.iut.jeu_de_la_vie.model.cellule.Cellule;
import projet.iut.jeu_de_la_vie.model.cellulesVivantes.CellulesVivantes; import projet.iut.jeu_de_la_vie.model.cellulesVivantes.CellulesVivantes;
import projet.iut.jeu_de_la_vie.model.plateau.Plateau; import projet.iut.jeu_de_la_vie.model.plateau.Plateau;
/** /**
* Point d'entré du model * Point d'entré du model
* @author Yohann Breuil * @author Yohann Breuil
@ -22,7 +23,6 @@ public class Manager implements ObserverBDJ {
private IBoucleDeJeu boucleDeJeu; private IBoucleDeJeu boucleDeJeu;
private ChangeurRegle changeurRegle; private ChangeurRegle changeurRegle;
private boolean jeuLance; private boolean jeuLance;
private FragmentPlateau fragmentPlateau;
public Manager(){ public Manager(){
@ -127,12 +127,4 @@ public class Manager implements ObserverBDJ {
public void setCellsColor(int color){ public void setCellsColor(int color){
Cellule.setLivingColor(color); Cellule.setLivingColor(color);
} }
public FragmentPlateau getFragmentPlateau() {
return fragmentPlateau;
}
public void setFragmentPlateau(FragmentPlateau fragmentPlateau) {
this.fragmentPlateau = fragmentPlateau;
}
} }

@ -1,30 +1,23 @@
package projet.iut.jeu_de_la_vie.view; package projet.iut.jeu_de_la_vie.view;
import android.content.Intent; import android.content.Intent;
import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import java.awt.font.NumericShaper;
import java.util.List;
import projet.iut.jeu_de_la_vie.R; import projet.iut.jeu_de_la_vie.R;
import projet.iut.jeu_de_la_vie.model.FragmentPlateau;
import projet.iut.jeu_de_la_vie.model.Manager; import projet.iut.jeu_de_la_vie.model.Manager;
import projet.iut.jeu_de_la_vie.model.cellule.Cellule; import projet.iut.jeu_de_la_vie.model.cellule.Cellule;
import projet.iut.jeu_de_la_vie.model.plateau.Plateau; import projet.iut.jeu_de_la_vie.view.fragment.FragmentPlateau;
import projet.iut.jeu_de_la_vie.view.fragment.MenuFragment;
public class LauncherActivity extends AppCompatActivity { public class LauncherActivity extends AppCompatActivity {
@ -42,6 +35,7 @@ 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);
@ -70,10 +64,7 @@ public class LauncherActivity extends AppCompatActivity {
manager.getActualiseurCellule().getArbitre().getPlateau().getCell(0, 1).setAlive(true); manager.getActualiseurCellule().getArbitre().getPlateau().getCell(0, 1).setAlive(true);
}); });
*/ */
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainerView,FragmentPlateau.class,null).commit(); getSupportFragmentManager().beginTransaction().add(R.id.menuView,MenuFragment.class,null).commit();
FragmentPlateau frag = new FragmentPlateau();
getSupportFragmentManager().putFragment(new Bundle(),"main",frag);
manager.setFragmentPlateau(frag);
} }
public void updateGame (){ public void updateGame (){
@ -83,8 +74,8 @@ public class LauncherActivity extends AppCompatActivity {
@Override @Override
protected void onStart (){ protected void onStart (){
super.onStart(); super.onStart();
FragmentPlateau fragment = new FragmentPlateau(); //FragmentPlateau fragment = new FragmentPlateau();
fragment.setPlateau(manager.getActualiseurCellule().getArbitre().getPlateau()); //fragment.setPlateau(manager.getActualiseurCellule().getArbitre().getPlateau());
} }
@Override @Override
@ -113,9 +104,10 @@ public class LauncherActivity extends AppCompatActivity {
Log.d("d", "" + manager.getNumberOfLines()); Log.d("d", "" + manager.getNumberOfLines());
Log.d("d", "" + manager.getNomberOfColumns()); Log.d("d", "" + manager.getNomberOfColumns());
Log.d("d", "" + Cellule.getLivingColor()); Log.d("d", "" + Cellule.getLivingColor());
Intent intent = new Intent(this, GameActivity.class); //Intent intent = new Intent(this, GameActivity.class);
startActivity(intent); //startActivity(intent);
//setContentView(new PlateauView(this, manager.getNomberOfColumns() ,manager.getNumberOfLines())); //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;

@ -1,4 +1,4 @@
package projet.iut.jeu_de_la_vie.model; package projet.iut.jeu_de_la_vie.view.fragment;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
@ -14,7 +14,7 @@ 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.plateau.Plateau;
public class FragmentPlateau extends Fragment { public class FragmentPlateau extends Fragment {
/*
private Plateau plateau; private Plateau plateau;
public Plateau getPlateau() { public Plateau getPlateau() {
@ -24,9 +24,9 @@ public class FragmentPlateau extends Fragment {
public void setPlateau(Plateau plateau) { public void setPlateau(Plateau plateau) {
this.plateau = plateau; this.plateau = plateau;
} }
*/
public FragmentPlateau(){ public FragmentPlateau(){
super(R.layout.vue_jeu_tmp); //<-- lui passer la future vue du jeu super(R.layout.game_activity); //<-- lui passer la future vue du jeu
} }
@Override @Override

@ -0,0 +1,11 @@
package projet.iut.jeu_de_la_vie.view.fragment;
import androidx.fragment.app.Fragment;
import projet.iut.jeu_de_la_vie.R;
public class MenuFragment extends Fragment {
public MenuFragment() {
super(R.layout.menu_principal);
}
}

@ -6,8 +6,8 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView" android:id="@+id/fragmentContainerViewId"
android:name="projet.iut.jeu_de_la_vie.model.FragmentPlateau" android:name="projet.iut.jeu_de_la_vie.view.fragment.FragmentPlateau"
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"

@ -2,7 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout" android:id="@+id/menuView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save