1 /*
2 * Copyright 2010-2014 OpenXcom Developers.
3 *
4 * This file is part of OpenXcom.
5 *
6 * OpenXcom is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * OpenXcom is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "ActionMenuItem.h"
20 #include "../Interface/Text.h"
21 #include "../Interface/Frame.h"
22 #include "../Engine/Palette.h"
23 #include "../Engine/Game.h"
24 #include "../Resource/ResourcePack.h"
25
26 namespace OpenXcom
27 {
28
29 /**
30 * Sets up an Action menu item.
31 * @param id The unique identifier of the menu item.
32 * @param game Pointer to the game.
33 * @param x Position on the x-axis.
34 * @param y Position on the y-asis.
35 */
ActionMenuItem(int id,Game * game,int x,int y)36 ActionMenuItem::ActionMenuItem(int id, Game *game, int x, int y) : InteractiveSurface(270, 40, x + 25, y - (id*40)), _highlighted(false), _action(BA_NONE), _tu(0)
37 {
38 Font *big = game->getResourcePack()->getFont("FONT_BIG"), *small = game->getResourcePack()->getFont("FONT_SMALL");
39 Language *lang = game->getLanguage();
40
41 _frame = new Frame(getWidth(), getHeight(), 0, 0);
42 _frame->setHighContrast(true);
43 _frame->setColor(Palette::blockOffset(0)+7);
44 _frame->setBackground(Palette::blockOffset(0)+14);
45 _frame->setThickness(9);
46
47 _txtDescription = new Text(200, 20, 10, 13);
48 _txtDescription->initText(big, small, lang);
49 _txtDescription->setBig();
50 _txtDescription->setHighContrast(true);
51 _txtDescription->setColor(Palette::blockOffset(0)-1);
52 _txtDescription->setVisible(true);
53
54 _txtAcc = new Text(100, 20, 140, 13);
55 _txtAcc->initText(big, small, lang);
56 _txtAcc->setBig();
57 _txtAcc->setHighContrast(true);
58 _txtAcc->setColor(Palette::blockOffset(0)-1);
59
60 _txtTU = new Text(80, 20, 210, 13);
61 _txtTU->initText(big, small, lang);
62 _txtTU->setBig();
63 _txtTU->setHighContrast(true);
64 _txtTU->setColor(Palette::blockOffset(0)-1);
65 }
66
67 /**
68 * Deletes the ActionMenuItem.
69 */
~ActionMenuItem()70 ActionMenuItem::~ActionMenuItem()
71 {
72 delete _frame;
73 delete _txtDescription;
74 delete _txtAcc;
75 delete _txtTU;
76 }
77
78 /**
79 * Links with an action and fills in the text fields.
80 * @param action The battlescape action.
81 * @param description The actions description.
82 * @param accuracy The actions accuracy, including the Acc> prefix.
83 * @param timeunits The timeunits string, including the TUs> prefix.
84 * @param tu The timeunits value.
85 */
setAction(BattleActionType action,std::wstring description,std::wstring accuracy,std::wstring timeunits,int tu)86 void ActionMenuItem::setAction(BattleActionType action, std::wstring description, std::wstring accuracy, std::wstring timeunits, int tu)
87 {
88 _action = action;
89 _txtDescription->setText(description);
90 _txtAcc->setText(accuracy);
91 _txtTU->setText(timeunits);
92 _tu = tu;
93 _redraw = true;
94 }
95
96 /**
97 * Gets the action that was linked to this menu item.
98 * @return Action that was linked to this menu item.
99 */
getAction() const100 BattleActionType ActionMenuItem::getAction() const
101 {
102 return _action;
103 }
104
105 /**
106 * Gets the action tus that were linked to this menu item.
107 * @return The timeunits that were linked to this menu item.
108 */
getTUs() const109 int ActionMenuItem::getTUs() const
110 {
111 return _tu;
112 }
113
114 /**
115 * Replaces a certain amount of colors in the surface's palette.
116 * @param colors Pointer to the set of colors.
117 * @param firstcolor Offset of the first color to replace.
118 * @param ncolors Amount of colors to replace.
119 */
setPalette(SDL_Color * colors,int firstcolor,int ncolors)120 void ActionMenuItem::setPalette(SDL_Color *colors, int firstcolor, int ncolors)
121 {
122 Surface::setPalette(colors, firstcolor, ncolors);
123 _frame->setPalette(colors, firstcolor, ncolors);
124 _txtDescription->setPalette(colors, firstcolor, ncolors);
125 _txtAcc->setPalette(colors, firstcolor, ncolors);
126 _txtTU->setPalette(colors, firstcolor, ncolors);
127 }
128
129 /**
130 * Draws the bordered box.
131 */
draw()132 void ActionMenuItem::draw()
133 {
134 _frame->blit(this);
135 _txtDescription->blit(this);
136 _txtAcc->blit(this);
137 _txtTU->blit(this);
138 }
139
140 /**
141 * Processes a mouse hover in event.
142 * @param action Pointer to an action.
143 * @param state Pointer to a state.
144 */
mouseIn(Action * action,State * state)145 void ActionMenuItem::mouseIn(Action *action, State *state)
146 {
147 _highlighted = true;
148 _frame->setBackground(Palette::blockOffset(0) + 11);
149 draw();
150 InteractiveSurface::mouseIn(action, state);
151 }
152
153
154 /**
155 * Processes a mouse hover out event.
156 * @param action Pointer to an action.
157 * @param state Pointer to a state.
158 */
mouseOut(Action * action,State * state)159 void ActionMenuItem::mouseOut(Action *action, State *state)
160 {
161 _highlighted = false;
162 _frame->setBackground(Palette::blockOffset(0) + 14);
163 draw();
164 InteractiveSurface::mouseOut(action, state);
165 }
166
167
168 }
169