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

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

DbgEventList::DbgEventList(CWnd *pParent)
    : CDialog(IDD, pParent)
{
    //{{AFX_DATA_INIT(DbgEventList)
    //}}AFX_DATA_INIT
}

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

BEGIN_MESSAGE_MAP(DbgEventList, CDialog)
    //{{AFX_MSG_MAP(DbgEventList)
    ON_COMMAND(IDC_EVENT_START, OnEventStart)
    //}}AFX_MSG_MAP
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();
}