Initial commit of Dink Smallwood HD source. See the "Programmer readme.txt" for information on how to set it up.

git-svn-id: svn://rtsoft.com/rtsvn/projects/RTDink@1469 353e56fe-9613-0410-8469-b96ad8e6f29c
This commit is contained in:
seth 2017-09-12 04:57:47 +00:00
parent dfbc2348a5
commit d4f66a5d2e
115 changed files with 37737 additions and 0 deletions

View file

@ -0,0 +1,169 @@
#include "PlatformPrecomp.h"
#include "ActionButtonComponent.h"
#include "util/GLESUtils.h"
#include "Entity/EntityUtils.h"
#include "BaseApp.h"
#include "../dink/dink.h"
ActionButtonComponent::ActionButtonComponent()
{
SetName("ActionButton");
m_mode = MODE_MAGIC;
}
ActionButtonComponent::~ActionButtonComponent()
{
}
void ActionButtonComponent::OnAdd(Entity *pEnt)
{
EntityComponent::OnAdd(pEnt);
m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
if (GetParent()->GetName() != "magic")
{
m_mode = MODE_WEAPON;
}
/*
m_pSize2d = &GetParent()->GetVar("size2d")->GetVector2();
m_pScale = &GetParent()->GetShared()->GetVarWithDefault("scale", Variant(1.0f))->GetFloat();
m_pRotation = &GetParent()->GetVar("rotation")->GetFloat(); //in degrees
m_pColor = &GetParent()->GetShared()->GetVarWithDefault("color", Variant(MAKE_RGBA(255,255,255,255)))->GetUINT32();
m_pColorMod = &GetParent()->GetShared()->GetVarWithDefault("colorMod", Variant(MAKE_RGBA(255,255,255,255)))->GetUINT32();
m_pAlignment = &GetParent()->GetVar("alignment")->GetUINT32();
*/
m_pAlpha = &GetParent()->GetShared()->GetVarWithDefault("alpha", Variant(1.0f))->GetFloat();
//register ourselves to render if the parent does
GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&ActionButtonComponent::OnRender, this, _1));
GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&ActionButtonComponent::OnUpdate, this, _1));
UpdateIcon();
}
void ActionButtonComponent::OnRemove()
{
EntityComponent::OnRemove();
}
void ActionButtonComponent::OnRender(VariantList *pVList)
{
CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
Surface *pSurf;
switch (m_mode)
{
case MODE_MAGIC:
pSurf = DinkGetMagicIconImage();
break;
case MODE_WEAPON:
pSurf = DinkGetWeaponIconImage();
break;
}
if (pSurf)
{
rtRectf srcRect = pSurf->GetRectf();
rtRectf dstRect = srcRect;
if (IsLargeScreen())
{
dstRect = rtRectf(0,0, 90,90);
} else
{
dstRect = rtRectf(0,0, 44,39);
}
dstRect.AdjustPosition(vFinalPos.x, vFinalPos.y);
if (IsLargeScreen())
{
dstRect.AdjustPosition(19, 25);
} else
{
dstRect.AdjustPosition(9, 12);
}
pSurf->BlitEx(dstRect, srcRect, MAKE_RGBA(255* *m_pAlpha,255* *m_pAlpha,255* *m_pAlpha,255* *m_pAlpha));
if (g_dglo.GetActiveView() == DinkGlobals::VIEW_ZOOMED)
{
int alpha = int(255.0f * *m_pAlpha);
if (alpha > 2)
{
if (m_mode ==MODE_MAGIC)
{
float percent = DinkGetMagicChargePercent();
if (percent > 0)
{
//LogMsg("Magic: %.2f", DinkGetMagicChargePercent());
rtRectf rBar(0,0, iPhoneMapX2X(54)*percent, iPhoneMapY2X(3));
rBar.AdjustPosition(vFinalPos.x, vFinalPos.y);
rBar.AdjustPosition(iPhoneMapX2X(6), iPhoneMapY2X(-4));
if (percent == 1)
{
DrawFilledRect(rBar, MAKE_RGBA(0, 180, 0, 255* *m_pAlpha));
DrawRect(rBar, MAKE_RGBA(0, 255, 0, 255* *m_pAlpha));
} else
{
DrawFilledRect(rBar, MAKE_RGBA(0, 100, 0, 255* *m_pAlpha));
DrawRect(rBar, MAKE_RGBA(0, 255, 0, 170* *m_pAlpha));
}
}
} else
{
float percent = DinkGetHealthPercent();
//LogMsg("Magic: %.2f", DinkGetMagicChargePercent());
rtRectf rBar(0,0, iPhoneMapX2X(54)*percent, iPhoneMapY2X(3));
rBar.AdjustPosition(vFinalPos.x, vFinalPos.y);
rBar.AdjustPosition(iPhoneMapX2X(6), iPhoneMapY2X(-4));
DrawFilledRect(rBar, MAKE_RGBA(180, 0, 0, 255* *m_pAlpha));
DrawRect(rBar, MAKE_RGBA(255, 0, 0, 255* *m_pAlpha));
}
}
}
}
}
void ActionButtonComponent::OnUpdate(VariantList *pVList)
{
}
void ActionButtonComponent::UpdateIcon()
{
}
Entity * CreateActionButtonEntity(Entity *pParentEnt, string name, string fileName, float x, float y)
{
Entity *pButtonEnt = CreateOverlayButtonEntity(pParentEnt, name, fileName, x, y);
pButtonEnt->AddComponent(new ActionButtonComponent);
return pButtonEnt;
}

