Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a color picker to mod-settings menu, and make it possible to check the color and alpha #896

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

RainTrap341
Copy link

I noticed the modsettings menu is not friendly to color string like "255 255 255 255". So I add a ImagePanel and a ColorPicker which helps.
The mod-settings menu now is able to check the color and edit through a color picker. And the change in the color picker is written to ConVar once each slider/textField gets modified.

1
2

Code review:

Add 2 categories: "color", "alpha". The hud elements will show if the ConVarData has right type.

void function ModSettings_AddColorSetting(string conVar, string buttonLabel, void functionref() onPress = null, int stackPos = 2)
{
	if ( !( getstackinfos( stackPos )[ "func" ] in file.setFuncs ) || !file.setFuncs[ expect string( getstackinfos( stackPos )[ "func" ] ) ] )
		throw getstackinfos( stackPos )[ "src" ] + " #" + getstackinfos( stackPos )[ "line" ] + "\nCannot add a button before a category and mod title!"

	ConVarData data


	data.conVar = conVar
	data.type = "color"
	data.displayName = buttonLabel
	data.modName = file.currentMod
	data.catName = file.currentCat
	data.onPress = onPress

	file.conVarList.append( data )
}

void  function ModSettings_AddAlphaSetting(string conVar, string displayName, int stackPos = 2)
{
	if ( !( getstackinfos( stackPos )[ "func" ] in file.setFuncs ) || !file.setFuncs[ expect string( getstackinfos( stackPos )[ "func" ] ) ] )
		throw getstackinfos( stackPos )[ "src" ] + " #" + getstackinfos( stackPos )[ "line" ] + "\nCannot add a button before a category and mod title!"

	ConVarData data

	data.catName = file.currentCat
	data.conVar = conVar
	data.modName = file.currentMod
	data.displayName = displayName
	data.type = "alpha"
	data.sliderEnabled = true
	data.forceClamp = false
	data.min = 0
	data.max = 1
	data.stepSize = 0.05

	file.conVarList.append( data )
}

Testing:

If you want to test it, just call the two functions above like:

ModSettings_AddColorSetting("EntityStatus.health_common_fgcolor","#HUD_DEFAULT_COLORS_OPTION")
ModSettings_AddAlphaSetting("EntityStatus.core_label_alpha","#SETTING_ALPHA" )

The ImagePanel will show the convar color auto.

@github-actions github-actions bot added needs testing Changes from the PR still need to be tested needs code review Changes from PR still need to be reviewed in code labels Oct 18, 2024
@NachosChipeados
Copy link
Contributor

Just noticed that all sliders show "RuiButton" on the top left corner when you hover over them. No idea why that happens
https://github.com/user-attachments/assets/d52f81da-5f23-4334-8c67-3110f8debacb

@RainTrap341
Copy link
Author

Just noticed that all sliders show "RuiButton" on the top left corner when you hover over them. No idea why that happens https://github.com/user-attachments/assets/d52f81da-5f23-4334-8c67-3110f8debacb

The color string should be with 4 int between 0-255, like "91 255 31 255". I noticed your "1.0 0.5 5 0.0",the defualt value supposed to int, and reset, then it should work.

Copy link
Contributor

@NachosChipeados NachosChipeados left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm that both sliders work properly. Didn't review code though, besides the bugs i mentioned before

Titanfall.2.2024-10-18.13-15-54.mp4

- Improve ColorPicker layout
- Add clamp to values
- Remove dialog while ColorPicker open which cause CTM
- Fix ConVar not updated due to textfield
@RainTrap341
Copy link
Author

Can confirm that both sliders work properly. Didn't review code though, besides the bugs i mentioned before

Titanfall.2.2024-10-18.13-15-54.mp4

I forgot to consider situation when user may use float by accident, now it goes with a clamp function which make them into integers. Also I got some fix. It's supposed to be more friendly.

@RainTrap341
Copy link
Author

1
Now with displayName as subtitle.

Use Color struct instead table.
Modified the strings used by ThrowInvalidValue.
@@ -130,6 +130,13 @@
"Path": "ui/ns_slider.nut",
"RunOn": "UI"
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation looks weird, tabs vs spaces issue I assume

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Various formatting issues in this file. Notably the {} after functions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

RainTrap341 and others added 2 commits November 1, 2024 08:54
- replaces spaces with tab
- add reset logic to colorVGUI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs code review Changes from PR still need to be reviewed in code needs testing Changes from the PR still need to be tested
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants