Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

UT2004RPG.RPGInteraction


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
//RPGInteraction - Level/stat info and creates levelup menu
//Also saves stats on level change for Listen and Standalone servers
//because on those types of games people often quit in the middle (which servers almost never do)
class RPGInteraction extends Interaction
    config(UT2004RPG);

var MutUT2004RPG RPGMut;
var bool bDefaultBindings, bDefaultArtifactBindings; //use default keybinds because user didn't set any
var RPGStatsInv StatsInv;
var float LastLevelMessageTime;
var config int LevelMessagePointThreshold; //player must have more than this many stat points for message to display
var Font TextFont;
var color EXPBarColor, WhiteColor, RedTeamTint, BlueTeamTint;
var localized string LevelText, StatsMenuText, ArtifactText;

event Initialized()
{
    local EInputKey key;
    local string tmp;

    if (ViewportOwner.Actor.Level.NetMode != NM_Client)
        foreach ViewportOwner.Actor.DynamicActors(class'MutUT2004RPG', RPGMut)
            break;

    //detect if user made custom binds for our aliases
    for (key = IK_None; key < IK_OEMClear; key = EInputKey(key + 1))
    {
        tmp = ViewportOwner.Actor.ConsoleCommand("KEYNAME"@Key);
        tmp = ViewportOwner.Actor.ConsoleCommand("KEYBINDING"@tmp);
        if (tmp ~= "rpgstatsmenu")
            bDefaultBindings = false;
        else if (tmp ~= "activateitem" || tmp ~= "nextitem" || tmp ~= "previtem")
            bDefaultArtifactBindings = false;
        if (!bDefaultBindings && !bDefaultArtifactBindings)
            break;
    }

    TextFont = Font(DynamicLoadObject("UT2003Fonts.jFontSmall", class'Font'));
}

//Detect pressing of a key bound to one of our aliases
//KeyType() would be more appropriate for what's done here, but Key doesn't seem to work/be set correctly for that function
//which prevents ConsoleCommand() from working on it
function bool KeyEvent(EInputKey Key, EInputAction Action, float Delta)
{
    local string tmp;

    if (Action != IST_Press)
        return false;

    //Use console commands to get the name of the numeric Key, and then the alias bound to that keyname
    if (!bDefaultBindings)
    {
        tmp = ViewportOwner.Actor.ConsoleCommand("KEYNAME"@Key);
        tmp = ViewportOwner.Actor.ConsoleCommand("KEYBINDING"@tmp);
    }

    //If it's our alias (which doesn't actually exist), then act on it
    if (tmp ~= "rpgstatsmenu" || (bDefaultBindings && Key == IK_L))
    {
        if (StatsInv == None)
            FindStatsInv();
        if (StatsInv == None)
            return false;
        //Show stat menu
        ViewportOwner.GUIController.OpenMenu("UT2004RPG.RPGStatsMenu");
        RPGStatsMenu(GUIController(ViewportOwner.GUIController).TopPage()).InitFor(StatsInv);
        LevelMessagePointThreshold = StatsInv.Data.PointsAvailable;
        return true;
    }
    else if (bDefaultArtifactBindings)
    {
        if (Key == IK_U)
        {
            ViewportOwner.Actor.ActivateItem();
            return true;
        }
        else if (Key == IK_LeftBracket)
        {
            ViewportOwner.Actor.PrevItem();
            return true;
        }
        else if (Key == IK_RightBracket)
        {
            if (ViewportOwner.Actor.Pawn != None)
                ViewportOwner.Actor.Pawn.NextItem();
            return true;
        }
    }

    //Don't care about this event, pass it on for further processing
    return false;
}

