Exemple #1
0
static void window_title_editor_mouseup(rct_window * w, rct_widgetindex widgetIndex)
{
    bool commandEditorOpen = (window_find_by_class(WC_TITLE_COMMAND_EDITOR) != nullptr);
    switch (widgetIndex)
    {
    case WIDX_TITLE_EDITOR_CLOSE:
        window_close(w);
        break;

    //////////////////////////////////////////////////////////////////////////////////////////////////////
    // Presets tab
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    case WIDX_TITLE_EDITOR_NEW_BUTTON:
        if (!commandEditorOpen)
        {
            // TODO: This should probably be 'NEW'
            window_text_input_open(w, widgetIndex, STR_TITLE_EDITOR_ACTION_DUPLICATE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, STR_NONE, 0, 64);
        }
        break;
    case WIDX_TITLE_EDITOR_DUPLICATE_BUTTON:
        if (!commandEditorOpen && _editingTitleSequence != nullptr)
        {
            window_text_input_open(w, widgetIndex, STR_TITLE_EDITOR_ACTION_DUPLICATE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, STR_STRING, (uintptr_t)_sequenceName, 64);
        }
        break;
    case WIDX_TITLE_EDITOR_DELETE_BUTTON:
        if (window_title_editor_check_can_edit())
        {
            title_sequence_manager_delete(_selectedTitleSequence);
            window_title_editor_load_sequence(0);
        }
        break;
    case WIDX_TITLE_EDITOR_RENAME_BUTTON:
        if (window_title_editor_check_can_edit() && _editingTitleSequence != nullptr)
        {
            window_text_input_open(w, widgetIndex, STR_TRACK_MANAGE_RENAME, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, STR_STRING, (uintptr_t)_sequenceName, 64);
        }
        break;

    //////////////////////////////////////////////////////////////////////////////////////////////////////
    // Editor tab
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    case WIDX_TITLE_EDITOR_ADD_SAVE:
        if (!_isSequenceReadOnly && !title_is_previewing_sequence() && !commandEditorOpen)
        {
            auto intent = Intent(WC_LOADSAVE);
            intent.putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME);
            intent.putExtra(INTENT_EXTRA_CALLBACK, (void *) window_title_editor_add_park_callback);
            context_open_intent(&intent);
        }
        break;
    case WIDX_TITLE_EDITOR_REMOVE_SAVE:
        if (window_title_editor_check_can_edit())
        {
            if (w->selected_list_item != -1)
            {
                TitleSequenceRemovePark(_editingTitleSequence, w->selected_list_item);
                if (w->selected_list_item >= (sint16)_editingTitleSequence->NumSaves)
                {
                    w->selected_list_item--;
                }
            }
        }
        break;
    case WIDX_TITLE_EDITOR_RENAME_SAVE:
        if (window_title_editor_check_can_edit())
        {
            if (w->selected_list_item != -1)
            {
                window_text_input_open(w, widgetIndex, STR_FILEBROWSER_RENAME_SAVE_TITLE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SAVE, STR_STRING, (uintptr_t)_editingTitleSequence->Saves[w->selected_list_item], 52 - 1);
            }
        }
        break;
    case WIDX_TITLE_EDITOR_LOAD_SAVE:
        if (w->selected_list_item >= 0 && w->selected_list_item < (sint16)_editingTitleSequence->NumSaves)
        {
            auto handle = TitleSequenceGetParkHandle(_editingTitleSequence, w->selected_list_item);
            auto stream = (IStream *)handle->Stream;
            auto hintPath = String::ToStd(handle->HintPath);

            bool isScenario = ParkImporter::ExtensionIsScenario(hintPath);
            auto objectMgr = OpenRCT2::GetContext()->GetObjectManager();
            auto parkImporter = std::unique_ptr<IParkImporter>(ParkImporter::Create(hintPath));
            auto result = parkImporter->LoadFromStream(stream, isScenario);
            objectMgr->LoadObjects(result.RequiredObjects.data(), result.RequiredObjects.size());
            parkImporter->Import();

            if (isScenario)
                scenario_begin();
            else
                game_load_init();

            TitleSequenceCloseParkHandle(handle);
            window_title_editor_open(WINDOW_TITLE_EDITOR_TAB_SAVES);
        }
        break;

    //////////////////////////////////////////////////////////////////////////////////////////////////////
    // Commands tab
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    case WIDX_TITLE_EDITOR_INSERT:
        if (window_title_editor_check_can_edit())
        {
            if (w->selected_list_item != -1)
                window_title_command_editor_open(_editingTitleSequence, w->selected_list_item + 1, true);
            else
                window_title_command_editor_open(_editingTitleSequence, (sint32)_editingTitleSequence->NumCommands, true);
        }
        break;
    case WIDX_TITLE_EDITOR_EDIT:
        if (window_title_editor_check_can_edit())
        {
            if (w->selected_list_item != -1 && w->selected_list_item < (sint16)_editingTitleSequence->NumCommands)
            {
                window_title_command_editor_open(_editingTitleSequence, w->selected_list_item, false);
            }
        }
        break;
    case WIDX_TITLE_EDITOR_DELETE:
        if (window_title_editor_check_can_edit())
        {
            if (w->selected_list_item != -1 && w->selected_list_item < (sint16)_editingTitleSequence->NumCommands)
            {
                for (sint32 i = w->selected_list_item; i < (sint16)_editingTitleSequence->NumCommands - 1; i++)
                {
                    _editingTitleSequence->Commands[i] = _editingTitleSequence->Commands[i + 1];
                }
                _editingTitleSequence->NumCommands--;
                if (w->selected_list_item >= (sint16)_editingTitleSequence->NumCommands)
                {
                    w->selected_list_item--;
                }
                TitleSequenceSave(_editingTitleSequence);
            }
        }
        break;
    case WIDX_TITLE_EDITOR_SKIP_TO:
    {
        sint32 position = w->selected_list_item;
        if (title_is_previewing_sequence() && position != -1 && position < (sint32)_editingTitleSequence->NumCommands)
        {
            ITitleSequencePlayer * player = window_title_editor_get_player();
            title_sequence_player_seek(player, position);
            title_sequence_player_update(player);
        }
        break;
    }
    case WIDX_TITLE_EDITOR_MOVE_DOWN:
        if (window_title_editor_check_can_edit())
        {
            if (w->selected_list_item != -1 && w->selected_list_item < (sint16)_editingTitleSequence->NumCommands - 1)
            {
                TitleCommand * a = &_editingTitleSequence->Commands[w->selected_list_item];
                TitleCommand * b = &_editingTitleSequence->Commands[w->selected_list_item + 1];
                TitleCommand tmp = *a;
                *a = *b;
                *b = tmp;
                w->selected_list_item++;
                TitleSequenceSave(_editingTitleSequence);
            }
        }
        break;
    case WIDX_TITLE_EDITOR_MOVE_UP:
        if (window_title_editor_check_can_edit())
        {
            if (w->selected_list_item > 0 && w->selected_list_item < (sint16)_editingTitleSequence->NumCommands)
            {
                TitleCommand * a = &_editingTitleSequence->Commands[w->selected_list_item - 1];
                TitleCommand * b = &_editingTitleSequence->Commands[w->selected_list_item];
                TitleCommand tmp = *b;
                *b = *a;
                *a = tmp;
                w->selected_list_item--;
                TitleSequenceSave(_editingTitleSequence);
            }
        }
        break;
    case WIDX_TITLE_EDITOR_REPLAY:
        if (title_is_previewing_sequence())
        {
            ITitleSequencePlayer * player = window_title_editor_get_player();
            title_sequence_player_reset(player);
            title_sequence_player_update(player);
        }
        break;
    case WIDX_TITLE_EDITOR_STOP:
        if (title_is_previewing_sequence())
        {
            title_stop_previewing_sequence();
        }
        break;
    case WIDX_TITLE_EDITOR_PLAY:
        if (!title_is_previewing_sequence() || _selectedTitleSequence != title_get_current_sequence())
        {
            if (!title_preview_sequence(_selectedTitleSequence))
            {
                context_show_error(STR_ERR_FAILED_TO_LOAD_TITLE_SEQUENCE, STR_NONE);
            }
            else if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO))
            {
                gPreviewingTitleSequenceInGame = true;
            }
        }
        break;
    case WIDX_TITLE_EDITOR_SKIP:
        if (title_is_previewing_sequence())
        {
            ITitleSequencePlayer * player = window_title_editor_get_player();
            sint32 position = title_sequence_player_get_current_position(player) + 1;
            if (position >= (sint32)_editingTitleSequence->NumCommands)
            {
                position = 0;
            }
            title_sequence_player_seek(player, position);
            title_sequence_player_update(player);
        }
        break;
    }
}
Exemple #2
0
static void window_title_editor_mouseup(rct_window *w, sint32 widgetIndex)
{
	bool commandEditorOpen = (window_find_by_class(WC_TITLE_COMMAND_EDITOR) != NULL);
	switch (widgetIndex) {
	case WIDX_TITLE_EDITOR_CLOSE:
		window_close(w);
		break;

	//////////////////////////////////////////////////////////////////////////////////////////////////////
	// Presets tab
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	case WIDX_TITLE_EDITOR_NEW_BUTTON:
		if (!commandEditorOpen) {
			// TODO: This should probably be 'NEW'
			window_text_input_open(w, widgetIndex, STR_TITLE_EDITOR_ACTION_DUPLICATE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, STR_NONE, 0, 64);
		}
		break;
	case WIDX_TITLE_EDITOR_DUPLICATE_BUTTON:
		if (!commandEditorOpen && _editingTitleSequence != NULL) {
			window_text_input_open(w, widgetIndex, STR_TITLE_EDITOR_ACTION_DUPLICATE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, STR_STRING, (uintptr_t)_editingTitleSequence->Name, 64);
		}
		break;
	case WIDX_TITLE_EDITOR_DELETE_BUTTON:
		if (window_title_editor_check_can_edit()) {
			title_sequence_manager_delete(_selectedTitleSequence);
			window_title_editor_load_sequence(0);
		}
		break;
	case WIDX_TITLE_EDITOR_RENAME_SAVE_BUTTON:
		if (window_title_editor_check_can_edit() && _editingTitleSequence != NULL) {
			window_text_input_open(w, widgetIndex, STR_TRACK_MANAGE_RENAME, STR_TITLE_EDITOR_ENTER_NAME_FOR_SEQUENCE, STR_STRING, (uintptr_t)_editingTitleSequence->Name, 64);
		}
		break;

	//////////////////////////////////////////////////////////////////////////////////////////////////////
	// Editor tab
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	case WIDX_TITLE_EDITOR_ADD_SAVE:
		if (!_isSequenceReadOnly && !_isSequencePlaying && !commandEditorOpen) {
			window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME, NULL);
			gLoadSaveCallback = window_title_editor_add_park_callback;
		}
		break;
	case WIDX_TITLE_EDITOR_REMOVE_SAVE:
		if (window_title_editor_check_can_edit()) {
			if (w->selected_list_item != -1) {
				TitleSequenceRemovePark(_editingTitleSequence, w->selected_list_item);
				if (w->selected_list_item >= (sint16)_editingTitleSequence->NumSaves) {
					w->selected_list_item--;
				}
			}
		}
		break;
	case WIDX_TITLE_EDITOR_RENAME_SAVE:
		if (window_title_editor_check_can_edit()) {
			if (w->selected_list_item != -1) {
				window_text_input_open(w, widgetIndex, STR_FILEBROWSER_RENAME_SAVE_TITLE, STR_TITLE_EDITOR_ENTER_NAME_FOR_SAVE, STR_STRING, (uintptr_t)_editingTitleSequence->Saves[w->selected_list_item], 52 - 1);
			}
		}
		break;
	case WIDX_TITLE_EDITOR_LOAD_SAVE:
		if (w->selected_list_item >= 0 && w->selected_list_item < (sint16)_editingTitleSequence->NumSaves) {
			TitleSequenceParkHandle * handle = TitleSequenceGetParkHandle(_editingTitleSequence, w->selected_list_item);
			if (handle->IsScenario) {
				scenario_load_rw(handle->RWOps);
				scenario_begin();
			} else {
				game_load_sv6(handle->RWOps);
				game_load_init();
			}
			TitleSequenceCloseParkHandle(handle);
			window_title_editor_open(WINDOW_TITLE_EDITOR_TAB_SAVES);
		}
		break;

	//////////////////////////////////////////////////////////////////////////////////////////////////////
	// Commands tab
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	case WIDX_TITLE_EDITOR_INSERT:
		if (window_title_editor_check_can_edit()) {
			if (w->selected_list_item != -1) {
				window_title_command_editor_open(_editingTitleSequence, w->selected_list_item + 1, true);
			} else {
				window_title_command_editor_open(_editingTitleSequence, (sint32)_editingTitleSequence->NumCommands, true);
			}
		}
		break;
	case WIDX_TITLE_EDITOR_EDIT:
		if (window_title_editor_check_can_edit()) {
			if (w->selected_list_item != -1 && w->selected_list_item < (sint16)_editingTitleSequence->NumCommands) {
				window_title_command_editor_open(_editingTitleSequence, w->selected_list_item, false);
			}
		}
		break;
	case WIDX_TITLE_EDITOR_DELETE:
		if (window_title_editor_check_can_edit()) {
			if (w->selected_list_item != -1 && w->selected_list_item < (sint16)_editingTitleSequence->NumCommands) {
				for (sint32 i = w->selected_list_item; i < (sint16)_editingTitleSequence->NumCommands - 1; i++) {
					_editingTitleSequence->Commands[i] = _editingTitleSequence->Commands[i + 1];
				}
				_editingTitleSequence->NumCommands--;
				if (w->selected_list_item >= (sint16)_editingTitleSequence->NumCommands) {
					w->selected_list_item--;
				}
				TileSequenceSave(_editingTitleSequence);
			}
		}
		break;
	case WIDX_TITLE_EDITOR_SKIP_TO:
	{
		sint32 position = w->selected_list_item;
		if (_isSequencePlaying && position != -1 && position < (sint32)_editingTitleSequence->NumCommands) {
			ITitleSequencePlayer * player = window_title_editor_get_player();
			title_sequence_player_seek(player, position);
			title_sequence_player_update(player);
		}
		break;
	}
	case WIDX_TITLE_EDITOR_MOVE_DOWN:
		if (window_title_editor_check_can_edit()) {
			if (w->selected_list_item != -1 && w->selected_list_item < (sint16)_editingTitleSequence->NumCommands - 1) {
				TitleCommand * a = &_editingTitleSequence->Commands[w->selected_list_item];
				TitleCommand * b = &_editingTitleSequence->Commands[w->selected_list_item + 1];
				TitleCommand tmp = *a;
				*a = *b;
				*b = tmp;
				w->selected_list_item++;
				TileSequenceSave(_editingTitleSequence);
			}
		}
		break;
	case WIDX_TITLE_EDITOR_MOVE_UP:
		if (window_title_editor_check_can_edit()) {
			if (w->selected_list_item > 0 && w->selected_list_item < (sint16)_editingTitleSequence->NumCommands) {
				TitleCommand * a = &_editingTitleSequence->Commands[w->selected_list_item - 1];
				TitleCommand * b = &_editingTitleSequence->Commands[w->selected_list_item];
				TitleCommand tmp = *b;
				*b = *a;
				*a = tmp;
				w->selected_list_item--;
				TileSequenceSave(_editingTitleSequence);
			}
		}
		break;
	case WIDX_TITLE_EDITOR_REPLAY:
		if (_isSequencePlaying) {
			ITitleSequencePlayer * player = window_title_editor_get_player();
			title_sequence_player_reset(player);
			title_sequence_player_update(player);
		}
		break;
	case WIDX_TITLE_EDITOR_STOP:
		if (_isSequencePlaying) {
			gTitleCurrentSequence = 0;
			_isSequencePlaying = false;
		}
		break;
	case WIDX_TITLE_EDITOR_PLAY:
		if (!_isSequencePlaying && (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) {
			gTitleCurrentSequence = (uint16)_selectedTitleSequence;
			_isSequencePlaying = true;
		}
		break;
	case WIDX_TITLE_EDITOR_SKIP:
		if (_isSequencePlaying) {
			ITitleSequencePlayer * player = window_title_editor_get_player();
			sint32 position = title_sequence_player_get_current_position(player) + 1;
			if (position >= (sint32)_editingTitleSequence->NumCommands) {
				position = 0;
			}
			title_sequence_player_seek(player, position);
			title_sequence_player_update(player);
		}
		break;
	}
}