Skip to content

Commit

Permalink
✉️ MSG_EDI_REINIT_WATER_REQUESTED
Browse files Browse the repository at this point in the history
                // I tried making all water modes toggleable, see RigsOfRods#3142
                //    but I gave up on HydraX, it always looks different when started for 2nd time.
                // For the time being, only basic water modes are toggleable.
  • Loading branch information
ohlidalp committed Sep 20, 2024
1 parent d2f7ed1 commit 5bdf133
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 36 deletions.
2 changes: 1 addition & 1 deletion source/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ const char* MsgTypeToString(MsgType type)
case MSG_SIM_ADD_FREEFORCE_REQUESTED : return "MSG_SIM_ADD_FREEFORCE_REQUESTED";
case MSG_SIM_MODIFY_FREEFORCE_REQUESTED : return "MSG_SIM_MODIFY_FREEFORCE_REQUESTED";
case MSG_SIM_REMOVE_FREEFORCE_REQUESTED : return "MSG_SIM_REMOVE_FREEFORCE_REQUESTED";
case MSG_SIM_REINIT_WATER_REQUESTED : return "MSG_SIM_REINIT_WATER_REQUESTED";
case MSG_EDI_REINIT_WATER_REQUESTED : return "MSG_EDI_REINIT_WATER_REQUESTED";

case MSG_GUI_OPEN_MENU_REQUESTED : return "MSG_GUI_OPEN_MENU_REQUESTED";
case MSG_GUI_CLOSE_MENU_REQUESTED : return "MSG_GUI_CLOSE_MENU_REQUESTED";
Expand Down
2 changes: 1 addition & 1 deletion source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ enum MsgType
MSG_SIM_ADD_FREEFORCE_REQUESTED, //!< Payload = RoR::FreeForceRequest* (owner)
MSG_SIM_MODIFY_FREEFORCE_REQUESTED, //!< Payload = RoR::FreeForceRequest* (owner)
MSG_SIM_REMOVE_FREEFORCE_REQUESTED, //!< Payload = RoR::FreeForceID_t* (owner)
MSG_SIM_REINIT_WATER_REQUESTED,
// GUI
MSG_GUI_OPEN_MENU_REQUESTED,
MSG_GUI_CLOSE_MENU_REQUESTED,
Expand All @@ -151,6 +150,7 @@ enum MsgType
MSG_EDI_CREATE_PROJECT_REQUESTED, //!< Payload = RoR::CreateProjectRequest* (owner)
MSG_EDI_MODIFY_PROJECT_REQUESTED, //!< Payload = RoR::UpdateProjectRequest* (owner)
MSG_EDI_DELETE_PROJECT_REQUESTED, //!< Payload = RoR::CacheEntryPtr* (owner)
MSG_EDI_REINIT_WATER_REQUESTED,
};

const char* MsgTypeToString(MsgType type);
Expand Down
2 changes: 1 addition & 1 deletion source/main/gfx/IWater.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class IWater //!< Common to classic water (Water.cpp, `class Water`) and HydraX
virtual void SetWaterGridOptions(Hydrax::Module::ProjectedGrid::Options options) {};

protected:
GfxWaterMode m_active_water_mode; //!< A snapshot of cvar `gfx_water_mode` at the time of water creation - because the cvar can change (i.e. via TopMenubar or scripting, see also `MSG_SIM_REINIT_WATER_REQUESTED`)
GfxWaterMode m_active_water_mode; //!< A snapshot of cvar `gfx_water_mode` at the time of water creation - because the cvar can change (i.e. via TopMenubar or scripting, see also `MSG_EDI_REINIT_WATER_REQUESTED`)
};

/// @} // addtogroup Gfx
Expand Down
50 changes: 32 additions & 18 deletions source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,28 +648,42 @@ void TopMenubar::Draw(float dt)
ImGui::PushID("water");
ImGui::TextDisabled("%s", _LC("TopMenubar", "Water:"));

if (water_mode_combostring == "")
IWater* iwater = App::GetGameContext()->GetTerrain()->getWater();

// I tried making all water modes toggleable, see https://github.com/RigsOfRods/rigs-of-rods/pull/3142
// but I gave up on HydraX, it always looks different when started for 2nd time.
// For the time being, only basic water modes are toggleable.

