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

GUI2K4.CustomFilter


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
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
//==============================================================================
//	Base class for custom server browser filters
//
//	Created by Ron Prestenback
//	© 2003, Epic Games, Inc.  All Rights Reserved
//==============================================================================
class CustomFilter extends Object
    DependsOn(MasterServerClient)
    Config(ServerFilters)
    PerObjectConfig;

enum EDataType
{
    DT_Unique,      // Only one item with this key can exist
    DT_Ranged,      // Max of two items with this key can exist, and QueryType cannot be QT_Equals
    DT_Multiple     // Allow multiple items with the same name
};

struct AFilterRule
{
    var MasterServerClient.QueryData    FilterItem; // Key, Value, QueryType
    var EDataType                       FilterType;
    var string                          ItemName;   // FriendlyName
};

struct CurrentFilter
{
    var AFilterRule Item;
    var int ItemIndex;          // Index of item
};

var protected config array<AFilterRule> Rules;
var protected config string             DefaultTitle;
var protected config bool               Active;

var protected array<CurrentFilter>      AllRules;
var protected string                    Title;
var protected bool                      bEnabled;

var protected bool                      bDirty;


function Created()
{
    CancelChanges();
}

function CancelChanges()
{
    Title = DefaultTitle;
    bEnabled = Active;
    InitializeRules();

    bDirty = False;
}

// Initialize all stored rules into the instance set
protected function InitializeRules()
{
    local int i;

    if (AllRules.Length > 0)
        AllRules.Remove(0, AllRules.Length);

    // Create working set of rules from stored values
    for (i = 0; i < Rules.Length; i++)
        AddRule(Rules[i].ItemName, Rules[i].FilterItem.Key, Rules[i].FilterItem.Value, Rules[i].FilterItem.QueryType, Rules[i].FilterType);
}

function bool SetTitle( string NewTitle )
{
    bDirty = bDirty || NewTitle != Title;
    Title = NewTitle;
    return true;
}

function bool SetActive( bool NewActive )
{
    bDirty = bDirty || NewActive != bEnabled;
    bEnabled = NewActive;
    return true;
}

function SetRules( array<CurrentFilter> NewRules )
{
    AllRules = NewRules;
    bDirty = True;
}



function string GetTitle()
{
    return Title;
}

function bool IsActive()
{
    return bEnabled;
}

function GetQueryRules( out array<AFilterRule> OutRules )
{
    Save();
    OutRules = Rules;
}

function GetRules( out array<CurrentFilter> OutRules )
{
    OutRules = AllRules;
}

function Save( optional bool bForceSave )
{
    local int i;
    if ( bDirty || bForceSave )
    {
        DefaultTitle = Title;
        Active = bEnabled;

        if ( Rules.Length > 0 )
            Rules.Remove(0, Rules.Length);

        for (i = 0; i < AllRules.Length; i++)
            Rules[Rules.Length] = AllRules[i].Item;

        SaveConfig();
    }

    bDirty = False;
}

//==============================================================================
//
// Query functions
//

function int Count()
{
    return AllRules.Length;
}

function bool FindRule( out AFilterRule Rule, string ItemName, optional string Value )
{
    local int i;

    i = FindRuleIndex(ItemName,Value);
    return GetRule(i, Rule);
}

function bool GetRule( int Index, out AFilterRule Rule )
{
    if ( ValidIndex(Index) )
    {
        Rule = AllRules[Index].Item;
        return True;
    }

    return False;
}

function int FindRuleIndex(string ItemName, optional string Value)
{
    local int i, j;

    j = InStr(ItemName, ".");
    if (j != -1)
        ItemName = Mid(ItemName, j+1);

    for (i = 0; i < AllRules.Length; i++)
        if (AllRules[i].Item.FilterItem.Key ~= ItemName)
        {
            if (Value == "" || (Value != "" && Value ~= AllRules[i].Item.FilterItem.Value))
                return i;
        }

    return -1;
}

