summaryrefslogtreecommitdiff
path: root/src/T2DLL/PeopleSearchDlg.cpp
blob: 77aad69cab302c91a6b1c7993df976a8f5fb1e5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "StdAfx.h"
#include "PeopleSearchDlg.h"
#include "T2DlgItemListBox.h"
#include "T2FloorInfo.h"
#include "T2Name.h"
#include "T2NameList.h"
#include "T2People.h"
#include "T2PeopleArrayList.h"
#include "T2Tenant.h"
#include "../T2TowerDoc.h"
#include "T2WorldDef.h"
#include "UT2Utils.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

PeopleSearchDlg::PeopleSearchDlg() {
    mDeleteOnClose = true;
}

/*virtual*/ PeopleSearchDlg::~PeopleSearchDlg() {
}

void PeopleSearchDlg::Create(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt) {
    mDocument = inDoc;

    T2DLGTEMPLATE tmpl;
    tmpl.resID = 7110;
    tmpl.pt = inPt;
    tmpl.moduleHandle = inInstance;

    Realize(inParentWnd, &tmpl, inDoc, NULL, inDoc->mWorldDef->GetPalette(), false, inParentWnd, 110, true);
    ShowWindow(SW_HIDE);
}

void PeopleSearchDlg::DoFind() {
    T2DlgItemListBox *listBox = (T2DlgItemListBox *) GetDlgItem(1000);
    if (!listBox)
        return;

    int sel = listBox->GetCurSel();
    if (sel == -1)
        return;

    T2Name *theName = (T2Name *) listBox->GetItemDataPtr(sel);
    mDocument->DoFind(theName);
}

void PeopleSearchDlg::DoDelete() {
    T2DlgItemListBox *listBox = (T2DlgItemListBox *) GetDlgItem(1000);
    if (!listBox)
        return;

    int sel = listBox->GetCurSel();
    if (sel == -1)
        return;

    T2Name *theName = (T2Name *) listBox->GetItemDataPtr(sel);
    mDocument->mNameDB->RemoveName(theName);
    listBox->DeleteString(sel);
}

/*virtual*/ void PeopleSearchDlg::OnT2Create() {
    T2DlgItemListBox *listBox = (T2DlgItemListBox *) GetDlgItem(1000);

    if (!listBox)
        return;

    HFONT theFont = GetFont();
    if (theFont)
        listBox->SetFont(theFont);

    listBox->ResetContent();

    T2NameList *theNameList = mDocument->mNameDB;
    T2Name *theName;
    LArrayIterator iter(*theNameList);

    while (iter.Next(&theName)) {
        int type = theName->GetType();
        if (type == kPeopleNameType) {
            CString name;
            unsigned int id;
            theName->GetName(name, id);

            T2People *thePeople = mDocument->mPeopleArrayList->FindPeople(id);
            if (thePeople) {
                CString roomNum;
                CString text;

                if (thePeople->GetWorkTenant() > 1) {
                    T2Tenant *theTenant = mDocument->mFloorInfo->GetTenant(thePeople->GetWorkTenant());
                    if (theTenant)
                        UT2Utils::GetRoomNumberString(theTenant->GetRoomNumber(mDocument->mFloorInfo), roomNum);
                }

                roomNum += "       ";
                text = roomNum.Left(7);
                text += name;

                int ind = listBox->AddString(text);
                listBox->SetItemDataPtr(ind, theName);
            }
        }
    }
}