if (!iwater || (iwater && iwater->GetActiveWaterMode() != GfxWaterMode::HYDRAX))
{
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::NONE));
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::BASIC));
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::REFLECT));
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::FULL_FAST));
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::FULL_HQ));
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::HYDRAX));
ImTerminateComboboxString(water_mode_combostring);
}
// No water or non-HydraX water
if (water_mode_combostring == "")
{
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::NONE));
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::BASIC));
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::REFLECT));
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::FULL_FAST));
ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::FULL_HQ));
//ImAddItemToComboboxString(water_mode_combostring, ToLocalizedString(GfxWaterMode::HYDRAX)); // FIXME: Glitchy
ImTerminateComboboxString(water_mode_combostring);
}

if (DrawGCombo(App::gfx_water_mode, _LC("TopMenubar", "Mode"), water_mode_combostring.c_str()))
{
App::GetGameContext()->PushMessage(Message(MSG_SIM_REINIT_WATER_REQUESTED));
if (DrawGCombo(App::gfx_water_mode, _LC("TopMenubar", "Mode"), water_mode_combostring.c_str()))
{
App::GetGameContext()->PushMessage(Message(MSG_EDI_REINIT_WATER_REQUESTED));
}
ImGui::TextDisabled("(HydraX only in main menu)");
if (DrawGCheckbox(App::gfx_water_waves, _LC("TopMenubar", "Waves")))
{
App::GetGameContext()->PushMessage(Message(MSG_EDI_REINIT_WATER_REQUESTED));
}
}

if (DrawGCheckbox(App::gfx_water_waves, _LC("TopMenubar", "Waves")))
else
{
App::GetGameContext()->PushMessage(Message(MSG_SIM_REINIT_WATER_REQUESTED));
}

IWater* iwater = App::GetGameContext()->GetTerrain()->getWater();
// HydraX water
ImGui::Text("HydraX active");
ImGui::TextDisabled("(change only in main menu)");
}

if (iwater
&& iwater->GetActiveWaterMode() != GfxWaterMode::HYDRAX
Expand Down
26 changes: 13 additions & 13 deletions source/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,19 +1253,6 @@ int main(int argc, char *argv[])
break;
}

case MSG_SIM_REINIT_WATER_REQUESTED:
{
try
{
App::GetGameContext()->GetTerrain()->initWater();
}
catch (...)
{
HandleMsgQueueException(m.type);
}
break;
}

// -- GUI events ---

case MSG_GUI_OPEN_MENU_REQUESTED:
Expand Down Expand Up @@ -1594,6 +1581,19 @@ int main(int argc, char *argv[])
break;
}

case MSG_EDI_REINIT_WATER_REQUESTED:
{
try
{
App::GetGameContext()->GetTerrain()->initWater();
}
catch (...)
{
HandleMsgQueueException(m.type);
}
break;
}

default:;
}

Expand Down
2 changes: 1 addition & 1 deletion source/main/scripting/bindings/MsgQueueAngelscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void RoR::RegisterMessageQueue(asIScriptEngine* engine)
result = engine->RegisterEnumValue("MsgType", "MSG_APP_UNLOAD_SCRIPT_REQUESTED", MSG_APP_UNLOAD_SCRIPT_REQUESTED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("MsgType", "MSG_APP_SCRIPT_THREAD_STATUS", MSG_APP_SCRIPT_THREAD_STATUS); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("MsgType", "MSG_APP_REINIT_INPUT_REQUESTED", MSG_APP_REINIT_INPUT_REQUESTED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("MsgType", "MSG_SIM_REINIT_WATER_REQUESTED", MSG_SIM_REINIT_WATER_REQUESTED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("MsgType", "MSG_EDI_REINIT_WATER_REQUESTED", MSG_EDI_REINIT_WATER_REQUESTED); ROR_ASSERT(result >= 0);
// Networking
result = engine->RegisterEnumValue("MsgType", "MSG_NET_CONNECT_REQUESTED", MSG_NET_CONNECT_REQUESTED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("MsgType", "MSG_NET_CONNECT_STARTED", MSG_NET_CONNECT_STARTED); ROR_ASSERT(result >= 0);
Expand Down
2 changes: 1 addition & 1 deletion source/main/terrain/Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void RoR::Terrain::fixCompositorClearColor()

void RoR::Terrain::initWater()
{
// Clean up old water (see `MSG_SIM_REINIT_WATER_REQUESTED`)
// Clean up old water (see `MSG_EDI_REINIT_WATER_REQUESTED`)
if (m_water)
{
delete m_water;
Expand Down

0 comments on commit 5bdf133

Please sign in to comment.