use of se.oort.diplicity.apigen.UnitWrapper in project android-diplicity by zond.
the class GameActivity method showMap.
public void showMap() {
hideAllExcept(R.id.map_view);
final Sendable<String> renderer = new Sendable<String>() {
@Override
public void send(String url) {
((MapView) findViewById(R.id.map_view)).load(GameActivity.this, url);
}
};
if (game.Started) {
findViewById(R.id.rewind).setVisibility(View.VISIBLE);
FloatingActionButton firstPhaseButton = (FloatingActionButton) findViewById(R.id.rewind);
if (phaseMeta.PhaseOrdinal < 3) {
firstPhaseButton.setEnabled(false);
firstPhaseButton.setAlpha(0.3f);
} else {
firstPhaseButton.setEnabled(true);
firstPhaseButton.setAlpha(1.0f);
firstPhaseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
firstPhase();
}
});
}
findViewById(R.id.previous).setVisibility(View.VISIBLE);
FloatingActionButton previousPhaseButton = (FloatingActionButton) findViewById(R.id.previous);
if (phaseMeta.PhaseOrdinal < 2) {
previousPhaseButton.setEnabled(false);
previousPhaseButton.setAlpha(0.3f);
} else {
previousPhaseButton.setEnabled(true);
previousPhaseButton.setAlpha(1.0f);
previousPhaseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
prevPhase();
}
});
}
findViewById(R.id.next).setVisibility(View.VISIBLE);
FloatingActionButton nextPhaseButton = (FloatingActionButton) findViewById(R.id.next);
if (game.NewestPhaseMeta != null && game.NewestPhaseMeta.get(0).PhaseOrdinal <= phaseMeta.PhaseOrdinal) {
nextPhaseButton.setEnabled(false);
nextPhaseButton.setAlpha(0.3f);
} else {
nextPhaseButton.setEnabled(true);
nextPhaseButton.setAlpha(1.0f);
nextPhaseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nextPhase();
}
});
}
FloatingActionButton lastPhaseButton = (FloatingActionButton) findViewById(R.id.fast_forward);
if (game.NewestPhaseMeta != null && game.NewestPhaseMeta.get(0).PhaseOrdinal <= phaseMeta.PhaseOrdinal + 1) {
lastPhaseButton.setEnabled(false);
lastPhaseButton.setAlpha(0.3f);
} else {
lastPhaseButton.setEnabled(true);
lastPhaseButton.setAlpha(1.0f);
findViewById(R.id.fast_forward).setVisibility(View.VISIBLE);
lastPhaseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lastPhase();
}
});
}
String url = getBaseURL() + "Game/" + game.ID + "/Phase/" + phaseMeta.PhaseOrdinal + "/Map";
if (getLocalDevelopmentMode() && !getLocalDevelopmentModeFakeID().equals("")) {
url = url + "?fake-id=" + getLocalDevelopmentModeFakeID();
}
renderer.send(url);
if (member != null && !phaseMeta.Resolved) {
handleReq(JoinObservable.when(JoinObservable.from(optionsService.GetOptions(game.ID, phaseMeta.PhaseOrdinal.toString())).and(orderService.ListOrders(game.ID, phaseMeta.PhaseOrdinal.toString())).and(phaseService.PhaseLoad(game.ID, phaseMeta.PhaseOrdinal.toString())).then(new Func3<SingleContainer<Map<String, OptionsService.Option>>, MultiContainer<Order>, SingleContainer<Phase>, Object>() {
@Override
public Object call(SingleContainer<Map<String, OptionsService.Option>> opts, MultiContainer<Order> ords, SingleContainer<Phase> phase) {
options = opts.Properties;
orders.clear();
for (SingleContainer<Order> orderContainer : ords.Properties) {
String srcProvince = orderContainer.Properties.Parts.get(0);
if (srcProvince.indexOf('/') != -1) {
srcProvince = srcProvince.substring(0, srcProvince.indexOf('/'));
}
orders.put(srcProvince, orderContainer.Properties);
}
boolean hasBuildOpts = false;
boolean hasDisbandOpts = false;
for (OptionsService.Option opt : options.values()) {
if (opt.Next.containsKey("Build")) {
hasBuildOpts = true;
}
if (opt.Next.containsKey("Disband")) {
hasDisbandOpts = true;
}
}
int units = 0;
int scs = 0;
for (UnitWrapper unit : phase.Properties.Units) {
if (unit.Unit.Nation.equals(member.Nation)) {
units++;
}
}
for (SC sc : phase.Properties.SCs) {
if (sc.Owner.equals(member.Nation)) {
scs++;
}
}
if (hasBuildOpts && units < scs) {
Toast.makeText(GameActivity.this, getResources().getString(R.string.you_can_build_n_this_phase, getResources().getQuantityString(R.plurals.unit, scs - units, scs - units)), Toast.LENGTH_LONG).show();
} else if (hasDisbandOpts && scs < units) {
Toast.makeText(GameActivity.this, getResources().getString(R.string.you_have_to_disband_n_this_phase, getResources().getQuantityString(R.plurals.unit, units - scs, units - scs)), Toast.LENGTH_LONG).show();
}
return null;
}
})).toObservable(), new Sendable<Object>() {
@Override
public void send(Object o) {
acceptOrders();
}
}, getResources().getString(R.string.loading_state));
}
} else {
findViewById(R.id.rewind).setVisibility(View.GONE);
findViewById(R.id.previous).setVisibility(View.GONE);
findViewById(R.id.next).setVisibility(View.GONE);
findViewById(R.id.fast_forward).setVisibility(View.GONE);
handleReq(variantService.GetStartPhase(game.Variant), new Sendable<SingleContainer<VariantService.Phase>>() {
@Override
public void send(SingleContainer<VariantService.Phase> phaseSingleContainer) {
String url = null;
for (Link link : phaseSingleContainer.Links) {
if (link.Rel.equals("map")) {
url = link.URL;
break;
}
}
if (url != null) {
renderer.send(url);
} else {
App.firebaseCrashReport("No map URL found in variant " + game.Variant + "?");
Toast.makeText(getBaseContext(), R.string.unknown_error, Toast.LENGTH_SHORT).show();
}
}
}, getResources().getString(R.string.loading_start_state));
}
}
Aggregations