Advertisement
Guest User

ButtonManager

a guest
Jul 5th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.96 KB | None | 0 0
  1. package bg.ittalents.traffichero.main;
  2.  
  3. import com.badlogic.gdx.Game;
  4. import com.badlogic.gdx.Gdx;
  5. import com.badlogic.gdx.scenes.scene2d.Actor;
  6. import com.badlogic.gdx.scenes.scene2d.actions.Actions;
  7. import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
  8. import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
  9. import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
  10.  
  11. import bg.ittalents.traffichero.screen.*;
  12.  
  13. public class ButtonManager {
  14.  
  15.  
  16. private TextFieldManager fieldManager = new TextFieldManager();
  17. private static boolean receivesEmailNotifications;
  18. public ButtonManager() {
  19.  
  20. }
  21.  
  22. public static boolean isReceivesEmailNotifications() {
  23. return receivesEmailNotifications;
  24. }
  25.  
  26. public static void setReceivesEmailNotifications(boolean receivesEmailNotifications) {
  27. ButtonManager.receivesEmailNotifications = receivesEmailNotifications;
  28. }
  29.  
  30.  
  31. //Creating Buttons For LoginScreen
  32. public TextButton loginButtons(String buttonName) {
  33. if (buttonName.equals("loginButton")) {
  34. TextButton loginButton = new TextButton("Login",Constants.skin);
  35. loginButton.addAction(Actions.alpha(Constants.DEFAULT_ALPHA));
  36. loginButton.addListener(new ChangeListener() {
  37. @Override
  38. public void changed(ChangeEvent event, Actor actor) {
  39. boolean validation = true;
  40. MainScreen.getGreetingLabel().setText(TextFieldManager.getUsernameLogin().getText());
  41. if(TextFieldManager.getUsernameLogin().getText().length() < Constants.MIN_PASSWORD_USERNAME_AND_NICKNAME_LENGTH) {
  42. fieldManager.setUsernameInvalidInput();
  43. validation = false;
  44. }if(TextFieldManager.getPasswordLogin().getText().length() < Constants.MIN_PASSWORD_USERNAME_AND_NICKNAME_LENGTH) {
  45. fieldManager.setPasswordInvalidInput();
  46. }
  47. else if(validation) {
  48. MainScreen.getGreetingLabel().setText("Welcome " + TextFieldManager.getUsernameLogin().getText());
  49. ((Game) Gdx.app.getApplicationListener()).setScreen(new MainScreen());
  50. }
  51. }
  52. });
  53. return loginButton;
  54. } else if (buttonName.equals("registrationButton")){
  55. TextButton registrationButton = new TextButton("Registration",Constants.skin);
  56. registrationButton.addAction(Actions.alpha(Constants.DEFAULT_ALPHA));
  57. registrationButton.addListener(new ChangeListener() {
  58. @Override
  59. public void changed(ChangeEvent event, Actor actor) {
  60. ((Game) Gdx.app.getApplicationListener()).setScreen(new RegistrationScreen());
  61. }
  62. });
  63. return registrationButton;
  64. }else if (buttonName.equals("registerButton")) {
  65. TextButton regButton = new TextButton("Register",Constants.skin);
  66. regButton.addListener(new ChangeListener() {
  67. @Override
  68. public void changed(ChangeEvent event, Actor actor) {
  69. ((Game) Gdx.app.getApplicationListener()).setScreen(new MainScreen());
  70. }
  71. });
  72. return regButton;
  73. }else if(buttonName.equals("playOffline")){
  74. TextButton playOfflineButton = new TextButton("Play Offline",Constants.skin);
  75. playOfflineButton.addAction(Actions.alpha(Constants.CUSTOM_ALPHA));
  76. playOfflineButton.addListener(new ChangeListener() {
  77. @Override
  78. public void changed(ChangeEvent event, Actor actor) {
  79. ((Game) Gdx.app.getApplicationListener()).setScreen(new GameScreen());
  80. }
  81. });
  82. return playOfflineButton;
  83. }
  84. return null;
  85. }
  86. public TextButton afterLoginScreenButtons(String buttonName) {
  87. if (buttonName.equals("Play")) {
  88. TextButton playButton = new TextButton("PLAY",Constants.skin);
  89.  
  90. playButton.addAction(Actions.alpha(Constants.DEFAULT_ALPHA));
  91. playButton.addListener(new ChangeListener() {
  92. @Override
  93. public void changed(ChangeEvent event, Actor actor) {
  94.  
  95. ((Game) Gdx.app.getApplicationListener()).setScreen(new ChooseLevelScreen());
  96. }
  97. });
  98. return playButton;
  99. } else if (buttonName.equals("Change Profile")) {
  100. TextButton changeProfileButton= new TextButton("CHANGE PROFILE",Constants.skin);
  101. changeProfileButton.addAction(Actions.alpha(Constants.DEFAULT_ALPHA));
  102. changeProfileButton.addListener(new ChangeListener() {
  103. @Override
  104. public void changed(ChangeEvent event, Actor actor) {
  105. ((Game) Gdx.app.getApplicationListener()).setScreen(new ChangeProfileScreen());
  106. }
  107. });
  108. return changeProfileButton;
  109. } else if (buttonName.equals("HeightScore")) {
  110. TextButton heightScoreButton= new TextButton("HIGH SCORE",Constants.skin);
  111. heightScoreButton.addAction(Actions.alpha(Constants.DEFAULT_ALPHA));
  112. heightScoreButton.addListener(new ChangeListener() {
  113. @Override
  114. public void changed(ChangeEvent event, Actor actor) {
  115. ((Game) Gdx.app.getApplicationListener()).setScreen(new HighScoreScreen());
  116. }
  117. });
  118. return heightScoreButton;
  119. }
  120. return null;
  121. }
  122.  
  123. public TextButton levelButtons(String buttonName) {
  124. if (buttonName.equals("Level 1")) {
  125. TextButton levelOneButton = new TextButton("Level 1",Constants.skin);
  126. levelOneButton.addAction(Actions.alpha(Constants.DEFAULT_ALPHA));
  127. levelOneButton.addListener(new ChangeListener() {
  128. @Override
  129. public void changed(ChangeEvent event, Actor actor) {
  130. if(LoginScreen.getBackgroundMusic()!= null) {
  131. LoginScreen.getBackgroundMusic().pause();
  132. }
  133. ((Game) Gdx.app.getApplicationListener()).setScreen(new GameScreen());
  134. }
  135. });
  136. return levelOneButton;
  137. } else if (buttonName.equals("Level 2")) {
  138. TextButton levelTwoButton = new TextButton("Level 2",Constants.skin);
  139. levelTwoButton.addAction(Actions.alpha(Constants.DEFAULT_ALPHA));
  140. levelTwoButton.addListener(new ChangeListener() {
  141. @Override
  142. public void changed(ChangeEvent event, Actor actor) {
  143.  
  144. LoginScreen.getBackgroundMusic().pause();
  145. ((Game) Gdx.app.getApplicationListener()).setScreen(new GameScreen());
  146. }
  147. });
  148. return levelTwoButton;
  149. } else if (buttonName.equals("Level 3")) {
  150. TextButton levelThreeButton = new TextButton("Level 3",Constants.skin);
  151. levelThreeButton.addAction(Actions.alpha(Constants.DEFAULT_ALPHA));
  152. levelThreeButton.addListener(new ChangeListener() {
  153. @Override
  154. public void changed(ChangeEvent event, Actor actor) {
  155. LoginScreen.getBackgroundMusic().pause();
  156. ((Game) Gdx.app.getApplicationListener()).setScreen(new GameScreen());
  157. }
  158. });
  159. return levelThreeButton;
  160. }
  161. return null;
  162. }
  163.  
  164. public TextButton settingsScreenButtons(String buttonName) {
  165. if (buttonName.equals("Change Nickname")) {
  166. TextButton changeNicknameButton = new TextButton(" Change\nNickname", Constants.skin);
  167. changeNicknameButton.addAction(Actions.alpha(Constants.DEFAULT_ALPHA));
  168. changeNicknameButton.addListener(new ChangeListener() {
  169. @Override
  170. public void changed(ChangeEvent event, Actor actor) {
  171.  
  172. ((Game) Gdx.app.getApplicationListener()).setScreen(new bg.ittalents.traffichero.screen.ChangeNicknameScreen());
  173. }
  174. });
  175. return changeNicknameButton;
  176. }
  177. {
  178. TextButton changePassButton = new TextButton(" Change\nPassword", Constants.skin);
  179. changePassButton.addAction(Actions.alpha(Constants.DEFAULT_ALPHA));
  180. changePassButton.addListener(new ChangeListener() {
  181. @Override
  182. public void changed(ChangeEvent event, Actor actor) {
  183. ((Game) Gdx.app.getApplicationListener()).setScreen(new ChangeUserPassword());
  184. }
  185. });
  186. return changePassButton;
  187. }
  188. }
  189.  
  190.  
  191.  
  192. public CheckBox settingsScreenCheckBoxes(final String checkBoxName){
  193. if(checkBoxName.equals("emailCheckbox")){
  194. final CheckBox emailCheckBox = new CheckBox("Send email if somebody\n beat your HeightScore?", Constants.skin);
  195.  
  196. emailCheckBox.setChecked(true);
  197. emailCheckBox.addListener(new ChangeListener() {
  198. @Override
  199. public void changed(ChangeEvent event, Actor actor) {
  200. if (emailCheckBox.isChecked()){
  201. setReceivesEmailNotifications(true);
  202. }else{
  203. setReceivesEmailNotifications(false);
  204. }
  205. }
  206. });
  207. return emailCheckBox;
  208. }
  209. if(checkBoxName.equals("soundCheckbox")){
  210. final CheckBox soundEffectCheckBox= new CheckBox("Sounds Effect", Constants.skin);
  211. soundEffectCheckBox.setChecked(true);
  212. soundEffectCheckBox.addListener(new ChangeListener() {
  213. @Override
  214. public void changed(ChangeEvent event, Actor actor) {
  215. if(soundEffectCheckBox.isChecked()){
  216. LoginScreen.getClickSound().setVolume(0, 0);
  217. }else{
  218. LoginScreen.getClickSound().setVolume(0, 0.2f);
  219. }
  220. }
  221. });
  222. return soundEffectCheckBox;
  223. }if(checkBoxName.equals("backgroundCheckbox")){
  224. final CheckBox backgroundMusicCheckBox= new CheckBox("Background Music", Constants.skin);
  225. backgroundMusicCheckBox.setChecked(true);
  226. backgroundMusicCheckBox.addListener(new ChangeListener() {
  227. @Override
  228. public void changed(ChangeEvent event, Actor actor) {
  229. if (backgroundMusicCheckBox.isChecked()) {
  230. LoginScreen.getBackgroundMusic().play();
  231.  
  232. } else {
  233. LoginScreen.getBackgroundMusic().pause();
  234.  
  235. }
  236. }
  237. });
  238. return backgroundMusicCheckBox;
  239. }
  240. return null;
  241. }
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement