Skip to content

Commit

Permalink
ADD: weapon manager improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1t3lord committed Sep 20, 2024
1 parent 9f5fdda commit 12ded06
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 10 deletions.
86 changes: 76 additions & 10 deletions src/xrGame/ImUtils/WeaponManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct
bool can_show_inv_grid_y{};
bool can_show_inv_grid_width{};
bool can_show_inv_grid_height{};
bool can_show_silencer_x{};
bool can_show_silencer_y{};

bool can_show_modal_icon_selection_window{};

Expand Down Expand Up @@ -134,6 +136,12 @@ struct
int inv_grid_y{};
u32 cfg_inv_grid_y{};

int silencer_x{};
int cfg_silencer_x{};

int silencer_y{};
int cfg_silencer_y{};

size_t icons_count{};

Fvector4 hit_power;
Expand Down Expand Up @@ -190,7 +198,7 @@ void RenderWeaponManagerWindow()
if (!imgui_weapon_manager.init)
{
// clear bool flags that line_exist checking for correct init/uninit cycle
memset((&imgui_weapon_manager.init + sizeof(imgui_weapon_manager.init)), 0, 31);
memset((&imgui_weapon_manager.init + sizeof(imgui_weapon_manager.init)), 0, 33);

imgui_weapon_manager.current_slot = slot_type;
imgui_weapon_manager.weapon_id = pItem->object_id();
Expand All @@ -202,7 +210,7 @@ void RenderWeaponManagerWindow()
imgui_weapon_manager.inv_grid_y = pItem->GetInvGridRect().y1;
imgui_weapon_manager.inv_grid_width = pItem->GetInvGridRect().x2;
imgui_weapon_manager.inv_grid_height = pItem->GetInvGridRect().y2;

if (Render)
{
imgui_weapon_manager.ui_icons = Render->getSurface("ui\\ui_icon_equipment");
Expand All @@ -229,6 +237,8 @@ void RenderWeaponManagerWindow()
imgui_weapon_manager.upgrade_disp_crouch = pWeapon->Get_PDM_Crouch();
imgui_weapon_manager.upgrade_disp_crouch_no_acc = pWeapon->Get_PDM_Crouch_NA();
imgui_weapon_manager.fire_dispersion_condition_factor = pWeapon->getFireDispersionConditionFactor();
imgui_weapon_manager.silencer_x = pWeapon->GetSilencerX();
imgui_weapon_manager.silencer_y = pWeapon->GetSilencerY();
}

// icons
Expand Down Expand Up @@ -469,6 +479,24 @@ void RenderWeaponManagerWindow()
imgui_weapon_manager.can_show_inv_grid_height = true;
imgui_weapon_manager.cfg_inv_grid_height = pSettings->r_u32(pSectionName, "inv_grid_height");
}

if (pSettings->line_exist(pSectionName, "silencer_x"))
{
if (pWeapon)
{
imgui_weapon_manager.can_show_silencer_x = true;
imgui_weapon_manager.cfg_silencer_x = pSettings->r_s32(pSectionName, "silencer_x");
}
}

if (pSettings->line_exist(pSectionName, "silencer_y"))
{
if (pWeapon)
{
imgui_weapon_manager.can_show_silencer_y = true;
imgui_weapon_manager.cfg_silencer_y = pSettings->r_s32(pSectionName, "silencer_y");
}
}
}
}

Expand All @@ -495,15 +523,31 @@ void RenderWeaponManagerWindow()
ImGui::Text("Grid Width: %d", pItem->GetInvGridRect().x2);
ImGui::Text("Grid Height: %d", pItem->GetInvGridRect().y2);


if (imgui_weapon_manager.ui_icons.Surface != nullptr)
{
float x = imgui_weapon_manager.inv_grid_x * INV_GRID_WIDTH(isHQIcons);
float y = imgui_weapon_manager.inv_grid_y * INV_GRID_HEIGHT(isHQIcons);
float w = imgui_weapon_manager.inv_grid_width * INV_GRID_WIDTH(isHQIcons);
float h = imgui_weapon_manager.inv_grid_height * INV_GRID_HEIGHT(isHQIcons);

ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.f, 0.f, 0.f, 0.f));

ImGui::ImageButton("WeaponIconInWeaponManager", imgui_weapon_manager.ui_icons.Surface, { w,h }, { x / imgui_weapon_manager.ui_icons.w, y / imgui_weapon_manager.ui_icons.h }, { (x + w) / imgui_weapon_manager.ui_icons.w, (y + h) / imgui_weapon_manager.ui_icons.h });

ImGui::PopStyleColor(3);
}

