diff --git a/Dialog/DoorConfigDialog.cpp b/Dialog/DoorConfigDialog.cpp index b5af798f..2b28f8d9 100644 --- a/Dialog/DoorConfigDialog.cpp +++ b/Dialog/DoorConfigDialog.cpp @@ -245,18 +245,20 @@ void DoorConfigDialog::RenderGraphicsView_Preview() int Y_av = (door_CurY1 + door_CurY2) / 2; float X_av_rate = static_cast(X_av) / static_cast(tmpCurrentRoom->GetWidth()); float Y_av_rate = static_cast(Y_av) / static_cast(tmpCurrentRoom->GetHeight()); - int V_all = ui->GraphicsView_Preview->verticalScrollBar()->pageStep() + - ui->GraphicsView_Preview->verticalScrollBar()->maximum(); - int H_all = ui->GraphicsView_Preview->horizontalScrollBar()->pageStep() + - ui->GraphicsView_Preview->horizontalScrollBar()->maximum(); + float Heightrate_L1_over_L0 = qMin(1.0f, static_cast(tmpCurrentRoom->GetHeight()) / static_cast(tmpCurrentRoom->GetLayer0Height())); + float Widthrate_L1_over_L0 = qMin(1.0f, static_cast(tmpCurrentRoom->GetWidth()) / static_cast(tmpCurrentRoom->GetLayer0Width())); + int V_all = Heightrate_L1_over_L0 * (ui->GraphicsView_Preview->verticalScrollBar()->pageStep() + + ui->GraphicsView_Preview->verticalScrollBar()->maximum()); + int H_all = Widthrate_L1_over_L0 * (ui->GraphicsView_Preview->horizontalScrollBar()->pageStep() + + ui->GraphicsView_Preview->horizontalScrollBar()->maximum()); int X_val = static_cast(H_all * X_av_rate); int Y_val = static_cast(V_all * Y_av_rate); ui->GraphicsView_Preview->verticalScrollBar()->setSliderPosition( qMin(qMax(Y_val, 1) - ui->GraphicsView_Preview->verticalScrollBar()->pageStep() / 2, - ui->GraphicsView_Preview->verticalScrollBar()->maximum())); + (int)(Heightrate_L1_over_L0 * (float)ui->GraphicsView_Preview->verticalScrollBar()->maximum()))); ui->GraphicsView_Preview->horizontalScrollBar()->setSliderPosition( qMin(qMax(X_val, 1) - ui->GraphicsView_Preview->horizontalScrollBar()->pageStep() / 2, - ui->GraphicsView_Preview->horizontalScrollBar()->maximum())); + (int)(Widthrate_L1_over_L0 * (float)ui->GraphicsView_Preview->horizontalScrollBar()->maximum()))); } /// @@ -282,6 +284,15 @@ void DoorConfigDialog::RenderGraphicsView_DestinationDoor(int doorIDinRoom) ui->GraphicsView_DestinationDoor->setScene(scene); ui->GraphicsView_DestinationDoor->setAlignment(Qt::AlignTop | Qt::AlignLeft); + if(tmpDestinationRoom->GetRoomID() == tmpCurrentRoom->GetRoomID()) + { + tmpDestinationRoom->GetDoor(DoorID)->SetDoorPlace(static_cast(ui->SpinBox_DoorX->value()), + static_cast((ui->SpinBox_DoorX->value() + ui->SpinBox_DoorWidth->value() - 1)), + static_cast(ui->SpinBox_DoorY->value()), + static_cast((ui->SpinBox_DoorY->value() + ui->SpinBox_DoorHeight->value() - 1))); + UpdateDoorLayerGraphicsView_DestinationDoor(); + } + // Set scrollbars LevelComponents::Door *tmpdoor = tmpDestinationRoom->GetDoor(doorIDinRoom); door_DesX1 = tmpdoor->GetX1(); @@ -292,18 +303,20 @@ void DoorConfigDialog::RenderGraphicsView_DestinationDoor(int doorIDinRoom) int Y_av = (door_DesY1 + door_DesY2) / 2; float X_av_rate = static_cast(X_av) / static_cast(tmpDestinationRoom->GetWidth()); float Y_av_rate = static_cast(Y_av) / static_cast(tmpDestinationRoom->GetHeight()); - int V_all = ui->GraphicsView_DestinationDoor->verticalScrollBar()->pageStep() + - ui->GraphicsView_DestinationDoor->verticalScrollBar()->maximum(); - int H_all = ui->GraphicsView_DestinationDoor->horizontalScrollBar()->pageStep() + - ui->GraphicsView_DestinationDoor->horizontalScrollBar()->maximum(); + float Heightrate_L1_over_L0 = qMin(1.0f, static_cast(tmpDestinationRoom->GetHeight()) / static_cast(tmpDestinationRoom->GetLayer0Height())); + float Widthrate_L1_over_L0 = qMin(1.0f, static_cast(tmpDestinationRoom->GetWidth()) / static_cast(tmpDestinationRoom->GetLayer0Width())); + int V_all = Heightrate_L1_over_L0 * (ui->GraphicsView_DestinationDoor->verticalScrollBar()->pageStep() + + ui->GraphicsView_DestinationDoor->verticalScrollBar()->maximum()); + int H_all = Widthrate_L1_over_L0 * (ui->GraphicsView_DestinationDoor->horizontalScrollBar()->pageStep() + + ui->GraphicsView_DestinationDoor->horizontalScrollBar()->maximum()); int X_val = static_cast(H_all * X_av_rate); int Y_val = static_cast(V_all * Y_av_rate); ui->GraphicsView_DestinationDoor->verticalScrollBar()->setSliderPosition( qMin(qMax(Y_val, 1) - ui->GraphicsView_DestinationDoor->verticalScrollBar()->pageStep() / 2, - ui->GraphicsView_DestinationDoor->verticalScrollBar()->maximum())); + (int)(Heightrate_L1_over_L0 * (float)ui->GraphicsView_DestinationDoor->verticalScrollBar()->maximum()))); ui->GraphicsView_DestinationDoor->horizontalScrollBar()->setSliderPosition( qMin(qMax(X_val, 1) - ui->GraphicsView_DestinationDoor->horizontalScrollBar()->pageStep() / 2, - ui->GraphicsView_DestinationDoor->horizontalScrollBar()->maximum())); + (int)(Widthrate_L1_over_L0 * (float)ui->GraphicsView_DestinationDoor->horizontalScrollBar()->maximum()))); } /// diff --git a/Dialog/RoomConfigDialog.cpp b/Dialog/RoomConfigDialog.cpp index 0177d624..dd590fca 100644 --- a/Dialog/RoomConfigDialog.cpp +++ b/Dialog/RoomConfigDialog.cpp @@ -7,11 +7,10 @@ constexpr const char *RoomConfigDialog::TilesetNamesSetData[0x5C]; constexpr const char *RoomConfigDialog::LayerPrioritySetData[3]; constexpr const char *RoomConfigDialog::AlphaBlendAttrsSetData[12]; -constexpr const char *RoomConfigDialog::Layer0MappingTypeParamSetData[2]; constexpr unsigned int RoomConfigDialog::BGLayerdataPtrsData[166]; // static variables used by RoomConfigDialog -static QStringList TilesetNamesSet, LayerPrioritySet, AlphaBlendAttrsSet, Layer0MappingTypeParamSet; +static QStringList TilesetNamesSet, LayerPrioritySet, AlphaBlendAttrsSet; static std::vector BGLayerdataPtrs[0x5C]; /// @@ -29,32 +28,23 @@ RoomConfigDialog::RoomConfigDialog(QWidget *parent, DialogParams::RoomConfigPara ui->ComboBox_TilesetID->addItems(TilesetNamesSet); ui->ComboBox_LayerPriority->addItems(LayerPrioritySet); ui->ComboBox_AlphaBlendAttribute->addItems(AlphaBlendAttrsSet); - ui->ComboBox_Layer0MappingType->addItems(Layer0MappingTypeParamSet); ui->ComboBox_TilesetID->setCurrentIndex(CurrentRoomParams->CurrentTilesetIndex); - ui->CheckBox_Layer0Enable->setChecked(CurrentRoomParams->Layer0Enable); ui->CheckBox_Layer0Alpha->setChecked(CurrentRoomParams->Layer0Alpha); int LayerPriorityID = CurrentRoomParams->LayerPriorityAndAlphaAttr & 3; ui->ComboBox_LayerPriority->setCurrentIndex((LayerPriorityID < 2) ? LayerPriorityID : (LayerPriorityID - 1)); ui->ComboBox_AlphaBlendAttribute->setCurrentIndex((CurrentRoomParams->LayerPriorityAndAlphaAttr - 4) >> 2); // == (LayerPriorityAndAlphaAttr - 8) >> 2 + 1 - if (CurrentRoomParams->Layer0Enable) { - ui->ComboBox_Layer0MappingType->setCurrentIndex((((CurrentRoomParams->Layer0MappingTypeParam) & 0x30) >> 4) - - 1); - if((CurrentRoomParams->Layer0MappingTypeParam & 0x10) == 0x10) - { - ui->spinBox_Layer0Width->setValue(CurrentRoomParams->Layer0Width); - ui->spinBox_Layer0Height->setValue(CurrentRoomParams->Layer0Height); - } else { - ui->spinBox_Layer0Width->setEnabled(false); - ui->spinBox_Layer0Height->setEnabled(false); - } - } - ui->CheckBox_Layer0AutoScroll->setChecked(CurrentRoomParams->Layer0MappingTypeParam == 0x22); + ui->spinBox_Layer0MappingType->setValue(CurrentRoomParams->Layer0MappingTypeParam); ui->ComboBox_Layer0Picker->setEnabled(CurrentRoomParams->Layer0MappingTypeParam >= 0x20); + ui->spinBox_Layer0Width->setValue(CurrentRoomParams->Layer0Width); + ui->spinBox_Layer0Height->setValue(CurrentRoomParams->Layer0Height); ui->SpinBox_RoomWidth->setValue(CurrentRoomParams->RoomWidth); ui->SpinBox_RoomHeight->setValue(CurrentRoomParams->RoomHeight); ui->CheckBox_Layer2Enable->setChecked(CurrentRoomParams->Layer2Enable); ui->CheckBox_BGLayerEnable->setChecked(CurrentRoomParams->BackgroundLayerEnable); - ui->CheckBox_BGLayerAutoScroll->setChecked(CurrentRoomParams->BackgroundLayerAutoScrollEnable); + ui->spinBox_BGLayerScrollingFlag->setValue(CurrentRoomParams->BGLayerScrollFlag); + ui->spinBox_LayerGfxEffect01->setValue(CurrentRoomParams->LayerGFXEffect01); + ui->spinBox_LayerGfxEffect02->setValue(CurrentRoomParams->LayerGFXEffect02); + ui->spinBox_BgmVolume->setValue(CurrentRoomParams->BGMVolume); // Initialize the selection for the BG selection combobox bool CurrentBGSelectionAvailable = false; @@ -78,7 +68,7 @@ RoomConfigDialog::RoomConfigDialog(QWidget *parent, DialogParams::RoomConfigPara ui->graphicsView->infoLabel = ui->graphicViewDetailsLabel; int _tilesetPtr = WL4Constants::TilesetDataTable + CurrentRoomParams->CurrentTilesetIndex * 36; currentTileset = new LevelComponents::Tileset(_tilesetPtr, CurrentRoomParams->CurrentTilesetIndex); - int L0ptr = (ui->ComboBox_Layer0MappingType->currentIndex() == 1) ? CurrentRoomParams->Layer0DataPtr : 0; + int L0ptr = ((ui->spinBox_Layer0MappingType->value() & 0x30) == LevelComponents::LayerTile8x8) ? CurrentRoomParams->Layer0DataPtr : 0; ; ui->graphicsView->UpdateGraphicsItems(currentTileset, CurrentRoomParams->BackgroundLayerDataPtr, L0ptr); @@ -102,26 +92,15 @@ DialogParams::RoomConfigParams RoomConfigDialog::GetConfigParams() // Get all the Room Configuration data configParams.CurrentTilesetIndex = ui->ComboBox_TilesetID->currentIndex(); - configParams.Layer0Enable = ui->CheckBox_Layer0Enable->isChecked(); configParams.Layer0Alpha = ui->CheckBox_Layer0Alpha->isChecked(); - if (configParams.Layer0Enable) + configParams.Layer0MappingTypeParam = ui->spinBox_Layer0MappingType->value(); + if((configParams.Layer0MappingTypeParam & 0x10) == LevelComponents::LayerMap16) { - if (ui->ComboBox_Layer0MappingType->isEnabled()) // only happens in a special Toxic landfill Tileset - { - configParams.Layer0MappingTypeParam = (ui->ComboBox_Layer0MappingType->currentIndex() + 1) << 4; - } - else // normal cases - { - configParams.Layer0MappingTypeParam = 0x10; - } - if(configParams.Layer0MappingTypeParam == 0x10) { - configParams.Layer0Width = ui->spinBox_Layer0Width->value(); - configParams.Layer0Height = ui->spinBox_Layer0Height->value(); - } - if (ui->CheckBox_Layer0AutoScroll->isChecked()) - configParams.Layer0MappingTypeParam = 22; - configParams.Layer0DataPtr = ui->ComboBox_Layer0Picker->currentText().toUInt(nullptr, 16); + configParams.Layer0Width = ui->spinBox_Layer0Width->value(); + configParams.Layer0Height = ui->spinBox_Layer0Height->value(); } + configParams.Layer0DataPtr = ui->ComboBox_Layer0Picker->currentText().toUInt(nullptr, 16); + configParams.Layer2Enable = ui->CheckBox_Layer2Enable->isChecked(); switch (ui->ComboBox_LayerPriority->currentIndex()) { @@ -137,7 +116,7 @@ DialogParams::RoomConfigParams RoomConfigDialog::GetConfigParams() } configParams.LayerPriorityAndAlphaAttr += (ui->ComboBox_AlphaBlendAttribute->currentIndex() << 2); configParams.BackgroundLayerEnable = ui->CheckBox_BGLayerEnable->isChecked(); - configParams.BackgroundLayerAutoScrollEnable = ui->CheckBox_BGLayerAutoScroll->isChecked(); + configParams.BGLayerScrollFlag = ui->spinBox_BGLayerScrollingFlag->value(); if (configParams.BackgroundLayerEnable) { configParams.BackgroundLayerDataPtr = ui->ComboBox_BGLayerPicker->currentText().toUInt(nullptr, 16); @@ -148,6 +127,9 @@ DialogParams::RoomConfigParams RoomConfigDialog::GetConfigParams() } configParams.RoomHeight = ui->SpinBox_RoomHeight->value(); configParams.RoomWidth = ui->SpinBox_RoomWidth->value(); + configParams.LayerGFXEffect01 = ui->spinBox_LayerGfxEffect01->value(); + configParams.LayerGFXEffect02 = ui->spinBox_LayerGfxEffect02->value(); + configParams.BGMVolume = ui->spinBox_BgmVolume->value(); return configParams; } @@ -175,12 +157,6 @@ void RoomConfigDialog::StaticComboBoxesInitialization() AlphaBlendAttrsSet << AlphaBlendAttrsSetData[i]; } - // Initialize the selections for the types of layer mapping for layer 0 - for (unsigned int i = 0; i < sizeof(Layer0MappingTypeParamSetData) / sizeof(Layer0MappingTypeParamSetData[0]); ++i) - { - Layer0MappingTypeParamSet << Layer0MappingTypeParamSetData[i]; - } - // Initialize the selections for the tilesets's available BGs for (unsigned int i = 0, idx = 0; idx < sizeof(BGLayerdataPtrsData) / sizeof(BGLayerdataPtrsData[0]); ++i) { @@ -194,42 +170,6 @@ void RoomConfigDialog::StaticComboBoxesInitialization() } } -/// -/// Slot function for CheckBox_Layer0Enable_stateChanged. -/// -void RoomConfigDialog::on_CheckBox_Layer0Enable_stateChanged(int state) -{ - if (state == Qt::Checked) - { - ui->CheckBox_Layer0Alpha->setEnabled(true); - // Extra UI changes for Toxic Landfill dust Layer0 - if (ui->ComboBox_TilesetID->currentIndex() == 0x21) - ui->ComboBox_Layer0MappingType->setEnabled(true); - // CurrentRoomParams->Layer0MappingTypeParam & 0x20) != 0x20 - if(ui->ComboBox_Layer0MappingType->currentIndex() == 0) // Map16 - { - ui->spinBox_Layer0Width->setEnabled(true); - ui->spinBox_Layer0Height->setEnabled(true); - ui->spinBox_Layer0Width->setValue(ui->SpinBox_RoomWidth->value()); - ui->spinBox_Layer0Height->setValue(ui->SpinBox_RoomHeight->value()); - } else { - ui->spinBox_Layer0Width->setEnabled(false); - ui->spinBox_Layer0Height->setEnabled(false); - } - } - else - { - DontEnableLayerSizeSpinboxes = true; - ui->spinBox_Layer0Width->setEnabled(false); - ui->spinBox_Layer0Height->setEnabled(false); - ui->CheckBox_Layer0Alpha->setChecked(false); - ui->CheckBox_Layer0Alpha->setEnabled(false); - ui->ComboBox_Layer0MappingType->setCurrentIndex(0); - ui->ComboBox_Layer0MappingType->setEnabled(false); - DontEnableLayerSizeSpinboxes = false; - } -} - /// /// Slot function for CheckBox_Layer0Alpha_stateChanged. /// @@ -242,40 +182,6 @@ void RoomConfigDialog::on_CheckBox_Layer0Alpha_stateChanged(int state) } } -/// -/// Slot function for ComboBox_Layer0MappingType_currentIndexChanged. -/// -void RoomConfigDialog::on_ComboBox_Layer0MappingType_currentIndexChanged(int index) -{ - (void) index; - if (ComboBoxInitialized) - { - if(DontEnableLayerSizeSpinboxes) return; - - int BGptr = ui->ComboBox_BGLayerPicker->currentText().toUInt(nullptr, 16); - int L0ptr = ui->ComboBox_Layer0Picker->currentText().toUInt(nullptr, 16); - if ((ui->ComboBox_Layer0MappingType->currentIndex() == 0)) // Tile16 - { - ui->spinBox_Layer0Width->setEnabled(true); - ui->spinBox_Layer0Height->setEnabled(true); - ui->spinBox_Layer0Width->setValue(ui->SpinBox_RoomWidth->value()); - ui->spinBox_Layer0Height->setValue(ui->SpinBox_RoomHeight->value()); - ui->CheckBox_Layer0AutoScroll->setChecked(false); - ui->CheckBox_Layer0AutoScroll->setEnabled(false); - ui->ComboBox_Layer0Picker->setEnabled(false); - ui->graphicsView->UpdateGraphicsItems(currentTileset, BGptr, 0); - } - else // Tile8x8 - { - ui->spinBox_Layer0Width->setEnabled(false); - ui->spinBox_Layer0Height->setEnabled(false); - ui->ComboBox_Layer0Picker->setEnabled(true); - ui->graphicsView->UpdateGraphicsItems(currentTileset, BGptr, L0ptr); - ui->ComboBox_LayerPriority->setCurrentIndex(0); - } - } -} - /// /// Slot function for ComboBox_TilesetID_currentIndexChanged. /// @@ -306,16 +212,21 @@ void RoomConfigDialog::on_ComboBox_TilesetID_currentIndexChanged(int index) } if (BGLayerdataPtrs[index].size() > 0) { - ui->CheckBox_BGLayerEnable->setChecked(true); + ui->CheckBox_BGLayerEnable->setEnabled(true); } else { - ui->CheckBox_BGLayerEnable->setChecked(false); + ui->CheckBox_BGLayerEnable->setEnabled(false); } ui->ComboBox_BGLayerPicker->addItems(elements); - ui->CheckBox_Layer0Enable->setChecked(false); - ui->CheckBox_Layer0Enable->setChecked(true); // trigger on_CheckBox_Layer0Enable_stateChanged() - ui->CheckBox_Layer2Enable->setChecked(true); + if(index == 0x21 && ui->spinBox_Layer0MappingType->value() >= 0x20) + { + ui->ComboBox_Layer0Picker->setEnabled(true); + } + else + { + ui->ComboBox_Layer0Picker->setEnabled(false); + } // Extra UI changes for Toxic Landfill dust Layer0 if (ui->ComboBox_TilesetID->currentIndex() == 0x21) @@ -329,7 +240,7 @@ void RoomConfigDialog::on_ComboBox_TilesetID_currentIndexChanged(int index) } int BGptr = ui->ComboBox_BGLayerPicker->currentText().toUInt(nullptr, 16); int L0ptr = ui->ComboBox_Layer0Picker->currentText().toUInt(nullptr, 16); - if (ui->ComboBox_Layer0MappingType->currentIndex() == 0) + if ((ui->spinBox_Layer0MappingType->value() & 0x20) == 0) L0ptr = 0; ui->graphicsView->UpdateGraphicsItems(currentTileset, BGptr, L0ptr); } @@ -342,8 +253,6 @@ void RoomConfigDialog::on_CheckBox_BGLayerEnable_stateChanged(int state) { int tilesetIndex = ui->ComboBox_TilesetID->currentIndex(); ui->ComboBox_BGLayerPicker->setEnabled(state == Qt::Checked && BGLayerdataPtrs[tilesetIndex].size()); - ui->CheckBox_BGLayerAutoScroll->setChecked(false); - ui->CheckBox_BGLayerAutoScroll->setEnabled(state == Qt::Checked); if (ui->ComboBox_BGLayerPicker->count() > 0) { for (int i = ui->ComboBox_BGLayerPicker->count() - 1; i >= 0; i--) @@ -370,7 +279,7 @@ void RoomConfigDialog::on_ComboBox_BGLayerPicker_currentIndexChanged(int index) { int BGptr = ui->ComboBox_BGLayerPicker->currentText().toUInt(nullptr, 16); int L0ptr = ui->ComboBox_Layer0Picker->currentText().toUInt(nullptr, 16); - if (ui->ComboBox_Layer0MappingType->currentIndex() == 0) + if ((ui->spinBox_Layer0MappingType->value() & 0x30) == LevelComponents::LayerMap16) L0ptr = 0; ui->graphicsView->UpdateGraphicsItems(currentTileset, BGptr, L0ptr); } @@ -384,10 +293,9 @@ void RoomConfigDialog::on_ComboBox_Layer0Picker_currentIndexChanged(int index) (void) index; if (ComboBoxInitialized) { - ui->CheckBox_Layer0AutoScroll->setEnabled(true); int BGptr = ui->ComboBox_BGLayerPicker->currentText().toUInt(nullptr, 16); int L0ptr = ui->ComboBox_Layer0Picker->currentText().toUInt(nullptr, 16); - if (ui->ComboBox_Layer0MappingType->currentIndex() == 0) + if ((ui->spinBox_Layer0MappingType->value() & 0x30) == LevelComponents::LayerMap16) L0ptr = 0; ui->graphicsView->UpdateGraphicsItems(currentTileset, BGptr, L0ptr); } @@ -399,7 +307,7 @@ void RoomConfigDialog::on_ComboBox_Layer0Picker_currentIndexChanged(int index) void RoomConfigDialog::on_ComboBox_LayerPriority_currentIndexChanged(int index) { (void) index; - if (ui->ComboBox_Layer0MappingType->currentIndex() == 1) + if ((ui->spinBox_Layer0MappingType->value() & 0x30) == LevelComponents::LayerTile8x8) ui->ComboBox_LayerPriority->setCurrentIndex(0); } @@ -486,3 +394,129 @@ void RoomConfigDialog::on_spinBox_Layer0Height_valueChanged(int arg1) ui->spinBox_Layer0Height->setStyleSheet(""); } } + +/// +/// Slot function for spinBox_BGLayerScrollingFlag_valueChanged. +/// +/// +/// The spinbox value. +/// +void RoomConfigDialog::on_spinBox_BGLayerScrollingFlag_valueChanged(int arg1) +{ + switch(arg1) + { + // TODO: Add more info for other cases, 1-7 are all meaningful cases + case 1: ui->label_CurBGLayerScrollingType->setText("No scrolling"); break; + case 3: ui->label_CurBGLayerScrollingType->setText("Hide BG Layer"); break; + case 7: ui->label_CurBGLayerScrollingType->setText("full BG Layer autoscroll"); break; + default: ui->label_CurBGLayerScrollingType->setText("Unknown"); + } +} + +/// +/// Slot function for spinBox_Layer0MappingType_valueChanged. +/// +/// +/// The spinbox value. +/// +void RoomConfigDialog::on_spinBox_Layer0MappingType_valueChanged(int arg1) +{ + switch(arg1) + { + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + case 0x08: + case 0x09: + case 0x0A: + case 0x0B: + case 0x0C: + case 0x0D: + case 0x0E: + case 0x0F: + { + ui->label_CurLayer0MappingType->setText("Disabled"); break; + } + case 0x10: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + case 0x19: + case 0x1A: + case 0x1B: + case 0x1C: + case 0x1D: + case 0x1E: + case 0x1F: + { + ui->spinBox_Layer0Width->setValue(ui->SpinBox_RoomWidth->value()); + ui->spinBox_Layer0Height->setValue(ui->SpinBox_RoomHeight->value()); + ui->label_CurLayer0MappingType->setText("Map16"); + break; + } + case 0x11: ui->label_CurLayer0MappingType->setText("Map16 & The Big Board result Bar control"); break; + case 0x12: ui->label_CurLayer0MappingType->setText("Map16 & asyn cam-based H-scroll"); break; + case 0x20: + case 0x21: + case 0x23: + case 0x24: + case 0x25: + case 0x26: + case 0x27: + case 0x28: + case 0x29: + case 0x2A: + case 0x2B: + case 0x2C: + case 0x2D: + case 0x2E: + case 0x2F: + { + ui->label_CurLayer0MappingType->setText("Tile8x8"); break; + } + case 0x22: ui->label_CurLayer0MappingType->setText("Tile8x8 & autoscroll"); break; + } + + if (arg1 >= LevelComponents::LayerMap16) // Enable L0 + { + ui->CheckBox_Layer0Alpha->setEnabled(true); + int BGptr = ui->ComboBox_BGLayerPicker->currentText().toUInt(nullptr, 16); + int L0ptr = ui->ComboBox_Layer0Picker->currentText().toUInt(nullptr, 16); + if(arg1 >= LevelComponents::LayerMap16 && arg1 < LevelComponents::LayerTile8x8) // Map16 + { + ui->spinBox_Layer0Width->setEnabled(true); + ui->spinBox_Layer0Height->setEnabled(true); + ui->spinBox_Layer0Width->setValue(ui->SpinBox_RoomWidth->value()); + ui->spinBox_Layer0Height->setValue(ui->SpinBox_RoomHeight->value()); + ui->ComboBox_Layer0Picker->setEnabled(false); + ui->graphicsView->UpdateGraphicsItems(currentTileset, BGptr, 0); + } else if (arg1 >= LevelComponents::LayerTile8x8) { //Map8 + ui->spinBox_Layer0Width->setEnabled(false); + ui->spinBox_Layer0Height->setEnabled(false); + if(ui->ComboBox_TilesetID->currentIndex() == 0x21) // Extra UI changes for Toxic Landfill dust Layer0 + { + ui->ComboBox_Layer0Picker->setEnabled(true); + ui->graphicsView->UpdateGraphicsItems(currentTileset, BGptr, L0ptr); + } else { + ui->ComboBox_Layer0Picker->setEnabled(false); + } + ui->ComboBox_LayerPriority->setCurrentIndex(0); + } else if (arg1 >= LevelComponents::LayerTile8x8) { //Dsiabled or other customized cases + ui->spinBox_Layer0Width->setEnabled(false); + ui->spinBox_Layer0Height->setEnabled(false); + } + } + else // Disable L0 + { + ui->CheckBox_Layer0Alpha->setChecked(false); + ui->CheckBox_Layer0Alpha->setEnabled(false); + } +} diff --git a/Dialog/RoomConfigDialog.h b/Dialog/RoomConfigDialog.h index 52908712..2933368d 100644 --- a/Dialog/RoomConfigDialog.h +++ b/Dialog/RoomConfigDialog.h @@ -21,7 +21,6 @@ namespace DialogParams struct RoomConfigParams { int CurrentTilesetIndex; - bool Layer0Enable; bool Layer0Alpha; int LayerPriorityAndAlphaAttr; int Layer0MappingTypeParam; @@ -32,24 +31,28 @@ namespace DialogParams bool Layer2Enable; int Layer0DataPtr; bool BackgroundLayerEnable; - bool BackgroundLayerAutoScrollEnable; + unsigned char BGLayerScrollFlag; int BackgroundLayerDataPtr; unsigned short *LayerData[3]; //only use it when room & layer0 size change + unsigned char LayerGFXEffect01; + unsigned char LayerGFXEffect02; + unsigned short BGMVolume; // Default constructor RoomConfigParams() { memset(this, 0, sizeof(struct RoomConfigParams)); } // Construct this param struct using a Room object RoomConfigParams(LevelComponents::Room *room) : - CurrentTilesetIndex(room->GetTilesetID()), Layer0Enable(room->GetLayer0MappingParam() != 0), + CurrentTilesetIndex(room->GetTilesetID()), Layer0Alpha(room->IsLayer0ColorBlendingEnabled()), LayerPriorityAndAlphaAttr(room->GetLayerEffectsParam()), Layer0MappingTypeParam(room->GetLayer0MappingParam()), RoomWidth(room->GetWidth()), RoomHeight(room->GetHeight()), Layer2Enable(room->IsLayer2Enabled()), Layer0DataPtr((room->GetLayer0MappingParam() & 0x20) ? room->GetLayerDataPtr(0) : 0), - BackgroundLayerEnable(room->IsBGLayerEnabled()) + BackgroundLayerEnable(room->IsBGLayerEnabled()), LayerGFXEffect01(room->GetLayerGFXEffect01()), + LayerGFXEffect02(room->GetLayerGFXEffect02()), BGMVolume(room->GetBgmvolume()) { - if((Layer0MappingTypeParam & 0x10) == 0x10){ + if((Layer0MappingTypeParam & 0x10) == LevelComponents::LayerMap16){ Layer0Width = room->GetLayer(0)->GetLayerWidth(); Layer0Height = room->GetLayer(0)->GetLayerHeight(); } else { Layer0Width = 0; Layer0Height = 0; @@ -62,13 +65,10 @@ namespace DialogParams if (BackgroundLayerEnable) { BackgroundLayerDataPtr = room->GetLayerDataPtr(3); - BackgroundLayerAutoScrollEnable = room->IsBGLayerAutoScrollEnabled(); - } - else - { + } else { BackgroundLayerDataPtr = WL4Constants::BGLayerDefaultPtr; - BackgroundLayerAutoScrollEnable = false; } + BGLayerScrollFlag = room->GetBGLayerScrollFlag(); } ~RoomConfigParams() @@ -98,9 +98,7 @@ class RoomConfigDialog : public QDialog DialogParams::RoomConfigParams GetConfigParams(); private slots: - void on_CheckBox_Layer0Enable_stateChanged(int state); void on_CheckBox_Layer0Alpha_stateChanged(int state); - void on_ComboBox_Layer0MappingType_currentIndexChanged(int index); void on_ComboBox_TilesetID_currentIndexChanged(int index); void on_CheckBox_BGLayerEnable_stateChanged(int state); void on_ComboBox_BGLayerPicker_currentIndexChanged(int index); @@ -110,10 +108,11 @@ private slots: void on_SpinBox_RoomHeight_valueChanged(int arg1); void on_spinBox_Layer0Width_valueChanged(int arg1); void on_spinBox_Layer0Height_valueChanged(int arg1); + void on_spinBox_BGLayerScrollingFlag_valueChanged(int arg1); + void on_spinBox_Layer0MappingType_valueChanged(int arg1); private: bool ComboBoxInitialized = false; - bool DontEnableLayerSizeSpinboxes = false; Ui::RoomConfigDialog *ui; void ShowTilesetDetails(int tilesetIndex); void ShowMappingType20LayerDetails(int _layerdataAddr, LevelComponents::Layer *_tmpLayer); @@ -245,13 +244,6 @@ private slots: "EVA 00%, EVB 100%" }; - // Enumeration of the available layer mapping types - static constexpr const char *Layer0MappingTypeParamSetData[2] = - { - "Map16", - "Tile8x8" - }; - // Enumeration of the available BGs per tileset (RLE format) static constexpr const unsigned int BGLayerdataPtrsData[166] = { diff --git a/Dialog/RoomConfigDialog.ui b/Dialog/RoomConfigDialog.ui index 91643044..fa94e49b 100644 --- a/Dialog/RoomConfigDialog.ui +++ b/Dialog/RoomConfigDialog.ui @@ -7,7 +7,7 @@ 0 0 900 - 662 + 762 @@ -71,22 +71,84 @@ - + + + + + Background Layer Scrolling Flag: + + + + + + + + + + + + + + - false + true - - Enable Background Autoscroll + + 255 + + + 16 + + + + + + + + + <html><head/><body><p><span style=" font-weight:600;">Layer 0 Mapping Type</span></p><p>This property is hardly used. It's only used if you're using the Toxic Landfill Tileset with an existing dust foreground.</p></body></html> + + + Layer 0 Mapping Type: + + + + + + + + + + + + + + + + true + + + 47 + + + 16 - + - <html><head/><body><p><span style=" font-weight:600;">Enable Layer 0</span></p><p>Layer 0 is the only layer that's able to be used as the front layer for color blending.</p><p>This option, if check marked, enables Layer 0.</p></body></html> + <html><head/><body><p><span style=" font-weight:600;">Use existing Layer 0</span></p><p><br/></p><p>Select the foreground layer pointer.</p></body></html> - Enable Layer 0 + Use existing Layer 0: + + + + + + + false @@ -99,6 +161,9 @@ + + false + 19 @@ -116,6 +181,9 @@ + + false + 14 @@ -137,16 +205,6 @@ - - - - <html><head/><body><p><span style=" font-weight:600;">Alpha Blend Attributes</span></p><p>See the Helpfile for information.</p></body></html> - - - Alpha Blend Attributes: - - - @@ -155,103 +213,110 @@ - + - <html><head/><body><p><span style=" font-weight:600;">Layer 0 Mapping Type</span></p><p>This property is hardly used. It's only used if you're using the Toxic Landfill Tileset with an existing dust foreground.</p></body></html> + <html><head/><body><p><span style=" font-weight:600;">Enable Layer 2</span></p><p><br/></p><p>Enable layer X to set its mapping type from 0x00 to 0x01.</p><p><br/></p><p>Layer X can be Layer 0 or Layer 2.</p></body></html> - Layer 0 Mapping Type: + Enable Layer 2 - - - false + + + <html><head/><body><p><span style=" font-weight:600;">Layer Priority</span></p><p><br/></p><p>There's several available priority settings that Wario Land 4's game engine supports, you can use one of them.</p></body></html> + + + Layer Priority: - - - <html><head/><body><p><span style=" font-weight:600;">Use existing Layer 0</span></p><p><br/></p><p>Select the foreground layer pointer.</p></body></html> - + + + + - Use existing Layer 0: + Room Width: - - - false + + + 19 + + + 255 - - - false - + - Enable Layer 0 Autoscroll + Room Height: - - - <html><head/><body><p><span style=" font-weight:600;">Enable Layer 2</span></p><p><br/></p><p>Enable layer X to set its mapping type from 0x00 to 0x01.</p><p><br/></p><p>Layer X can be Layer 0 or Layer 2.</p></body></html> + + + 14 - - Enable Layer 2 + + 255 - - - <html><head/><body><p><span style=" font-weight:600;">Layer Priority</span></p><p><br/></p><p>There's several available priority settings that Wario Land 4's game engine supports, you can use one of them.</p></body></html> - + - Layer Priority: + Layer graphic effect flag 1 (Hex up to FF): - + + + 255 + + + 16 + + - + - Room Width: + Layer graphic effect flag 2 (Hex up to FF): - - - 19 - + 255 + + 16 + - + - Room Height: + BGM Volume (Hex up to FFFF): - - - 14 - + - 255 + 65535 + + + 16 diff --git a/EditorWindow/MainGraphicsView.cpp b/EditorWindow/MainGraphicsView.cpp index 6a2e4574..ac4591dd 100644 --- a/EditorWindow/MainGraphicsView.cpp +++ b/EditorWindow/MainGraphicsView.cpp @@ -674,12 +674,6 @@ void MainGraphicsView::keyPressEvent(QKeyEvent *event) case Qt::Key_Backspace: case Qt::Key_Delete: { - if (singleton->GetCurrentRoom()->CountDoors() < 2) - { - QMessageBox::critical(nullptr, QString("Error"), - QString("Deleting the last Door in a Room is not allowed!")); - return; - } singleton->DeleteDoor(singleton->GetCurrentRoom()->GetDoor(SelectedDoorID)->GetGlobalDoorID()); SelectedDoorID = -1; singleton->RenderScreenElementsLayersUpdate(0xFFFFFFFFu, -1); diff --git a/LevelComponents/Level.h b/LevelComponents/Level.h index beaf920d..39758ae7 100644 --- a/LevelComponents/Level.h +++ b/LevelComponents/Level.h @@ -72,7 +72,9 @@ namespace LevelComponents int GetTimeCountdownCounter(enum __LevelDifficulty LevelDifficulty); std::vector GetDoors() { return doors; } // get Doors without copying the data std::vector GetRooms() { return rooms; } + void AddRoom(Room *newroom) { rooms.push_back(newroom); } std::string GetLevelName() { return LevelName; } + unsigned int GetLevelID() { return LevelID; } void SetLevelName(std::string newlevelname) { LevelName = newlevelname; } void RedistributeDoor(); std::vector GetRoomDoors(unsigned int roomId); // get Doors and copy the data diff --git a/LevelComponents/Room.cpp b/LevelComponents/Room.cpp index 09f237e9..77fb4d64 100644 --- a/LevelComponents/Room.cpp +++ b/LevelComponents/Room.cpp @@ -22,6 +22,7 @@ namespace LevelComponents /// /// /// Zero-based ID for the room in the level. + /// This won't be used to load data, so you can set roomId and load another room /// /// /// Level index value from 0x03000023 at run-time. @@ -126,7 +127,7 @@ namespace LevelComponents layers[i] = new Layer(*room->GetLayer(i)); } - SetLayerPriorityAndAlphaAttributes(room->GetRoomHeader().LayerEffects); + SetLayerPriorityAndAlphaAttributes(room->GetRoomHeader().LayerPriorityColorBlendingFlag); // Set up camera control data if (CameraControlType == LevelComponents::HasControlAttrs) @@ -905,7 +906,7 @@ namespace LevelComponents { // Prioritize the layers int priorityFlag = layerPriorityAndAlphaAttr; - RoomHeader.LayerEffects = (unsigned char) layerPriorityAndAlphaAttr; + RoomHeader.LayerPriorityColorBlendingFlag = (unsigned char) layerPriorityAndAlphaAttr; switch (priorityFlag & 3) { case 0: @@ -1008,16 +1009,9 @@ namespace LevelComponents /// /// Set attributes relate to layer 3 autoscroll in Room header struct in sake of saving changes. /// - void Room::SetBGLayerAutoScrollEnabled(bool enability) + void Room::SetBGLayerScrollFlag(unsigned char flag) { - if (enability) - { - RoomHeader.Layer3Scrolling = '\x07'; - } - else - { - RoomHeader.Layer3Scrolling = RoomHeader.Layer3MappingType ? '\x01' : '\x03'; - } + RoomHeader.Layer3Scrolling = flag; } /// @@ -1176,9 +1170,10 @@ namespace LevelComponents Layer2MappingType(room->GetLayer(2)->GetMappingType()), Layer3MappingType(room->GetLayer(3)->GetMappingType()), Layer0Data(0), // set manually Layer1Data(0), Layer2Data(0), Layer3Data(0), CameraControlType(room->GetCameraControlType()), - Layer3Scrolling(room->GetBGScrollParameter()), LayerEffects(room->GetLayerEffectsParam()), DATA_1B(0), + Layer3Scrolling(room->GetBGScrollParameter()), LayerPriorityColorBlendingFlag(room->GetLayerEffectsParam()), DATA_1B(0), EntityTableHard(0), // set manually - EntityTableNormal(0), EntityTableSHard(0) + EntityTableNormal(0), EntityTableSHard(0), LayerGFXEffect01(room->GetLayerGFXEffect01()), + LayerGFXEffect02(room->GetLayerGFXEffect02()), BGMVolume(room->GetBgmvolume()) {} /// diff --git a/LevelComponents/Room.h b/LevelComponents/Room.h index d48cebe3..7e3415f1 100644 --- a/LevelComponents/Room.h +++ b/LevelComponents/Room.h @@ -30,12 +30,14 @@ namespace LevelComponents unsigned int Layer3Data; unsigned char CameraControlType; unsigned char Layer3Scrolling; - unsigned char LayerEffects; + unsigned char LayerPriorityColorBlendingFlag; unsigned char DATA_1B; unsigned int EntityTableHard; unsigned int EntityTableNormal; unsigned int EntityTableSHard; - unsigned char DATA_28[4]; + unsigned char LayerGFXEffect01; + unsigned char LayerGFXEffect02; + unsigned short BGMVolume; __RoomHeader() {} __RoomHeader(Room *room); @@ -151,7 +153,10 @@ namespace LevelComponents // Getters size_t CountDoors() { return doors.size(); } - size_t GetBGScrollParameter() { return RoomHeader.Layer3Scrolling; } + unsigned char GetBGScrollParameter() { return RoomHeader.Layer3Scrolling; } + unsigned char GetLayerGFXEffect01() { return RoomHeader.LayerGFXEffect01; } + unsigned char GetLayerGFXEffect02() { return RoomHeader.LayerGFXEffect02; } + unsigned short GetBgmvolume() { return RoomHeader.BGMVolume; } std::vector GetCameraControlRecords(bool create_new_instances = false) { if (!create_new_instances) @@ -183,7 +188,7 @@ namespace LevelComponents Layer *GetLayer(int LayerID) { return layers[LayerID]; } int GetLayer0MappingParam() { return RoomHeader.Layer0MappingType; } int GetLayerDataPtr(unsigned int LayerNum); - int GetLayerEffectsParam() { return RoomHeader.LayerEffects; } + int GetLayerEffectsParam() { return RoomHeader.LayerPriorityColorBlendingFlag; } unsigned int GetLevelID() { return LevelID; } struct __RoomHeader GetRoomHeader() { return RoomHeader; } unsigned int GetRoomID() { return RoomID; } @@ -191,7 +196,7 @@ namespace LevelComponents int GetTilesetID() { return RoomHeader.TilesetID; } int GetEntityX(int index); int GetEntityY(int index); - bool IsBGLayerAutoScrollEnabled() { return RoomHeader.Layer3Scrolling == '\x07'; } + unsigned char GetBGLayerScrollFlag() { return RoomHeader.Layer3Scrolling; } bool IsBGLayerEnabled() { return RoomHeader.Layer3MappingType; } bool IsCameraBoundaryDirty() { return CameraBoundaryDirty; } bool IsLayer0ColorBlendingEnabled() { return Layer0ColorBlending; } @@ -205,8 +210,11 @@ namespace LevelComponents void DeleteEntity(int index); void DeleteEntity(int difficulty, int index); void ClearEntitylist(int difficulty); + void SetLayerGFXEffect01(unsigned char flag) { RoomHeader.LayerGFXEffect01 = flag; } + void SetLayerGFXEffect02(unsigned char flag) { RoomHeader.LayerGFXEffect02 = flag; } + void SetBgmvolume(unsigned short bgmvolume) { RoomHeader.BGMVolume = bgmvolume; } void SetBGLayerEnabled(bool enability) { RoomHeader.Layer3MappingType = enability ? '\x20' : '\x00'; } - void SetBGLayerAutoScrollEnabled(bool enability); + void SetBGLayerScrollFlag(unsigned char flag); void SetCameraBoundaryDirty(bool dirty) { CameraBoundaryDirty = dirty; } void SetCameraControlType(__CameraControlType new_control_type) { diff --git a/ScriptInterface.cpp b/ScriptInterface.cpp index 3aaf8de4..aa3e08c1 100644 --- a/ScriptInterface.cpp +++ b/ScriptInterface.cpp @@ -42,7 +42,7 @@ int ScriptInterface::GetCurRoomId() return singleton->GetCurrentRoomId(); } -void ScriptInterface::Test_DecompressData(int mappingtype, int address) +void ScriptInterface::_DecompressData(int mappingtype, int address) { int tmpw = 0, tmph = 0; unsigned short *LayerData = nullptr; @@ -90,7 +90,7 @@ void ScriptInterface::Test_DecompressData(int mappingtype, int address) singleton->GetOutputWidgetPtr()->PrintString(tmpstr); } -unsigned int ScriptInterface::Test_GetLayerDecomdataPointer(int layerId) +unsigned int ScriptInterface::_GetLayerDecomdataPointer(int layerId) { switch(layerId) { @@ -119,7 +119,20 @@ unsigned int ScriptInterface::Test_GetLayerDecomdataPointer(int layerId) } } -void ScriptInterface::Test_ExportLayerData(QString filePath, int layerid) +void ScriptInterface::_PrintRoomHeader() +{ + LevelComponents::__RoomHeader header = singleton->GetCurrentRoom()->GetRoomHeader(); + QString roomheaderstr; + for(size_t i = 0; i < sizeof(LevelComponents::__RoomHeader); i++) + { + roomheaderstr.push_back(QString::number(((unsigned char *)&header)[i], 16).toUpper()); + if((i + 1) % 4 == 0) roomheaderstr.push_back(" "); + roomheaderstr.push_back(" "); + } + log(roomheaderstr); +} + +void ScriptInterface::_ExportLayerData(QString filePath, int layerid) { log("Export Layer Data from current Room."); if(!filePath.compare("")) @@ -165,7 +178,7 @@ void ScriptInterface::Test_ExportLayerData(QString filePath, int layerid) log("Done!"); } -void ScriptInterface::Test_ImportLayerData(QString fileName, int layerid) +void ScriptInterface::_ImportLayerData(QString fileName, int layerid) { log("Import Layer Data from current Room."); // Load gfx bin file @@ -235,7 +248,7 @@ void ScriptInterface::Test_ImportLayerData(QString fileName, int layerid) log("Done!"); } -void ScriptInterface::Test_ExportEntityListData(QString filePath, int entitylistid) +void ScriptInterface::_ExportEntityListData(QString filePath, int entitylistid) { log("Export Entity List Data from current Room."); if(!filePath.compare("")) @@ -282,7 +295,7 @@ void ScriptInterface::Test_ExportEntityListData(QString filePath, int entitylist log("Done!"); } -void ScriptInterface::Test_ImportEntityListData(QString fileName, int entitylistid) +void ScriptInterface::_ImportEntityListData(QString fileName, int entitylistid) { log("Import Entity List Data from current Room."); if(!fileName.compare("")) diff --git a/ScriptInterface.h b/ScriptInterface.h index 1f1c93cc..c0f81283 100644 --- a/ScriptInterface.h +++ b/ScriptInterface.h @@ -22,12 +22,13 @@ class ScriptInterface : public QObject Q_INVOKABLE int GetCurRoomId(); // Test - Q_INVOKABLE void Test_DecompressData(int mappingtype, int address); - Q_INVOKABLE unsigned int Test_GetLayerDecomdataPointer(int layerId); - Q_INVOKABLE void Test_ExportLayerData(QString filePath = QString(""), int layerid = -1); - Q_INVOKABLE void Test_ImportLayerData(QString fileName = QString(""), int layerid = -1); - Q_INVOKABLE void Test_ExportEntityListData(QString filePath = QString(""), int entitylistid = -1); - Q_INVOKABLE void Test_ImportEntityListData(QString filePath = QString(""), int entitylistid = -1); + Q_INVOKABLE void _DecompressData(int mappingtype, int address); + Q_INVOKABLE unsigned int _GetLayerDecomdataPointer(int layerId); + Q_INVOKABLE void _PrintRoomHeader(); + Q_INVOKABLE void _ExportLayerData(QString filePath = QString(""), int layerid = -1); + Q_INVOKABLE void _ImportLayerData(QString fileName = QString(""), int layerid = -1); + Q_INVOKABLE void _ExportEntityListData(QString filePath = QString(""), int entitylistid = -1); + Q_INVOKABLE void _ImportEntityListData(QString filePath = QString(""), int entitylistid = -1); // Setter Q_INVOKABLE void SetCurrentRoomId(int roomid); diff --git a/WL4EditorWindow.cpp b/WL4EditorWindow.cpp index 8a19dc9a..1af4aafe 100644 --- a/WL4EditorWindow.cpp +++ b/WL4EditorWindow.cpp @@ -347,7 +347,7 @@ void WL4EditorWindow::SetChangeCurrentRoomEnabled(bool state) /// void WL4EditorWindow::SetCurrentRoomId(int roomid) { - if (!selectedRoom) + if (static_cast(selectedRoom) == roomid) return; if(roomid < 0 || roomid >= static_cast(CurrentLevel->GetRooms().size())) return; @@ -531,7 +531,7 @@ void WL4EditorWindow::RoomConfigReset(DialogParams::RoomConfigParams *currentroo currentroomconfig->LayerData[0] = nullptr; } } - if (!currentroomconfig->Layer0Enable && nextroomconfig->Layer0Enable) + if (!currentroomconfig->Layer0MappingTypeParam && nextroomconfig->Layer0MappingTypeParam) { if ((nextroomconfig->Layer0MappingTypeParam & 0x30) == LevelComponents::LayerMap16) { @@ -545,12 +545,12 @@ void WL4EditorWindow::RoomConfigReset(DialogParams::RoomConfigParams *currentroo currentRoom->SetLayer(0, currentLayer0); } } - else if (currentroomconfig->Layer0Enable && !nextroomconfig->Layer0Enable) + else if (currentroomconfig->Layer0MappingTypeParam && !nextroomconfig->Layer0MappingTypeParam) { currentRoom->GetLayer(0)->SetDisabled(); } - if ((currentroomconfig->Layer0Enable & 0x30) != LevelComponents::LayerTile8x8 && + if ((currentroomconfig->Layer0MappingTypeParam & 0x30) != LevelComponents::LayerTile8x8 && (nextroomconfig->Layer0MappingTypeParam & 0x30) == LevelComponents::LayerTile8x8) { LevelComponents::Layer *currentLayer0 = currentRoom->GetLayer(0); @@ -736,8 +736,11 @@ void WL4EditorWindow::RoomConfigReset(DialogParams::RoomConfigParams *currentroo if (nextroomconfig->Layer0DataPtr) currentRoom->SetLayerDataPtr(0, nextroomconfig->Layer0DataPtr); currentRoom->SetBGLayerEnabled(nextroomconfig->BackgroundLayerEnable); - currentRoom->SetBGLayerAutoScrollEnabled(nextroomconfig->BackgroundLayerAutoScrollEnable); + currentRoom->SetBGLayerScrollFlag(nextroomconfig->BGLayerScrollFlag); currentRoom->SetLayerDataPtr(3, nextroomconfig->BackgroundLayerDataPtr); + currentRoom->SetLayerGFXEffect01(nextroomconfig->LayerGFXEffect01); + currentRoom->SetLayerGFXEffect02(nextroomconfig->LayerGFXEffect02); + currentRoom->SetBgmvolume(nextroomconfig->BGMVolume); // reset LayerDataPtr in RoomHeader because Layer::SetDisabled() doesn't change the data in RoomHeader for (int i = 0; i < 3; ++i) @@ -768,7 +771,15 @@ void WL4EditorWindow::DeleteDoor(int globalDoorIndex) { // You cannot delete the vortex, it is always the first Door. if (globalDoorIndex == 0) + { + OutputWidget->PrintString("Deleting portal Door not permitted!"); + return; + } + if (CurrentLevel->GetDoors().size() == 1) + { + OutputWidget->PrintString("Deleting the last Door in the Room not permitted! Spriteset is based on Doors."); return; + } // Delete the Door from the Room Door list CurrentLevel->GetRooms()[CurrentLevel->GetDoors()[globalDoorIndex]->GetRoomID()]->DeleteDoor(globalDoorIndex); @@ -1068,28 +1079,41 @@ bool WL4EditorWindow::UnsavedChangesPrompt(QString str) /// Clear eventhing in the current room. /// But at least one door will be kept. /// -void WL4EditorWindow::CurrentRoomClearEverything() +/// +/// Optional param for showing warning of deleting doors. +/// +/// +/// Optional param for selecting a room to clear, set -1 as a default value for current room. +/// +void WL4EditorWindow::ClearEverythingInRoom(bool no_warning) { bool IfDeleteAllDoors = false; // Show asking deleting Doors messagebox - QMessageBox IfDeleteDoors; - IfDeleteDoors.setWindowTitle(tr("WL4Editor")); - IfDeleteDoors.setText( - "You just triggered the clear-all shortcut (current room).\nDo you want to delete all the doors, too?\n(One " - "door will be kept to render camera boxes correctly.\nCamera settings will be unaffected regardless.)"); - QPushButton *CancelClearingButton = IfDeleteDoors.addButton(tr("Cancel Clearing"), QMessageBox::RejectRole); - QPushButton *NoButton = IfDeleteDoors.addButton(tr("No"), QMessageBox::NoRole); - QPushButton *YesButton = IfDeleteDoors.addButton(tr("Yes"), QMessageBox::ApplyRole); - IfDeleteDoors.setDefaultButton(CancelClearingButton); - IfDeleteDoors.exec(); - - if (IfDeleteDoors.clickedButton() == YesButton) + if(no_warning == false) { - IfDeleteAllDoors = true; + QMessageBox IfDeleteDoors; + IfDeleteDoors.setWindowTitle(tr("WL4Editor")); + IfDeleteDoors.setText( + "You just triggered the clear-all shortcut (current room).\nDo you want to delete all the doors, too?\n(One " + "door will be kept to render camera boxes correctly.\nCamera settings will be unaffected regardless.)"); + QPushButton *CancelClearingButton = IfDeleteDoors.addButton(tr("Cancel Clearing"), QMessageBox::RejectRole); + QPushButton *NoButton = IfDeleteDoors.addButton(tr("No"), QMessageBox::NoRole); + QPushButton *YesButton = IfDeleteDoors.addButton(tr("Yes"), QMessageBox::ApplyRole); + IfDeleteDoors.setDefaultButton(CancelClearingButton); + IfDeleteDoors.exec(); + + if (IfDeleteDoors.clickedButton() == YesButton) + { + IfDeleteAllDoors = true; + } + else if (IfDeleteDoors.clickedButton() != NoButton) + { + return; + } } - else if (IfDeleteDoors.clickedButton() != NoButton) + else { - return; + IfDeleteAllDoors = true; } // Clear Layers 0, 1, 2 @@ -1847,7 +1871,7 @@ void WL4EditorWindow::on_actionOutput_window_triggered() /// void WL4EditorWindow::on_actionClear_all_triggered() { - CurrentRoomClearEverything(); + ClearEverythingInRoom(); } /// @@ -1880,3 +1904,53 @@ void WL4EditorWindow::on_actionRect_Select_Mode_toggled(bool arg1) { ui->graphicsView->SetRectSelectMode(arg1); } + +/// +/// Add a new Room to the current Level. +/// +void WL4EditorWindow::on_actionNew_Room_triggered() +{ + // Create new Room based on current Room + int newRoomId = CurrentLevel->GetRooms().size(); + if (newRoomId == 16) + { + OutputWidget->PrintString("Cannot add more Room to the current Level!"); + return; + } + int roomTableAddress = ROMUtils::PointerFromData(WL4Constants::RoomDataTable + CurrentLevel->GetLevelID() * 4); + CurrentLevel->AddRoom(new LevelComponents::Room(roomTableAddress + selectedRoom * 0x2C, newRoomId, CurrentLevel->GetLevelID())); + + // Add one Door to the new Room as well as spriteset settings + { + // Create a new door struct with blank fields + LevelComponents::__DoorEntry newDoorEntry; + memset(&newDoorEntry, 0, sizeof(LevelComponents::__DoorEntry)); + + // Initialize the fields + newDoorEntry.DoorTypeByte = (unsigned char) 2; + newDoorEntry.EntitySetID = (unsigned char) 1; + newDoorEntry.RoomID = (unsigned char) newRoomId; + newDoorEntry.DoorTypeByte = LevelComponents::DoorType::Instant; + LevelComponents::Door *newDoor = + new LevelComponents::Door(newDoorEntry, (unsigned char) newRoomId, CurrentLevel->GetDoors().size()); + int entitysetId = CurrentLevel->GetRooms()[selectedRoom]->GetCurrentEntitySetID(); + newDoor->SetEntitySetID(entitysetId); + newDoor->SetDestinationDoor(CurrentLevel->GetDoors()[0]); + + // Add the new door to the Level object and re-render the screen + CurrentLevel->AddDoor(newDoor); + + // Set Current Entity list + CurrentLevel->GetRooms()[newRoomId]->SetCurrentEntitySet(entitysetId); + } + + // Reset LevelHeader param + CurrentLevel->GetLevelHeader()->NumOfMap++; + + // UI updates + SetCurrentRoomId(newRoomId); + OutputWidget->PrintString("Created a new blank room (# " + QString::number(newRoomId) + ") using the current room's settings."); + + // Clear everything in the new room + ClearEverythingInRoom(true); +} diff --git a/WL4EditorWindow.h b/WL4EditorWindow.h index 1128774f..5ab78e74 100644 --- a/WL4EditorWindow.h +++ b/WL4EditorWindow.h @@ -54,7 +54,7 @@ class WL4EditorWindow : public QMainWindow static bool SaveCurrentFile() { return ROMUtils::SaveLevel(ROMUtils::ROMFilePath); } bool SaveCurrentFileAs(); bool UnsavedChangesPrompt(QString str); - void CurrentRoomClearEverything(); + void ClearEverythingInRoom(bool no_warning = false); protected: void resizeEvent(QResizeEvent *event); @@ -151,6 +151,7 @@ private slots: void on_actionRect_Select_Mode_toggled(bool arg1); void on_actionUndo_global_triggered(); void on_actionRedo_global_triggered(); + void on_actionNew_Room_triggered(); }; #endif // WL4EDITORWINDOW_H diff --git a/WL4EditorWindow.ui b/WL4EditorWindow.ui index 9eb935c4..ed8f80a4 100644 --- a/WL4EditorWindow.ui +++ b/WL4EditorWindow.ui @@ -126,7 +126,7 @@ 0 0 1900 - 21 + 23 @@ -165,6 +165,7 @@ Add + @@ -546,6 +547,11 @@ Ctrl+Shift+Y + + + New Room + +