Skip to content

Commit

Permalink
* UPD: [xrGame] refactor player_hud_tune
Browse files Browse the repository at this point in the history
  • Loading branch information
yohjimane committed May 31, 2024
1 parent 032f81d commit f6ce30b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 124 deletions.
1 change: 1 addition & 0 deletions src/xrEngine/editor_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ENGINE_API ide final :
auto GetState() const { return m_state; }
void SetState(visible_state state);
void SwitchToNextState();
bool IsActiveState() const { return m_state == visible_state::full; }

public:
// Interface implementations
Expand Down
10 changes: 5 additions & 5 deletions src/xrGame/ActorInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool g_bAutoClearCrouch = true;

void CActor::IR_OnKeyboardPress(int cmd)
{
if (GamePersistent().GetHudTuner().get_open_state())
if (GamePersistent().GetHudTuner().get_open_state() && Device.editor().IsActiveState())
return;

if (Remote())
Expand Down Expand Up @@ -212,7 +212,7 @@ void CActor::IR_OnKeyboardPress(int cmd)

void CActor::IR_OnMouseWheel(float x, float y)
{
if (GamePersistent().GetHudTuner().get_open_state())
if (GamePersistent().GetHudTuner().get_open_state() && Device.editor().IsActiveState())
return;

if (inventory().Action((y > 0) ? (u16)kWPN_ZOOM_INC : (u16)kWPN_ZOOM_DEC, CMD_START))
Expand All @@ -226,7 +226,7 @@ void CActor::IR_OnMouseWheel(float x, float y)

void CActor::IR_OnKeyboardRelease(int cmd)
{
if (GamePersistent().GetHudTuner().get_open_state())
if (GamePersistent().GetHudTuner().get_open_state() && Device.editor().IsActiveState())
return;

if (Remote())
Expand Down Expand Up @@ -268,7 +268,7 @@ void CActor::IR_OnKeyboardRelease(int cmd)

void CActor::IR_OnKeyboardHold(int cmd)
{
if (GamePersistent().GetHudTuner().get_open_state())
if (GamePersistent().GetHudTuner().get_open_state() && Device.editor().IsActiveState())
return;

if (Remote() || !g_Alive())
Expand Down Expand Up @@ -348,7 +348,7 @@ void CActor::OnAxisMove(float x, float y, float scale, bool invert)

void CActor::IR_OnMouseMove(int dx, int dy)
{
if (GamePersistent().GetHudTuner().get_open_state())
if (GamePersistent().GetHudTuner().get_open_state() && Device.editor().IsActiveState())
return;

PIItem iitem = inventory().ActiveItem();
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/Missile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void CMissile::UpdateCL()
CActor* pActor = smart_cast<CActor*>(H_Parent());
if (pActor && !pActor->AnyMove() && this == pActor->inventory().ActiveItem())
{
if (!GamePersistent().GetHudTuner().get_open_state() && GetState() == eIdle && (Device.dwTimeGlobal - m_dw_curr_substate_time > 20000))
if (!((GamePersistent().GetHudTuner().get_open_state() && Device.editor().IsActiveState())) && GetState() == eIdle && (Device.dwTimeGlobal - m_dw_curr_substate_time > 20000))
{
SwitchState(eBore);
ResetSubStateTime();
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ void CWeapon::UpdateCL()
CActor* pActor = smart_cast<CActor*>(H_Parent());
if (pActor && !pActor->AnyMove() && this == pActor->inventory().ActiveItem())
{
if (!GamePersistent().GetHudTuner().get_open_state() && GetState() == eIdle && (Device.dwTimeGlobal - m_dw_curr_substate_time > 20000) &&
if (!((GamePersistent().GetHudTuner().get_open_state() && Device.editor().IsActiveState())) && GetState() == eIdle && (Device.dwTimeGlobal - m_dw_curr_substate_time > 20000) &&
!IsZoomed() && g_player_hud->attached_item(1) == nullptr)
{
if (AllowBore())
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/player_hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void attachable_hud_item::update(bool bForce)
reload_measures();
}

if (GamePersistent().GetHudTuner().get_open_state())
if (GamePersistent().GetHudTuner().get_open_state() && Device.editor().IsActiveState())
m_measures.update(m_attach_offset);

m_parent->calc_transform(m_attach_place_idx, m_attach_offset, m_item_transform);
Expand Down
1 change: 0 additions & 1 deletion src/xrGame/player_hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ struct hud_item_measures

Fvector m_item_attach[2]; // pos,rot

int overriding_hud_idx = -1;
Fvector m_hands_offset[2][3]; // pos,rot/ normal,aim,GL

u16 m_fire_bone;
Expand Down
133 changes: 46 additions & 87 deletions src/xrGame/player_hud_tune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,84 +21,44 @@ CHudTuner::CHudTuner()
paused = fsimilar(Device.time_factor(), EPS);
}

void CHudTuner::SetDefaultValues()
void CHudTuner::ResetToDefaultValues()
{
if (current_hud_item)
{
curr_hand_pos = current_hud_item->m_measures.m_hands_attach[0];
curr_hand_rot = current_hud_item->m_measures.m_hands_attach[1];
curr_hand_pos_offset = current_hud_item->m_measures.m_hands_offset[0][0];
curr_hand_rot_offset = current_hud_item->m_measures.m_hands_offset[1][0];
curr_hand_pos_offset_aim = current_hud_item->m_measures.m_hands_offset[0][1];
curr_hand_rot_offset_aim = current_hud_item->m_measures.m_hands_offset[1][1];
curr_hand_pos_offset_gl = current_hud_item->m_measures.m_hands_offset[0][2];
curr_hand_rot_offset_gl = current_hud_item->m_measures.m_hands_offset[1][2];
curr_item_attach_pos_offset = current_hud_item->m_measures.m_item_attach[0];
curr_item_attach_rot_offset = current_hud_item->m_measures.m_item_attach[1];
curr_fire_point_offset = current_hud_item->m_measures.m_fire_point_offset;
curr_fire_point_2_offset = current_hud_item->m_measures.m_fire_point2_offset;
curr_shell_point_offset = current_hud_item->m_measures.m_shell_point_offset;
current_hud_item->reload_measures();
curr_measures = current_hud_item->m_measures;
}
else
{
Fvector zero = { 0, 0, 0 };
curr_hand_pos = zero;
curr_hand_rot = zero;
new_hand_pos_offset = curr_hand_pos_offset = zero;
new_hand_rot_offset = curr_hand_rot_offset = zero;
new_hand_pos_offset_aim = curr_hand_pos_offset_aim = zero;
new_hand_rot_offset_aim = curr_hand_rot_offset_aim = zero;
new_hand_pos_offset_gl = curr_hand_pos_offset_gl = zero;
new_hand_rot_offset_gl = curr_hand_rot_offset_gl = zero;
new_item_attach_pos_offset = curr_item_attach_pos_offset = zero;
new_item_attach_rot_offset = curr_item_attach_rot_offset = zero;
new_fire_point_offset = curr_fire_point_offset = zero;
new_fire_point_2_offset = curr_fire_point_2_offset = zero;
new_shell_point_offset = curr_shell_point_offset = zero;
curr_measures.m_hands_attach[0] = zero;
curr_measures.m_hands_attach[1] = zero;
curr_measures.m_hands_offset[0][0] = zero;
curr_measures.m_hands_offset[1][0] = zero;
curr_measures.m_hands_offset[0][1] = zero;
curr_measures.m_hands_offset[1][1] = zero;
curr_measures.m_hands_offset[0][2] = zero;
curr_measures.m_hands_offset[1][2] = zero;
curr_measures.m_item_attach[0] = zero;
curr_measures.m_item_attach[1] = zero;
curr_measures.m_fire_point_offset = zero;
curr_measures.m_fire_point2_offset = zero;
curr_measures.m_shell_point_offset = zero;
}
}

void CHudTuner::ResetToDefaultValues()
{
new_hand_pos = curr_hand_pos;
new_hand_rot = curr_hand_rot;
new_hand_pos_offset = curr_hand_pos_offset;
new_hand_rot_offset = curr_hand_rot_offset;
new_hand_pos_offset_aim = curr_hand_pos_offset_aim;
new_hand_rot_offset_aim = curr_hand_rot_offset_aim;
new_hand_pos_offset_gl = curr_hand_pos_offset_gl;
new_hand_rot_offset_gl = curr_hand_rot_offset_gl;
new_item_attach_pos_offset = curr_item_attach_pos_offset;
new_item_attach_rot_offset = curr_item_attach_rot_offset;
new_fire_point_offset = curr_fire_point_offset;
new_fire_point_2_offset = curr_fire_point_2_offset;
new_shell_point_offset = curr_shell_point_offset;
new_measures = curr_measures;
}

void CHudTuner::UpdateValues()
{
if (current_hud_item)
{
current_hud_item->m_measures.m_hands_offset[0][0] = new_hand_pos_offset;
current_hud_item->m_measures.m_hands_offset[1][0] = new_hand_rot_offset;
current_hud_item->m_measures.m_hands_offset[0][1] = new_hand_pos_offset_aim;
current_hud_item->m_measures.m_hands_offset[1][1] = new_hand_rot_offset_aim;
current_hud_item->m_measures.m_hands_offset[0][2] = new_hand_pos_offset_gl;
current_hud_item->m_measures.m_hands_offset[1][2] = new_hand_rot_offset_gl;
current_hud_item->m_measures.m_item_attach[0] = new_item_attach_pos_offset;
current_hud_item->m_measures.m_item_attach[1] = new_item_attach_rot_offset;
current_hud_item->m_measures.m_fire_point_offset = new_fire_point_offset;
current_hud_item->m_measures.m_fire_point2_offset = new_fire_point_2_offset;
current_hud_item->m_measures.m_shell_point_offset = new_shell_point_offset;

u8 idx = current_hud_item->m_parent_hud_item->GetCurrentHudOffsetIdx();
new_hand_pos.set(curr_hand_pos);
new_hand_rot.set(curr_hand_rot);
new_hand_pos.add(current_hud_item->m_measures.m_hands_offset[0][0]);
new_hand_rot.add(current_hud_item->m_measures.m_hands_offset[1][0]);

current_hud_item->m_measures.m_hands_attach[0] = new_hand_pos;
current_hud_item->m_measures.m_hands_attach[1] = new_hand_rot;
new_measures.m_hands_attach[0].set(curr_measures.m_hands_attach[0]);
new_measures.m_hands_attach[1].set(curr_measures.m_hands_attach[1]);
new_measures.m_hands_attach[0].add(new_measures.m_hands_offset[0][0]);
new_measures.m_hands_attach[1].add(new_measures.m_hands_offset[1][0]);

current_hud_item->m_measures = new_measures;
}
}

Expand All @@ -115,7 +75,6 @@ void CHudTuner::OnFrame()
if (current_hud_item != hud_item)
{
current_hud_item = hud_item;
SetDefaultValues();
ResetToDefaultValues();
}

Expand Down Expand Up @@ -160,17 +119,17 @@ void CHudTuner::OnFrame()
ImGui::SliderFloat("Position step", &_delta_pos, 0.0000001f, 0.001f, "%.7f");
ImGui::SliderFloat("Rotation step", &_delta_rot, 0.000001f, 0.1f, "%.6f");

ImGui::DragFloat3(hud_adj_modes[HUD_POS], (float*)&new_hand_pos_offset, _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_ROT], (float*)&new_hand_rot_offset, _delta_rot, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_POS_AIM], (float*)&new_hand_pos_offset_aim, _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_ROT_AIM], (float*)&new_hand_rot_offset_aim, _delta_rot, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_POS_GL], (float*)&new_hand_pos_offset_gl, _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_ROT_GL], (float*)&new_hand_rot_offset_gl, _delta_rot, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[ITEM_POS], (float*)&new_item_attach_pos_offset, _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[ITEM_ROT], (float*)&new_item_attach_rot_offset, _delta_rot, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[FIRE_POINT], (float*)&new_fire_point_offset, _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[FIRE_POINT_2], (float*)&new_fire_point_2_offset, _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[SHELL_POINT], (float*)&new_shell_point_offset, _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_POS], (float*)&new_measures.m_hands_offset[0][0], _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_ROT], (float*)&new_measures.m_hands_offset[1][0], _delta_rot, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_POS_AIM], (float*)&new_measures.m_hands_offset[0][1], _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_ROT_AIM], (float*)&new_measures.m_hands_offset[1][1], _delta_rot, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_POS_GL], (float*)&new_measures.m_hands_offset[0][2], _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[HUD_ROT_GL], (float*)&new_measures.m_hands_offset[1][2], _delta_rot, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[ITEM_POS], (float*)&new_measures.m_item_attach[0], _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[ITEM_ROT], (float*)&new_measures.m_item_attach[1], _delta_rot, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[FIRE_POINT], (float*)&new_measures.m_fire_point_offset, _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[FIRE_POINT_2], (float*)&new_measures.m_fire_point2_offset, _delta_pos, 0.f, 0.f, "%.7f");
ImGui::DragFloat3(hud_adj_modes[SHELL_POINT], (float*)&new_measures.m_shell_point_offset, _delta_pos, 0.f, 0.f, "%.7f");

