Torque3D Documentation / _generateds / afxEA_GuiText.cpp

afxEA_GuiText.cpp

Engine/source/afx/ea/afxEA_GuiText.cpp

More...

Classes:

Detailed Description

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#include <typeinfo>
 28#include "afx/arcaneFX.h"
 29#include "afx/afxChoreographer.h"
 30#include "afx/afxEffectDefs.h"
 31#include "afx/afxEffectWrapper.h"
 32#include "afx/ce/afxGuiText.h"
 33#include "afx/ui/afxGuiTextHud.h"
 34
 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 36// afxEA_GuiText 
 37
 38class afxEA_GuiText : public afxEffectWrapper
 39{
 40  typedef afxEffectWrapper Parent;
 41
 42  enum {
 43    UNDEFINED,
 44    USER_TEXT,
 45    SHAPE_NAME
 46  };
 47
 48  afxGuiTextData* text_data;
 49  S32             text_src;
 50  LinearColorF          text_clr;
 51
 52  void            do_runtime_substitutions();
 53
 54public:
 55  /*C*/           afxEA_GuiText();
 56
 57  virtual void    ea_set_datablock(SimDataBlock*);
 58  virtual bool    ea_start();
 59  virtual bool    ea_update(F32 dt);
 60};
 61
 62//~~~~~~~~~~~~~~~~~~~~//
 63
 64afxEA_GuiText::afxEA_GuiText()
 65{
 66  text_data = 0;
 67  text_src = UNDEFINED;
 68  text_clr.set(1,1,1,1);
 69}
 70
 71void afxEA_GuiText::ea_set_datablock(SimDataBlock* db)
 72{
 73  text_data = dynamic_cast<afxGuiTextData*>(db);
 74}
 75
 76bool afxEA_GuiText::ea_start()
 77{
 78  if (!text_data)
 79  {
 80    Con::errorf("afxEA_GuiText::ea_start() -- missing or incompatible datablock.");
 81    return false;
 82  }
 83
 84  do_runtime_substitutions();
 85
 86  if (text_data->text_str == ST_NULLSTRING || text_data->text_str[0] == '\0')
 87  {
 88    Con::errorf("afxEA_GuiText::ea_start() -- empty text string.");
 89    return false;
 90  }
 91
 92  text_clr = text_data->text_clr;
 93
 94  if (dStricmp("#shapeName", text_data->text_str) == 0)
 95    text_src = SHAPE_NAME;
 96  else
 97    text_src = USER_TEXT;
 98
 99  return true;
100}
101
102bool afxEA_GuiText::ea_update(F32 dt)
103{
104  switch (text_src)
105  {
106  case USER_TEXT:
107    {
108      LinearColorF temp_clr = text_clr;
109      if (mDo_fades)
110        temp_clr.alpha = mFade_value;
111      afxGuiTextHud::addTextItem(mUpdated_pos, text_data->text_str, temp_clr);
112    }
113    break;
114  case SHAPE_NAME:
115    {
116      const char* name = 0;
117      SceneObject* cons_obj = 0;
118      afxConstraint* pos_cons = getPosConstraint();
119      if (pos_cons)
120      {
121        ShapeBase* shape = dynamic_cast<ShapeBase*>(pos_cons->getSceneObject());
122        if (shape)
123        {
124          name = shape->getShapeName();
125          cons_obj = shape;
126        }
127      }
128      if (name && name[0] != '\0')
129      {
130        LinearColorF temp_clr = text_clr;
131        if (mDo_fades)
132          temp_clr.alpha = mFade_value;
133        afxGuiTextHud::addTextItem(mUpdated_pos, name, temp_clr, cons_obj);
134      }
135    }
136    break;
137  }
138
139  return true;
140}
141
142void afxEA_GuiText::do_runtime_substitutions()
143{
144  // only clone the datablock if there are substitutions
145  if (text_data->getSubstitutionCount() > 0)
146  {
147    // clone the datablock and perform substitutions
148    afxGuiTextData* orig_db = text_data;
149    text_data = new afxGuiTextData(*orig_db, true);
150    orig_db->performSubstitutions(text_data, mChoreographer, mGroup_index);
151  }
152}
153
154//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
155
156class afxEA_GuiTextDesc : public afxEffectAdapterDesc, public afxEffectDefs 
157{
158  static afxEA_GuiTextDesc desc;
159
160public:
161  virtual bool  testEffectType(const SimDataBlock*) const;
162  virtual bool  requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const;
163  virtual bool  runsOnServer(const afxEffectWrapperData*) const { return false; }
164  virtual bool  runsOnClient(const afxEffectWrapperData*) const { return true; }
165
166  virtual afxEffectWrapper* create() const { return new afxEA_GuiText; }
167};
168
169afxEA_GuiTextDesc afxEA_GuiTextDesc::desc;
170
171bool afxEA_GuiTextDesc::testEffectType(const SimDataBlock* db) const
172{
173  return (typeid(afxGuiTextData) == typeid(*db));
174}
175
176bool afxEA_GuiTextDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const
177{
178  return (timing.lifetime < 0);
179}
180
181//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
182