Example #1
0
	private void fireItemConsumedEvent() {
		ItemConsumedEvent event = new ItemConsumedEvent(readyToDraggableItem);
		playerServices.getEventBus().fireEventFromSource(event, this);

		if (isCorrect()) {
			sendEventCode(model.getEventCode(ImageGapModule.EVENT_CORRECT));
		} else {
			sendEventCode(model.getEventCode(ImageGapModule.EVENT_WRONG));
		}
	}
Example #2
0
	@Override
	public void reset() {
		readyToDraggableItem = null;
		consumedItem = null;
		view.setImageUrl("");
		view.setDisabled(model.isDisabled());

		if (model.isVisible()) {
			view.show();
		} else {
			view.hide();
		}
	}
Example #3
0
	private void hideAnswers() {
		if(!model.isActivity() && isConnectedWithMath){
			this.isShowAnswersActive = false;
			view.setDisabled(false);
		}
		
		if ((!model.isActivity() || !this.isShowAnswersActive)) { return; }

		this.isShowAnswersActive = false;

		reset();
		view.resetStyles();
		view.setDisabled(false);
		setState(currentState);
		readyToDraggableItem = userReadyToDraggableItem;
		userReadyToDraggableItem = null;
	}
Example #4
0
	private void removeItem() {
		if (consumedItem != null) {
			view.setImageUrl("");
			fireItemReturnedEvent(consumedItem);
			consumedItem = null;
			ValueChangedEvent valueEvent = new ValueChangedEvent(model.getId(), "", "", "0");
			playerServices.getEventBus().fireEvent(valueEvent);
		}
	}
Example #5
0
	private void insertItem() {
		if (readyToDraggableItem != null) {
			view.setImageUrl(readyToDraggableItem.getValue());
			consumedItem = readyToDraggableItem;
			fireItemConsumedEvent();
			String score = Integer.toString(getScore());
			ValueChangedEvent valueEvent = new ValueChangedEvent(model.getId(), "", consumedItem.getId(), score);
			playerServices.getEventBus().fireEvent(valueEvent);
			view.makeDraggable(this);
		}
	}
Example #6
0
	public boolean isCorrect() {
		if (consumedItem != null) {
			String[] answers = model.getAnswerId().split(";");
			for (int i = 0; i < answers.length; i++) {
				String answer = answers[i];
				if (consumedItem.getId().compareTo(answer) == 0) {
					return true;
				}
			}
		}

		return false;
	}
Example #7
0
	@Override
	public void addView(IModuleView display) {
		if (display instanceof IDisplay) {
			view = (IDisplay) display;
			view.addListener(new IViewListener() {
				@Override
				public void onClicked() {
					viewClicked();
				}
			});
			view.makeDroppable(this);
			view.setDisabled(model.isDisabled());
		}
	}
Example #8
0
	private void showAnswers() {
		if(!model.isActivity() && isConnectedWithMath){
			this.isShowAnswersActive = true;
			if(!isSetGapAnswers){
				view.resetStyles();
			}
			view.setDisabled(true);
			view.removeClass("ui-state-disabled");
		}
		
		if (!model.isActivity() || this.isShowAnswersActive) { return; }

		this.isShowAnswersActive = true;
		userReadyToDraggableItem = readyToDraggableItem;

		showAnswersModeDisabled = view.getDisabled();
		this.currentState = getState();
		view.resetStyles();
		view.setDisabled(true);
		setCorrectImage();
		view.showCorrectAnswers();
		view.removeClass("ui-state-disabled");
	}
Example #9
0
	@Override
	public void setShowErrorsMode() {
		if (this.isShowAnswersActive) hideAnswers();
		isShowErrorsMode = true;
		workModeDisabled = view.getDisabled();
		view.setDisabled(true);
		if (model.isActivity()) {
			if (getScore() > 0) {
				view.showAsCorrect();
			} else {
				view.showAsError();
			}
		}
		view.removeClass("ui-state-disabled");
	}
Example #10
0
	public ImageGapPresenter(ImageGapModule model, IPlayerServices services) {
		this.model = model;
		this.playerServices = services;
		isVisible = model.isVisible();
		connectHandlers();
	}
Example #11
0
	private boolean isActivity() {
		return model.isActivity();
	}
Example #12
0
	@Override
	public String getName() {
		return model.getId();
	}
Example #13
0
	@Override
	public int getScore() {
		return model.isActivity() && isCorrect() ? 1 : 0;
	}
Example #14
0
	@Override
	public int getMaxScore() {
		return model.isActivity() ? 1 : 0;
	}
Example #15
0
	@Override
	public int getErrorCount() {
		return consumedItem != null && getScore() == 0 && model.isActivity() ? 1 : 0;
	}
Example #16
0
	@Override
	public String getSerialId() {
		return model.getId();
	}
Example #17
0
	private void setCorrectImage() {
		String[] answers = model.getAnswerId().split(";");
		ImageSourcePresenter igp = (ImageSourcePresenter) playerServices.getModule(answers[0]);
		view.setImageUrl(igp.getImageUrl());
	}
Example #18
0
	private void fireItemReturnedEvent(DraggableItem previouslyConsumedItem) {
		ItemReturnedEvent event = new ItemReturnedEvent(previouslyConsumedItem);
		playerServices.getEventBus().fireEvent(event);

		sendEventCode(model.getEventCode(ImageGapModule.EVENT_EMPTY));
	}