View file

@ -0,0 +1,56 @@
// ***************************************************************
// ActionButtonComponent - Creation date: 3/15/2010
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2010 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef ActionButtonComponent_h__
#define ActionButtonComponent_h__
#include "Entity/Component.h"
#include "Entity/Entity.h"
#include "Renderer/SurfaceAnim.h"
class ActionButtonComponent: public EntityComponent
{
public:
ActionButtonComponent();
virtual ~ActionButtonComponent();
virtual void OnAdd(Entity *pEnt);
virtual void OnRemove();
enum eMode
{
MODE_MAGIC,
MODE_WEAPON
};
private:
void OnRender(VariantList *pVList);
void OnUpdate(VariantList *pVList);
bool IsMagic() {return m_mode == MODE_MAGIC;}
void UpdateIcon();
CL_Vec2f *m_pPos2d;
/*
CL_Vec2f *m_pSize2d;
float *m_pScale;
uint32 *m_pColor;
uint32 *m_pColorMod;
uint32 *m_pAlignment;
float *m_pRotation; //in degrees
*/
float *m_pAlpha;
eMode m_mode;
};
Entity * CreateActionButtonEntity(Entity *pParentEnt, string name, string fileName, float x, float y);
#endif // ActionButtonComponent_h__

View file

@ -0,0 +1,87 @@
#include "PlatformPrecomp.h"
#include "CursorComponent.h"
#include "util/GLESUtils.h"
#include "Entity/EntityUtils.h"
#include "BaseApp.h"
CursorComponent::CursorComponent()
{
SetName("Cursor");
}
CursorComponent::~CursorComponent()
{
}
void CursorComponent::OnAdd(Entity *pEnt)
{
EntityComponent::OnAdd(pEnt);
m_pArrowEnt = NULL;
m_bDisable = false;
m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
//register ourselves to render if the parent does
GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&CursorComponent::OnRender, this, _1));
GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&CursorComponent::OnUpdate, this, _1));
AddInputMovementFocusIfNeeded(GetParent());
GetParent()->GetFunction("OnInput")->sig_function.connect(1, boost::bind(&CursorComponent::OnInput, this, _1));
GetParent()->GetParent()->GetFunction("OnKillingControls")->sig_function.connect(1, boost::bind(&CursorComponent::OnKillingControls, this, _1));
}
void CursorComponent::OnRemove()
{
EntityComponent::OnRemove();
}
void CursorComponent::OnKillingControls(VariantList *pVList)
{
RemoveFocusIfNeeded(this->GetParent());
m_bDisable = true;
}
void CursorComponent::OnUpdatePos(CL_Vec2f vPos)
{
//LogMsg("Got %s", PrintVector2(vPos).c_str());
DinkSetCursorPosition(NativeToDinkCoords(vPos));
}
void CursorComponent::OnRender(VariantList *pVList)
{
//CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
}
void CursorComponent::OnUpdate(VariantList *pVList)
{
}
void CursorComponent::OnInput( VariantList *pVList )
{
//0 = message type, 1 = parent coordinate offset
CL_Vec2f pt = pVList->Get(1).GetVector2();
//pt += GetAlignmentOffset(*m_pSize2d, eAlignment(*m_pAlignment));
switch (eMessageType( int(pVList->Get(0).GetFloat())))
{
case MESSAGE_TYPE_GUI_CLICK_START:
//HandleClickStart(pt);
OnUpdatePos(pt);
break;
case MESSAGE_TYPE_GUI_CLICK_END:
if (!m_bDisable)
{
OnUpdatePos(pt);
g_dglo.m_dirInput[DINK_INPUT_BUTTON1] = true;
g_dglo.m_dirInputFinished[DINK_INPUT_BUTTON1] = true;
}
//HandleClickEnd(pt);
break;
case MESSAGE_TYPE_GUI_CLICK_MOVE:
case MESSAGE_TYPE_GUI_CLICK_MOVE_RAW:
OnUpdatePos(pt);
break;
}
}

View file

