Update menus to use PositionMenuSegment
- Updated ModMenuModule::SpawnVehicleMenu and SpawnObjectMenu to use ModMenuModule::PositionMenuSegment instead of PositionRotationSegment - Fixed missing OnShow and OnHide methods in ModMenuModule::SpawnVehicleMenu
This commit is contained in:
parent
ed076eeb38
commit
9271c1dae6
@ -1,5 +1,5 @@
|
||||
#include "spawn-object-menu.h"
|
||||
#include "../segments/position-rotation-segment.h"
|
||||
#include "../segments/position-menu-segment.h"
|
||||
#include "../segments/spawn-object-segment.h"
|
||||
#include "../root.h"
|
||||
#include "../utils/spawn-object.h"
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
ModMenuModule::SpawnObjectMenu::SpawnObjectMenu()
|
||||
{
|
||||
m_posRotSegment = CreateSegment<ModMenuModule::PositionRotationSegment>("ModMenu_SpawnObjectMenu_PosRotSegment");
|
||||
m_positionMenuSegment = CreateSegment<ModMenuModule::PositionMenuSegment>("ModMenu_SpawnObjectMenu_PositionMenuSegment");
|
||||
m_spawnObjectSegment = CreateSegment<ModMenuModule::SpawnObjectSegment>("ModMenu_SpawnObjectMenu_SpawnSegment");
|
||||
}
|
||||
|
||||
@ -27,10 +27,7 @@ bool ModMenuModule::SpawnObjectMenu::Attach()
|
||||
|
||||
uiRoot->AddComponent<UiModule::Spacer>(vertCont, 0, options.menuSpacerHeight);
|
||||
|
||||
AttachSegment(m_posRotSegment, this, vertCont);
|
||||
|
||||
uiRoot->AddComponent<UiModule::Spacer>(vertCont, 0, options.menuSpacerHeight);
|
||||
|
||||
AttachSegment(m_positionMenuSegment, this, vertCont);
|
||||
AttachSegment(m_spawnObjectSegment, this, vertCont);
|
||||
|
||||
// spawn button
|
||||
@ -45,7 +42,8 @@ bool ModMenuModule::SpawnObjectMenu::Attach()
|
||||
|
||||
void ModMenuModule::SpawnObjectMenu::Detach()
|
||||
{
|
||||
DetachSegment(m_posRotSegment);
|
||||
SaveCurrentSelectedIndex();
|
||||
DetachSegment(m_positionMenuSegment);
|
||||
DetachSegment(m_spawnObjectSegment);
|
||||
DestroyMenu();
|
||||
}
|
||||
@ -67,15 +65,16 @@ void ModMenuModule::SpawnObjectMenu::OnMenuAction(UiModule::Selectable* item, Ui
|
||||
ModMenuModule::MenuManager::GetInstance()->RemoveLastMenu();
|
||||
break;
|
||||
default:
|
||||
m_positionMenuSegment->OnPassedMenuAction(item, id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ModMenuModule::SpawnObjectMenu::Spawn()
|
||||
{
|
||||
auto positionSegmentDataOpt = m_posRotSegment->GetSegmentData();
|
||||
auto positionSegmentDataOpt = m_positionMenuSegment->GetSegmentData();
|
||||
if (!positionSegmentDataOpt.has_value()) {
|
||||
spdlog::error("Cannot spawn object: failed to get position rotation segment data.");
|
||||
spdlog::error("Cannot spawn object: failed to get PositionMenuSegment data.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -83,7 +82,7 @@ void ModMenuModule::SpawnObjectMenu::Spawn()
|
||||
|
||||
auto spawnObjectSegmentDataOpt = m_spawnObjectSegment->GetSegmentData();
|
||||
if (!spawnObjectSegmentDataOpt.has_value()) {
|
||||
spdlog::error("Cannot spawn object: failed to get spawn object segment data.");
|
||||
spdlog::error("Cannot spawn object: failed to get SpawnObjectSegment data.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include "../segment-support.h"
|
||||
|
||||
namespace ModMenuModule {
|
||||
class PositionRotationSegment;
|
||||
class PositionMenuSegment;
|
||||
class SpawnObjectSegment;
|
||||
|
||||
class SpawnObjectMenu : public MenuBase, public SegmentSupport {
|
||||
@ -21,7 +21,7 @@ namespace ModMenuModule {
|
||||
void OnMenuAction(UiModule::Selectable* item, UiModule::MenuItemId id) override;
|
||||
void Spawn();
|
||||
|
||||
PositionRotationSegment* m_posRotSegment = nullptr;
|
||||
PositionMenuSegment* m_positionMenuSegment = nullptr;
|
||||
SpawnObjectSegment* m_spawnObjectSegment = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
#include "spawn-vehicle-menu.h"
|
||||
#include "../segments/position-menu-segment.h"
|
||||
#include "../segments/spawn-vehicle-segment.h"
|
||||
#include "../../../converters/car-model.h"
|
||||
#include "../../../converters/yes-no.h"
|
||||
#include "../../../converters/car-remap.h"
|
||||
#include "../root.h"
|
||||
#include "../utils/spawn-car-at-player.h"
|
||||
#include "../utils/spawn-car.h"
|
||||
|
||||
ModMenuModule::SpawnVehicleMenu::SpawnVehicleMenu()
|
||||
{
|
||||
m_spawnVehicleSegment = CreateSegment<ModMenuModule::SpawnVehicleSegment>("ModMenu_SpawnVehicleMenu_SpawnSegment");
|
||||
m_positionMenuSegment = CreateSegment<PositionMenuSegment>("ModMenu_SpawnVehicleMenu_PositionMenuSegment");
|
||||
m_spawnVehicleSegment = CreateSegment<SpawnVehicleSegment>("ModMenu_SpawnVehicleMenu_SpawnSegment");
|
||||
}
|
||||
|
||||
ModMenuModule::SpawnVehicleMenu::~SpawnVehicleMenu()
|
||||
@ -26,6 +26,9 @@ bool ModMenuModule::SpawnVehicleMenu::Attach()
|
||||
|
||||
m_menuController->CreateItem<UiModule::Text>(vertCont, L"Go back", options.textSize);
|
||||
|
||||
uiRoot->AddComponent<UiModule::Spacer>(vertCont, 0, options.menuSpacerHeight);
|
||||
|
||||
AttachSegment(m_positionMenuSegment, this, vertCont);
|
||||
AttachSegment(m_spawnVehicleSegment, this, vertCont);
|
||||
|
||||
// spawn button
|
||||
@ -40,10 +43,21 @@ bool ModMenuModule::SpawnVehicleMenu::Attach()
|
||||
|
||||
void ModMenuModule::SpawnVehicleMenu::Detach()
|
||||
{
|
||||
DetachSegment(m_positionMenuSegment);
|
||||
DetachSegment(m_spawnVehicleSegment);
|
||||
DestroyMenu();
|
||||
}
|
||||
|
||||
void ModMenuModule::SpawnVehicleMenu::OnShow()
|
||||
{
|
||||
SetSegmentsVisible(true);
|
||||
}
|
||||
|
||||
void ModMenuModule::SpawnVehicleMenu::OnHide()
|
||||
{
|
||||
SetSegmentsVisible(false);
|
||||
}
|
||||
|
||||
void ModMenuModule::SpawnVehicleMenu::OnMenuAction(UiModule::Selectable* item, UiModule::MenuItemId id)
|
||||
{
|
||||
switch (id) {
|
||||
@ -51,28 +65,38 @@ void ModMenuModule::SpawnVehicleMenu::OnMenuAction(UiModule::Selectable* item, U
|
||||
ModMenuModule::MenuManager::GetInstance()->RemoveLastMenu();
|
||||
break;
|
||||
default:
|
||||
m_positionMenuSegment->OnPassedMenuAction(item, id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ModMenuModule::SpawnVehicleMenu::Spawn()
|
||||
{
|
||||
auto segmentDataOpt = m_spawnVehicleSegment->GetSegmentData();
|
||||
if (!segmentDataOpt.has_value()) {
|
||||
spdlog::error("Cannot spawn vehicle: failed to get segment data.");
|
||||
auto spawnSegmentDataOpt = m_spawnVehicleSegment->GetSegmentData();
|
||||
if (!spawnSegmentDataOpt.has_value()) {
|
||||
spdlog::error("Cannot spawn vehicle: failed to get SpawnVehicleSegment data.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto& segmentData = segmentDataOpt.value();
|
||||
auto positionSegmentDataOpt = m_positionMenuSegment->GetSegmentData();
|
||||
if (!positionSegmentDataOpt.has_value()) {
|
||||
spdlog::error("Cannot spawn vehicle: failed to get PositionMenuSegment data");
|
||||
return;
|
||||
}
|
||||
|
||||
bool success = ModMenuModule::Utils::SpawnCarAtPlayer(
|
||||
segmentData.model,
|
||||
segmentData.remap,
|
||||
segmentData.palette
|
||||
auto& spawnSegmentData = spawnSegmentDataOpt.value();
|
||||
auto& positionSegmentData = positionSegmentDataOpt.value();
|
||||
|
||||
bool success = ModMenuModule::Utils::SpawnCar(
|
||||
positionSegmentData.position,
|
||||
positionSegmentData.rotation,
|
||||
spawnSegmentData.model,
|
||||
spawnSegmentData.remap,
|
||||
spawnSegmentData.palette
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
std::wstring modelStr = CarModelConverter::ConvertToString(segmentData.model);
|
||||
std::wstring modelStr = CarModelConverter::ConvertToString(spawnSegmentData.model);
|
||||
ToastManager::GetInstance()->Show({ L"Failed to spawn " + modelStr, ToastType::Error });
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "../segment-support.h"
|
||||
|
||||
namespace ModMenuModule {
|
||||
class PositionMenuSegment;
|
||||
class SpawnVehicleSegment;
|
||||
|
||||
class SpawnVehicleMenu : public MenuBase, public SegmentSupport {
|
||||
@ -14,10 +15,13 @@ namespace ModMenuModule {
|
||||
private:
|
||||
virtual bool Attach() override;
|
||||
virtual void Detach() override;
|
||||
virtual void OnShow() override;
|
||||
virtual void OnHide() override;
|
||||
|
||||
void OnMenuAction(UiModule::Selectable* item, UiModule::MenuItemId id) override;
|
||||
void Spawn();
|
||||
|
||||
PositionMenuSegment* m_positionMenuSegment = nullptr;
|
||||
SpawnVehicleSegment* m_spawnVehicleSegment = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user