Пример #1
0
  public final void updateFontsProperties(String language) {
    Preferences fontPrefs = Gdx.app.getPreferences(propertyName);

    // store screen width for detecting screen fontSize change
    // on later startups, which will require font regeneration
    fontPrefs.putString("tag", versionTag);
    fontPrefs.putInteger("display-width", Gdx.graphics.getWidth());
    fontPrefs.putInteger("display-height", Gdx.graphics.getHeight());
    fontPrefs.putString("lang", language);
    fontPrefs.flush();
  }
Пример #2
0
  public void processSignInHASHED(
      String username,
      String password) // this is for when we do the auto login cause we getting the hashed prefs
      {

    String url =
        "http://45.33.62.187/api/v1/player/?username_hash="
            + username
            + "&password_hash="
            + password
            + "&format=json";
    String getPlayer = apiCall.httpGet(url, httpReturns.size());

    System.out.println("trying to sign in hashed with " + username + " " + password);

    if (getPlayer.equalsIgnoreCase("FAILED")
        || getPlayer.equalsIgnoreCase("CANCELLED")
        || getPlayer.equalsIgnoreCase("EMPTY")) {
      // menuComponents.add(3, new MenuComponent(300, 400, 100, 50, Assets.menuFailedRegion));
      System.out.println("login with hash " + getPlayer);
      Preferences prefs = Gdx.app.getPreferences("LOGIN");
      prefs.putString("USERNAME_HASHED", "");
      prefs.putString("PASSWORD_HASHED", "");
      prefs.flush(); // saves the blank hashes to the prefs file
      this.signIn();
    } else {
      System.out.println("JSON NOT MEPTY");
      JSONObject json = new JSONObject(getPlayer);
      JSONArray playerArray = json.getJSONArray("objects");
      JSONObject player0 = playerArray.getJSONObject(0);
      int wins = player0.getInt("wins");
      int losses = player0.getInt("losses");
      String usernameS = player0.getString("username");
      String charityURL = player0.getString("charity");

      // store players id during this playing session in proofOfConcept (best place I can think of
      // at the moment)
      int id = player0.getInt("id");
      game.setPlayerID(id);

      String getCharity =
          apiCall.httpGet("http://45.33.62.187" + charityURL + "?format=json", httpReturns.size());
      if (getCharity.equalsIgnoreCase("FAILED")
          || getCharity.equalsIgnoreCase("CANCELLED")
          || getCharity.equalsIgnoreCase("EMPTY")) {
        // menuComponents.add(new MenuComponent(300, 400, 100, 50, Assets.menuFailedRegion));
        // //should be 3 unless 3 is already there, then it will be 4
      } else {
        JSONObject jsonCharity = new JSONObject(getCharity);
        String charityName = jsonCharity.getString("name");
        int charityIcon = jsonCharity.getInt("icon");
        int charityID = jsonCharity.getInt("id");
        game.setCharityID(charityID);

        System.out.println("Go to welcome");

        this.welcome(usernameS, wins, losses, charityName, charityIcon);
      }
    }
  }
  void loadSkeleton(final FileHandle skeletonFile) {
    if (skeletonFile == null) return;

    try {
      // Setup a texture atlas that uses a white image for images not found in the atlas.
      Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888);
      pixmap.setColor(new Color(1, 1, 1, 0.33f));
      pixmap.fill();
      final AtlasRegion fake = new AtlasRegion(new Texture(pixmap), 0, 0, 32, 32);
      pixmap.dispose();

      String atlasFileName = skeletonFile.nameWithoutExtension();
      if (atlasFileName.endsWith(".json"))
        atlasFileName = new FileHandle(atlasFileName).nameWithoutExtension();
      FileHandle atlasFile = skeletonFile.sibling(atlasFileName + ".atlas");
      if (!atlasFile.exists()) atlasFile = skeletonFile.sibling(atlasFileName + ".atlas.txt");
      TextureAtlasData data =
          !atlasFile.exists() ? null : new TextureAtlasData(atlasFile, atlasFile.parent(), false);
      TextureAtlas atlas =
          new TextureAtlas(data) {
            public AtlasRegion findRegion(String name) {
              AtlasRegion region = super.findRegion(name);
              if (region == null) {
                // Look for separate image file.
                FileHandle file = skeletonFile.sibling(name + ".png");
                if (file.exists()) {
                  Texture texture = new Texture(file);
                  texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
                  region = new AtlasRegion(texture, 0, 0, texture.getWidth(), texture.getHeight());
                  region.name = name;
                }
              }
              return region != null ? region : fake;
            }
          };

      // Load skeleton data.
      String extension = skeletonFile.extension();
      if (extension.equalsIgnoreCase("json") || extension.equalsIgnoreCase("txt")) {
        SkeletonJson json = new SkeletonJson(atlas);
        json.setScale(ui.scaleSlider.getValue());
        skeletonData = json.readSkeletonData(skeletonFile);
      } else {
        SkeletonBinary binary = new SkeletonBinary(atlas);
        binary.setScale(ui.scaleSlider.getValue());
        skeletonData = binary.readSkeletonData(skeletonFile);
        if (skeletonData.getBones().size == 0) throw new Exception("No bones in skeleton data.");
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      ui.toast("Error loading skeleton: " + skeletonFile.name());
      lastModifiedCheck = 5;
      return;
    }

    skeleton = new Skeleton(skeletonData);
    skeleton.setToSetupPose();
    skeleton = new Skeleton(skeleton); // Tests copy constructors.
    skeleton.updateWorldTransform();

    state = new AnimationState(new AnimationStateData(skeletonData));
    state.addListener(
        new AnimationStateAdapter() {
          public void event(TrackEntry entry, Event event) {
            ui.toast(event.getData().getName());
          }
        });

    this.skeletonFile = skeletonFile;
    prefs.putString("lastFile", skeletonFile.path());
    prefs.flush();
    lastModified = skeletonFile.lastModified();
    lastModifiedCheck = checkModifiedInterval;

    // Populate UI.

    ui.window.getTitleLabel().setText(skeletonFile.name());
    {
      Array<String> items = new Array();
      for (Skin skin : skeletonData.getSkins()) items.add(skin.getName());
      ui.skinList.setItems(items);
    }
    {
      Array<String> items = new Array();
      for (Animation animation : skeletonData.getAnimations()) items.add(animation.getName());
      ui.animationList.setItems(items);
    }
    ui.trackButtons.getButtons().first().setChecked(true);

    // Configure skeleton from UI.

    if (ui.skinList.getSelected() != null) skeleton.setSkin(ui.skinList.getSelected());
    setAnimation();

    // ui.animationList.clearListeners();
    // state.setAnimation(0, "walk", true);
  }
