summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2ToolHelpWnd.cpp
blob: c730a2a1dca0c15c8a4169a3f13041b0b6fafd7c (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include "T2ToolDef.h"
#include "T2ToolHelpWnd.h"

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

#line 20
IMPLEMENT_DYNCREATE(T2ToolHelpWnd, CFrameWnd);

T2ToolHelpWnd::T2ToolHelpWnd() {
    mVisible = false;
}

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

BEGIN_MESSAGE_MAP(T2ToolHelpWnd, CFrameWnd)
    ON_WM_ERASEBKGND()
    ON_WM_DESTROY()
END_MESSAGE_MAP()

void T2ToolHelpWnd::OpenToolHelp(POINT& inPt, int inMode, const char* inStr1, const char* inStr2, T2ToolDef* inToolDef, int inValiation) {
#pragma var_order(rect5, rect, save, unit, var48, var4C, rgn, rect2, rect4, rect3, pDC)
    int var48 = inPt.x;
    int var4C = inPt.y;

    if (inMode == kToolHelpMode0) {
        mHeader = inStr2;
        mHeader = mHeader.Left(mHeader.Find("\n"));
        mText = inStr2;
        mText = mText.Mid(mText.Find("\n") + 1);
        mComment = "";
    } else if (inMode == kToolHelpMode1) {
        mHeader = inStr1;
        mText = inStr2;
        mComment = "";
    } else if (inMode == kToolHelpMode2) {
        CString tmp;
        mHeader = *inToolDef->mToolName[inValiation];

        // "設置費:" - Installation fee:
        mText = "\x90\xDD\x92\x75\x94\xEF\x81\x46";
        mText += *inToolDef->mPriceString[inValiation];

        // "\n維持費:" - Maintenance costs:
        mText += "\n\x88\xDB\x8E\x9D\x94\xEF\x81\x46";
        mText += *inToolDef->mOutMoneyString[inValiation];

        // "\n電 力:%d" - Power: %d
        tmp.Format("\n\x93\x64\x81\x40\x97\xCD\x81\x46\x25\x64", inToolDef->mConsumptionPower[inValiation]);
        mText += tmp;

        // "\n設置数:%d/" - Installed number: %d/
        tmp.Format("\n\x90\xDD\x92\x75\x90\x94\x81\x46\x25\x64\x81\x5E", inToolDef->mCurBuildCount);
        mText += tmp;

        if (inToolDef->mMaxBuildCount == 0) {
            // "無制限" - Unlimited
            mText += "\x96\xB3\x90\xA7\x8C\xC0";
        } else {
            tmp.Format("%d", inToolDef->mMaxBuildCount);
            mText += tmp;
        }

        mComment = *inToolDef->mCommentString[inValiation];
    }

    mHeader.TrimRight();
    mText.TrimRight();
    mComment.TrimRight();

    mFont.CreatePointFont(90, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E");
    mWndClass = AfxRegisterWndClass(CS_NOCLOSE, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH));

    CRect rect(0, 0, 50, 50);
    Create(mWndClass, "", WS_POPUP, rect, AfxGetMainWnd(), NULL, WS_EX_TOPMOST);

    CRect rect2;
    GetClientRect(rect2);
    ClientToScreen(rect2);

    CRect rect3;
    rect3.top = rect2.top - rect.top;
    rect3.left = rect2.left - rect.left;
    rect3.bottom = rect.bottom - rect2.bottom;
    rect3.right = rect.right - rect2.right;

    CDC *pDC = GetDC();
    int save = pDC->SaveDC();
    pDC->SelectObject(mFont);

    mRect.SetRectEmpty();
    // "1234567890123456789"
    pDC->DrawText("\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58\x82\x4F\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58", &mRect, DT_SINGLELINE | DT_CALCRECT);
    pDC->DrawText(mText, &mRect, DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);

    if (mComment != "") {
        CRect innerRect;
        innerRect.SetRectEmpty();
        pDC->DrawText("\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58\x82\x4F\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58", innerRect, DT_SINGLELINE | DT_CALCRECT);
        pDC->DrawText(mComment, &innerRect, DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);

        mRect.right = max(mRect.right, innerRect.right);
        mRect.bottom += innerRect.bottom + 10;
    }

    if (mHeader != "") {
        CRect innerRect;
        innerRect.SetRectEmpty();
        pDC->DrawText(mHeader, &innerRect, DT_CALCRECT | DT_NOPREFIX);

        mRect.right = max(mRect.right, innerRect.right);
        mRect.bottom += innerRect.bottom + 10;
    }

    mRect.NormalizeRect();
    mRect.OffsetRect(-mRect.left, -mRect.top);

    CRect rect4;
    rect4.SetRect(10, 10, 10, 10);
    mRect.OffsetRect(rect4.left, rect4.top);

    CRect rect5;
    rect5 = mRect;
    rect5 += rect4;
    rect5.InflateRect(0, 0, 0, 16);
    rect5.NormalizeRect();
    rect5.OffsetRect(-rect5.left, -rect5.top);
    rect5.OffsetRect(var48, var4C);
    rect5 += rect3;

    SetWindowPos(NULL, rect5.left, rect5.top, rect5.Width(), rect5.Height(), SWP_NOZORDER | SWP_NOACTIVATE);

    rect5 -= rect3;
    rect5.OffsetRect(-rect5.left, -rect5.top);

    CRect unit(1, 1, 1, 1);
    rect5 -= unit;

    mRgn.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom, 10, 10);

    CRgn rgn;
    rgn.CreateRectRgn(0, 0, 1, 1);
    rgn.CopyRgn(&mRgn);
    rgn.OffsetRgn(rect3.left, rect3.top);
    ::SetWindowRgn(m_hWnd, rgn, true);
    rgn.Detach();

    pDC->RestoreDC(save);
    ReleaseDC(pDC);

    ShowWindow(SW_SHOWNA);
    mVisible = true;
}

