Page 1 of 1
Mod the personal battery display?
Posted: Sat Aug 17, 2019 10:00 pm
by Jon8RFC
Before I spend hours and hours trying to learn how to barely use lua and look at how other mods works, is it even possible for me to remove the armor's battery display, and create a more useful one in its place, as a mod?
I thought I could just cleanly replace about 50 .pngs (and add percentages!) to give me a more usable/visible battery display since it's absolutely tiny, but it seems like the battery display is coded into a 33-pixel height, and there's just a single .png for the battery outline.
![battery_display.png](./download/file.php?id=52670)
- battery_display.png (40.56 KiB) Viewed 3669 times
EDIT:
viewtopic.php?f=190&t=75129
Re: Mod the personal battery display?
Posted: Sun Aug 18, 2019 5:49 am
by eradicator
Base-game guis can not be modded.
Re: Mod the personal battery display?
Posted: Sun Aug 18, 2019 9:11 am
by Jon8RFC
Thanks for saving me more confusion. I only spent about 30 minutes trying to figure out where to even begin with it before deciding I should ask.
Re: Mod the personal battery display?
Posted: Sun Aug 18, 2019 10:09 am
by darkfrei
Re: Mod the personal battery display?
Posted: Sun Aug 18, 2019 10:27 am
by dockmeister
You cannot modify or add any widgets, you can however modify the styles.
Code: Select all
data.raw["gui-style"].default["battery_widget"].size = {50, 200}
data.raw["gui-style"].default["battery_progressbar"].bar_width = 40
Re: Mod the personal battery display?
Posted: Sun Aug 18, 2019 3:38 pm
by Jon8RFC
Oh, nice! Thanks for the mod link and widget info.
Re: Mod the personal battery display?
Posted: Sun Sep 01, 2019 12:29 am
by Jon8RFC
Thanks for the info. Unfortunately, I can't join multiplayer servers with it, but at least I can play locally with it:
viewtopic.php?f=190&t=75129
Re: Mod the personal battery display?
Posted: Sun Sep 01, 2019 7:56 am
by eradicator
Jon8RFC wrote: Sun Sep 01, 2019 12:29 am
Thanks for the info. Unfortunately, I can't join multiplayer servers with it, but at least I can play locally with it:
viewtopic.php?f=190&t=75129
If you change base game files then obviously you can not join multiplayer. Was that unexpected to you?
battery_progressbar is a style and moddable as explained by @dockmeister. battery.png looks like it's a utility_sprite, so that should be moddable too. Maybe you're unfamiliar with lua and need detailed help?
Re: Mod the personal battery display?
Posted: Sun Sep 01, 2019 9:09 am
by eradicator
Proof of concept.
Technically you don't even need a custom picture as the old one is auto-stretched to the new gui size. Note that this code is far more verbose than it needs to be to hopefully make it easier to understand.
Code: Select all
--name of mod containing battery picture
local modpath = '__test-mod-C__'
--config
local picture_height = 111
local picture_width = 26
local gui_height = 84
local gui_width = picture_width
local bar_width = 14
local bar_height = gui_height - 11
--code
data.raw["gui-style"].default.battery_widget = {
type = "empty_widget_style",
size = {picture_width, gui_height} --default: 21,54
}
data.raw["gui-style"].default.battery_progressbar = {
type = "progressbar_style",
top_padding = 0 , --0
bar_width = bar_width, --13
height = bar_height, --33
color = {g=1},
bar = {
filename = "__core__/graphics/gui.png",
position = {223, 0 },
size = { 1, 11},
scale = 1,
},
other_colors = {
{less_than = 0.33, color = {r = 1 }},
{less_than = 0.66, color = {r = 1, g = 0.5, b = 0.25}},
{less_than = 1 , color = { g = 1 }},
}
}
data.raw['utility-sprites'].default.battery_indicator = {
filename = modpath..'/battery_26x111.png',
priority = "extra-high-no-scale",
width = picture_width, --21
height = picture_height, --54
}
Re: Mod the personal battery display?
Posted: Sun Sep 01, 2019 12:35 pm
by Jon8RFC
eradicator wrote: Sun Sep 01, 2019 7:56 am
Jon8RFC wrote: Sun Sep 01, 2019 12:29 am
Thanks for the info. Unfortunately, I can't join multiplayer servers with it, but at least I can play locally with it:
viewtopic.php?f=190&t=75129
If you change base game files then obviously you can not join multiplayer. Was that unexpected to you?
battery_progressbar is a style and moddable as explained by @dockmeister. battery.png looks like it's a utility_sprite, so that should be moddable too. Maybe you're unfamiliar with lua and need detailed help?
Heh, actually, yes I use other locally-modified files in multiplayer regularly, so I was somewhat surprised. I don't want the performance hit of a "fix", especially after reading FFF309 referencing how and why a specific issue was handled. What I do
could possibly be exploited (by someone more clever than myself) to gain an unfair advantage in whatever the team-based Factorio multiplayer game is (just based on a specific bug report a year or two ago), but it's pointless in single or non-team multiplayer. I like the ability, but more than that I don't want the massive performance hit of the only likely fix...and everyone will suffer from it.
Looking in the wiki, I utilized utility-sprites.lua and "utility-sprites" was in the wiki but not plain "style", so I figured I was out of luck since "gui-style" wasn't the same as style.lua. Other things are named consistently, so I just figured I was out of luck since that file absolutely needed to be edited. That was a pretty big misdirection to me and I interpreted it literally.
Thanks, yes, I do need detailed help since I was in the mindset of a very dumbed-down version of "here's my modification to overwrite portions of the original file using a similar folder hierarchy and similarly named file" rather than "here's my modification using different words, without file references, and without a folder hierarchy". I had looked at my few mods I use, but since I didn't know the other end of what they were doing, I couldn't piece it together.
Having the mod you made, and knowing what its goal is for the original files since I had figured that part out, now I also know that naming conventions aren't necessarily consistent and how I'm supposed to reference files, so hopefully I can figure out pretty much anything else with this example. It helped a lot. Thanks!
Re: Mod the personal battery display?
Posted: Sun Sep 01, 2019 12:54 pm
by eradicator
Jon8RFC wrote: Sun Sep 01, 2019 12:29 am
Heh, actually, yes I use other locally-modified files in multiplayer regularly, so I was somewhat surprised. I don't want the performance hit of a "fix", especially after reading FFF309 referencing how and why a specific issue was handled. What I do
could possibly be exploited (by someone more clever than myself) to gain an unfair advantage in whatever the team-based Factorio multiplayer game is (just based on a specific bug report a year or two ago), but it's pointless in single or non-team multiplayer. I like the ability, but more than that I don't want the massive performance hit of the only likely fix...and everyone will suffer from it.
No idea what you're conspiring about there but factorio is really simple: Any changes to *code* will be detected and have to be consistent for everyone in multiplayer. Any changes to graphic/sound assets (vulgo "png files") go unchecked and each player can do whatever they want with them. (Well, due to graphics being references in code you can't change the file dimensions or it won't load at all, but the content doesn't matter).
Also the filenames of code files (vulgo ".lua files") are completely irrelevant to anything but the require() statement that imports each file. There's no need to "replicate directory structures" or anything.
If you plan on continuing to mod i recommend you get a text editor that supports recursive directory searching (such as Notepad++). I just did a 2 second search though all of the games code files for "battery.png" and knew what i needed to know.
Re: Mod the personal battery display?
Posted: Sun Sep 01, 2019 1:03 pm
by Jon8RFC
eradicator wrote: Sun Sep 01, 2019 12:54 pm
If you plan on continuing to mod i recommend you get a text editor that supports recursive directory searching (such as Notepad++). I just did a 2 second search though all of the games code files for "battery.png" and knew what i needed to know.
Yes, I use notepad++ and that's how I found where battery_widget and battery_progressbar were, which was quick and easy.
Thanks again for the mod--that helped a lot. Knowing what I wanted changed, and seeing the way to do it through a mod rather than direct editing, made it all click. Now I can better understand how my downloaded mods work. All I needed was one example of something I already understood and you gave me a great example.