// This function returns index for an item name and ItemIndex (for finding the absolute index of multi-items)
function int FindItemIndex(string ItemName, int ItemIndex)
{
    local int i;

    for (i = 0; i < AllRules.Length; i++)
        if (AllRules[i].Item.FilterItem.Key ~= ItemName && AllRules[i].ItemIndex == ItemIndex)
            return i;

    return -1;
}

protected function int FindLastIndex(string ItemName)
{
    local int i, j;

    j = -1;
    for (i = 0; i < AllRules.Length; i++)
    {
        if (AllRules[i].Item.FilterItem.Key ~= ItemName && AllRules[i].ItemIndex > j)
            j = AllRules[i].ItemIndex;
    }

    return j;
}

function int FindInnerIndex(string ItemName, string Value)
{
    local int i, j;

    j = InStr(ItemName, ".");
    if (j != -1)
        ItemName = Mid(ItemName, j+1);

    for (i = 0; i < AllRules.Length; i++)
        if (AllRules[i].Item.FilterItem.Key ~= ItemName && AllRules[i].Item.FilterItem.Value ~= Value)
            return AllRules[i].ItemIndex;

    return -1;
}

function string GetRuleKey(int Index)
{
    if (ValidIndex(Index))
        return AllRules[Index].Item.FilterItem.Key;

    return "";
}

function string GetRuleType(int Index)
{
    if (ValidIndex(Index))
        return GetDataTypeString(AllRules[Index].Item.FilterType);

    return "";
}

function string GetRuleQueryType( int Index )
{
    if ( ValidIndex(Index) )
        return string(GetEnum(enum'EQueryType', AllRules[Index].Item.FilterItem.QueryType));

    return "";
}

// Returns all values for a rule - works for single and multiple rules
function array<string> GetRuleValues(int Index)
{
    local int i;
    local array<string> Ar;
    local array<CurrentFilter> Subset;

    Subset = GetRuleSetAt(Index);

    for (i = 0; i < Subset.Length; i++)
        Ar[i] = Subset[i].Item.FilterItem.Value;

    return Ar;
}

function array<CurrentFilter> GetRuleSet(string ItemName)
{
    local int i;
    local array<CurrentFilter> RuleAr;

    ChopClass(ItemName);

    for (i = 0; i < AllRules.Length; i++)
        if (AllRules[i].Item.FilterItem.Key ~= ItemName)
            RuleAr[RuleAr.Length] = AllRules[i];

    return RuleAr;
}

function array<CurrentFilter> GetRuleSetAt(int Index)
{
    local array<CurrentFilter> RuleAr;

    if (ValidIndex(Index))
        RuleAr = GetRuleSet(AllRules[Index].Item.FilterItem.Key);

 return RuleAr;
}

function PostEdit(string NewTitle, array<CustomFilter.AFilterRule> NewRules)
{
    local int i;
    AllRules.Remove(0,AllRules.Length);
    Title = NewTitle;
    for (i=0;i<NewRules.Length;i++)
        AddRule(NewRules[i].ItemName,NewRules[i].FilterItem.Key, NewRules[i].FilterItem.Value, NewRules[i].FilterItem.QueryType, NewRules[i].FilterType);

    bDirty = true;
    Save();
}

function float AddRule(string NewName, string NewKey, string NewValue, MasterServerClient.EQueryType QType, EDataType DType)
{
    local int i, j;
    local CurrentFilter                 NewRule;
    local AFilterRule                   NewItem;
    local MasterServerClient.QueryData  KeyPair;


    j = FindLastIndex(NewKey);
    NewRule.ItemIndex = j+1;

    i = AllRules.Length;

    // Not found, so just add it
    KeyPair.Key = NewKey;
    KeyPair.Value = NewValue;
    KeyPair.QueryType = QType;

    NewItem.ItemName = NewName;
    NewItem.FilterItem = KeyPair;
    NewItem.FilterType = DType;

    NewRule.Item = NewItem;
    AllRules[i] = NewRule;

    bDirty = True;
    return i;
}


function bool RemoveRule(string ItemName)
{
    local int i;
    local bool bSuccess;

    for ( i = AllRules.Length - 1; i >= 0; i-- )
    {
        if (AllRules[i].Item.FilterItem.Key ~= ItemName)
        {
            bDirty = True;
            bSuccess = True;
            AllRules.Remove(i--, 1);
        }
    }
    return bSuccess;
}

