Skip to content

Instantly share code, notes, and snippets.

@pardeike
Created December 23, 2022 15:14
Show Gist options
  • Save pardeike/ea469f4231a17be3b67ffba16752dbd5 to your computer and use it in GitHub Desktop.
Save pardeike/ea469f4231a17be3b67ffba16752dbd5 to your computer and use it in GitHub Desktop.
var allMax = Mathf.Max(0.04f, suicideBomberChance, toxicSplasherChance, tankyOperatorChance, minerChance, electrifierChance, albinoChance, darkSlimerChance, healerChance);
var max = Mathf.Min(1f, 2f * allMax);
list.Dialog_FloatSlider("SuicideBomberChance", _ => "{0:0.00%}", false, ref suicideBomberChance, 0f, Mathf.Min(max, 1f - toxicSplasherChance - tankyOperatorChance - minerChance - electrifierChance - albinoChance - darkSlimerChance - healerChance));
list.Dialog_FloatSlider("ToxicSplasherChance", _ => "{0:0.00%}", false, ref toxicSplasherChance, 0f, Mathf.Min(max, 1f - suicideBomberChance - tankyOperatorChance - minerChance - electrifierChance - albinoChance - darkSlimerChance - healerChance));
list.Dialog_FloatSlider("TankyOperatorChance", _ => "{0:0.00%}", false, ref tankyOperatorChance, 0f, Mathf.Min(max, 1f - suicideBomberChance - toxicSplasherChance - minerChance - electrifierChance - albinoChance - darkSlimerChance - healerChance));
list.Dialog_FloatSlider("MinerChance", _ => "{0:0.00%}", false, ref minerChance, 0f, Mathf.Min(max, 1f - suicideBomberChance - toxicSplasherChance - tankyOperatorChance - electrifierChance - albinoChance - darkSlimerChance - healerChance));
list.Dialog_FloatSlider("ElectrifierChance", _ => "{0:0.00%}", false, ref electrifierChance, 0f, Mathf.Min(max, 1f - suicideBomberChance - toxicSplasherChance - tankyOperatorChance - minerChance - albinoChance - darkSlimerChance - healerChance));
list.Dialog_FloatSlider("AlbinoChance", _ => "{0:0.00%}", false, ref albinoChance, 0f, Mathf.Min(max, 1f - suicideBomberChance - toxicSplasherChance - tankyOperatorChance - minerChance - electrifierChance - darkSlimerChance - healerChance));
list.Dialog_FloatSlider("DarkSlimerChance", _ => "{0:0.00%}", false, ref darkSlimerChance, 0f, Mathf.Min(max, 1f - suicideBomberChance - toxicSplasherChance - tankyOperatorChance - minerChance - electrifierChance - albinoChance - healerChance));
list.Dialog_FloatSlider("HealerChance", _ => "{0:0.00%}", false, ref healerChance, 0f, Mathf.Min(max, 1f - suicideBomberChance - toxicSplasherChance - tankyOperatorChance - minerChance - electrifierChance - albinoChance - darkSlimerChance));
var normalChance = 1f - suicideBomberChance - toxicSplasherChance - tankyOperatorChance - minerChance - electrifierChance - albinoChance - darkSlimerChance - healerChance;
list.Gap(-6f);
list.Dialog_Text(GameFont.Tiny, "NormalZombieChance", string.Format("{0:0.00%}", normalChance));
public static void Dialog_FloatSlider(this Listing_Standard list, string labelId, Func<float, string> labelFormatFunc, bool logarithmic, ref float value, float min, float max, Func<float, float> formatFunc = null)
{
list.Help(labelId, 32f);
list.Gap(12f);
var format = labelFormatFunc(value);
var valstr = string.Format(format, formatFunc != null ? formatFunc(value) : value);
var srect = list.GetRect(24f);
srect.xMin += inset;
srect.xMax -= inset;
var inValue = logarithmic ? (float)(1 - Math.Pow(1 - (double)value, 10)) : value;
if (inValue < min)
inValue = min;
if (inValue > max)
inValue = max;
var outValue = Widgets.HorizontalSlider_NewTemp(srect, inValue, min, max, false, null, labelId.SafeTranslate(), valstr, -1f);
value = logarithmic ? (float)(1 - Math.Pow(1 - outValue, 1 / (double)10)) : outValue;
if (value < min)
value = min;
if (value > max)
value = max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment