Skip to content

Commit

Permalink
[feature][cleanup]
Browse files Browse the repository at this point in the history
* added: config for arrow slot (scaling, offset, ...)
* added: arrow/bolt name if bow/crossbow is equipped to current items
* adjusted: default config
* added: config how many arrow/bolt types are max looked for in the
  inventory, highest dmg first (can be scrolled with left key)
* fixed: bolts and arrows will just be assigned to the correct weapon
  type
* cleanup: in theory the non souls mode should work as well
* fixed: after exit of the mcm the first setting of left and right will
  be executed (and should work now correctly)
  • Loading branch information
mlthelama committed Jan 24, 2023
1 parent 11b30cc commit d26472a
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 140 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.20)

set(NAME "LamasTinyHUD" CACHE STRING "")
set(VERSION 1.0.8.0 CACHE STRING "")
set(VERSION 1.0.8.1 CACHE STRING "")

# ---- Options ----

Expand Down
119 changes: 118 additions & 1 deletion mcm/Config/LamasTinyHUD/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,58 @@
"sourceType": "ModSettingFloat"
}
},
{
"id": "fHudArrowImageScaleWidth:HudSetting",
"text": "$LamasTinyHUD_HudSetting_ArrowHudImageScaleWidth_OptionText",
"type": "slider",
"help": "$LamasTinyHUD_HudSetting_ArrowHudImageScaleWidth_InfoText",
"valueOptions": {
"min": 0.02,
"max": 5.0,
"step": 0.01,
"formatString": "{2}",
"sourceType": "ModSettingFloat"
}
},
{
"id": "fHudArrowImageScaleHeight:HudSetting",
"text": "$LamasTinyHUD_HudSetting_ArrowHudImageScaleHeight_OptionText",
"type": "slider",
"help": "$LamasTinyHUD_HudSetting_ArrowHudImageScaleHeight_InfoText",
"valueOptions": {
"min": 0.02,
"max": 5.0,
"step": 0.01,
"formatString": "{2}",
"sourceType": "ModSettingFloat"
}
},
{
"id": "fArrowIconScaleWidth:HudSetting",
"text": "$LamasTinyHUD_HudSetting_ArrowIconScaleWidth_OptionText",
"type": "slider",
"help": "$LamasTinyHUD_HudSetting_ArrowIconScaleWidth_InfoText",
"valueOptions": {
"min": 0.01,
"max": 2.0,
"step": 0.01,
"formatString": "{2}",
"sourceType": "ModSettingFloat"
}
},
{
"id": "fArrowIconScaleHeight:HudSetting",
"text": "$LamasTinyHUD_HudSetting_ArrowIconScaleHeight_OptionText",
"type": "slider",
"help": "$LamasTinyHUD_HudSetting_ArrowIconScaleHeight_InfoText",
"valueOptions": {
"min": 0.01,
"max": 2.0,
"step": 0.01,
"formatString": "{2}",
"sourceType": "ModSettingFloat"
}
},
{
"text": "$LamasTinyHUD_HudSetting_HeaderText_Offset",
"type": "header",
Expand Down Expand Up @@ -607,6 +659,45 @@
"formatString": "{0}",
"sourceType": "ModSettingFloat"
}
},
{
"id": "fArrowSlotOffsetX:HudSetting",
"text": "$LamasTinyHUD_HudSetting_ArrowSlotOffsetX_OptionText",
"type": "slider",
"help": "$LamasTinyHUD_HudSetting_ArrowSlotOffsetX_InfoText",
"valueOptions": {
"min": -500.0,
"max": 500.0,
"step": 1.0,
"formatString": "{0}",
"sourceType": "ModSettingFloat"
}
},
{
"id": "fArrowSlotOffsetY:HudSetting",
"text": "$LamasTinyHUD_HudSetting_ArrowSlotOffsetY_OptionText",
"type": "slider",
"help": "$LamasTinyHUD_HudSetting_ArrowSlotOffsetY_InfoText",
"valueOptions": {
"min": -500.0,
"max": 500.0,
"step": 1.0,
"formatString": "{0}",
"sourceType": "ModSettingFloat"
}
},
{
"id": "fArrowSlotCountTextOffset:HudSetting",
"text": "$LamasTinyHUD_HudSetting_ArrowSlotCountTextOffset_OptionText",
"type": "slider",
"help": "$LamasTinyHUD_HudSetting_ArrowSlotCountTextOffset_InfoText",
"valueOptions": {
"min": 0.0,
"max": 10.0,
"step": 0.5,
"formatString": "{1}",
"sourceType": "ModSettingFloat"
}
}
]
},
Expand Down Expand Up @@ -696,7 +787,7 @@
}
},
{
"text": "$LamasTinyHUD_GraphicSetting_Font_Color",
"text": "$LamasTinyHUD_GraphicSetting_HeaderText_Font",
"type": "header"
},
{
Expand Down Expand Up @@ -725,6 +816,19 @@
"sourceType": "ModSettingFloat"
}
},
{
"id": "fArrowCountFontSize:GraphicSetting",
"text": "$LamasTinyHUD_GraphicSetting_ArrowCountFontSize_OptionText",
"type": "slider",
"help": "$LamasTinyHUD_GraphicSetting_ArrowCountFontSize_InfoText",
"valueOptions": {
"min": 10.0,
"max": 35.0,
"step": 1.0,
"formatString": "{0}",
"sourceType": "ModSettingFloat"
}
},
{
"text": "$LamasTinyHUD_GraphicSetting_HeaderText_Color",
"type": "header",
Expand Down Expand Up @@ -913,6 +1017,19 @@
"formatString": "{0}",
"sourceType": "ModSettingInt"
}
},
{
"id": "uMaxAmmunitionType:MiscSetting",
"text": "$LamasTinyHUD_MiscSetting_MaxAmmunitionType_OptionText",
"type": "slider",
"help": "$LamasTinyHUD_MiscSetting_MaxAmmunitionType_InfoText",
"valueOptions": {
"min": 2,
"max": 6,
"step": 1,
"formatString": "{0}",
"sourceType": "ModSettingInt"
}
}
]
}
Expand Down
43 changes: 26 additions & 17 deletions mcm/Config/LamasTinyHUD/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,30 @@ sResetSlot =
[HudSetting]
sDisplayResolutionWidth =
sDisplayResolutionHeight =
fHudImageScaleWidth = 0.230000
fHudImageScaleHeight = 0.230000
fHudImagePositionWidth = 140.000000
fHudImagePositionHeight = 140.000000
fHudSlotPositionOffset = 105.000000
fHudKeyPositionOffset = 38.000000
fKeyIconScaleWidth = 0.380000
fKeyIconScaleHeight = 0.380000
fIconScaleWidth = 0.100000
fIconScaleHeight = 0.100000
fHudImageScaleWidth = 0.23
fHudImageScaleHeight = 0.23
fHudImagePositionWidth = 200
fHudImagePositionHeight = 775
fHudSlotPositionOffset = 105
fHudKeyPositionOffset = 38
fKeyIconScaleWidth = 0.38
fKeyIconScaleHeight = 0.38
fIconScaleWidth = 0.1
fIconScaleHeight = 0.1
fSlotCountTextOffset = 20
fToggleKeyOffsetX = 115
fToggleKeyOffsetY = 115
fCurrentItemsOffsetX = -400.000000
fCurrentItemsOffsetY = 130.000000
fSlotItemNameOffsetX = -65
fCurrentItemsOffsetX = -45
fCurrentItemsOffsetY = 200
fSlotItemNameOffsetX = -45
fSlotItemNameOffsetY = 65
fArrowSlotOffsetX = -115
fArrowSlotOffsetY = 115
fHudArrowImageScaleWidth = 0.13
fHudArrowImageScaleHeight = 0.13
fArrowIconScaleWidth = 0.05
fArrowIconScaleHeight = 0.05
fArrowSlotCountTextOffset = 12