//Find local player's stats inventory item
function FindStatsInv()
{
    local Inventory Inv;
    local RPGStatsInv FoundStatsInv;

    for (Inv = ViewportOwner.Actor.Inventory; Inv != None; Inv = Inv.Inventory)
    {
        StatsInv = RPGStatsInv(Inv);
        if (StatsInv != None)
            return;
        else
        {
            //atrocious hack for Jailbreak's bad code in JBTag (sets its Inventory property to itself)
            if (Inv.Inventory == Inv)
            {
                Inv.Inventory = None;
                foreach ViewportOwner.Actor.DynamicActors(class'RPGStatsInv', FoundStatsInv)
                {
                    if (FoundStatsInv.Owner == ViewportOwner.Actor || FoundStatsInv.Owner == ViewportOwner.Actor.Pawn)
                    {
                        StatsInv = FoundStatsInv;
                        Inv.Inventory = StatsInv;
                        break;
                    }
                }
                return;
            }
        }
    }
}

function PostRender(Canvas Canvas)
{
    local float XL, YL, XLSmall, YLSmall, EXPBarX, EXPBarY;

    if ( ViewportOwner.Actor.Pawn == None || ViewportOwner.Actor.Pawn.Health <= 0
         || (ViewportOwner.Actor.myHud != None && ViewportOwner.Actor.myHud.bShowScoreBoard)
         || ViewportOwner.Actor.myHud.bHideHUD )
        return;

    if (StatsInv == None)
        FindStatsInv();
    if (StatsInv == None)
        return;

    if (TextFont != None)
        Canvas.Font = TextFont;
    Canvas.FontScaleX = Canvas.ClipX / 1024.f;
    Canvas.FontScaleY = Canvas.ClipY / 768.f;
    Canvas.TextSize(LevelText@StatsInv.Data.Level, XL, YL);

    // increase size of the display if necessary for really high levels
    XL = FMax(XL + 9.f * Canvas.FontScaleX, 135.f * Canvas.FontScaleX);
    Canvas.Style = 5;
    Canvas.DrawColor = EXPBarColor;
    EXPBarX = Canvas.ClipX - XL - 1.f;
    EXPBarY = Canvas.ClipY * 0.75 - YL * 3.75;
    Canvas.SetPos(EXPBarX, EXPBarY);
    Canvas.DrawTile(Material'InterfaceContent.Hud.SkinA', XL * StatsInv.Data.Experience / StatsInv.Data.NeededExp, 15.0 * Canvas.FontScaleY, 836, 454, -386 * StatsInv.Data.Experience / StatsInv.Data.NeededExp, 36);
    if ( ViewportOwner.Actor.PlayerReplicationInfo == None || ViewportOwner.Actor.PlayerReplicationInfo.Team == None
         || ViewportOwner.Actor.PlayerReplicationInfo.Team.TeamIndex != 0 )
        Canvas.DrawColor = BlueTeamTint;
    else
        Canvas.DrawColor = RedTeamTint;
    Canvas.SetPos(EXPBarX, EXPBarY);
    Canvas.DrawTile(Material'InterfaceContent.Hud.SkinA', XL, 15.0 * Canvas.FontScaleY, 836, 454, -386, 36);
    Canvas.DrawColor = WhiteColor;
    Canvas.SetPos(EXPBarX, EXPBarY);
    Canvas.DrawTile(Material'InterfaceContent.Hud.SkinA', XL, 16.0 * Canvas.FontScaleY, 836, 415, -386, 38);

    Canvas.Style = 2;
    Canvas.DrawColor = WhiteColor;
    Canvas.SetPos(EXPBarX + 9.f * Canvas.FontScaleX, Canvas.ClipY * 0.75 - YL * 5.0);
    Canvas.DrawText(LevelText@StatsInv.Data.Level);
    Canvas.FontScaleX *= 0.75;
    Canvas.FontScaleY *= 0.75;
    Canvas.TextSize(StatsInv.Data.Experience$"/"$StatsInv.Data.NeededExp, XLSmall, YLSmall);
    Canvas.SetPos(Canvas.ClipX - XL * 0.5 - XLSmall * 0.5, Canvas.ClipY * 0.75 - YL * 3.75 + 12.5 * Canvas.FontScaleY - YLSmall * 0.5);
    Canvas.DrawText(StatsInv.Data.Experience$"/"$StatsInv.Data.NeededExp);
    Canvas.FontScaleX *= 1.33333;
    Canvas.FontScaleY *= 1.33333;

    if (bDefaultBindings)
    {
        Canvas.TextSize(StatsMenuText, XL, YL);
        Canvas.SetPos(Canvas.ClipX - XL - 1, Canvas.ClipY * 0.75 - YL * 1.25);
        Canvas.DrawText(StatsMenuText);
        if (StatsInv.Data.PointsAvailable > LevelMessagePointThreshold && ViewportOwner.Actor.Level.TimeSeconds >= LastLevelMessageTime + 1.0)
        {
            ViewportOwner.Actor.ReceiveLocalizedMessage(class'LevelUpHUDMessage', 0);
            LastLevelMessageTime = ViewportOwner.Actor.Level.TimeSeconds;
        }
        else if (StatsInv.Data.PointsAvailable < LevelMessagePointThreshold)
            LevelMessagePointThreshold = StatsInv.Data.PointsAvailable;
    }
    else if (StatsInv.Data.PointsAvailable > LevelMessagePointThreshold && ViewportOwner.Actor.Level.TimeSeconds >= LastLevelMessageTime + 1.0)
    {
        ViewportOwner.Actor.ReceiveLocalizedMessage(class'LevelUpHUDMessage', 1);
        LastLevelMessageTime = ViewportOwner.Actor.Level.TimeSeconds;
    }
    else if (StatsInv.Data.PointsAvailable < LevelMessagePointThreshold)
        LevelMessagePointThreshold = StatsInv.Data.PointsAvailable;

    if (RPGArtifact(ViewportOwner.Actor.Pawn.SelectedItem) != None)
    {
        //Draw Artifact HUD info
        Canvas.SetPos(0, Canvas.ClipY * 0.75 - YL * 5.0);
        Canvas.DrawText(ViewportOwner.Actor.Pawn.SelectedItem.ItemName);
        if (ViewportOwner.Actor.Pawn.SelectedItem.IconMaterial != None)
        {
            Canvas.SetPos(0, Canvas.ClipY * 0.75 - YL * 3.75);
            Canvas.DrawTile(ViewportOwner.Actor.Pawn.SelectedItem.IconMaterial, YL * 2, YL * 2, 0, 0, ViewportOwner.Actor.Pawn.SelectedItem.IconMaterial.MaterialUSize(), ViewportOwner.Actor.Pawn.SelectedItem.IconMaterial.MaterialVSize());
        }
        if (bDefaultArtifactBindings)
        {
            Canvas.SetPos(0, Canvas.ClipY * 0.75 - YL * 1.25);
            Canvas.DrawText(ArtifactText);
        }
    }

    Canvas.FontScaleX = Canvas.default.FontScaleX;
    Canvas.FontScaleY = Canvas.default.FontScaleY;
}

event NotifyLevelChange()
{
    //close stats menu if it's open
    FindStatsInv();
    if (StatsInv != None && StatsInv.StatsMenu != None)
        StatsInv.StatsMenu.CloseClick(None);
    StatsInv = None;

    //Save player data (standalone/listen servers only)
    if (RPGMut != None)
    {
        RPGMut.SaveData();
        RPGMut = None;
    }

    SaveConfig();
    Master.RemoveInteraction(self);
}

defaultproperties
{
     bDefaultBindings=True
     bDefaultArtifactBindings=True
     EXPBarColor=(B=128,G=255,R=128,A=255)
     WhiteColor=(B=255,G=255,R=255,A=255)
     RedTeamTint=(R=100,A=100)
     BlueTeamTint=(B=102,G=66,R=37,A=150)
     LevelText="Level:"
     StatsMenuText="Press L for stats/levelup menu"
     ArtifactText="U to use, brackets to switch"
     bVisible=True
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Sat 15/7/2006 17:15:14.000 - Creation time: Wed 7/2/2007 19:16:50.203 - Created with UnCodeX