Skip to content

Commit

Permalink
[feature]
Browse files Browse the repository at this point in the history
* added: better filtering for "Pages", allow filtering of "Postion"
  • Loading branch information
mlthelama committed Jan 26, 2023
1 parent da96779 commit f1428af
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 64 deletions.
14 changes: 14 additions & 0 deletions mcm/Config/LamasTinyHUD/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@
"propertyName": "bSpellLeft"
}
},
{
"id": "uPositionSelect:Page",
"text": "$LamasTinyHUD_PositionSelect_OptionText",
"type": "enum",
"help": "$LamasTinyHUD_PositionSelect_InfoText",
"valueOptions": {
"options": ["$LamasTinyHUD_Controls_Config_Top", "$LamasTinyHUD_Controls_Config_Right", "$LamasTinyHUD_Controls_Config_Bottom", "$LamasTinyHUD_Controls_Config_Left", "$LamasTinyHUD_Controls_Config_All"],
"sourceType": "ModSettingInt",
"defaultValue": 0
}
},
{
"id": "uPageList:Page",
"text": "$LamasTinyHUD_PageList",
Expand Down Expand Up @@ -306,6 +317,9 @@
{
"type": "empty"
},
{
"type": "empty"
},
{
"text": "$LamasTinyHUD_Pages_Left",
"type": "header"
Expand Down
1 change: 1 addition & 0 deletions mcm/Config/LamasTinyHUD/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sTriggerConfig =
fMasterScale = 1

[Page]
uPositionSelect = 4
uPageList = 0
sPage =
sPosition =
Expand Down
Binary file modified mcm/Interface/Translations/LamasTinyHUD_english.txt
Binary file not shown.
Binary file modified mcm/scripts/LamasTinyHUD_MCM.pex
Binary file not shown.
58 changes: 32 additions & 26 deletions mcm/source/Scripts/LamasTinyHUD_MCM.psc
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ Event OnConfigClose() native
string function GetResolutionWidth() native
string function GetResolutionHeight() native

string[] function GetSectionNames() native
string function GetPage(int a_index) native
string function GetPosition(int a_index) native
int function GetSelectionType(int a_index, bool a_left) native
string function GetFormString(int a_index, bool a_left) native
int function GetSlotAction(int a_index, bool a_left) native
int function GetHandSelection(int a_index) native
string function GetFormName(int a_index, bool a_left) native
function ResetSection(int a_index) native
function SetActionValue(int a_index, bool a_left, int a_value) native
string[] function GetSectionNames(int a_position) native
string function GetPage(int a_index, int a_position) native
string function GetPosition(int a_index, int a_position) native
int function GetSelectionType(int a_index, bool a_left, int a_position) native
string function GetFormString(int a_index, bool a_left, int a_position) native
int function GetSlotAction(int a_index, bool a_left, int a_position) native
int function GetHandSelection(int a_index, int a_position) native
string function GetFormName(int a_index, bool a_left, int a_position) native
function ResetSection(int a_index, int a_position) native
function SetActionValue(int a_index, bool a_left, int a_value, int a_position) native
function InitConfigForPosition(int a_position) native

function ResetSlot()
ResetSection(GetModSettingInt("uPageList:Page"))
string[] menu_list = GetSectionNames()
ResetSection(GetModSettingInt("uPageList:Page"), GetModSettingInt("uPositionSelect:Page"))
string[] menu_list = GetSectionNames(GetModSettingInt("uPositionSelect:Page"))
SetMenuOptions("uPageList:Page", menu_list, menu_list)
SetModSettingInt("uPageList:Page", 0)
RefreshMenu()
Expand All @@ -37,10 +37,11 @@ endfunction
Event OnSettingChange(String a_ID)
if (a_ID == "uPageList:Page")
int idx = GetModSettingInt(a_ID)
int position = GetModSettingInt("uPositionSelect:Page")

SetModSettingString("sPage:Page", GetPage(idx))
SetModSettingString("sPosition:Page", GetPosition(idx))
int type = GetSelectionType(idx, false)
SetModSettingString("sPage:Page", GetPage(idx, position))
SetModSettingString("sPosition:Page", GetPosition(idx, position))
int type = GetSelectionType(idx, false, position)
if (type < 0)
SetModSettingInt("uType:Page", 0)
else
Expand All @@ -49,42 +50,47 @@ Event OnSettingChange(String a_ID)
;magic, power, scroll, empty (to allow if something should be unequiped)
bSpell = (type == 1) || (type == 4) || (type == 7) || (type == 8)

SetModSettingInt("uHandSelection:Page", GetHandSelection(idx))
SetModSettingInt("uSlotAction:Page", GetSlotAction(idx, false))
SetModSettingString("sFormName:Page", GetFormName(idx, false))
SetModSettingString("sSelectedItemForm:Page", GetFormString(idx, false))
SetModSettingInt("uHandSelection:Page", GetHandSelection(idx, position))
SetModSettingInt("uSlotAction:Page", GetSlotAction(idx, false, position))
SetModSettingString("sFormName:Page", GetFormName(idx, false, position))
SetModSettingString("sSelectedItemForm:Page", GetFormString(idx, false, position))

type = GetSelectionType(idx, true)
type = GetSelectionType(idx, true, position)
bSpellLeft = (type == 1) || (type == 8)
if (type < 0)
SetModSettingInt("uTypeLeft:Page", 0)
else
SetModSettingInt("uTypeLeft:Page", type)
endif

SetModSettingInt("uSlotActionLeft:Page", GetSlotAction(idx, true))
SetModSettingString("sFormNameLeft:Page", GetFormName(idx, true))
SetModSettingString("sSelectedItemFormLeft:Page", GetFormString(idx, true))
SetModSettingInt("uSlotActionLeft:Page", GetSlotAction(idx, true, position))
SetModSettingString("sFormNameLeft:Page", GetFormName(idx, true, position))
SetModSettingString("sSelectedItemFormLeft:Page", GetFormString(idx, true, position))

RefreshMenu()

elseif (a_ID == "uSlotAction:Page")
int value = GetModSettingInt(a_ID)
SetActionValue(GetModSettingInt("uPageList:Page"), False, value)
SetActionValue(GetModSettingInt("uPageList:Page"), False, value, GetModSettingInt("uPositionSelect:Page"))
RefreshMenu()
elseif (a_ID == "uSlotActionLeft:Page")
int value = GetModSettingInt(a_ID)
SetActionValue(GetModSettingInt("uPageList:Page"), True, value)
SetActionValue(GetModSettingInt("uPageList:Page"), True, value, GetModSettingInt("uPositionSelect:Page"))
RefreshMenu()
elseif (a_ID == "bEldenDemonSouls:MiscSetting")
bElden = GetModSettingBool(a_ID)
RefreshMenu()
elseif(a_ID == "uPositionSelect:Page")
string[] menu_list = GetSectionNames(GetModSettingInt(a_ID))
SetMenuOptions("uPageList:Page", menu_list, menu_list)
SetModSettingInt("uPageList:Page", 0)
RefreshMenu()
endif
EndEvent

Event OnPageSelect(string a_page)
if ( a_page == "$LamasTinyHUD_Pages")
string[] menu_list = GetSectionNames()
string[] menu_list = GetSectionNames(GetModSettingInt("uPositionSelect:Page"))
SetMenuOptions("uPageList:Page", menu_list, menu_list)
RefreshMenu()
elseif ( a_page == "$LamasTinyHUD_HudSetting" )
Expand Down
53 changes: 30 additions & 23 deletions src/papyrus/papyrus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,36 @@ namespace papyrus {
return fmt::format(FMT_STRING("{:.2f}"), ui::ui_renderer::get_resolution_height());
}

std::vector<RE::BSFixedString> hud_mcm::get_section_names(RE::TESQuest*) {
const auto sections = util::helper::get_configured_section_page_names();
std::vector<RE::BSFixedString> hud_mcm::get_section_names(RE::TESQuest*, uint32_t a_position) {
const auto sections = util::helper::get_configured_section_page_names(a_position);
std::vector<RE::BSFixedString> sections_bs_string;
for (const auto& section : sections) {
sections_bs_string.emplace_back(section);
}
logger::trace("Returning {} sections"sv, sections_bs_string.size());
logger::trace("Returning {} sections for Position {}"sv, sections_bs_string.size(), a_position);
return sections_bs_string;
}

RE::BSFixedString hud_mcm::get_page(RE::TESQuest*, const uint32_t a_index) {
RE::BSFixedString hud_mcm::get_page(RE::TESQuest*, const uint32_t a_index, uint32_t a_position) {
logger::trace("page was requested for index {}"sv, a_index);
if (const auto section = get_section_by_index(a_index); !section.empty()) {
if (const auto section = get_section_by_index(a_index, a_position); !section.empty()) {
return std::to_string(config::custom_setting::get_page_by_section(section));
}
return "";
}

RE::BSFixedString hud_mcm::get_position(RE::TESQuest*, const uint32_t a_index) {
RE::BSFixedString hud_mcm::get_position(RE::TESQuest*, const uint32_t a_index, uint32_t a_position) {
logger::trace("position was requested for index {}"sv, a_index);
if (const auto section = get_section_by_index(a_index); !section.empty()) {
if (const auto section = get_section_by_index(a_index, a_position); !section.empty()) {
return std::to_string(config::custom_setting::get_position_by_section(section));
}
return "";
}

uint32_t hud_mcm::get_selection_type(RE::TESQuest*, const uint32_t a_index, const bool a_left) {
uint32_t
hud_mcm::get_selection_type(RE::TESQuest*, const uint32_t a_index, const bool a_left, uint32_t a_position) {
uint32_t type = 0;
if (const auto section = get_section_by_index(a_index); !section.empty()) {
if (const auto section = get_section_by_index(a_index, a_position); !section.empty()) {
if (a_left) {
type = config::custom_setting::get_type_left_by_section(section);
} else {
Expand All @@ -71,9 +72,10 @@ namespace papyrus {
return type;
}

RE::BSFixedString hud_mcm::get_form_string(RE::TESQuest*, const uint32_t a_index, const bool a_left) {
RE::BSFixedString
hud_mcm::get_form_string(RE::TESQuest*, const uint32_t a_index, const bool a_left, uint32_t a_position) {
std::string form_string;
if (const auto section = get_section_by_index(a_index); !section.empty()) {
if (const auto section = get_section_by_index(a_index, a_position); !section.empty()) {
if (a_left) {
form_string = config::custom_setting::get_item_form_left_by_section(section);
} else {
Expand All @@ -83,9 +85,9 @@ namespace papyrus {
return form_string;
}

uint32_t hud_mcm::get_slot_action(RE::TESQuest*, const uint32_t a_index, const bool a_left) {
uint32_t hud_mcm::get_slot_action(RE::TESQuest*, const uint32_t a_index, const bool a_left, uint32_t a_position) {
uint32_t action = 0;
if (const auto section = get_section_by_index(a_index); !section.empty()) {
if (const auto section = get_section_by_index(a_index, a_position); !section.empty()) {
if (a_left) {
action = config::custom_setting::get_slot_action_left_by_section(section);
} else {
Expand All @@ -96,18 +98,19 @@ namespace papyrus {
return action;
}

uint32_t hud_mcm::get_hand_selection(RE::TESQuest*, const uint32_t a_index) {
uint32_t hud_mcm::get_hand_selection(RE::TESQuest*, const uint32_t a_index, uint32_t a_position) {
uint32_t hand = 0;
if (const auto section = get_section_by_index(a_index); !section.empty()) {
if (const auto section = get_section_by_index(a_index, a_position); !section.empty()) {
hand = config::custom_setting::get_hand_selection_by_section(section);
}
logger::trace("return hand {} index {}"sv, hand, a_index);
return hand;
}

RE::BSFixedString hud_mcm::get_form_name(RE::TESQuest*, const uint32_t a_index, const bool a_left) {
RE::BSFixedString
hud_mcm::get_form_name(RE::TESQuest*, const uint32_t a_index, const bool a_left, uint32_t a_position) {
std::string form_string;
if (const auto section = get_section_by_index(a_index); !section.empty()) {
if (const auto section = get_section_by_index(a_index, a_position); !section.empty()) {
if (a_left) {
form_string = config::custom_setting::get_item_form_left_by_section(section);
} else {
Expand All @@ -127,16 +130,20 @@ namespace papyrus {
return form->GetName();
}

void hud_mcm::reset_section(RE::TESQuest*, const uint32_t a_index) {
void hud_mcm::reset_section(RE::TESQuest*, const uint32_t a_index, uint32_t a_position) {
logger::trace("reset section was called for index {}"sv, a_index);
if (const auto section = get_section_by_index(a_index); !section.empty()) {
if (const auto section = get_section_by_index(a_index, a_position); !section.empty()) {
config::custom_setting::reset_section(section);
}
}

void hud_mcm::set_action_value(RE::TESQuest*, const uint32_t a_index, const bool a_left, const uint32_t a_value) {
void hud_mcm::set_action_value(RE::TESQuest*,
const uint32_t a_index,
const bool a_left,
const uint32_t a_value,
uint32_t a_position) {
logger::trace("set action was called for index {}, left {}, value {}"sv, a_index, a_left, a_value);
if (const auto section = get_section_by_index(a_index); !section.empty()) {
if (const auto section = get_section_by_index(a_index, a_position); !section.empty()) {
if (a_left) {
config::custom_setting::write_slot_action_left_by_section(section, a_value);
} else {
Expand Down Expand Up @@ -181,9 +188,9 @@ namespace papyrus {
return true;
}

std::string hud_mcm::get_section_by_index(const uint32_t a_index) {
std::string hud_mcm::get_section_by_index(const uint32_t a_index, uint32_t a_position) {
std::string section;
if (const auto sections = util::helper::get_configured_section_page_names();
if (const auto sections = util::helper::get_configured_section_page_names(a_position);
!sections.empty() && is_size_ok(a_index, sections.size())) {
section = sections.at(a_index);
}
Expand Down
22 changes: 11 additions & 11 deletions src/papyrus/papyrus.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ namespace papyrus {
static RE::BSFixedString get_resolution_width(RE::TESQuest*);
static RE::BSFixedString get_resolution_height(RE::TESQuest*);

static std::vector<RE::BSFixedString> get_section_names(RE::TESQuest*);
static RE::BSFixedString get_page(RE::TESQuest*, uint32_t a_index);
static RE::BSFixedString get_position(RE::TESQuest*, uint32_t a_index);
static uint32_t get_selection_type(RE::TESQuest*, uint32_t a_index, bool a_left);
static RE::BSFixedString get_form_string(RE::TESQuest*, uint32_t a_index, bool a_left);
static uint32_t get_slot_action(RE::TESQuest*, uint32_t a_index, bool a_left);
static uint32_t get_hand_selection(RE::TESQuest*, uint32_t a_index);
static RE::BSFixedString get_form_name(RE::TESQuest*, uint32_t a_index, bool a_left);
static void reset_section(RE::TESQuest*, uint32_t a_index);
static void set_action_value(RE::TESQuest*, uint32_t a_index, bool a_left, uint32_t a_value);
static std::vector<RE::BSFixedString> get_section_names(RE::TESQuest*, uint32_t a_position);
static RE::BSFixedString get_page(RE::TESQuest*, uint32_t a_index, uint32_t a_position);
static RE::BSFixedString get_position(RE::TESQuest*, uint32_t a_index, uint32_t a_position);
static uint32_t get_selection_type(RE::TESQuest*, uint32_t a_index, bool a_left, uint32_t a_position);
static RE::BSFixedString get_form_string(RE::TESQuest*, uint32_t a_index, bool a_left, uint32_t a_position);
static uint32_t get_slot_action(RE::TESQuest*, uint32_t a_index, bool a_left, uint32_t a_position);
static uint32_t get_hand_selection(RE::TESQuest*, uint32_t a_index, uint32_t a_position);
static RE::BSFixedString get_form_name(RE::TESQuest*, uint32_t a_index, bool a_left, uint32_t a_position);
static void reset_section(RE::TESQuest*, uint32_t a_index, uint32_t a_position);
static void set_action_value(RE::TESQuest*, uint32_t a_index, bool a_left, uint32_t a_value, uint32_t a_position);
static void init_config_for_position(RE::TESQuest*, uint32_t a_position);

static bool Register(RE::BSScript::IVirtualMachine* a_vm);

private:
static bool is_size_ok(uint32_t a_idx, uint64_t a_size);
static std::string get_section_by_index(uint32_t a_index);
static std::string get_section_by_index(uint32_t a_index, uint32_t a_position);
};

void Register();
Expand Down
14 changes: 11 additions & 3 deletions src/util/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,20 @@ namespace util {
config::custom_setting::read_setting();
}

std::vector<std::string> helper::get_configured_section_page_names() {
std::vector<std::string> helper::get_configured_section_page_names(uint32_t a_position) {
//4 is all
std::vector<std::string> names;
for (const auto entries = config::custom_setting::get_sections(); const auto& entry : entries) {
names.emplace_back(entry.pItem);
if (a_position == static_cast<uint32_t>(handle::position_setting::position_type::total)) {
names.emplace_back(entry.pItem);
} else {
auto section_position = config::custom_setting::get_position_by_section(entry.pItem);
if (section_position == a_position) {
names.emplace_back(entry.pItem);
}
}
}
logger::trace("got {} sections"sv, names.size());
logger::trace("got {} sections, for position {}"sv, names.size(), a_position);
return names;
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace util {
uint32_t a_hand);

static void read_configs();
static std::vector<std::string> get_configured_section_page_names();
static std::vector<std::string> get_configured_section_page_names(uint32_t a_position = 4);
static RE::TESForm* get_form_from_mod_id_string(const std::string& a_str);
static bool is_two_handed(RE::TESForm*& a_form);
static handle::slot_setting::slot_type get_type(RE::TESForm*& a_form);
Expand Down

0 comments on commit f1428af

Please sign in to comment.