void DialogueSupervisor::Draw() {
	if (_current_dialogue == NULL) {
		IF_PRINT_WARNING(MAP_DEBUG) << "attempted to draw dialogue window when no dialogue was active" << endl;
		return;
	}

	// TODO: Check if speaker ID is 0 and if so, call Draw function with NULL arguments
	MapSprite* speaker = reinterpret_cast<MapSprite*>(MapMode::CurrentInstance()->GetObjectSupervisor()->GetObject(_current_dialogue->GetCurrentSpeaker()));
	_dialogue_window.Draw(&speaker->GetName(), speaker->GetFacePortrait());
} // void DialogueSupervisor::Draw()
void DialogueSupervisor::AnnounceDialogueUpdate(uint32 dialogue_id) {
	map<uint32, vector<uint32> >::iterator entry = _sprite_references.find(dialogue_id);

	// Note that we don't print a warning if no entry was found, because the case where a dialogue exists
	// but is not referenced by any sprites is a valid one
	if (entry == _sprite_references.end())
		return;

	// Update the dialogue status of all sprites that reference this dialogue
	for (uint32 i = 0; i < entry->second.size(); i++) {
		MapSprite* referee = static_cast<MapSprite*>(MapMode::CurrentInstance()->GetObjectSupervisor()->GetObject(entry->second[i]));
		if (referee == NULL) {
			IF_PRINT_WARNING(MAP_DEBUG) << "map sprite: " << entry->second[i] << " references dialogue: " << dialogue_id << " but sprite object did not exist"<< endl;
		}
		else {
			referee->UpdateDialogueStatus();
		}
	}
}
Beispiel #3
0
void DialogueSupervisor::_BeginLine()
{
    // Starts possible events at new line.
    MapMode *map_mode = MapMode::CurrentInstance();
    std::string line_event = _current_dialogue->GetLineBeginEvent(_line_counter);
    if(!line_event.empty() && !map_mode->GetEventSupervisor()->IsEventActive(line_event)) {
        map_mode->GetEventSupervisor()->StartEvent(line_event);
    }

    // The current speaker id
    uint32 speaker_id = _current_dialogue->GetLineSpeaker(_line_counter);

    // Starts possible emote first.
    std::string emote_event = _current_dialogue->GetLineEmote(_line_counter);
    if(!emote_event.empty() && !_emote_triggered) {
        MapSprite* sprite = (speaker_id > 0) ?
            dynamic_cast<MapSprite *>(map_mode->GetObjectSupervisor()->GetObject(speaker_id))
            : NULL;

        if(sprite) {
            sprite->Emote(emote_event, (vt_map::private_map::ANIM_DIRECTIONS)sprite->GetCurrentAnimationDirection());
            _state = DIALOGUE_STATE_EMOTE;
            _emote_triggered = true;
            return;
        }
    }

    _emote_triggered = true;
    _state = DIALOGUE_STATE_LINE;
    _current_options = dynamic_cast<MapDialogueOptions *>(_current_dialogue->GetLineOptions(_line_counter));

    // Initialize the line timer
    if(_current_dialogue->GetLineDisplayTime(_line_counter) >= 0) {
        _line_timer.Initialize(_current_dialogue->GetLineDisplayTime(_line_counter));
        _line_timer.Run();
    }
    // If the line has no timer specified, set the line time to zero and put the timer in the finished state
    else {
        _line_timer.Initialize(0);
        _line_timer.Finish();
    }

    // Setup the text and graphics for the dialogue window
    _dialogue_window.Clear();
    _dialogue_window.GetDisplayTextBox().SetDisplayText(_current_dialogue->GetLineText(_line_counter));

    MapObject *object = speaker_id > 0 ? map_mode->GetObjectSupervisor()->GetObject(speaker_id) : NULL;
    if(object && object->GetType() != SPRITE_TYPE) {
        IF_PRINT_WARNING(MAP_DEBUG) << "dialogue #" << _current_dialogue->GetDialogueID()
            << " referenced a map object which was not a sprite with id: " << speaker_id << std::endl;
        return;
    }

    if(!object) {
        // Clear the speaker name and potential portrait.
        _dialogue_window.GetNameText().Clear();
        _dialogue_window.SetPortraitImage(NULL);
    } else {
        MapSprite *speaker = dynamic_cast<MapSprite *>(object);
        _dialogue_window.GetNameText().SetText(speaker->GetName());
        _dialogue_window.SetPortraitImage(speaker->GetFacePortrait());
    }

    if(_current_options) {
        for(uint32 i = 0; i < _current_options->GetNumberOptions(); ++i)
            _dialogue_window.GetDisplayOptionBox().AddOption(_current_options->GetOptionText(i));

        _dialogue_window.GetDisplayOptionBox().SetSelection(0);
        _state = DIALOGUE_STATE_OPTION;
    }
}
Beispiel #4
0
/**
 * Compile the track from an input stream.
 * @param in The input stream.
 * @throws TrackCompileExn
 */
