2017-04-02 03:03:37 +00:00
|
|
|
#include "CHudVisorBeamMenu.hpp"
|
2017-04-08 20:40:36 +00:00
|
|
|
#include "GameGlobalObjects.hpp"
|
|
|
|
#include "CGameState.hpp"
|
|
|
|
#include "CGuiFrame.hpp"
|
|
|
|
#include "CGuiModel.hpp"
|
|
|
|
#include "CGuiTextPane.hpp"
|
|
|
|
#include "CStringTable.hpp"
|
|
|
|
#include "Audio/CSfxManager.hpp"
|
2017-04-02 03:03:37 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2017-04-02 03:03:37 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static const char* BaseMenuNames[] = {"BaseWidget_VisorMenu", "BaseWidget_BeamMenu"};
|
2017-04-02 03:03:37 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static const char* TextNames[] = {"TextPane_VisorMenu", "TextPane_BeamMenu"};
|
2017-04-08 20:40:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static const char* BaseTitleNames[] = {"basewidget_visormenutitle", "basewidget_beammenutitle"};
|
2017-04-08 20:40:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static const char* ModelNames[] = {"model_visor", "model_beam"};
|
2017-04-08 20:40:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static const char MenuItemOrders[2][4] = {{'1', '0', '3', '2'}, {'3', '2', '1', '0'}};
|
2017-04-08 20:40:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static const int MenuStringIdx[2][4] = {
|
2017-04-08 20:40:36 +00:00
|
|
|
{0, 2, 1, 3}, // Combat, XRay, Scan, Thermal
|
|
|
|
{4, 5, 6, 7} // Power, Ice, Wave, Plasma
|
|
|
|
};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static const u16 SelectionSfxs[] = {SFXui_select_visor, SFXui_select_beam};
|
2017-04-08 20:40:36 +00:00
|
|
|
|
|
|
|
CHudVisorBeamMenu::CHudVisorBeamMenu(CGuiFrame& baseHud, EHudVisorBeamMenu type,
|
2018-02-15 04:37:21 +00:00
|
|
|
const rstl::reserved_vector<bool, 4>& enables)
|
2018-12-08 05:30:43 +00:00
|
|
|
: x0_baseHud(baseHud), x4_type(type) {
|
|
|
|
x14_24_visibleDebug = true;
|
|
|
|
x14_25_visibleGame = true;
|
|
|
|
x14_26_dirty = true;
|
|
|
|
|
|
|
|
x7c_animDur = g_tweakGui->GetBeamVisorMenuAnimTime();
|
|
|
|
x80_24_swapBeamControls = g_GameState->GameOptions().GetSwapBeamControls();
|
|
|
|
|
|
|
|
EHudVisorBeamMenu swappedType;
|
|
|
|
if (x80_24_swapBeamControls)
|
|
|
|
swappedType = EHudVisorBeamMenu(1 - int(x4_type));
|
|
|
|
else
|
|
|
|
swappedType = x4_type;
|
|
|
|
|
|
|
|
x20_textpane_menu = static_cast<CGuiTextPane*>(x0_baseHud.FindWidget(TextNames[int(swappedType)]));
|
|
|
|
x1c_basewidget_menutitle = x0_baseHud.FindWidget(BaseTitleNames[int(swappedType)]);
|
|
|
|
x18_basewidget_menu = x0_baseHud.FindWidget(BaseMenuNames[int(swappedType)]);
|
|
|
|
|
|
|
|
x24_model_ghost = static_cast<CGuiModel*>(x0_baseHud.FindWidget(hecl::Format("%sghost", ModelNames[int(x4_type)])));
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SMenuItem& item = x28_menuItems[i];
|
|
|
|
item.x0_model_loz = static_cast<CGuiModel*>(
|
|
|
|
x0_baseHud.FindWidget(hecl::Format("%sloz%c", ModelNames[int(x4_type)], MenuItemOrders[int(x4_type)][i])));
|
|
|
|
item.x4_model_icon = static_cast<CGuiModel*>(
|
|
|
|
x0_baseHud.FindWidget(hecl::Format("%sicon%c", ModelNames[int(x4_type)], MenuItemOrders[int(x4_type)][i])));
|
|
|
|
item.xc_opacity = enables[i] ? 1.f : 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x4_type == EHudVisorBeamMenu::Visor) {
|
|
|
|
x20_textpane_menu->TextSupport().SetFontColor(g_tweakGuiColors->GetVisorMenuTextFont());
|
|
|
|
x20_textpane_menu->TextSupport().SetOutlineColor(g_tweakGuiColors->GetVisorMenuTextOutline());
|
|
|
|
} else {
|
|
|
|
x20_textpane_menu->TextSupport().SetFontColor(g_tweakGuiColors->GetBeamMenuTextFont());
|
|
|
|
x20_textpane_menu->TextSupport().SetOutlineColor(g_tweakGuiColors->GetBeamMenuTextOutline());
|
|
|
|
}
|
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor titleColor = zeus::skWhite;
|
2018-12-08 05:30:43 +00:00
|
|
|
titleColor.a() = 0.f;
|
|
|
|
x1c_basewidget_menutitle->SetColor(titleColor);
|
|
|
|
|
|
|
|
x20_textpane_menu->TextSupport().SetText(g_MainStringTable->GetString(MenuStringIdx[int(x4_type)][x8_selectedItem]));
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SMenuItem& item = x28_menuItems[i];
|
|
|
|
item.x0_model_loz->SetColor(g_tweakGuiColors->GetVisorBeamMenuLozColor());
|
|
|
|
UpdateMenuWidgetTransform(i, *item.x0_model_loz, 1.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
Update(0.f, true);
|
|
|
|
}
|
2017-04-08 20:40:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHudVisorBeamMenu::UpdateMenuWidgetTransform(int idx, CGuiWidget& w, float t) {
|
|
|
|
float translate = t * g_tweakGui->GetVisorBeamMenuItemTranslate();
|
|
|
|
float scale =
|
|
|
|
t * g_tweakGui->GetVisorBeamMenuItemInactiveScale() + (1.f - t) * g_tweakGui->GetVisorBeamMenuItemActiveScale();
|
|
|
|
if (x4_type == EHudVisorBeamMenu::Visor) {
|
|
|
|
if (idx == 2)
|
|
|
|
idx = 3;
|
|
|
|
else if (idx == 3)
|
|
|
|
idx = 2;
|
|
|
|
} else {
|
|
|
|
if (idx == 1)
|
|
|
|
idx = 2;
|
|
|
|
else if (idx == 2)
|
|
|
|
idx = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (idx) {
|
|
|
|
case 0:
|
|
|
|
w.SetO2WTransform(x18_basewidget_menu->GetWorldTransform() * zeus::CTransform::Translate(0.f, 0.f, translate) *
|
|
|
|
zeus::CTransform::Scale(scale));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
w.SetO2WTransform(x18_basewidget_menu->GetWorldTransform() * zeus::CTransform::Translate(translate, 0.f, 0.f) *
|
|
|
|
zeus::CTransform::Scale(scale));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
w.SetO2WTransform(x18_basewidget_menu->GetWorldTransform() * zeus::CTransform::Translate(0.f, 0.f, -translate) *
|
|
|
|
zeus::CTransform::Scale(scale));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
w.SetO2WTransform(x18_basewidget_menu->GetWorldTransform() * zeus::CTransform::Translate(-translate, 0.f, 0.f) *
|
|
|
|
zeus::CTransform::Scale(scale));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-04-08 20:40:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHudVisorBeamMenu::Update(float dt, bool init) {
|
|
|
|
bool curSwapBeamControls = g_GameState->GameOptions().GetSwapBeamControls();
|
|
|
|
if (x80_24_swapBeamControls != curSwapBeamControls) {
|
|
|
|
x80_24_swapBeamControls = curSwapBeamControls;
|
2017-04-08 20:40:36 +00:00
|
|
|
EHudVisorBeamMenu swappedType;
|
|
|
|
if (x80_24_swapBeamControls)
|
2018-12-08 05:30:43 +00:00
|
|
|
swappedType = EHudVisorBeamMenu(1 - int(x4_type));
|
2017-04-08 20:40:36 +00:00
|
|
|
else
|
2018-12-08 05:30:43 +00:00
|
|
|
swappedType = x4_type;
|
2017-04-08 20:40:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x18_basewidget_menu = x0_baseHud.FindWidget(BaseMenuNames[int(swappedType)]);
|
2017-04-08 20:40:36 +00:00
|
|
|
x20_textpane_menu = static_cast<CGuiTextPane*>(x0_baseHud.FindWidget(TextNames[int(swappedType)]));
|
|
|
|
x1c_basewidget_menutitle = x0_baseHud.FindWidget(BaseTitleNames[int(swappedType)]);
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SMenuItem& item = x28_menuItems[i];
|
|
|
|
UpdateMenuWidgetTransform(i, *item.x4_model_icon, item.x8_positioner);
|
|
|
|
UpdateMenuWidgetTransform(i, *item.x0_model_loz, 1.f);
|
2017-04-08 20:40:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateMenuWidgetTransform(x8_selectedItem, *x24_model_ghost, x28_menuItems[x8_selectedItem].x8_positioner);
|
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CColor activeColor = g_tweakGuiColors->GetVisorBeamMenuItemActive();
|
|
|
|
zeus::CColor inactiveColor = g_tweakGuiColors->GetVisorBeamMenuItemInactive();
|
|
|
|
zeus::CColor lozColor = g_tweakGuiColors->GetVisorBeamMenuLozColor();
|
|
|
|
zeus::CColor tmpColors[4];
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SMenuItem& item = x28_menuItems[i];
|
|
|
|
if (item.xc_opacity > 0.f)
|
|
|
|
item.xc_opacity = std::min(item.xc_opacity + dt, 1.f);
|
2019-02-24 07:15:54 +00:00
|
|
|
tmpColors[i] = zeus::CColor::lerp(activeColor, zeus::skClear, item.xc_opacity);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (x6c_animPhase) {
|
|
|
|
case EAnimPhase::Steady:
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SMenuItem& item = x28_menuItems[i];
|
|
|
|
zeus::CColor& color0 = (x8_selectedItem == i) ? activeColor : inactiveColor;
|
|
|
|
zeus::CColor& color1 = (x8_selectedItem == i) ? lozColor : inactiveColor;
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor iconColor = (item.xc_opacity == 0.f) ? zeus::skClear : color0 + tmpColors[i];
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CColor lColor = (item.xc_opacity == 0.f) ? lozColor : color1 + tmpColors[i];
|
|
|
|
item.x4_model_icon->SetColor(iconColor);
|
|
|
|
item.x0_model_loz->SetColor(lColor);
|
|
|
|
item.x8_positioner = (x8_selectedItem == i) ? 0.f : 1.f;
|
2017-04-08 20:40:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x24_model_ghost->SetColor(activeColor);
|
|
|
|
break;
|
|
|
|
case EAnimPhase::SelectFlash: {
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor color = zeus::skWhite;
|
2018-12-08 05:30:43 +00:00
|
|
|
color.a() = 0.f;
|
|
|
|
x1c_basewidget_menutitle->SetColor(color);
|
|
|
|
|
|
|
|
zeus::CColor& color0 = std::fmod(x10_interp, 0.1f) > 0.05f ? activeColor : inactiveColor;
|
|
|
|
SMenuItem& item0 = x28_menuItems[xc_pendingSelection];
|
|
|
|
color = color0 + tmpColors[xc_pendingSelection];
|
|
|
|
item0.x4_model_icon->SetColor(color);
|
|
|
|
item0.x0_model_loz->SetColor(color);
|
|
|
|
|
|
|
|
SMenuItem& item1 = x28_menuItems[x8_selectedItem];
|
|
|
|
color = zeus::CColor::lerp(inactiveColor, activeColor, x10_interp) + tmpColors[x8_selectedItem];
|
|
|
|
item1.x4_model_icon->SetColor(color);
|
|
|
|
item1.x0_model_loz->SetColor(lozColor);
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
x28_menuItems[i].x8_positioner = (x8_selectedItem == i) ? 1.f - x10_interp : 1.f;
|
|
|
|
|
|
|
|
x24_model_ghost->SetColor(zeus::CColor::lerp(activeColor, inactiveColor, item1.x8_positioner));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EAnimPhase::Animate:
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SMenuItem& item = x28_menuItems[i];
|
|
|
|
zeus::CColor& color0 = (x8_selectedItem == i) ? activeColor : inactiveColor;
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor iconColor = (item.xc_opacity == 0.f) ? zeus::skClear : color0 + tmpColors[i];
|
2018-12-08 05:30:43 +00:00
|
|
|
item.x4_model_icon->SetColor(iconColor);
|
|
|
|
item.x0_model_loz->SetColor((item.xc_opacity == 0.f || x8_selectedItem == i) ? lozColor : inactiveColor);
|
|
|
|
item.x8_positioner = (x8_selectedItem == i) ? 1.f - x10_interp : 1.f;
|
2017-04-08 20:40:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x24_model_ghost->SetColor(
|
|
|
|
zeus::CColor::lerp(activeColor, inactiveColor, x28_menuItems[x8_selectedItem].x8_positioner));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x78_textFader > 0.f) {
|
|
|
|
x78_textFader = std::max(0.f, x78_textFader - dt);
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor color = zeus::skWhite;
|
2018-12-08 05:30:43 +00:00
|
|
|
color.a() = x78_textFader / x7c_animDur;
|
|
|
|
x1c_basewidget_menutitle->SetColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x14_26_dirty || init) {
|
|
|
|
x14_26_dirty = false;
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SMenuItem& item = x28_menuItems[i];
|
|
|
|
UpdateMenuWidgetTransform(i, *item.x4_model_icon, item.x8_positioner);
|
2017-04-08 20:40:36 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateMenuWidgetTransform(x8_selectedItem, *x24_model_ghost, x28_menuItems[x8_selectedItem].x8_positioner);
|
|
|
|
}
|
2017-04-08 20:40:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!x14_24_visibleDebug || !x14_25_visibleGame)
|
|
|
|
return;
|
2018-06-21 21:04:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x1c_basewidget_menutitle->SetVisibility(x1c_basewidget_menutitle->GetGeometryColor().a() != 0.f,
|
|
|
|
ETraversalMode::Children);
|
2017-04-08 20:40:36 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SMenuItem& item = x28_menuItems[i];
|
|
|
|
item.x4_model_icon->SetIsVisible(item.x4_model_icon->GetGeometryColor().a() != 0.f);
|
|
|
|
}
|
2017-04-03 01:39:23 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHudVisorBeamMenu::UpdateHudAlpha(float alpha) {
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor color = zeus::skWhite;
|
2018-12-08 05:30:43 +00:00
|
|
|
color.a() = g_GameState->GameOptions().GetHUDAlpha() / 255.f * alpha;
|
|
|
|
x18_basewidget_menu->SetColor(color);
|
2017-04-08 20:40:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHudVisorBeamMenu::SetIsVisibleGame(bool v) {
|
|
|
|
x14_25_visibleGame = v;
|
|
|
|
bool vis = x14_24_visibleDebug && x14_25_visibleGame;
|
|
|
|
x18_basewidget_menu->SetVisibility(vis, ETraversalMode::Children);
|
|
|
|
if (vis)
|
|
|
|
Update(0.f, true);
|
2017-04-08 20:40:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHudVisorBeamMenu::SetPlayerHas(const rstl::reserved_vector<bool, 4>& enables) {
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SMenuItem& item = x28_menuItems[i];
|
|
|
|
if (item.xc_opacity == 0.f && enables[i])
|
|
|
|
item.xc_opacity = FLT_EPSILON;
|
|
|
|
}
|
2017-04-08 20:40:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHudVisorBeamMenu::SetSelection(int selection, int pending, float interp) {
|
|
|
|
if (x8_selectedItem == selection && xc_pendingSelection == pending && x10_interp == interp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pending != selection) {
|
|
|
|
if (x6c_animPhase != EAnimPhase::SelectFlash)
|
|
|
|
CSfxManager::SfxStart(SelectionSfxs[int(x4_type)], 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
|
|
|
|
x6c_animPhase = EAnimPhase::SelectFlash;
|
|
|
|
} else if (interp < 1.f) {
|
|
|
|
x6c_animPhase = EAnimPhase::Animate;
|
|
|
|
x20_textpane_menu->TextSupport().SetText(
|
|
|
|
g_MainStringTable->GetString(MenuStringIdx[int(x4_type)][x8_selectedItem]));
|
|
|
|
x20_textpane_menu->TextSupport().SetTypeWriteEffectOptions(true, 0.1f, 16.f);
|
|
|
|
} else {
|
|
|
|
if (x6c_animPhase != EAnimPhase::Steady)
|
|
|
|
x78_textFader = x7c_animDur;
|
|
|
|
x6c_animPhase = EAnimPhase::Steady;
|
|
|
|
}
|
|
|
|
|
|
|
|
x14_26_dirty = true;
|
|
|
|
x8_selectedItem = selection;
|
|
|
|
xc_pendingSelection = pending;
|
|
|
|
x10_interp = interp;
|
2017-04-03 01:39:23 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|