if (ImGui::TreeNode("Addons"))
{
if (pWeapon)
{
ImGui::Text("Silencer X: %d", pWeapon->GetSilencerX());
ImGui::Text("Silencer Y: %d", pWeapon->GetSilencerY());
}

ImGui::TreePop();
}


Expand Down Expand Up @@ -623,7 +667,7 @@ void RenderWeaponManagerWindow()

static_assert(kWeaponManagerTableColumnSize > 0 && "specify positive number");

if (ImGui::BeginTable("icons##Editing_WeaponManager", kWeaponManagerTableColumnSize))
if (ImGui::BeginTable("icons##Editing_WeaponManager", kWeaponManagerTableColumnSize, ImGuiTableFlags_Borders))
{
int row_max = std::ceil(imgui_weapon_manager.icons_count / kWeaponManagerTableColumnSize);
R_ASSERT(row_max > 0 && "something is wrong");
Expand Down Expand Up @@ -687,12 +731,6 @@ void RenderWeaponManagerWindow()
ImGui::EndTable();
}

if (ImGui::Button("Close##SelectIcon_Editing_WeaponManager"))
{
imgui_weapon_manager.can_show_modal_icon_selection_window = false;
ImGui::CloseCurrentPopup();
}

ImGui::EndPopup();
}

Expand Down Expand Up @@ -723,6 +761,8 @@ void RenderWeaponManagerWindow()
imgui_weapon_manager.inv_grid_width = imgui_weapon_manager.cfg_inv_grid_width;
imgui_weapon_manager.inv_grid_x = imgui_weapon_manager.cfg_inv_grid_x;
imgui_weapon_manager.inv_grid_y = imgui_weapon_manager.cfg_inv_grid_y;
imgui_weapon_manager.silencer_x = imgui_weapon_manager.cfg_silencer_x;
imgui_weapon_manager.silencer_y = imgui_weapon_manager.cfg_silencer_y;

if (pItem)
{
Expand Down Expand Up @@ -825,6 +865,32 @@ void RenderWeaponManagerWindow()
}
}

if (ImGui::TreeNode("Addons"))
{
if (imgui_weapon_manager.can_show_silencer_x)
{
if (ImGui::SliderInt("Silencer X##Editing", &imgui_weapon_manager.silencer_x, -4096, 4096, "%d", flags))
{
if (pWeapon)
{
pWeapon->SetSilencerX(imgui_weapon_manager.silencer_x);
}
}
}
if (imgui_weapon_manager.can_show_silencer_y)
{
if (ImGui::SliderInt("Silencer Y##Editing", &imgui_weapon_manager.silencer_y, -4096, 4096, "%d", flags))
{
if (pWeapon)
{
pWeapon->SetSilencerY(imgui_weapon_manager.silencer_y);
}
}
}

ImGui::TreePop();
}

ImGui::TreePop();
}

Expand Down
10 changes: 10 additions & 0 deletions src/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,16 @@ void CWeapon::OnAnimationEnd(u32 state)
inherited::OnAnimationEnd(state);
}

void CWeapon::SetSilencerX(int value)
{
m_iSilencerX = value;
}

void CWeapon::SetSilencerY(int value)
{
m_iSilencerY = value;
}

bool CWeapon::NeedBlockSprint() const
{
const static bool isBlockSprintInReload = EngineExternal()[EEngineExternalGame::EnableBlockSprintInReload];
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class CWeapon : public CHudItemObject,

int GetSilencerX() {return m_iSilencerX;}
int GetSilencerY() {return m_iSilencerY;}
void SetSilencerX(int value);
void SetSilencerY(int value);
int GetGrenadeLauncherX() {return m_iGrenadeLauncherX;}
int GetGrenadeLauncherY() {return m_iGrenadeLauncherY;}

Expand Down
5 changes: 5 additions & 0 deletions src/xrGame/ui/UIActorMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ void CUIActorMenu::SetInvBox(CInventoryBox* box)
}
}

const CUIDragDropListEx* CUIActorMenu::GetSlotList(u16 slot_idx) const
{
return GetSlotList(slot_idx);
}

void CUIActorMenu::SetMenuMode(EMenuMode mode)
{
SetCurrentItem( nullptr );
Expand Down
3 changes: 3 additions & 0 deletions src/xrGame/ui/UIActorMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ class CUIActorMenu : public CUIDialogWnd,
CInventoryOwner* GetPartner () {return m_pPartnerInvOwner;};
void SetInvBox (CInventoryBox* box);
CInventoryBox* GetInvBox () {return m_pInvBox;};

const CUIDragDropListEx* GetSlotList(u16 slot_idx) const;

private:
void PropertiesBoxForSlots (PIItem item, bool& b_show);
void PropertiesBoxForWeapon (CUICellItem* cell_item, PIItem item, bool& b_show);
Expand Down

0 comments on commit 12ded06

Please sign in to comment.