@ -0,0 +1,51 @@
// ***************************************************************
// CursorComponent - Creation date: ?/?/2009
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2009 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef CursorComponent_h__
#define CursorComponent_h__
#include "Entity/Component.h"
#include "Entity/Entity.h"
#include "../dink/dink.h"
class CursorComponent: public EntityComponent
{
public:
CursorComponent();
virtual ~CursorComponent();
virtual void OnAdd(Entity *pEnt);
virtual void OnRemove();
private:
void OnRender(VariantList *pVList);
void OnUpdate(VariantList *pVList);
void OnInput( VariantList *pVList );
void OnUpdatePos(CL_Vec2f vPos);
void OnKillingControls(VariantList *pVList);
CL_Vec2f *m_pPos2d;
/*
CL_Vec2f *m_pSize2d;
float *m_pScale;
uint32 *m_pColor;
uint32 *m_pColorMod;
float *m_pAlpha;
uint32 *m_pAlignment;
float *m_pRotation; //in degrees
*/
Entity *m_pArrowEnt;
bool m_bDisable;
};
#endif // CursorComponent_h__

View file

@ -0,0 +1,332 @@
#include "PlatformPrecomp.h"
#include "DragControlComponent.h"
#include "util/GLESUtils.h"
#include "Entity/EntityUtils.h"
#include "BaseApp.h"
#include "Entity/ArcadeInputComponent.h"
#include "GUI/GameMenu.h"
DragControlComponent::DragControlComponent()
{
SetName("DragControl");
SAMPLE_COUNT = 8; //unused
LENGTH_REQUIRED_FOR_MOVE = 16;
if (IsIphoneSize || IsIphone4Size) LENGTH_REQUIRED_FOR_MOVE = 32; //the screen is tiny, need a few more pixels
if (IsIphone4Size)
{
LENGTH_REQUIRED_FOR_MOVE *= 2;
}
}
DragControlComponent::~DragControlComponent()
{
}
void DragControlComponent::OnAdd(Entity *pEnt)
{
EntityComponent::OnAdd(pEnt);
m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
m_pSize2d = &GetParent()->GetVar("size2d")->GetVector2();
if (IsIPAD())
{
*m_pPos2d =(CL_Vec2f(0,29));
} else
{
*m_pPos2d = (iPhoneMap(0,29));
}
//fit the active area to match the active dink screen layout
if (g_dglo.GetActiveView() != DinkGlobals::VIEW_ZOOMED && IsDrawingDinkStatusBar())
{
if (IsIPAD())
{
*m_pSize2d = CL_Vec2f(865, 584);
} else
{
*m_pSize2d = iPhoneMap(380, 237);
}
} else
{
if (IsIPAD())
{
*m_pSize2d = CL_Vec2f(866, 715);
} else
{
*m_pSize2d = iPhoneMap(380, 286);
}
}
if (GetApp()->GetIconsOnLeft())
{
m_pPos2d->x += GetScreenSizeXf()-m_pSize2d->x;
}
m_lastTouch = CL_Vec2f(0,0);
/*
m_pScale = &GetParent()->GetShared()->GetVarWithDefault("scale", Variant(1.0f))->GetFloat();
m_pRotation = &GetParent()->GetVar("rotation")->GetFloat(); //in degrees
m_pColor = &GetParent()->GetShared()->GetVarWithDefault("color", Variant(MAKE_RGBA(255,255,255,255)))->GetUINT32();
m_pColorMod = &GetParent()->GetShared()->GetVarWithDefault("colorMod", Variant(MAKE_RGBA(255,255,255,255)))->GetUINT32();
m_pAlpha = &GetParent()->GetShared()->GetVarWithDefault("alpha", Variant(1.0f))->GetFloat();
m_pAlignment = &GetParent()->GetVar("alignment")->GetUINT32();
*/
//register ourselves to render if the parent does
//GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&DragControlComponent::OnRender, this, _1));
GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&DragControlComponent::OnUpdate, this, _1));
GetBaseApp()->m_sig_arcade_input.connect(1, boost::bind(&DragControlComponent::OnArcadeInput, this, _1));
GetParent()->GetVar("ignoreTouchesOutsideRect")->Set(uint32(1));
EntityComponent *pTouch = GetParent()->AddComponent(new TouchHandlerComponent);
//movement arrows
//for speed, we've disabled movement message handling in App.cpp, but we actually want them just here, so we'll hardwire it
AddInputMovementFocusIfNeeded(GetParent());
GetParent()->GetFunction("OnOverStart")->sig_function.connect(1, boost::bind(&DragControlComponent::OnOverStart, this, _1));
GetParent()->GetFunction("OnOverEnd")->sig_function.connect(1, boost::bind(&DragControlComponent::OnOverEnd, this, _1));
GetParent()->GetFunction("OnOverMove")->sig_function.connect(1, boost::bind(&DragControlComponent::OnOverMove, this, _1));
GetParent()->GetParent()->GetFunction("OnKillingControls")->sig_function.connect(1, boost::bind(&DragControlComponent::OnKillingControls, this, _1));
/*
EntityComponent *pFilter = m_pArrowEnt->AddComponent(new FilterInputComponent);
pFilter->GetVar("mode")->Set(uint32(FilterInputComponent::MODE_CLIP_INPUT_TO_ABSOLUTE_CLIP_RECT_AND_DISABLE_INPUT_CHILDREN));
pFilter->GetVar("clipRect")->Set(CL_Rectf(0,43,397, GetScreenSizeY()));
m_timeOfLastTouch = GetTick(TIMER_SYSTEM);
SetAlignmentEntity(m_pArrowEnt, ALIGNMENT_CENTER);
m_pArrowEnt->GetVar("pos2d")->Set(CL_Vec2f(80, 240));
m_vArrowImageSizeOver2 = m_pArrowEnt->GetVar("size2d")->GetVector2()/2;
*/
VariantList vTemp;
OnOverEnd(&vTemp);
}
void DragControlComponent::OnRemove()
{
EntityComponent::OnRemove();
}
void DragControlComponent::SendKey(eDinkInput key, bool bIsDown)
{
if (bIsDown)
{
g_dglo.m_dirInput[key] = true;
g_dglo.m_dirInputFinished[key] = false; //make sure it wasn't scheduled to stop pressing
} else
{
g_dglo.m_dirInputFinished[key] = true;
}
}
void DragControlComponent::OnKillingControls(VariantList *pVList)
{
RemoveFocusIfNeeded(GetParent());
}
void DragControlComponent::AddSample(DragUnit v)
{
if (DinkIsDoingScreenTransition()) return;
m_samples.push_back(v);
/*
if (m_samples.size() > SAMPLE_COUNT)
{
m_samples.pop_front();
}
*/
}
void DragControlComponent::OnOverStart(VariantList *pVList)
{
m_samples.clear();
m_lastTouch = pVList->Get(0).GetVector2();
}
void DragControlComponent::OnOverEnd(VariantList *pVList)
{
// CL_Vec2f vPos = pVList->Get(0).GetVector2();
// LogMsg("Got over end: %s", PrintVector2(vPos).c_str());
m_samples.clear();
m_lastTouch = CL_Vec2f(0,0);
ClearKeyInput();
}
void DragControlComponent::OnOverMove(VariantList *pVList)
{
AddSample( DragUnit(pVList->Get(0).GetVector2() - m_lastTouch, GetTick(TIMER_GAME)));
//SetPosition(pVList->Get(0).GetVector2());
m_lastTouch = pVList->Get(0).GetVector2();
}
void DragControlComponent::ClearKeyInput()
{
SendKey(DINK_INPUT_UP, false);
SendKey(DINK_INPUT_DOWN, false);
SendKey(DINK_INPUT_LEFT, false);
SendKey(DINK_INPUT_RIGHT, false);
}
void DragControlComponent::OnRender(VariantList *pVList)
{
CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
}
void DragControlComponent::ProcessLastJoystickReading()
{
if (m_samples.size() == 0) return;
//first, lets figure out what direction we want
CL_Vec2f vDir = CL_Vec2f(0,0);
std::deque< DragUnit> sampleTemp;
for (int i=m_samples.size()-1; i >= 0;)
{
//if (m_samples.size() < SAMPLE_COUNT) break;
/*
if (1)
//if (m_samples.at(i).m_timeMade+100 < GetTick(TIMER_GAME))
{
vDir = CL_Vec2f(0,0);
//would removing this stop us from moving?
for (int h=1; h < m_samples.size();h++)
{
vDir += m_samples[h].m_vPos;
}
if (vDir.length() < LENGTH_REQUIRED_FOR_MOVE)
{
//yes it would. Just let it be, for now.
//break;
} else
{
//it's not needed
}
m_samples.erase(m_samples.begin()+i);
continue;
} else
{
break;
}
*/
vDir += m_samples[i].m_vPos;
sampleTemp.push_front( m_samples[i]);
if (vDir.length() >= LENGTH_REQUIRED_FOR_MOVE)
{
//all done
break;
}
i--;
}
m_samples = sampleTemp;
//vDir = CL_Vec2f(0,0);
/*
for (unsigned int i=0; i < m_samples.size();i++)
{
vDir += m_samples[i].m_vPos;
}
*/
ClearKeyInput();
//LogMsg("vDir length is %.2f", vDir.length());
if (vDir.length() < LENGTH_REQUIRED_FOR_MOVE) return;
vDir.normalize();
//recalculate the points
sampleTemp.clear();
//sampleTemp.push_front(m_samples[m_samples.size()-1]);
sampleTemp.push_front(DragUnit( (vDir*LENGTH_REQUIRED_FOR_MOVE)*1.1, 0));
m_samples = sampleTemp;
#ifdef _DEBUG
//LogMsg("Dir is %s (%d samples)", PrintVector2(vDir).c_str(), m_samples.size());
#endif
//convert to 360 degrees
int dir = (int(RAD2DEG(atan2(vDir.y, vDir.x))+(90)));
const int maxDirections = 8;
int finaldir = mod(dir+ (360/ (maxDirections*2)), 360)/ (360/maxDirections);
//nah, let's do 8 actually
//LogMsg("Pressing %s, which is dir %d (final: %d)", PrintVector2(m_lastTouchDir).c_str(), dir, finaldir);
switch (finaldir)
{
case 0: SendKey(DINK_INPUT_UP, true); break;
case 1: SendKey(DINK_INPUT_RIGHT, true); SendKey(DINK_INPUT_UP, true); break;
case 2: SendKey(DINK_INPUT_RIGHT, true); break;
case 3: SendKey(DINK_INPUT_RIGHT, true); SendKey(DINK_INPUT_DOWN, true); break;
case 4: SendKey(DINK_INPUT_DOWN, true); break;
case 5: SendKey(DINK_INPUT_DOWN, true); SendKey(DINK_INPUT_LEFT, true); break;
case 6: SendKey(DINK_INPUT_LEFT, true); break;
case 7: SendKey(DINK_INPUT_LEFT, true); SendKey(DINK_INPUT_UP, true); break;
}
}
void DragControlComponent::OnArcadeInput(VariantList *pVList)
{
int vKey = pVList->Get(0).GetUINT32();
bool bIsDown = pVList->Get(1).GetUINT32() != 0;
//LogMsg("Key %d, down is %d", vKey, int(bIsDown));
switch (vKey)
{
case VIRTUAL_KEY_DIR_LEFT:
SendKey(DINK_INPUT_LEFT, bIsDown);
break;
case VIRTUAL_KEY_DIR_RIGHT:
SendKey(DINK_INPUT_RIGHT, bIsDown);
break;
case VIRTUAL_KEY_DIR_UP:
SendKey(DINK_INPUT_UP, bIsDown);
break;
case VIRTUAL_KEY_DIR_DOWN:
SendKey(DINK_INPUT_DOWN, bIsDown);
break;
}
}
void DragControlComponent::OnUpdate(VariantList *pVList)
{
ProcessLastJoystickReading();
}

