Untitled

mail@pastecode.io avatar
unknown
csharp
a month ago
4.0 kB
2
Indexable
Never
    private void OnGUI()
    {
        if (Application.isPlaying)
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical(GUILayout.MinWidth(300), GUILayout.ExpandWidth(true));
            LayoutReorderableInitiativeList();
            GUILayout.EndVertical();

            GUILayout.BeginVertical(GUILayout.MaxWidth(200));
            LayoutInitiativeButtons();
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            ChatboxInputField();
            GUILayout.EndHorizontal();
            if (GUILayout.Button("GM - Create Untargeted Attack"))
            {
                CreateBlankAttackEntry();
            }
            RenderAttackStack();
            GUILayout.EndVertical();
        }
        else
        {
            GUILayout.Label("Combat Tracker acessably only in Play mode.");
        }
    }

    private void RenderAttackStack()
    {
        GUILayout.BeginVertical("Box");
        GUILayout.BeginHorizontal();
        GUILayout.Label("Attacker", GUILayout.Width(100));
        GUILayout.Label("Target", GUILayout.Width(100));
        GUILayout.Label("Hit D/A", GUILayout.Width(70));
        //GUILayout.Label("Hit D/A", GUILayout.Width(50));
        GUILayout.Label("Damage", GUILayout.Width(50));
        GUILayout.Label("Y/N", GUILayout.Width(50));
        GUILayout.EndHorizontal();

        List<AttackTargetData> toRemove = new List<AttackTargetData>();

        for (int i = 0; i < combatData.attackStack.Count; i++)
        {
            // Direct reference to the element in the list
            AttackTargetData guiData = combatData.attackStack[i];

            DamageInstance(ref guiData);  // Pass by reference

            if (guiData.ToBeRemoved)
            {
                toRemove.Add(guiData);
            }

            // Update the item in the list if changes are made in DamageInstance
            combatData.attackStack[i] = guiData;
        }

        // Perform actual removal after the loop
        foreach (var item in toRemove)
        {
            combatData.attackStack.Remove(item);
        }
        GUILayout.EndVertical();
    }

    private void DamageInstance(ref AttackTargetData guiAttackData)
    {
        GUILayout.BeginHorizontal("Box");
        List<CharacterID> combatants = initiative.GetAllCombatants();

        RenderTargetDropdown(guiAttackData, combatants, "Attacker", isAttacker: true);
        RenderTargetDropdown(guiAttackData, combatants, "Target", isAttacker: false);

        int hitRoll = guiAttackData.HitRoll;
        int hitRollBonus = guiAttackData.HitRollBonus;
        int hitRollDisAdvantage = guiAttackData.HitRollDisAdvantage;
        int hitRollDisAdvantageBonus = guiAttackData.HitRollDisAdvantageBonus;

        AttackLogic(guiAttackData, hitRoll, hitRoll + hitRollBonus);
        AttackLogic(guiAttackData, hitRollDisAdvantage, hitRollDisAdvantage + hitRollDisAdvantageBonus);

        if (string.IsNullOrEmpty(guiAttackData.EditedDamageString))
        {
            guiAttackData.EditedDamageString = guiAttackData.TotalDamagesString;
        }

        Rect textFieldRect = GUILayoutUtility.GetRect(200, EditorGUIUtility.singleLineHeight);
        guiAttackData.EditedDamageString = EditorGUI.TextField(textFieldRect, "Total Damage:", guiAttackData.EditedDamageString);

        if (GUILayout.Button("✓", GUILayout.Width(20)))
        {
            bool succeeded = AttackMacroExecuteAttack(guiAttackData, guiAttackData.EditedDamageString);
            if (succeeded)
            {
                guiAttackData.ToBeRemoved = true;
            }
        }
        if (GUILayout.Button("X", GUILayout.Width(20)))
        {
            guiAttackData.ToBeRemoved = true;
        }
        GUILayout.EndHorizontal();
    }
Leave a Comment