Beispiel #1
0
 static void initMission(
     Mission mission, Mission parent, Element missionNode, Handler loadHandler) {
   Log.d(mission.getClass().getName(), "initing mission. id=" + mission.id);
   mission.xmlMissionNode = missionNode;
   mission.setParent(parent);
   mission.loadXML(loadHandler);
 }
Beispiel #2
0
  /**
   * Finishes the mission activity and sets the result code
   *
   * @param status Mission.STATUS_SUCCESS or FAIL or NEW
   */
  public void finish(Double status) {
    mission.setStatus(status);

    // if (status == Globals.STATUS_SUCCESS) {
    // setResult(Activity.RESULT_OK, result);
    // mission.runOnSuccessEvents();
    // } else if (status == Globals.STATUS_FAIL) {
    // setResult(Activity.RESULT_CANCELED, result);
    // mission.runOnFailEvents();
    // }

    mission.applyOnEndRules();

    finish();
  }
Beispiel #3
0
 @SuppressWarnings("unchecked")
 private void storeDirectSubmissions(Handler loadHandler) {
   List<Element> directSubMissionElements = xmlMissionNode.selectNodes("./mission");
   for (Element e : directSubMissionElements) {
     directSubMissions.add(Mission.create(e.attributeValue("id"), this, e, loadHandler));
   }
 }
Beispiel #4
0
  /** Starts the mission using an Intent that only has the minimal extras, namely the mission ID. */
  public void startMission() {
    Intent startingIntent = this.startingIntent;
    if (GeoQuestApp.useAdaptionEngine) {
      String alternMissionId = GeoQuestApp.adaptionEngine.getAlternativeMission(id);
      if (!alternMissionId.equals(id)) {
        if (Mission.existsMission(alternMissionId)) {
          AlternativeMission alternativeM = (AlternativeMission) Mission.get(alternMissionId);
          alternativeM.setPlaceholderId(id);
          startingIntent = ((Mission) alternativeM).startingIntent;
        } else {
          AlternativeMission alternativeM = AlternativeMission.create(alternMissionId, id);
          startingIntent = ((Mission) alternativeM).startingIntent;
        }
      }
    }

    if (startingIntent != null) {
      GeoQuestApp.stopAudio();
      getMainActivity().startActivityForResult(startingIntent, 1);
    } else Log.e(this.getClass().getName(), "Mission can NOT be started since Intent is null.");
  }
Beispiel #5
0
  /**
   * Called when the activity is first created. Setups google mapView, the map overlays and the
   * listeners
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(this.getClass().getName(), "creating activity");
    super.onCreate(savedInstanceState);

    // get extras
    Bundle extras = getIntent().getExtras();
    String id = extras.getString("missionID");
    mission = Mission.get(id);
    mission.setStatus(Globals.STATUS_RUNNING);

    setContentView(R.layout.main);

    // Setup Google MapView
    myMapView = (MapView) findViewById(R.id.mapview);
    myMapView.setBuiltInZoomControls(false);
    myMapView.displayZoomControls(false);

    String mapKind = mission.xmlMissionNode.attributeValue("mapkind");
    if (mapKind == null || mapKind.equals("map")) myMapView.setSatellite(false);
    else myMapView.setSatellite(true);

    myMapCtrl = myMapView.getController();

    myMapCtrl.setZoom(18);
    String zoomLevel = mission.xmlMissionNode.attributeValue("zoomlevel");
    if (zoomLevel != null) {
      int zoomLevelInt = Integer.parseInt(zoomLevel);
      if (zoomLevelInt > 0 && zoomLevelInt < 24) myMapCtrl.setZoom(zoomLevelInt);
    }

    // Setup Zoom Controls:
    Button zoomIn = (Button) findViewById(R.id.zoom_in);
    zoomIn.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            myMapCtrl.zoomIn();
          }
        });

    Button zoomOut = (Button) findViewById(R.id.zoom_out);
    zoomOut.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            myMapCtrl.zoomOut();
          }
        });

    // Initialize location stuff:
    locationListener =
        new GeoQuestLocationListener(this) {
          public void onRelevantLocationChanged(Location location) {
            super.onRelevantLocationChanged(location);
            GeoPoint point = location2GP(location);
            myMapCtrl.animateTo(point);

            // calculate distance to hotspots
            for (Iterator<HotspotOld> i = hotspots.listIterator(); i.hasNext(); ) {
              HotspotOld hotspot = i.next(); // TODO: throws a
              // ConcurrentModificationException
              // sometimes (hm)
              hotspot.inRange(location);
            }
          }
        };

    try {
      long timeStepMockMode = Long.parseLong(getText(R.string.map_mockGPSTimeInterval).toString());
      locationSource =
          new LocationSource(getApplicationContext(), locationListener, handler, timeStepMockMode);
      locationSource.setMode(LocationSource.REAL_MODE);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // startMissionsList
    startMissionPanel = (LinearLayout) findViewById(R.id.startMissionPanel);

    // Players Location Overlay
    myLocationOverlay = new MyLocationOverlay(this, myMapView);
    myLocationOverlay.enableCompass(); // doesn't work in the emulator?
    myLocationOverlay.enableMyLocation();
    myMapView.getOverlays().add(myLocationOverlay);

    GeoQuestApp.getInstance().setGoogleMap(myMapView);

    // Show loading screen to Parse the Game XML File
    // indirectly calls onCreateDialog() and initializes hotspots
    showDialog(READXML_DIALOG);

    mission.applyOnStartRules();
  }