View file

@ -0,0 +1,77 @@
// ***************************************************************
// DragControlComponent - Creation date: 4/27/2010
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2009 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef DragControlComponent_h__
#define DragControlComponent_h__
#include "Entity/Component.h"
#include "Entity/Entity.h"
#include "../dink/dink.h"
class DragUnit
{
public:
DragUnit(CL_Vec2f vPos, unsigned int time)
{
m_vPos = vPos;
m_timeMade = time;
}
CL_Vec2f m_vPos;
unsigned int m_timeMade; //in game ticks
};
class DragControlComponent: public EntityComponent
{
public:
DragControlComponent();
virtual ~DragControlComponent();
virtual void OnAdd(Entity *pEnt);
virtual void OnRemove();
private:
void OnRender(VariantList *pVList);
void OnUpdate(VariantList *pVList);
void OnStripUpdate(VariantList *pVList);
void SendKey(eDinkInput key, bool bIsDown);
void OnOverStart(VariantList *pVList);
void OnOverEnd(VariantList *pVList);
void OnOverMove(VariantList *pVList);
void ClearKeyInput();
void ProcessLastJoystickReading();
void ProcessArrowInput(CL_Vec2f vDir);
void OnKillingControls(VariantList *pVList);
void AddSample(DragUnit v);
void OnArcadeInput(VariantList *pVList);
CL_Vec2f *m_pPos2d;
CL_Vec2f *m_pSize2d;
/*
float *m_pScale;
uint32 *m_pColor;
uint32 *m_pColorMod;
float *m_pAlpha;
uint32 *m_pAlignment;
float *m_pRotation; //in degrees
*/
CL_Vec2f m_lastTouch;
unsigned int m_timeOfLastTouch;
std::deque< DragUnit> m_samples;
float SAMPLE_COUNT;
float LENGTH_REQUIRED_FOR_MOVE;
};
#endif // DragControlComponent_h__