void TrackCompiler::Compile(std::istream &in) const
{
	Parcel::ClassicRecordFile outFile;

	// Try to create the output file
	if (!outFile.CreateForWrite(outputFilename, 4, "\x8\rHoverRace track file\n\x1a")) {
		throw TrackCompileExn(boost::str(
			boost::format(_("Unable to create the output file: %s")) %
				Str::PU(outputFilename)));
	}
	log->Info(boost::str(
		boost::format(_("Compiling track (%s)")) %
			Str::PU(outputFilename)));

	// Header.
	if (!outFile.BeginANewRecord()) {
		throw TrackCompileExn(_("Unable to add a header to the output file"));
	}
	else {
		Parcel::ObjStreamPtr archivePtr(outFile.StreamOut());
		Parcel::ObjStream &archive = *archivePtr;
		CreateHeader(in, archive);
	}
	in.clear();
	in.seekg(0, std::ios::beg);

	// The track itself.
	LevelBuilder builder(log);
	if (!outFile.BeginANewRecord()) {
		throw TrackCompileExn(_("Unable to add the track to the output file"));
	}
	else {
		if (!builder.InitFromStream(in)) {
			throw TrackCompileExn(_("Track creation error"));
		}

		Parcel::ObjStreamPtr archivePtr(outFile.StreamOut());
		Parcel::ObjStream &archive = *archivePtr;
		builder.Serialize(archive);
	}
	in.clear();
	in.seekg(0, std::ios::beg);

	// The background image.
	if (!outFile.BeginANewRecord()) {
		throw TrackCompileExn(_("Unable to add a background image record"));
	}
	else {
		Parcel::ObjStreamPtr archivePtr(outFile.StreamOut());
		Parcel::ObjStream &archive = *archivePtr;
		AddBackgroundImage(in, archive);
	}
	in.clear();
	in.seekg(0, std::ios::beg);

	// The map sprite.
	if (!outFile.BeginANewRecord()) {
		throw TrackCompileExn(_("Unable to add a map record"));
	}
	else {
		Parcel::ObjStreamPtr archivePtr(outFile.StreamOut());
		Parcel::ObjStream &archive = *archivePtr;

		MapSprite mapSprite;

		int x0, x1, y0, y1;
		mapSprite.CreateMap(&builder, x0, y0, x1, y1);

		archive << x0;
		archive << x1;
		archive << y0;
		archive << y1;

		mapSprite.Serialize(archive);
	}

	log->Info(_("Compiled track successfully!"));
}
Beispiel #5
0
void MapMode::_UpdateExplore()
{
    // First go to menu mode if the user requested it
    if(_menu_enabled && InputManager->MenuPress()) {
        MenuMode *MM = new MenuMode();
        ModeManager->Push(MM);
        return;
    }

    // Only update the status effect supervisor in Exploration mode
    // and if they are allowed.
    if (_status_effects_enabled)
        _status_effect_supervisor.UpdateEffects();

    // Update the running state of the camera object. Check if the character is running and if so,
    // update the stamina value if the operation is permitted
    _camera->is_running = false;
    if(_camera->moved_position && !_running_disabled && InputManager->CancelState() &&
            (InputManager->UpState() || InputManager->DownState() || InputManager->LeftState() || InputManager->RightState())) {
        if(_unlimited_stamina) {
            _camera->is_running = true;
        } else if(_run_stamina > SystemManager->GetUpdateTime() * 2) {
            _run_stamina -= (SystemManager->GetUpdateTime() * 2);
            _camera->is_running = true;
        } else {
            _run_stamina = 0;
        }
    }
    // Regenerate the stamina at 1/2 the consumption rate
    else if(_run_stamina < 10000) {
        _run_stamina += SystemManager->GetUpdateTime();
        if(_run_stamina > 10000)
            _run_stamina = 10000;
    }

    // If the user requested a confirm event, check if there is a nearby object that the player may interact with
    // Interactions are currently limited to dialogue with sprites and opening of treasures
    if(InputManager->ConfirmPress()) {
        MapObject *obj = _object_supervisor->FindNearestInteractionObject(_camera);

        if(obj != NULL) {
            if(obj->GetType() == PHYSICAL_TYPE) {
                PhysicalObject *phs = reinterpret_cast<PhysicalObject *>(obj);

                if(!phs->GetEventIdWhenTalking().empty()) {
                    _camera->moving = false;
                    _camera->is_running = false;
                    if (!_event_supervisor->IsEventActive(phs->GetEventIdWhenTalking()))
                        _event_supervisor->StartEvent(phs->GetEventIdWhenTalking());
                    return;
                }
            }
            else if(obj->GetType() == SPRITE_TYPE) {
                MapSprite *sp = reinterpret_cast<MapSprite *>(obj);

                if(sp->HasAvailableDialogue()) {
                    _camera->moving = false;
                    _camera->is_running = false;
                    sp->InitiateDialogue();
                    return;
                }
            } else if(obj->GetType() == TREASURE_TYPE) {
                TreasureObject *treasure_object = reinterpret_cast<TreasureObject *>(obj);

                if(!treasure_object->GetTreasure()->IsTaken()) {
                    _camera->moving = false;
                    treasure_object->Open();
                }
            } else if(obj->GetType() == SAVE_TYPE && _save_points_enabled) {
                // Make sure the character will be centered in the save point
                SaveMode *save_mode = new SaveMode(true, obj->GetXPosition(), obj->GetYPosition() - 1.0f);
                ModeManager->Push(save_mode, false, false);
            }
        }
    }

    // Detect movement input from the user
    if(InputManager->UpState() || InputManager->DownState() || InputManager->LeftState() || InputManager->RightState()) {
        _camera->moving = true;
    } else {
        _camera->moving = false;
    }

    // Determine the direction of movement. Priority of movement is given to: up, down, left, right.
    // In the case of diagonal movement, the direction that the sprite should face also needs to be deduced.
    if(_camera->moving == true) {
        if(InputManager->UpState()) {
            if(InputManager->LeftState())
                _camera->SetDirection(MOVING_NORTHWEST);
            else if(InputManager->RightState())
                _camera->SetDirection(MOVING_NORTHEAST);
            else
                _camera->SetDirection(NORTH);
        } else if(InputManager->DownState()) {
            if(InputManager->LeftState())
                _camera->SetDirection(MOVING_SOUTHWEST);
            else if(InputManager->RightState())
                _camera->SetDirection(MOVING_SOUTHEAST);
            else
                _camera->SetDirection(SOUTH);
        } else if(InputManager->LeftState()) {
            _camera->SetDirection(WEST);
        } else if(InputManager->RightState()) {
            _camera->SetDirection(EAST);
        }
    } // if (_camera->moving == true)
} // void MapMode::_UpdateExplore()