Пример #4
0
  public void touched(float x, float y) {

    if (menuNumber == this.MENU_SPLASH) // splash
    {
      this.isSplash = false;
      try {
        System.out.println("Trying to get the prefs to login");
        Preferences prefs = Gdx.app.getPreferences("LOGIN");
        String username = prefs.getString("USERNAME_HASHED");
        String password = prefs.getString("PASSWORD_HASHED");
        if (username.length() > 0 && password.length() > 0) {
          System.out.println("gonna log in with " + username + " " + password);
          this.processSignInHASHED(
              username,
              password); // this should do the this.welcome at the end of it, so this should be ok.
        } else {
          this
              .signIn(); // if they are there, but they are length 0 cause they have logged out
                         // before.
        }
      } catch (Exception e) {
        System.out.println("ERROR: " + e);
        System.out.println("nope, going to sign in instead");
        this.signIn();
      }

    } else if (menuNumber == this.MENU_SIGNIN) // sign in
    {

      if (menuComponents.get(0).containsXY(x, y)) // LETS GO
      {
        menuComponents.get(0).texture = Assets.menuButtonSmallDarkRegion;
        this.processSignIn(
            menuTextFields.get("usernameTF").getText(), menuTextFields.get("passwordTF").getText());
      } else if (menuComponents.get(1).containsXY(x, y)) // SIGN UP
      {
        menuComponents.get(1).texture = Assets.menuButtonSmallDarkRegion;
        this.signUp();
      } else if (menuComponents.get(2).containsXY(x, y)) // shortcut to sign in as spence95
      {
        this.processSignIn("spence95", "abc");
      }

    } else if (menuNumber == this.MENU_WELCOME) // welcome
    {
      this.mainMenu();
    } else if (menuNumber == this.MENU_SIGNUP) // signup
    {

      if (menuComponents.get(0).containsXY(x, y)) // submit
      {
        // this.processSignUp(menuTextFields.get("usernameTF").getText(),
        // menuTextFields.get("passwordTF").getText(), menuTextFields.get("emailTF").getText(),
        // charityID);
        this.processSignUp(
            menuTextFields.get("usernameTF").getText(),
            menuTextFields.get("passwordTF").getText(),
            "",
            charityID);

        this.processSignIn(
            menuTextFields.get("usernameTF").getText(), menuTextFields.get("passwordTF").getText());
      } else if (menuComponents.get(1).containsXY(x, y)) // return
      {
        this.splash();
      }

    } else if (menuNumber == this.MENU_MAINMENU) // main menu
    {
      if (menuComponents.get(0).containsXY(x, y)) // play!
      {
        // goes to lobby (loading), lobby goes to game when ready
        this.pickClass();
        // game.setScreen(new LobbyScreen(game));
      } else if (menuComponents.get(1).containsXY(x, y)) // oiptions buttons
      {
        System.out.println("options clicked");
        this.options();

      } else if (menuComponents.get(2).containsXY(x, y)) // profile button
      {
        System.out.println("profile clicked");
      }

    } else if (menuNumber == this.MENU_OPTIONS) // options
    {
      if (menuComponents.get(0).containsXY(x, y)) // return button
      {
        this.mainMenu();
      } else if (menuComponents.get(4).containsXY(x, y)) // log out button
      {
        Preferences prefs = Gdx.app.getPreferences("LOGIN");
        prefs.putString("USERNAME_HASHED", "");
        prefs.putString("PASSWORD_HASHED", "");
        prefs.flush(); // saves the blank hashes to the prefs file
        this.splash();
      }
    } else if (menuNumber == this.MENU_GAMEOVER) // game over
    {
      this.mainMenu();
    } else if (menuNumber == this.MENU_PICK_CLASS) {
      if (menuComponents.get(0).containsXY(x, y)) // continue
      {
        game.setScreen(new LobbyScreen(game, "Rocketman"));
      } else if (menuComponents.get(1).containsXY(x, y)) // return
      {
        this.mainMenu();
      }
    }
  }
Пример #5
0
 protected void storeNewToken(GDXFacebookAccessToken token) {
   Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Storing new accessToken: " + token.getToken());
   preferences.putString("access_token", token.getToken());
   preferences.putLong("expires_at", token.getExpiresAt());
   preferences.flush();
 }
Пример #6
0
 public void saveFavorites(Array<FileHandle> favorites) {
   prefs.putString(keyName, json.toJson(new FavouriteData(favorites)));
   prefs.flush();
 }