View file

@ -0,0 +1,271 @@
#include "PlatformPrecomp.h"
#include "FPSControlComponent.h"
#include "util/GLESUtils.h"
#include "Entity/EntityUtils.h"
#include "BaseApp.h"
#include "GUI/GameMenu.h"
#define C_GUI_FADE_OUT_TIMER 400
#define C_GUI_FADE_IN_TIMER 150
FPSControlComponent::FPSControlComponent()
{
SetName("FPSControl");
}
FPSControlComponent::~FPSControlComponent()
{
}
void FPSControlComponent::OnAdd(Entity *pEnt)
{
EntityComponent::OnAdd(pEnt);
m_pArrowEnt = NULL;
m_pCenterBall = NULL;
m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
m_lastTouchDir = CL_Vec2f(0, 0); //the middle
m_bTouchingArrows = false;
//register ourselves to render if the parent does
GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnRender, this, _1));
GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnUpdate, this, _1));
float guiTrans = GetApp()->GetVar("gui_transparency")->GetFloat();
GetApp()->GetVar("gui_transparency")->Set(guiTrans);
GetBaseApp()->m_sig_arcade_input.connect(1, boost::bind(&FPSControlComponent::OnArcadeInput, this, _1));
m_arrowMinTransparency = guiTrans;
m_arrowMaxTransparency = rt_max(0.5f, guiTrans);
//movement arrows?
if (GetApp()->GetUsingTouchScreen())
{
m_pArrowEnt = CreateOverlayEntity(GetParent(), "arrow_gui", ReplaceWithDeviceNameInFileName("interface/iphone/arrows.rttex"), 0, 0);
EntityComponent *pStripComp = m_pArrowEnt->AddComponent(new TouchStripComponent);
m_pArrowEnt->GetVarWithDefault(string("touchPadding"), Variant(CL_Rectf(100, 100, 100, 100)))->GetRect();
//m_pArrowEnt->AddComponent(new TouchHandlerComponent);
//for speed, we've disabled movement message handling in App.cpp, but we actually want them just here, so we'll hardwire it
AddInputMovementFocusIfNeeded(m_pArrowEnt);
m_pArrowEnt->GetFunction("OnTouchStripUpdate")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnStripUpdate, this, _1));
m_pArrowEnt->GetFunction("OnOverStart")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnOverStart, this, _1));
m_pArrowEnt->GetFunction("OnOverEnd")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnOverEnd, this, _1));
GetParent()->GetParent()->GetFunction("OnKillingControls")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnKillingControls, this, _1));
SetAlphaEntity(m_pArrowEnt, 0);
FadeEntity(m_pArrowEnt, true, m_arrowMinTransparency, 300, 0);
//limit it to touches only on the left side of the screen
//m_pCenterBall = CreateOverlayEntity(m_pArrowEnt, "center_ball", "interface/center_ball.rttex",0,0);
if (m_pCenterBall)
{
m_pCenterBall->GetVar("color")->Set(MAKE_RGBA(255,255,255,0));
//SetAlphaEntity(m_pCenterBall, 0);
SetAlignmentEntity(m_pCenterBall, ALIGNMENT_CENTER);
}
m_timeOfLastTouch = GetTick(TIMER_SYSTEM);
SetAlignmentEntity(m_pArrowEnt, ALIGNMENT_CENTER);
CL_Vec2f vArrowPos = FlipXIfNeeded(iPhoneMap(CL_Vec2f(80, 240)));
if (IsIPAD())
{
if (IsInFlingMode())
{
vArrowPos = CL_Vec2f( FlipXIfNeeded(149-30), C_FLING_JOYSTICK_Y);
} else
{
vArrowPos = FlipXIfNeeded(CL_Vec2f(137-20, 651-80));
}
}
m_pArrowEnt->GetVar("pos2d")->Set(vArrowPos);
m_vArrowImageSizeOver2 = m_pArrowEnt->GetVar("size2d")->GetVector2()/2;
VariantList vList;
OnOverEnd(&vList);
}
}
void FPSControlComponent::OnRemove()
{
EntityComponent::OnRemove();
}
void SendKey(eDinkInput key, bool bIsDown)
{
if (bIsDown)
{
g_dglo.m_dirInput[key] = true;
g_dglo.m_dirInputFinished[key] = false; //make sure it wasn't scheduled to stop pressing
} else
{
g_dglo.m_dirInputFinished[key] = true;
}
}
void FPSControlComponent::ProcessLastJoystickReading()
{
CL_Vec2f vDir = m_lastTouchDir;
vDir.normalize();
if (m_pCenterBall)
m_pCenterBall->GetVar("pos2d")->Set(m_vArrowImageSizeOver2+vDir* (rt_min(m_lastTouchDir.length(), 1) * 58));
float deadSpace = 0.25f/2;
if (IsInFlingMode())
{
deadSpace *= 1.4f;
} else
{
if (IsIPADSize) deadSpace *= 2;
}
if (m_lastTouchDir.length() < deadSpace)
{
//dead space
if (m_pCenterBall)
{
m_pCenterBall->GetVar("pos2d")->Set(m_vArrowImageSizeOver2);
}
return;
}
//convert to 360 degrees
int dir = (int(RAD2DEG(atan2(m_lastTouchDir.y, m_lastTouchDir.x))+(90)));
const int maxDirections = 8;
int finaldir = mod(dir+ (360/ (maxDirections*2)), 360)/ (360/maxDirections);
//nah, let's do 8 actually
//LogMsg("Pressing %s, which is dir %d (final: %d)", PrintVector2(m_lastTouchDir).c_str(), dir, finaldir);
switch (finaldir)
{
case 0: SendKey(DINK_INPUT_UP, true); break;
case 1: SendKey(DINK_INPUT_RIGHT, true); SendKey(DINK_INPUT_UP, true); break;
case 2: SendKey(DINK_INPUT_RIGHT, true); break;
case 3: SendKey(DINK_INPUT_RIGHT, true); SendKey(DINK_INPUT_DOWN, true); break;
case 4: SendKey(DINK_INPUT_DOWN, true); break;
case 5: SendKey(DINK_INPUT_DOWN, true); SendKey(DINK_INPUT_LEFT, true); break;
case 6: SendKey(DINK_INPUT_LEFT, true); break;
case 7: SendKey(DINK_INPUT_LEFT, true); SendKey(DINK_INPUT_UP, true); break;
}
}
void FPSControlComponent::OnKillingControls(VariantList *pVList)
{
RemoveFocusIfNeeded(m_pArrowEnt);
}
void FPSControlComponent::OnArcadeInput(VariantList *pVList)
{
int vKey = pVList->Get(0).GetUINT32();
bool bIsDown = pVList->Get(1).GetUINT32() != 0;
//LogMsg("Key %d, down is %d", vKey, int(bIsDown));
switch (vKey)
{
case VIRTUAL_KEY_DIR_LEFT:
SendKey(DINK_INPUT_LEFT, bIsDown);
break;
case VIRTUAL_KEY_DIR_RIGHT:
SendKey(DINK_INPUT_RIGHT, bIsDown);
break;
case VIRTUAL_KEY_DIR_UP:
SendKey(DINK_INPUT_UP, bIsDown);
break;
case VIRTUAL_KEY_DIR_DOWN:
SendKey(DINK_INPUT_DOWN, bIsDown);
break;
}
}
void FPSControlComponent::OnOverStart(VariantList *pVList)
{
}
void FPSControlComponent::OnOverEnd(VariantList *pVList)
{
m_bTouchingArrows = false;
ClearKeyInput();
if (m_pCenterBall)
m_pCenterBall->GetVar("color")->Set(MAKE_RGBA(255,255,255,0));
//m_pArrowEnt->GetVar("alpha")->Set(1.0f);
FadeEntity(m_pArrowEnt, false, m_arrowMinTransparency, C_GUI_FADE_OUT_TIMER);
if (m_pCenterBall)
FadeEntity(m_pCenterBall, false, 0.0, C_GUI_FADE_OUT_TIMER/3);
}
void FPSControlComponent::ClearKeyInput()
{
SendKey(DINK_INPUT_UP, false);
SendKey(DINK_INPUT_DOWN, false);
SendKey(DINK_INPUT_LEFT, false);
SendKey(DINK_INPUT_RIGHT, false);
}
void FPSControlComponent::ProcessArrowInput(CL_Vec2f vDir)
{
if (m_bTouchingArrows || 1)
{
m_lastTouchDir = vDir*2 - CL_Vec2f(1, 1);
//update current position
ClearKeyInput();
ProcessLastJoystickReading();
} else
{
// m_lastTouchDir = CL_Vec2f(0,0);
if (m_pCenterBall)
m_pCenterBall->GetVar("pos2d")->Set(m_lastTouchDir);
}
}
void FPSControlComponent::OnStripUpdate(VariantList *pVList)
{
if (!m_bTouchingArrows)
{
m_bTouchingArrows = true;
//m_pArrowEnt->GetVar("pos2d")->Set( ConvertEntityClickToScreenCoords(pVList->Get(0).GetVector2(), pVList->Get(1).GetEntity()));
//ProcessArrowInput(pVList->Get(1).GetVector2());
if (m_pCenterBall)
m_pCenterBall->GetVar("color")->Set(MAKE_RGBA(255,255,255,255));
FadeEntity(m_pArrowEnt, false, m_arrowMaxTransparency, C_GUI_FADE_IN_TIMER);
if (m_pCenterBall)
FadeEntity(m_pCenterBall, false, m_arrowMaxTransparency, C_GUI_FADE_OUT_TIMER/3);
}
ProcessArrowInput(pVList->Get(1).GetVector2());
}
void FPSControlComponent::OnRender(VariantList *pVList)
{
CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
}
void FPSControlComponent::OnUpdate(VariantList *pVList)
{
}