UpdateValues();

Expand All @@ -188,27 +147,27 @@ void CHudTuner::OnFrame()
ImGui::LogToClipboard();
xr_sprintf(selectable, "[%s]\n", m_sect_name.c_str());
ImGui::LogText(selectable);
xr_sprintf(selectable, "item_position = %f,%f,%f\n", new_item_attach_pos_offset.x, new_item_attach_pos_offset.y, new_item_attach_pos_offset.z);
xr_sprintf(selectable, "hands_position%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_measures.m_hands_offset[0][0].x, new_measures.m_hands_offset[0][0].y, new_measures.m_hands_offset[0][0].z);
ImGui::LogText(selectable);
xr_sprintf(selectable, "item_orientation = %f,%f,%f\n", new_item_attach_rot_offset.x, new_item_attach_rot_offset.y, new_item_attach_rot_offset.z);
xr_sprintf(selectable, "hands_orientation%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_measures.m_hands_offset[1][0].x, new_measures.m_hands_offset[1][0].y, new_measures.m_hands_offset[1][0].z);
ImGui::LogText(selectable);
xr_sprintf(selectable, "fire_point = %f,%f,%f\n", new_fire_point_offset.x, new_fire_point_offset.y, new_fire_point_offset.z);
xr_sprintf(selectable, "aim_hud_offset_pos%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_measures.m_hands_offset[0][1].x, new_measures.m_hands_offset[0][1].y, new_measures.m_hands_offset[0][1].z);
ImGui::LogText(selectable);
xr_sprintf(selectable, "fire_point = %f,%f,%f\n", new_fire_point_2_offset.x, new_fire_point_2_offset.y, new_fire_point_2_offset.z);
xr_sprintf(selectable, "aim_hud_offset_rot%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_measures.m_hands_offset[1][1].x, new_measures.m_hands_offset[1][1].y, new_measures.m_hands_offset[1][1].z);
ImGui::LogText(selectable);
xr_sprintf(selectable, "shell_point = %f,%f,%f\n", new_shell_point_offset.x, new_shell_point_offset.y, new_shell_point_offset.z);
xr_sprintf(selectable, "gl_hud_offset_pos%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_measures.m_hands_offset[0][2].x, new_measures.m_hands_offset[0][2].y, new_measures.m_hands_offset[0][2].z);
ImGui::LogText(selectable);
xr_sprintf(selectable, "hands_position%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_hand_pos.x, new_hand_pos.y, new_hand_pos.z);
xr_sprintf(selectable, "gl_hud_offset_rot%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_measures.m_hands_offset[1][2].x, new_measures.m_hands_offset[1][2].y, new_measures.m_hands_offset[1][2].z);
ImGui::LogText(selectable);
xr_sprintf(selectable, "hands_orientation%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_hand_rot.x, new_hand_rot.y, new_hand_rot.z);
xr_sprintf(selectable, "item_position = %f,%f,%f\n", new_measures.m_item_attach[0].x, new_measures.m_item_attach[0].y, new_measures.m_item_attach[0].z);
ImGui::LogText(selectable);
xr_sprintf(selectable, "aim_hud_offset_pos%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_hand_pos_offset_aim.x, new_hand_pos_offset_aim.y, new_hand_pos_offset_aim.z);
xr_sprintf(selectable, "item_orientation = %f,%f,%f\n", new_measures.m_item_attach[1].x, new_measures.m_item_attach[1].y, new_measures.m_item_attach[1].z);
ImGui::LogText(selectable);
xr_sprintf(selectable, "aim_hud_offset_rot%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_hand_rot_offset_aim.x, new_hand_rot_offset_aim.y, new_hand_rot_offset_aim.z);
xr_sprintf(selectable, "fire_point = %f,%f,%f\n", new_measures.m_fire_point_offset.x, new_measures.m_fire_point_offset.y, new_measures.m_fire_point_offset.z);
ImGui::LogText(selectable);
xr_sprintf(selectable, "gl_hud_offset_pos%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_hand_pos_offset_gl.x, new_hand_pos_offset_gl.y, new_hand_pos_offset_gl.z);
xr_sprintf(selectable, "fire_point = %f,%f,%f\n", new_measures.m_fire_point2_offset.x, new_measures.m_fire_point2_offset.y, new_measures.m_fire_point2_offset.z);
ImGui::LogText(selectable);
xr_sprintf(selectable, "gl_hud_offset_rot%s = %f,%f,%f\n", (is_16x9) ? "_16x9" : "", new_hand_rot_offset_gl.x, new_hand_rot_offset_gl.y, new_hand_rot_offset_gl.z);
xr_sprintf(selectable, "shell_point = %f,%f,%f\n", new_measures.m_shell_point_offset.x, new_measures.m_shell_point_offset.y, new_measures.m_shell_point_offset.z);
ImGui::LogText(selectable);
ImGui::LogFinish();
}
Expand Down Expand Up @@ -236,7 +195,7 @@ void CHudTuner::OnFrame()
current_hud_item->m_parent_hud_item->TransformPosFromWorldToHud(point);
render.draw_aabb(point, debug_point_size, debug_point_size, debug_point_size, color_xrgb(255, 0, 0));
}

if (draw_fp2)
{
Fvector point;
Expand Down
32 changes: 4 additions & 28 deletions src/xrGame/player_hud_tune.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "player_hud.h"

class CHudTuner final : public xray::editor::ide_tool
{
public:
Expand All @@ -11,7 +13,6 @@ class CHudTuner final : public xray::editor::ide_tool
private:
pcstr tool_name() override { return "Hud Tuner"; }

void SetDefaultValues();
void ResetToDefaultValues();
void UpdateValues();

Expand Down Expand Up @@ -68,31 +69,6 @@ class CHudTuner final : public xray::editor::ide_tool
attachable_hud_item* current_hud_item{};
hud_item_idx current_hud_idx{ MAIN_ITEM };

Fvector curr_hand_pos{};
Fvector curr_hand_rot{};
Fvector curr_hand_pos_offset{};
Fvector curr_hand_rot_offset{};
Fvector curr_hand_pos_offset_aim{};
Fvector curr_hand_rot_offset_aim{};
Fvector curr_hand_pos_offset_gl{};
Fvector curr_hand_rot_offset_gl{};
Fvector curr_item_attach_pos_offset{};
Fvector curr_item_attach_rot_offset{};
Fvector curr_fire_point_offset{};
Fvector curr_fire_point_2_offset{};
Fvector curr_shell_point_offset{};

Fvector new_hand_pos{};
Fvector new_hand_rot{};
Fvector new_hand_pos_offset{};
Fvector new_hand_rot_offset{};
Fvector new_hand_pos_offset_aim{};
Fvector new_hand_rot_offset_aim{};
Fvector new_hand_pos_offset_gl{};
Fvector new_hand_rot_offset_gl{};
Fvector new_item_attach_pos_offset{};
Fvector new_item_attach_rot_offset{};
Fvector new_fire_point_offset{};
Fvector new_fire_point_2_offset{};
Fvector new_shell_point_offset{};
hud_item_measures curr_measures{};
hud_item_measures new_measures{};
};

0 comments on commit f6ce30b

Please sign in to comment.