Add a new widget to display weight with the format "##.#/##.#[unit]"
Summary
Features "Add a new widget to display weight as "##.#/##.#[unit]""
Purpose of change
I felt like this was a glaring hole in the information you could display in the sidebar, considering all the random stuff you can display over there, so I fixed it.
Describe the solution
Added a new functions in display,cpp to pull current units and concat current weight with max weight, and calculate what percent of the max they are to color them appropriately, then added the requisite code to widget.cpp to call on this information.
I then added a new widgets to legacy labels sidebar to display this new information, because that's the sidebar I use. If anyone wants it added to another sidebar, speak up.
Describe alternatives you've considered
Not doing the imperial version because pounds make no sense
Testing
Additional context
I'd like to thank my gf for being patient with me while I ignored the show we were watching all day today, and I'd like to thank chatGPT for holding my hand and helping me setup the compiler in visual code, and helping me with c++ syntax because my coding experience is limited to java from 15 years ago, and lua from writing software in the minecraft computercraft mod
My head hurts
I'd also like to thank @Zenefess for giving me some guidance on how widgets work when I first thought about doing this a month or two ago
Should probably rename the existing carry_weight_text variables to denote that they handle the carry weight as a percent, because it's somewhat ambiguous
Spell checker encountered unrecognized words in the in-game text added in this pull request. See below for details.
Click to expand
- Weight Carried (lb)
This alert is automatically generated. You can simply disregard if this is inaccurate, or (optionally) you can also add the new words to tools/spell_checker/dictionary.txt so they will not trigger an alert next time.
Hints for adding a new word to the dictionary
- If the word is normally in all lowercase, such as the noun
wordor the verbdoes, add it in its lower-case form; if the word is a proper noun, such as the surnameGeorge, add it in its initial-caps form; if the word is an acronym or has special letter case, such as the acronymCDDAor the unitmW, add it by preserving the case of all the letters. A word in the dictionary will also match its initial-caps form (if the word is in all lowercase) and all-uppercase form, so a word should be added to the dictionary in its normal letter case even if used in a different letter case in a sentence. - For a word to be added to the dictionary, it should either be a real, properly-spelled modern American English word, a foreign loan word (including romanized foreign names), or a foreign or made-up word that is used consistently and commonly enough in the game. Intentional misspelling (including eye dialect) of a word should not be added unless it has become a common terminology in the game, because while someone may have a legitimate use for it, another person may spell it that way accidentally.
Is there any reason to have separate widgets for kg and lbs?
In the settings: USE_METRIC_WEIGHTS contains the value kg or lbs. We read the variable and use whichever option is specified in it.
I could probably check that in the display function, I'll look into it when I get home tonight
I honestly threw the imperial one in as a complete after thought
made necessary changes to remove the code dedicated to the imperial version, and modified the metric function so it detects the users mass unit and adjusts accordingly. Also renamed all variable names to be non unit specific
unit = "lb";
lbs?
UPD. And it wouldn't hurt to add a space between the value and kg/lb.
Updated
Okay, I'm not good with the imperial system of measurement. Wiki says it's lb. But in the options, it's lbs. It's better to check with people who use it.
And it's definitely not correct to use kgs for metric.
xD Iooks like lbs is correct for imperial. You'd think as an american I'd know this, but shit makes no gd sense
~~The build test seems to be failing here due to map generation for the isherwood farm? Not something I touched, so not really sure if I need to be concerned about that or not.~~
Seems to have resolved itself after pulling from master
Presume you missed https://github.com/CleverRaven/Cataclysm-DDA/blob/master/src/units_utility.cpp#L91 and https://github.com/CleverRaven/Cataclysm-DDA/blob/master/src/units_utility.cpp#L143? (or weight_to_string but I agree that it's nicer for the unit to appear only once) Also you probably want to remove the (kg) from ll_weight_carried_value
Yeah, I sure did miss those, updated to implement them, as well as remove the stray (kg) you found.