View file

@ -0,0 +1,65 @@
// ***************************************************************
// FPSControlComponent - Creation date: ?/?/2009
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2009 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef FPSControlComponent_h__
#define FPSControlComponent_h__
#include "Entity/Component.h"
#include "Entity/Entity.h"
#include "../dink/dink.h"
#define C_FLING_JOYSTICK_Y (520+50)
class FPSControlComponent: public EntityComponent
{
public:
FPSControlComponent();
virtual ~FPSControlComponent();
virtual void OnAdd(Entity *pEnt);
virtual void OnRemove();
private:
void OnRender(VariantList *pVList);
void OnUpdate(VariantList *pVList);
void OnStripUpdate(VariantList *pVList);
void OnOverStart(VariantList *pVList);
void OnOverEnd(VariantList *pVList);
void ClearKeyInput();
void ProcessLastJoystickReading();
void ProcessArrowInput(CL_Vec2f vDir);
void OnKillingControls(VariantList *pVList);
void OnArcadeInput(VariantList *pVList);
CL_Vec2f *m_pPos2d;
/*
CL_Vec2f *m_pSize2d;
float *m_pScale;
uint32 *m_pColor;
uint32 *m_pColorMod;
float *m_pAlpha;
uint32 *m_pAlignment;
float *m_pRotation; //in degrees
*/
Entity *m_pArrowEnt;
Entity *m_pCenterBall; //will be a child of the arrowEnt
CL_Vec2f m_lastTouchDir;
unsigned int m_timeOfLastTouch;
bool m_bTouchingArrows;
CL_Vec2f m_vArrowImageSizeOver2;
float m_arrowMinTransparency;
float m_arrowMaxTransparency;
};
void SendKey(eDinkInput key, bool bIsDown);
#endif // FPSControlComponent_h__

