-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSetupEditorScreen.pde
More file actions
94 lines (80 loc) · 2.94 KB
/
Copy pathSetupEditorScreen.pde
File metadata and controls
94 lines (80 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
public class SetupEditorScreen extends Screen implements ClickListener{
private final ScreenDeleguate mScreenDeleguate;
private final DataDeleguate mData;
private final TextureDeleguate mTextures;
private final Level mCurrentlevel;
private final EditorDrawer mEditordrawer;
private TextButton mBackButton;
private TextButton mCreateButton;
public SetupEditorScreen(ScreenDeleguate screenDeleguate, DataDeleguate dataDeleguate, TextureDeleguate textures, Level level){
mScreenDeleguate = screenDeleguate;
mData = dataDeleguate;
mTextures = textures;
mCurrentlevel = level;
mEditordrawer = new EditorDrawer(dataDeleguate, textures, level);
mBackButton = new TextButton(width/2 - 150, height - 50, "Retour", 36, mTextures.mLeftSelector);
mCreateButton = new TextButton(width/2 + 150, height - 50, "Créer", 36, mTextures.mLeftSelector);
mBackButton.addListener(this);
mCreateButton.addListener(this);
}
public void drawScreen(){
background(mTextures.mBackgroundColor);
mEditordrawer.draw();
fill(mTextures.mTextColor);
mBackButton.drawButton();
mCreateButton.drawButton();
drawHeader();
}
private void drawHeader(){
textAlign(CENTER, CENTER);
textFont(mTextures.mFont, 36);
text("Niveau : " + mCurrentlevel.getname(), width/2, 100.);
textFont(mTextures.mFont, 18);
text("Dessinez le niveau", width/2, 150.);
}
public void onClick(Button src){
if(src == mBackButton){
// Le bouton Retour est cliqué, on affiche le menu
mScreenDeleguate.setMenuScreen();
} else if(src == mCreateButton){
// Le bouton créer est cliqué, on créé le niveau et on lance la page de création
mEditordrawer.saveLevel();
mData.mLevels.add(mCurrentlevel);
mScreenDeleguate.setMenuScreen();
}
mBackButton.removeListener(this);
mCreateButton.removeListener(this);
}
public void mouseClicked(){
mBackButton.isClick();
mCreateButton.isClick();
}
public void mouseReleased(){
mEditordrawer.mouseReleased();
}
public void mouseDragged(){
mEditordrawer.mouseDragged();
}
public void mousePressed(){
mEditordrawer.mousePressed();
}
public void mouseMoved(){
// La souris bouge, je préviens mes boutons et mes champs de texte
// Si la souris n'est sur aucun, je met le curseur par défaut
if(mBackButton.isMouseOnIt()) return;
else if(mCreateButton.isMouseOnIt()) return;
if(mEditordrawer.isMouseOnTheGrid() && !mousePressed){
cursor(HAND);
} else if(mEditordrawer.isMouseOnTheGrid() && mousePressed){
cursor(MOVE);
} else {
cursor(ARROW);
}
}
public void sizeChanged(){
// La taille de la fenetre change, je recalcule les positions des boutons et champs de texte
mBackButton.setPosition(width/2 - 150, height - 50);
mCreateButton.setPosition(width/2 + 150, height - 50);
mEditordrawer.setSize();
}
}