void T2ToolHelpWnd::CloseToolHelp() {
    if (mVisible) {
        ShowWindow(SW_HIDE);
        DestroyWindow();
        mVisible = false;
    }
}

BOOL T2ToolHelpWnd::OnEraseBkgnd(CDC* pDC) {
    int saved = pDC->SaveDC();

    CRect clientRect;
    GetClientRect(clientRect);
    pDC->FillSolidRect(clientRect, RGB(255, 255, 255));

    CBrush theBrush;
    theBrush.CreateStockObject(BLACK_BRUSH);
    pDC->FrameRgn(&mRgn, &theBrush, 1, 1);

    pDC->SetBkMode(TRANSPARENT);
    pDC->SetTextColor(RGB(0, 0, 0));
    pDC->SelectObject(mFont);

    CRect curRect = mRect;
    int curY = mRect.top;

    if (mHeader != "") {
        curRect.top = curY;
        curY += pDC->DrawText(mHeader, curRect, DT_CENTER);
        curY += 5;
        pDC->MoveTo(curRect.left + 15, curY);
        pDC->LineTo(curRect.right - 15, curY);
        curY += 5;
    }

    if (mText != "") {
        curRect.top = curY;
        curY += pDC->DrawText(mText, curRect, DT_WORDBREAK | DT_NOPREFIX);

        if (mComment != "") {
            curY += 5;
            pDC->MoveTo(curRect.left + 15, curY);
            pDC->LineTo(curRect.right - 15, curY);
            curY += 5;
        }
    }

    if (mComment != "") {
        curRect.top = curY;
        curY += pDC->DrawText(mComment, curRect, DT_WORDBREAK | DT_NOPREFIX);
    }

    pDC->RestoreDC(saved);
    return true;
}

void T2ToolHelpWnd::OnDestroy() {
    CFrameWnd::OnDestroy();
}