View file

@ -0,0 +1,112 @@
#include "PlatformPrecomp.h"
#include "InventoryComponent.h"
#include "util/GLESUtils.h"
#include "Entity/EntityUtils.h"
#include "BaseApp.h"
InventoryComponent::InventoryComponent()
{
m_activeFinger = -1;
SetName("Inventory");
}
InventoryComponent::~InventoryComponent()
{
}
void InventoryComponent::OnAdd(Entity *pEnt)
{
EntityComponent::OnAdd(pEnt);
m_pArrowEnt = NULL;
m_bGotFirstClick = false;
m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
//register ourselves to render if the parent does
GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&InventoryComponent::OnRender, this, _1));
GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&InventoryComponent::OnUpdate, this, _1));
AddInputMovementFocusIfNeeded(GetParent());
GetParent()->GetFunction("OnInput")->sig_function.connect(1, boost::bind(&InventoryComponent::OnInput, this, _1));
}
void InventoryComponent::OnRemove()
{
EntityComponent::OnRemove();
}
void InventoryComponent::OnUpdatePos(CL_Vec2f vPos)
{
//LogMsg("Got %s", PrintVector2(vPos).c_str());
DinkSetInventoryPosition(NativeToDinkCoords(vPos));
}
void InventoryComponent::OnRender(VariantList *pVList)
{
//CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
}
void InventoryComponent::OnUpdate(VariantList *pVList)
{
}
void InventoryComponent::OnInput( VariantList *pVList )
{
//0 = message type, 1 = parent coordinate offset
CL_Vec2f pt = pVList->Get(1).GetVector2();
//pt += GetAlignmentOffset(*m_pSize2d, eAlignment(*m_pAlignment));
switch (eMessageType( int(pVList->Get(0).GetFloat())))
{
case MESSAGE_TYPE_GUI_CLICK_START:
{
uint32 fingerID = pVList->Get(2).GetUINT32();
TouchTrackInfo *pTouch = GetBaseApp()->GetTouch(fingerID);
if (pTouch->WasHandled()) return;
pTouch->SetWasHandled(true);
m_activeFinger = fingerID;
}
OnUpdatePos(pt);
break;
case MESSAGE_TYPE_GUI_CLICK_END:
{
uint32 fingerID = pVList->Get(2).GetUINT32();
if (fingerID == m_activeFinger)
{
OnUpdatePos(pt);
/*
if (!m_bGotFirstClick)
{
//ignore this, they are just releasing from the previous menu's button
m_bGotFirstClick = true;
} else
{
*/
if (DinkSetInventoryPosition(NativeToDinkCoords(pt)))
{
g_dglo.m_dirInput[DINK_INPUT_BUTTON1] = true;
g_dglo.m_dirInputFinished[DINK_INPUT_BUTTON1] = true;
}
}
}
//HandleClickEnd(pt);
break;
case MESSAGE_TYPE_GUI_CLICK_MOVE:
{
uint32 fingerID = pVList->Get(2).GetUINT32();
if (fingerID == m_activeFinger) OnUpdatePos(pt);
}
break;
}
}

View file

@ -0,0 +1,42 @@
// ***************************************************************
// InventoryComponent - Creation date: ?/?/2009
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2009 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef InventoryComponent_h__
#define InventoryComponent_h__
#include "Entity/Component.h"
#include "Entity/Entity.h"
#include "../dink/dink.h"
class InventoryComponent: public EntityComponent
{
public:
InventoryComponent();
virtual ~InventoryComponent();
virtual void OnAdd(Entity *pEnt);
virtual void OnRemove();
private:
void OnRender(VariantList *pVList);
void OnUpdate(VariantList *pVList);
void OnInput( VariantList *pVList );
void OnUpdatePos(CL_Vec2f vPos);
CL_Vec2f *m_pPos2d;
int m_activeFinger;
Entity *m_pArrowEnt;
bool m_bGotFirstClick;
};
#endif // InventoryComponent_h__