1 /************************************************************************ 2 * * 3 * FreeSynd - a remake of the classic Bullfrog game "Syndicate". * 4 * * 5 * Copyright (C) 2013 Benoit Blancard <benblan@users.sourceforge.net>* 6 * * 7 * This program is free software; you can redistribute it and / or * 8 * modify it under the terms of the GNU General Public License as * 9 * published by the Free Software Foundation; either version 2 of the * 10 * License, or (at your option) any later version. * 11 * * 12 * This program is distributed in the hope that it will be useful, * 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 15 * General Public License for more details. * 16 * * 17 * You can view the GNU General Public License, online, at the GNU * 18 * project's web site; see <http://www.gnu.org/licenses/gpl.html>. * 19 * The full text of the license is also included in the file COPYING. * 20 * * 21 ************************************************************************/ 22 23 #ifndef MENUS_AGENTSELECTORRENDERER_H_ 24 #define MENUS_AGENTSELECTORRENDERER_H_ 25 26 #include "ipastim.h" 27 #include "menus/squadselection.h" 28 29 /*! 30 * The SelectorEvent class is the event that is used 31 * to tell where the player has clicked on the control panel. 32 */ 33 class SelectorEvent { 34 public: 35 /*! 36 * This enumeration lists the different types of event. 37 */ 38 enum EType { 39 kNone, 40 kSelectAgent, 41 kSelectIpa 42 }; 43 44 /*! The type of the event.*/ 45 EType eventType; 46 /*! What agent was clicked.*/ 47 size_t agentSlot; 48 /*! The type of IPA selected for eventType = kSelectIpa.*/ 49 IPAStim::IPAType IpaType; 50 /*! for eventType = kSelectIpa.*/ 51 int percentage; 52 }; 53 54 /*! 55 * This renderer manages the drawing of agent selector on the control panel 56 * in the gameplay menu. 57 */ 58 class AgentSelectorRenderer 59 { 60 public: 61 //! Check if player has clicked on a agent selector 62 bool hasClickedOnAgentSelector(int x, int y, SelectorEvent & evt); 63 //! Renders the agent's selectors 64 void render(SquadSelection & selection, Squad * pSquad); 65 66 private: 67 static const int kIpaBarWidth; 68 static const int kIpaBarHeight; 69 static const int kIpaBarLeft13; 70 static const int kIpaBarLeft24; 71 static const int kIpaBarTop12; 72 static const int kIpaBarTop34; 73 static const int kIpaYOffset; 74 75 /*! 76 * Checks if the player has clicked on an IPA bar for an agent. 77 * \return NULL if the player didn't click on a IPA meter. 78 */ 79 void scanCoordsForIPA(int x, int y, SelectorEvent & evt); 80 81 //! Draws all the elements for one bar 82 void drawIPABar(int agent, IPAStim *stim); 83 84 /*! 85 * Returns the Y coord of the top left corner of the IPA bar for a given agent slot and IPA Type. 86 */ getIpaBarTop(size_t agent,IPAStim::IPAType type)87 int getIpaBarTop(size_t agent, IPAStim::IPAType type) 88 { 89 int top; 90 if(agent > 1) 91 top = kIpaBarTop34; 92 else 93 top = kIpaBarTop12; 94 95 switch (type) { 96 case IPAStim::Adrenaline: 97 break; 98 case IPAStim::Perception: 99 top += kIpaYOffset; 100 break; 101 case IPAStim::Intelligence: 102 top += 2 * kIpaYOffset; 103 break; 104 default: 105 assert(false); 106 } 107 return top; 108 } 109 110 /*! 111 * Returns the X coord for all IPA bars for a given agent slot. 112 */ getIpaBarLeftForAgent(size_t agent)113 int getIpaBarLeftForAgent(size_t agent) 114 { 115 return (agent % 2 == 1) ? kIpaBarLeft24 : kIpaBarLeft13; 116 } 117 118 /*! 119 * Returns the color for drawing the IPA bar of given type. 120 */ colourForIpaType(IPAStim::IPAType type)121 int colourForIpaType(IPAStim::IPAType type) 122 { 123 switch (type) 124 { 125 case IPAStim::Adrenaline: 126 return fs_cmn::kColorLightRed; 127 case IPAStim::Perception: 128 return fs_cmn::kColorBlue; 129 case IPAStim::Intelligence: 130 return fs_cmn::kColorLightBrown; 131 default: 132 assert(false); 133 } 134 return -1; 135 } 136 dim_colour(IPAStim::IPAType type)137 int dim_colour(IPAStim::IPAType type) 138 { 139 switch (type) 140 { 141 case IPAStim::Adrenaline: 142 return fs_cmn::kColorDarkRed; 143 case IPAStim::Perception: 144 return fs_cmn::kColorBlueGrey; 145 case IPAStim::Intelligence: 146 return fs_cmn::kColorDarkBrown; 147 default: 148 assert(false); 149 } 150 return -1; 151 } 152 153 154 /*! 155 * 156 */ getPercentage(int left,int x)157 int getPercentage(int left, int x) 158 { 159 int offset = x - left; 160 return (int)(((float)offset / (float) kIpaBarWidth) * 100.0); 161 } 162 163 void drawSelectorForAgent(size_t agentSlot, PedInstance *pAgent, bool isSelected); 164 165 public: 166 //! gets percentage for any x coord getPercentageAnyX(size_t agent,int x)167 int getPercentageAnyX(size_t agent, int x) { 168 int barLeft = getIpaBarLeftForAgent(agent); 169 if (x < barLeft) 170 x = barLeft; 171 if (x > barLeft + kIpaBarWidth) 172 x = barLeft + kIpaBarWidth; 173 174 return getPercentage(barLeft, x); 175 } 176 }; 177 178 #endif // MENUS_AGENTSELECTORRENDERER_H_ 179