Comparing color tables and GUIStyle

Place to get help with not working mods / modding interface.
Post Reply
User avatar
MisterBrownZA
Burner Inserter
Burner Inserter
Posts: 8
Joined: Mon Nov 02, 2015 7:10 am
Contact:

Comparing color tables and GUIStyle

Post by MisterBrownZA »

Greetings,

I would like to know the following:

1. How would I be able to compare the current player color with a color table of my own (granted my own table has the full rgba).
eg.

Code: Select all

if (game.player.color == mycolors.white || game.local_player.color == mycolors.white) then
--#change player color
2. What is the best way to iterate through my table ?
eg.

Code: Select all

If (game.player.color in mycolors) then
--#true/false
3. I have no idea how to work with guistyle.
I created this:

Code: Select all

data.raw["gui-style"].default["my_label"] = 
{
	type="label_style",
	parent="label_style",
	color={r=1,g=1,b=1},
	fontcolor={r=0,g=0,b=0}
}

Code: Select all

path["flow"..ii].add({type="label",name="label"..ii, caption="caption", stype="my_label"})
However, whenever I try and use it in my code, it gives me an error stating that my_label doesn't exist... Can someone please explain this to me ? The wiki of guistyle only states the properties, but doesn't give a default value, min/max value, or any form of example of implementation.
4. I tried doing inline styles, and it will tell me that the key value doesn't exist
eg.

Code: Select all

player.gui.top.frame["flow"..ii]["label"..ii].style.fontcolor 	= {r=1,g=1,b=1}

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Comparing color tables and GUIStyle

Post by prg »

MisterBrownZA wrote:Greetings,

I would like to know the following:

1. How would I be able to compare the current player color with a color table of my own (granted my own table has the full rgba).
eg.

Code: Select all

if (game.player.color == mycolors.white || game.local_player.color == mycolors.white) then
--#change player color
The player color is also rgba, but game.local_player.color == mycolors.white will only ever be true if both colors are exactly the same table, not just tables that happen to contain the same values. You could try something like

Code: Select all

function compare_colors(c1, c2) return c1.r == c2.r and c1.g == c2.g and c1.b == c2.b and c1.a == c2.a end
But since the color values are floats you might want to see if they are close enough together instead of exactly the same.
MisterBrownZA wrote:2. What is the best way to iterate through my table ?
eg.

Code: Select all

If (game.player.color in mycolors) then
--#true/false

Code: Select all

for _, v in pairs(mycolors) do
    if compare_colors(game.local_player.color, v) then
        --color found
        break
    end
end
MisterBrownZA wrote:3. I have no idea how to work with guistyle.
Never done anything with that, either.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
MisterBrownZA
Burner Inserter
Burner Inserter
Posts: 8
Joined: Mon Nov 02, 2015 7:10 am
Contact:

Re: Comparing color tables and GUIStyle

Post by MisterBrownZA »

-snip-
Never done anything with that, either.[/quote]
Thanks for the assistance.

Was wondering about the table values as well... Will compare values instead then, thank you very much!

GUIstyle isn't documented very well, and I can't find a solid working example of implementation.

I have tried downloading some GUI's that are currently available, but when I try copy their example, I get the same error.

So I'm not sure what I'm doing wrong.

I'm hoping someone can assist with this!

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Comparing color tables and GUIStyle

Post by prg »

BTW turns out someone already wrote a deep compare function for tables.

Code: Select all

require "util"
util.table.compare(t1, t2)
Won't work from the console though since you can't use require there. Also won't work if you want to add name="white" or something like that to your own table.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: Comparing color tables and GUIStyle

Post by rk84 »

3. Is that in data.lua file or does data.lua request the file with that code?

You can dig the default values from Factorio\data\core\prototypes\style.lua

Also font_color with an underscore.
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

Post Reply

Return to “Modding help”