summaryrefslogtreecommitdiff
path: root/src/Plugins/Common/StdShopInfoDialog.cpp
blob: 67aee0b645555565eb1da7d13bb0067fc0bcb849 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "StdAfx.h"
#include "StdShopInfoDialog.h"
#include "../../T2DLL/T2DateTime.h"
#include "../../T2DLL/T2DlgItemArrows.h"
#include "../../T2DLL/T2DlgItemEdit.h"
#include "../../T2DLL/T2DlgItemMerchandiseField.h"
#include "../../T2DLL/T2Tenant.h"
#include "../../T2DLL/T2TenantMemberDef.h"
#include "../../T2DLL/T2TenantMemberTableDef.h"
#include "../../T2TowerDoc.h"
#include "../../T2DLL/T2WorldDef.h"

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

StdShopInfoDialog::StdShopInfoDialog(T2Tenant *inTenant)
    : StdTenantInfoDialog(inTenant)
    , mNumMerchandise(0)
{
}

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

/*virtual*/ void StdShopInfoDialog::GenerateComments() {
    StdTenantInfoDialog::GenerateComments();

    T2DateTime *now = GetDocument()->GetNow();
#line 40
    _ASSERT(now != NULL);

    if (GetTenant()->IsOpen()) {
        // EN: There aren't many customers.
        int id = 18;

        switch (GetTenant()->CalcEstimateColor()) {
            case 9:
                // EN: There aren't many customers.
                id = 18;
                break;
            case 14:
                // EN: There are a few customers.
                id = 19;
                break;
            case 12:
                // EN: Business is booming.
                id = 20;
                break;
        }

        AppendComment(id);

        if (id == 20 && now->IsHoliday(GetDocument())) {
            // EN: There are many customers due to the weekend.
            AppendComment(21);
        }

        if (id == 18 && GetDocument()->GetWorldDef()->IsRainyDay(now)) {
            // EN: There are fewer customers because its a rainy day.
            AppendComment(22);
        }
    } else {
        if (GetTenant()->GetStatus() == kTenantStatus11) {
            // EN: Will be opened tomorrow.
            AppendComment(23);
        }
    }
}

/*virtual*/ void StdShopInfoDialog::OnT2Create() {
    StdTenantInfoDialog::OnT2Create();

    if (!GetTenant()->IsFire())
        InitNormal();
    else
        InitFire();
}

/*virtual*/ void StdShopInfoDialog::OnT2OK() {
    StdTenantInfoDialog::OnT2OK();

    if (!GetTenant()->IsFire())
        SaveMerchandise();
}

void StdShopInfoDialog::InitNormal() {
    T2TenantMemberTableDef *theTMT = GetTenant()->GetMerchandiseTMT();
    if (theTMT) {
        mNumMerchandise = theTMT->GetNumOfElem();

        for (int i = 0; i < 4; i++) {
            T2TenantMemberDef *theMerchandise = (i < mNumMerchandise) ? theTMT->GetElem(i) : NULL;

            T2DlgItem *text = GetT2DlgItem(8001 + i * 4);
            if (text && theMerchandise) {
                CString name;
                theMerchandise->GetName(name);
                text->SetDescriptor(name);
            }

            T2DlgItem *merchandise = GetT2DlgItem(8002 + i * 4);
            if (merchandise) {
                if (theMerchandise)
                    merchandise->SetValue(theMerchandise->GetPercent());
                else
                    merchandise->EnableWindow(false);
            }

            T2DlgItemArrows *arrows = (T2DlgItemArrows *) GetT2DlgItem(8003 + i * 4);
            if (arrows) {
                if (theMerchandise)
                    arrows->SetValue(theMerchandise->GetPercent());

                arrows->SetMinValue(0);
                arrows->SetMaxValue(100);
                arrows->ShowWindow(SW_HIDE);
            }
        }
    }
}

void StdShopInfoDialog::InitFire() {
    for (int i = 0; i < 4; i++) {
        T2DlgItem *merchandise = GetT2DlgItem(8002 + i * 4);
        merchandise->EnableWindow(false);

        T2DlgItemArrows *arrows = (T2DlgItemArrows *) GetT2DlgItem(8003 + i * 4);
        arrows->ShowWindow(SW_HIDE);
    }
}

void StdShopInfoDialog::SaveMerchandise() {
    if (mNumMerchandise > 0) {
        int i, array[4];

        for (i = 0; i < 4; i++) {
            T2DlgItem *theField = GetT2DlgItem(8002 + i * 4);
            if (theField)
                array[i] = theField->GetValue();
            else
                break;
        }

        GetTenant()->SetMerchandise(i, array);
    }
}

/*virtual*/ BOOL StdShopInfoDialog::OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam) {
    BOOL result = false;
    WORD code = HIWORD(inWParam);
    WORD itemID = LOWORD(inWParam);

    for (int n = 0; n < 4; n++) {
        if (itemID == (8003 + n * 4)) {
            result = true;

            T2DlgItemArrows *arrows = (T2DlgItemArrows *) GetT2DlgItem(8003 + n * 4);
            T2DlgItemMerchandiseField *field = (T2DlgItemMerchandiseField *) GetT2DlgItem(8002 + n * 4);
            if (arrows && field) {
                int change = arrows->GetValue() - field->GetValue();
                if (change == 0)
                    break;

                for (int next = (n + 1) % mNumMerchandise; next != n; next = (next + 1) % mNumMerchandise) {
                    T2DlgItemArrows *nextArrows = (T2DlgItemArrows *) GetT2DlgItem(8003 + next * 4);
                    T2DlgItemMerchandiseField *nextField = (T2DlgItemMerchandiseField *) GetT2DlgItem(8002 + next * 4);

                    if (nextArrows && nextField) {
                        int nextValue = nextField->GetValue();
                        if ((change > 0 && nextValue > 0) || (change < 0 && nextValue < 100)) {
                            nextValue -= change;
                            nextField->SetValue(nextValue);
                            nextArrows->SetValue(nextValue);
                            nextField->Invalidate();

                            field->SetValue(arrows->GetValue());
                            field->SelectAll();
                            field->Invalidate();
                            break;
                        }
                    }
                }
            }
            break;
        }
    }

    if (!result)
        result = StdTenantInfoDialog::OnT2DialogCommand(inWParam, inLParam);

    return result;
}