1 /** @file secretswidget.cpp GUI widget for -.
2 *
3 * @authors Copyright © 2005-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4 * @authors Copyright © 2005-2015 Daniel Swanson <danij@dengine.net>
5 *
6 * @par License
7 * GPL: http://www.gnu.org/licenses/gpl.html
8 *
9 * <small>This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version. This program is distributed in the hope that it
13 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15 * Public License for more details. You should have received a copy of the GNU
16 * General Public License along with this program; if not, write to the Free
17 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA</small>
19 */
20
21 #include "hud/widgets/secretswidget.h"
22
23 #include "common.h"
24 #include "p_actor.h"
25
26 using namespace de;
27
SecretsWidget_Draw(guidata_secrets_t * scrts,Point2Raw const * offset)28 static void SecretsWidget_Draw(guidata_secrets_t *scrts, Point2Raw const *offset)
29 {
30 DENG2_ASSERT(scrts);
31 scrts->draw(offset? Vector2i(offset->xy) : Vector2i());
32 }
33
SecretsWidget_UpdateGeometry(guidata_secrets_t * scrts)34 static void SecretsWidget_UpdateGeometry(guidata_secrets_t *scrts)
35 {
36 DENG2_ASSERT(scrts);
37 scrts->updateGeometry();
38 }
39
guidata_secrets_t(dint player)40 guidata_secrets_t::guidata_secrets_t(dint player)
41 : HudWidget(function_cast<UpdateGeometryFunc>(SecretsWidget_UpdateGeometry),
42 function_cast<DrawFunc>(SecretsWidget_Draw),
43 player)
44 {}
45
~guidata_secrets_t()46 guidata_secrets_t::~guidata_secrets_t()
47 {}
48
reset()49 void guidata_secrets_t::reset()
50 {
51 _value = 1994;
52 }
53
draw(Vector2i const & offset) const54 void guidata_secrets_t::draw(Vector2i const &offset) const
55 {
56 #if !__JHEXEN__
57
58 dfloat const textOpacity = ::uiRendState->pageAlpha * ::cfg.common.hudColor[3];
59
60 if(_value == 1994) return;
61
62 if(!(::cfg.common.hudShownCheatCounters & (CCH_SECRETS | CCH_SECRETS_PRCNT))) return;
63 if(ST_AutomapIsOpen(player()) && ::cfg.common.automapHudDisplay == 0) return;
64 if(P_MobjIsCamera(::players[player()].plr->mo) && Get(DD_PLAYBACK)) return;
65 if(::cfg.common.hudCheatCounterShowWithAutomap && !ST_AutomapIsOpen(player())) return;
66
67 String valueAsText("Secret");
68 if(::cfg.common.hudShownCheatCounters & CCH_SECRETS)
69 {
70 valueAsText += String(" %1/%2").arg(_value).arg(totalSecret);
71 }
72 if(::cfg.common.hudShownCheatCounters & CCH_SECRETS_PRCNT)
73 {
74 valueAsText += String(" %1%2%%3")
75 .arg((cfg.common.hudShownCheatCounters & CCH_SECRETS) ? "(" : "")
76 .arg(totalSecret ? _value * 100 / totalSecret : 100)
77 .arg((cfg.common.hudShownCheatCounters & CCH_SECRETS) ? ")" : "");
78 }
79
80 DGL_MatrixMode(DGL_MODELVIEW);
81 DGL_PushMatrix();
82 DGL_Translatef(offset.x, offset.y, 0);
83 DGL_Scalef(::cfg.common.hudCheatCounterScale, ::cfg.common.hudCheatCounterScale, 1);
84 DGL_Enable(DGL_TEXTURE_2D);
85
86 FR_SetFont(font());
87 FR_SetColorAndAlpha(::cfg.common.hudColor[0], ::cfg.common.hudColor[1], ::cfg.common.hudColor[2], textOpacity);
88 FR_DrawTextXY(valueAsText.toUtf8().constData(), 0, 0);
89
90 DGL_Disable(DGL_TEXTURE_2D);
91 DGL_MatrixMode(DGL_MODELVIEW);
92 DGL_PopMatrix();
93
94 #else // !__JHEXEN__
95 DENG2_UNUSED(offset);
96 #endif
97 }
98
tick(timespan_t)99 void guidata_secrets_t::tick(timespan_t /*elapsed*/)
100 {
101 if(Pause_IsPaused() || !DD_IsSharpTick()) return;
102
103 player_t const &plr = ::players[player()];
104 _value = plr.secretCount;
105 }
106
updateGeometry()107 void guidata_secrets_t::updateGeometry()
108 {
109 #if !__JHEXEN__
110
111 Rect_SetWidthHeight(&geometry(), 0, 0);
112
113 if(_value == 1994) return;
114
115 if(!(::cfg.common.hudShownCheatCounters & (CCH_SECRETS | CCH_SECRETS_PRCNT))) return;
116 if(ST_AutomapIsOpen(player()) && ::cfg.common.automapHudDisplay == 0) return;
117 if(P_MobjIsCamera(::players[player()].plr->mo) && Get(DD_PLAYBACK)) return;
118 if(::cfg.common.hudCheatCounterShowWithAutomap && !ST_AutomapIsOpen(player())) return;
119
120 String valueAsText("Secret");
121 if(::cfg.common.hudShownCheatCounters & CCH_SECRETS)
122 {
123 valueAsText += String(" %1/%2").arg(_value).arg(totalSecret);
124 }
125 if(::cfg.common.hudShownCheatCounters & CCH_SECRETS_PRCNT)
126 {
127 valueAsText += String(" %1%2%%3")
128 .arg((cfg.common.hudShownCheatCounters & CCH_SECRETS) ? "(" : "")
129 .arg(totalSecret ? _value * 100 / totalSecret : 100)
130 .arg((cfg.common.hudShownCheatCounters & CCH_SECRETS) ? ")" : "");
131 }
132
133 FR_SetFont(font());
134 Size2Raw textSize; FR_TextSize(&textSize, valueAsText.toUtf8().constData());
135 Rect_SetWidthHeight(&geometry(), .5f + textSize.width * ::cfg.common.hudCheatCounterScale,
136 .5f + textSize.height * ::cfg.common.hudCheatCounterScale);
137
138 #endif // !__JHEXEN__
139 }
140