[GraphicSetting]
uBackgroundTransparency = 255
Expand All @@ -60,15 +67,17 @@ uSlotCountRed = 255
uSlotCountGreen = 255
uSlotCountBlue = 255
fSlotCountTextFontSize = 20
fCurrentItemsFontSize = 20.000000
fCurrentItemsFontSize = 20
uSlotButtonFeedback = 175
bDrawCurrentItemsText = 0
bDrawCurrentItemsText = 1
fArrowCountFontSize = 20

[MiscSetting]
bActionCheck = 0
bEmptyHandSetting = 1
bEmptyHandSetting = 0
bHideOutsideCombat = 0
fFadeTimerOutsideCombat = 5
bDisableInputQuickLoot = 0
bElderDemonSouls = 1
uMaxPageCount = 4
uMaxPageCount = 4
uMaxAmmunitionType = 3
Binary file modified mcm/Interface/Translations/LamasTinyHUD_english.txt
Binary file not shown.
4 changes: 2 additions & 2 deletions src/equip/equip_slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace equip {
return is_worn;
}

void equip_slot::un_equip_hand(const RE::BGSEquipSlot* a_slot,
void equip_slot::un_equip_hand(RE::BGSEquipSlot*& a_slot,
RE::PlayerCharacter*& a_player,
const action_type a_action) {
if (a_action != handle::slot_setting::acton_type::un_equip) {
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace equip {
}
}

void equip_slot::un_equip_object_ft_dummy_dagger(const RE::BGSEquipSlot*& a_slot,
void equip_slot::un_equip_object_ft_dummy_dagger(RE::BGSEquipSlot*& a_slot,
RE::PlayerCharacter*& a_player,
RE::ActorEquipManager*& a_actor_equip_manager) {
const auto dummy = RE::TESForm::LookupByID<RE::TESForm>(0x00020163)->As<RE::TESObjectWEAP>();
Expand Down
4 changes: 2 additions & 2 deletions src/equip/equip_slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace equip {
RE::PlayerCharacter*& a_player,
RE::ActorEquipManager*& a_actor_equip_manager);

static void un_equip_hand(const RE::BGSEquipSlot* a_slot, RE::PlayerCharacter*& a_player, action_type a_action);
static void un_equip_object_ft_dummy_dagger(const RE::BGSEquipSlot*& a_slot,
static void un_equip_hand(RE::BGSEquipSlot*& a_slot, RE::PlayerCharacter*& a_player, action_type a_action);
static void un_equip_object_ft_dummy_dagger(RE::BGSEquipSlot*& a_slot,
RE::PlayerCharacter*& a_player,
RE::ActorEquipManager*& a_actor_equip_manager);

Expand Down
7 changes: 6 additions & 1 deletion src/equip/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace equip {
}

void item::equip_weapon_or_shield(const RE::TESForm* a_form,
const RE::BGSEquipSlot* a_slot,
RE::BGSEquipSlot*& a_slot,
RE::PlayerCharacter*& a_player,
const bool a_weapon) {
auto left = a_slot == equip_slot::get_left_hand_slot();
Expand Down Expand Up @@ -194,6 +194,11 @@ namespace equip {
return;
}

if (const auto current_ammo = a_player->GetCurrentAmmo(); current_ammo && current_ammo->formID == obj->formID) {
logger::debug("Ammo {} already equipped, return."sv, obj->GetName());
return;
}

const auto equip_manager = RE::ActorEquipManager::GetSingleton();
equip_manager->EquipObject(a_player, obj);
logger::trace("equipped {}. return."sv, obj->GetName());
Expand Down
2 changes: 1 addition & 1 deletion src/equip/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace equip {
static bool is_item_worn(RE::TESBoundObject*& a_obj, RE::PlayerCharacter*& a_player);

static void equip_weapon_or_shield(const RE::TESForm* a_form,
const RE::BGSEquipSlot* a_slot,
RE::BGSEquipSlot*& a_slot,
RE::PlayerCharacter*& a_player,
bool a_weapon = true);

Expand Down
64 changes: 36 additions & 28 deletions src/event/equip_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,14 @@ namespace event {
return event_result::kContinue;
}

if (config::mcm_setting::get_draw_current_items_text() && (form->IsWeapon() || form->Is(RE::FormType::Spell))) {
if (config::mcm_setting::get_draw_current_items_text() && (
form->IsWeapon() || form->Is(RE::FormType::Spell) || form->IsAmmo())) {
handle::name_handle::get_singleton()->init_names(util::helper::get_hand_assignment());
}

//add check if we need to block left
if (config::mcm_setting::get_elden_demon_souls() && util::helper::is_two_handed(form)) {
//is two handed, if equipped
//hardcode left for now, cause we just need it there
const auto key_handle = handle::key_position_handle::get_singleton();
key_handle->set_position_lock(handle::position_setting::position_type::left, a_event->equipped ? 1 : 0);
const auto page_handle = handle::page_handle::get_singleton();
const auto page = page_handle->get_active_page_id_position(handle::position_setting::position_type::left);
const auto setting = page_handle->get_page_setting(page, handle::position_setting::position_type::left);
//use settings here
setting->draw_setting->icon_transparency = a_event->equipped ?
config::mcm_setting::get_icon_transparency_blocked() :
config::mcm_setting::get_icon_transparency();
//check if bow or crossbow, now we look for ammo that is in the favor list
if (a_event->equipped && form->Is(RE::FormType::Weapon)) {
if (const auto weapon = form->As<RE::TESObjectWEAP>(); weapon->IsBow() || weapon->IsCrossbow()) {
look_for_ammo(weapon->IsCrossbow());
if (const auto next_ammo = handle::ammo_handle::get_singleton()->get_next_ammo()) {
handle::setting_execute::execute_ammo(next_ammo);
}
}
} else {
handle::ammo_handle::get_singleton()->clear_ammo();
}
check_if_location_needs_block(form, a_event->equipped);
}

if (handle::edit_handle::get_singleton()->get_position() == handle::position_setting::position_type::total) {
Expand Down Expand Up @@ -125,7 +105,7 @@ namespace event {
RE::PlayerCharacter::GetSingleton()->AddObjectToContainer(obj, nullptr, 1, nullptr);
}


for (const auto data_item : data_) {
util::helper::write_notification(fmt::format("Name {}, Type {}, Action {}, Left {}",
data_item->form ? data_item->form->GetName() : "null",
Expand Down Expand Up @@ -186,17 +166,17 @@ namespace event {
}

void equip_event::look_for_ammo(const bool a_crossbow) {
auto max_items = 3;
const auto max_items = config::mcm_setting::get_max_ammunition_type();
auto player = RE::PlayerCharacter::GetSingleton();
const auto inv = equip::item::get_inventory(player, RE::FormType::Ammo);
std::multimap<uint32_t, handle::ammo_data*, std::greater<>> ammo_list;
for (const auto& [item, inv_data] : inv) {
const auto& [num_items, entry] = inv_data;
const auto ammo = item->As<RE::TESAmmo>();
if (!ammo->GetPlayable()) {
if (!ammo->GetPlayable() || ammo->GetRuntimeData().data.flags.any(RE::AMMO_DATA::Flag::kNonPlayable)) {
continue;
}
if (a_crossbow && ammo->IsBolt() && num_items != 0) {
if (a_crossbow && ammo->GetRuntimeData().data.flags.none(RE::AMMO_DATA::Flag::kNonBolt) && num_items != 0) {
logger::trace("found bolt {}, damage {}, count {}"sv,
ammo->GetName(),
ammo->GetRuntimeData().data.damage,
Expand All @@ -205,7 +185,8 @@ namespace event {
ammo_data->form = ammo;
ammo_data->item_count = num_items;
ammo_list.insert({ static_cast<uint32_t>(ammo->GetRuntimeData().data.damage), ammo_data });
} else if (num_items != 0) {
} else if (!a_crossbow && num_items != 0 && ammo->GetRuntimeData().data.flags.all(
RE::AMMO_DATA::Flag::kNonBolt)) {
logger::trace("found arrow {}, damage {}, count {}"sv,
ammo->GetName(),
ammo->GetRuntimeData().data.damage,
Expand All @@ -228,4 +209,31 @@ namespace event {
ammo_list.clear();
ammo_handle->init_ammo(sorted_ammo);
}

void equip_event::check_if_location_needs_block(RE::TESForm*& a_form, const bool a_equipped) {
//is two handed, if equipped
//hardcode left for now, cause we just need it there
const auto key_handle = handle::key_position_handle::get_singleton();
key_handle->set_position_lock(handle::position_setting::position_type::left, a_equipped ? 1 : 0);
const auto page_handle = handle::page_handle::get_singleton();
const auto page = page_handle->get_active_page_id_position(handle::position_setting::position_type::left);
const auto setting = page_handle->get_page_setting(page, handle::position_setting::position_type::left);
//use settings here
if (setting && setting->draw_setting && setting->draw_setting->icon_transparency) {
setting->draw_setting->icon_transparency = a_equipped ?
config::mcm_setting::get_icon_transparency_blocked() :
config::mcm_setting::get_icon_transparency();
}
//check if bow or crossbow, now we look for ammo that is in the favor list
if (a_equipped && a_form->Is(RE::FormType::Weapon)) {
if (const auto weapon = a_form->As<RE::TESObjectWEAP>(); weapon->IsBow() || weapon->IsCrossbow()) {
look_for_ammo(weapon->IsCrossbow());
if (const auto next_ammo = handle::ammo_handle::get_singleton()->get_next_ammo()) {
handle::setting_execute::execute_ammo(next_ammo);
}
}
} else {
handle::ammo_handle::get_singleton()->clear_ammo();
}
}
}
Loading

0 comments on commit d26472a

Please sign in to comment.