コード例 #1
0
        static Color AssigmentColor(StatPriority statPriority)
        {
            if (statPriority.IsManual)
            {
                return(Color.white);
            }

            if (statPriority.IsDefault)
            {
                return(Color.grey);
            }

            if (statPriority.IsOverride)
            {
                return(new Color(0.75f, 0.69f, 0.33f));
            }

            return(Color.cyan);
        }
コード例 #2
0
        static void StatPrioritySyncer(SyncWorker sync, ref StatPriority sp)
        {
            int     uid = selectedOutfitId;
            StatDef stat;

            if (sync.isWriting)
            {
                stat = sp.Stat;

                sync.Bind(ref uid);
                sync.Bind(ref stat);
                sync.Bind(ref sp.Weight);
            }
            else
            {
                stat = null;
                float weight = 0;

                sync.Bind(ref uid);
                sync.Bind(ref stat);
                sync.Bind(ref weight);

                var targetOutfit = Current.Game.outfitDatabase.AllOutfits.Find(o => o.uniqueId == uid);
                if (targetOutfit is ExtendedOutfit extendedOutfit)
                {
                    sp = extendedOutfit.StatPriorities.FirstOrDefault(o => o.Stat == stat);

                    if (sp != null)
                    {
                        sp.Weight = weight;
                    }
                    else
                    {
                        extendedOutfit.AddStatPriority(stat, weight);
                    }
                }
                else
                {
                    Log.Warning("Outfitted :: DESYNC INCOMING");
                }
            }
        }
コード例 #3
0
        public static List <StatPriority> WorktypeStatPriorities(Pawn pawn)
        {
            // get stat weights for each non-zero work priority.
            var worktypeStats = DefDatabase <WorkTypeDef> .AllDefsListForReading
                                .Select(wtd => new
            {
                priority = pawn?.workSettings?.GetPriority(wtd) ?? 0,
                worktype = wtd
            })
                                .Where(x => x.priority > 0)
                                .Select(x => new
            {
                x.priority,
                x.worktype,
                weights = WorktypeStatPriorities(x.worktype)
            });

            // no work assigned.
            if (!worktypeStats.Any())
            {
                return(new List <StatPriority>());
            }

            // normalize worktype priorities;
            // 1 - get the range (usually within 1-4, but may be up to 1-9 with Work Tab)
            var range        = new IntRange(worktypeStats.Min(s => s.priority), worktypeStats.Max(s => s.priority));
            var weights      = new Dictionary <StatDef, StatPriority>();
            var sumOfWeights = 0f;


            foreach (var worktype in worktypeStats)
            {
                // 2 - base to 0 (subtract minimum), scale to 0-1 (divide by maximum-minimum)
                // 3 - invert, so that 1 is 1, and max is 0.
                var normalizedPriority = range.min == range.max
                    ? 1
                    : 1 - (worktype.priority - range.min) / (range.max - range.min);
                foreach (var weight in worktype.weights)
                {
                    StatPriority statPriority;
                    if (weights.TryGetValue(weight.Stat, out statPriority))
                    {
                        statPriority.Weight += normalizedPriority * weight.Weight;
                    }
                    else
                    {
                        statPriority = new StatPriority(weight.Stat, normalizedPriority * weight.Weight);
                        weights.Add(weight.Stat, statPriority);
                    }

                    sumOfWeights += weight.Weight;
                }
            }

            // 4 - multiply weights by constant c, so that sum of weights is 10
            if (weights.Any() && sumOfWeights != 0)
            {
                foreach (var weight in weights)
                {
                    weight.Value.Weight *= 10 / sumOfWeights;
                }
            }

            return(weights.Values.ToList());
        }
コード例 #4
0
        static void DrawStatRow(ExtendedOutfit selectedOutfit, StatPriority statPriority, ref Vector2 cur, float width)
        {
            // set up rects
            Rect labelRect  = new Rect(cur.x, cur.y, (width - 24) / 2f, 30f);
            Rect sliderRect = new Rect(labelRect.xMax + 4f, cur.y + 5f, labelRect.width, 25f);
            Rect buttonRect = new Rect(sliderRect.xMax + 4f, cur.y + 3f, 16f, 16f);

            // draw label
            Text.Font = Text.CalcHeight(statPriority.Stat.LabelCap, labelRect.width) > labelRect.height
                            ? GameFont.Tiny
                            : GameFont.Small;

            GUI.color = AssigmentColor(statPriority);

            Widgets.Label(labelRect, statPriority.Stat.LabelCap);
            Text.Font = GameFont.Small;

            // draw button
            // if manually added, delete the priority
            string buttonTooltip = string.Empty;

            if (statPriority.IsManual)
            {
                buttonTooltip = ResourceBank.Strings.StatPriorityDelete(statPriority.Stat.LabelCap);
                if (Widgets.ButtonImage(buttonRect, ResourceBank.Textures.DeleteButton))
                {
                    selectedOutfit.RemoveStatPriority(statPriority.Stat);
                }
            }
            // if overridden auto assignment, reset to auto
            else if (statPriority.IsOverride)
            {
                buttonTooltip = ResourceBank.Strings.StatPriorityReset(statPriority.Stat.LabelCap);
                if (Widgets.ButtonImage(buttonRect, ResourceBank.Textures.ResetButton))
                {
                    statPriority.Weight = statPriority.Default;

                    if (MPApi.IsInMultiplayer)
                    {
                        ExtendedOutfitProxy.SetStatPriority(statPriority.Stat, statPriority.Default);
                    }
                }
            }

            // draw line behind slider
            GUI.color = new Color(.3f, .3f, .3f);
            for (int y = (int)cur.y; y < cur.y + 30; y += 5)
            {
                Widgets.DrawLineVertical((sliderRect.xMin + sliderRect.xMax) / 2f, y, 3f);
            }

            // draw slider
            GUI.color = AssigmentColor(statPriority);

            float weight = GUI.HorizontalSlider(sliderRect, statPriority.Weight, -MaxValue, MaxValue);

            if (Mathf.Abs(weight - statPriority.Weight) > 1e-4)
            {
                statPriority.Weight = weight;

                if (MPApi.IsInMultiplayer)
                {
                    ExtendedOutfitProxy.SetStatPriority(statPriority.Stat, weight);
                }
            }

            GUI.color = Color.white;

            // tooltips
            TooltipHandler.TipRegion(labelRect, statPriority.Stat.LabelCap + "\n\n" + statPriority.Stat.description);
            if (buttonTooltip != string.Empty)
            {
                TooltipHandler.TipRegion(buttonRect, buttonTooltip);
            }

            TooltipHandler.TipRegion(sliderRect, statPriority.Weight.ToStringByStyle(ToStringStyle.FloatTwo));

            // advance row
            cur.y += 30f;
        }
コード例 #5
0
 public static void SetStatPriority(StatDef stat, float weight)
 {
     selectedStatPriority = new StatPriority(stat, weight);
 }