function bool RemoveRuleAt(int Index)
{
    if (ValidIndex(Index))
        return RemoveRule(AllRules[Index].Item.FilterItem.Key);

    return false;
}

//==============================================================================
//
//	Saving & Loading
//

function ImportFilter(CustomFilter ImportFrom)
{
    SetTitle( ImportFrom.GetTitle() );
    SetActive( ImportFrom.IsActive() );

    ImportFrom.GetRules( AllRules );
    bDirty = True;
}

function ResetRules()
{
    CancelChanges();
}

function bool ChangeRule(int Index, string NewTag, string NewValue, MasterServerClient.EQueryType NewType)
{
    if (!ValidIndex(Index))
        return false;

    AllRules[Index].Item.ItemName = NewTag;
    AllRules[Index].Item.FilterItem.Value = NewValue;
    AllRules[Index].Item.FilterItem.QueryType = NewType;
    bDirty = True;
    return true;
}

function bool ValidIndex(int Index)
{
    return (Index >= 0 && Index < AllRules.Length);
}

//==============================================================================
//
//	Internal functions
//

static final function EDataType GetDataType(string DT)
{
    switch (DT)
    {
        case "DT_Multiple": return DT_Multiple;
        case "DT_Ranged":   return DT_Ranged;
        default:            return DT_Unique;
    }
}

static final function string GetDataTypeString(EDataType Type)
{
    if (Type == DT_Unique)
        return "DT_Unique";

    if (Type == DT_Ranged)
        return "DT_Ranged";

    if (Type == DT_Multiple)
        return "DT_Multiple";

    return "";
}

static final function string GetQueryString(MasterServerClient.EQueryType QT)
{
    switch (QT)
    {
        case QT_Equals:             return "QT_Equals";
        case QT_NotEquals:          return "QT_NotEquals";
        case QT_LessThan:           return "QT_LessThan";
        case QT_LessThanEquals:     return "QT_LessThanEquals";
        case QT_GreaterThan:        return "QT_GreaterThan";
        case QT_GreaterThanEquals:  return "QT_GreaterThanEquals";
        default:                    return "QT_Disabled";
    }

    return "";
}

static final function MasterServerClient.EQueryType GetQueryType(string QT)
{
    switch (QT)
    {
        case "QT_Equals":               return QT_Equals;
        case "QT_NotEquals":            return QT_NotEquals;
        case "QT_LessThan":             return QT_LessThan;
        case "QT_LessThanEquals":       return QT_LessThanEquals;
        case "QT_GreaterThan":          return QT_GreaterThan;
        case "QT_GreaterThanEquals":    return QT_GreaterThanEquals;
        default:                        return QT_Disabled;
    }
}

static final function AFilterRule StaticGenerateRule(string FriendlyName, string ItemName, string ItemVal, EDataType ItemDataType, MasterServerClient.EQueryType ItemQueryType)
{
    local AFilterRule                   NewItem;
    local MasterServerClient.QueryData  KeyPair;

    KeyPair.Key = ItemName;
    KeyPair.Value = ItemVal;
    KeyPair.QueryType = ItemQueryType;

    NewItem.ItemName = FriendlyName;
    NewItem.FilterItem = KeyPair;
    NewItem.FilterType = ItemDataType;

    return NewItem;
}

protected function string GetUniqueName(string Test, int Index)
{
    local int i, j;
    local string S;

    for (i = 0; i < AllRules.Length; i++)
    {
        if ( AllRules[i].ItemIndex == Index && AllRules[i].Item.ItemName ~= (Test $ S) )
        {
            S = " " $ string(++j);
            i = -1;
        }
    }

    return Test $ S;
}

static final function ChopClass(out string FullName)
{
    local int i;

    i = InStr(FullName, ".");
    while (i >= 0)
    {
        FullName = Mid(FullName, i+1);
        i = InStr(FullName, ".");
    }
}

defaultproperties
{
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Tue 24/10/2006 17:13:10.000 - Creation time: Wed 7/2/2007 19:16:36.171 - Created with UnCodeX