summaryrefslogtreecommitdiff
path: root/src/DbgEventList.cpp
blob: 107f33f00ce57d79515ab2dc39414b2ec1a31d1e (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
#include "DbgEventList.h"
#include "GlobalFunc.h"
#include "LArray.h"
#include "T2EventItem.h"
#include "T2TowerDoc.h"
#include "T2TowerEvent.h"
#include "T2WorldDef.h"

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

DbgEventList::DbgEventList(CWnd *pParentWnd)
    : CDialog(182, pParentWnd)
{
}

/*virtual*/ void DbgEventList::DoDataExchange(CDataExchange *pDX) {
    CWnd::DoDataExchange(pDX);
    DDX_Control(pDX, 1020, mList);
}

BEGIN_MESSAGE_MAP(DbgEventList, CDialog)
    ON_COMMAND(1021, OnEventStart)
END_MESSAGE_MAP()

/*virtual*/ BOOL DbgEventList::OnInitDialog() {
    CDialog::OnInitDialog();

    RECT rect;
    mList.GetClientRect(&rect);
    int width = rect.right;

    mList.InsertColumn(0, "Type", LVCFMT_LEFT, width / 6);
    mList.InsertColumn(1, "ID", LVCFMT_LEFT, width / 6);
    mList.InsertColumn(2, "Mode", LVCFMT_LEFT, width / 6);
    mList.InsertColumn(3, "Status", LVCFMT_LEFT, width / 6);
    mList.InsertColumn(4, "Start", LVCFMT_LEFT, width / 6);
    mList.InsertColumn(5, "End", LVCFMT_LEFT, width / 6);

    mTowerEvent = GetCurrentT2TowerDoc()->GetWorldDef()->GetTowerEvent();
    RefreshEvents();

    return true;
}

void DbgEventList::RefreshEvents() {
    mList.DeleteAllItems();
    AddEvents(mTowerEvent->mStandby, "Standby");
    AddEvents(mTowerEvent->mWaiting, "Waiting");
    AddEvents(mTowerEvent->mRunning, "Running");
}

void DbgEventList::AddEvents(LArray &array, const char *mode) {
    LArrayIterator iterator(array);
    CString str;
    T2EventItem *eventItem;

    while (iterator.Next(&eventItem)) {
        DWORD id = eventItem->GetID();
        str.Format("%c%c%c%c", ((BYTE *) &id)[3], ((BYTE *) &id)[2], ((BYTE *) &id)[1], ((BYTE *) &id)[0]);
        int index = mList.InsertItem(0, str);

        str.Format("%d", eventItem->GetSubID());
        mList.SetItemText(index, 1, str);

        str = mode;
        if (eventItem->mForceStart)
            str += "!";
        mList.SetItemText(index, 2, str);

        str.Format("%d", eventItem->GetStatus());
        mList.SetItemText(index, 3, str);

        str.Format("%d", eventItem->GetBeginTime());
        mList.SetItemText(index, 4, str);

        str.Format("%d", eventItem->GetEndTime());
        mList.SetItemText(index, 5, str);

        mList.SetItemData(index, (DWORD) eventItem);
    }
}

void DbgEventList::OnEventStart() {
    int numOfItems = mList.GetItemCount();
    for (int index = 0; index < numOfItems; index++) {
        if (mList.GetItemState(index, LVIS_SELECTED)) {
            T2EventItem *eventItem = (T2EventItem *) mList.GetItemData(index);
            eventItem->mForceStart = true;
        }
    }

    mTowerEvent->Idle(GetCurrentT2TowerDoc());
    RefreshEvents();
}