* Create the subsystem for keybindings.
This commit is contained in:
jean.chalard
2010-02-14 13:21:12 +00:00
parent 4913eec2fb
commit 56ce4a14ae
38 changed files with 2154 additions and 1477 deletions
+5
View File
@@ -110,6 +110,8 @@ install: $(TARGET_LIB) hge
hge: $(TARGET_HGE) hge: $(TARGET_HGE)
ifeq ($(TARGET_ARCHITECTURE),linux) ifeq ($(TARGET_ARCHITECTURE),linux)
$(TARGET_LIB): $(OBJS) $(TARGET_LIB): $(OBJS)
ar r $(TARGET_LIB) $(OBJS) ar r $(TARGET_LIB) $(OBJS)
@@ -120,6 +122,9 @@ clean:
$(RM) -f $(OBJS) $(HGE_OBJS) Makefile.$(TARGET_ARCHITECTURE) $(RM) -f $(OBJS) $(HGE_OBJS) Makefile.$(TARGET_ARCHITECTURE)
endif endif
Makefile.psp:
@echo > $@
Makefile.linux: Makefile.linux:
$(CXX) -o /dev/null src/testfeatures.c -L$(LIBDIR) -lfmod-3.75 > /dev/null 2>&1 ; if [ "0" = "$$?" ]; then echo 'FMOD=-DWITH_FMOD'; else echo 'FMOD=-DWITHOUT_FMOD'; fi > $@ $(CXX) -o /dev/null src/testfeatures.c -L$(LIBDIR) -lfmod-3.75 > /dev/null 2>&1 ; if [ "0" = "$$?" ]; then echo 'FMOD=-DWITH_FMOD'; else echo 'FMOD=-DWITHOUT_FMOD'; fi > $@
+100 -51
View File
@@ -16,6 +16,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <queue>
#include <map>
#include "JTypes.h" #include "JTypes.h"
@@ -23,27 +25,25 @@
//#define _MP3_ENABLED_ //#define _MP3_ENABLED_
#ifdef WIN32 #if defined(WIN32)
#include <windows.h> #include <windows.h>
typedef WPARAM LocalKeySym;
void JGEControl(); #elif defined(LINUX)
BOOL JGEGetKeyState(int key); #include <X11/XKBlib.h>
bool JGEGetButtonState(u32 button); typedef KeySym LocalKeySym;
bool JGEGetButtonClick(u32 button);
u32 JGEReadKey();
void JGEResetInput();
#elif LINUX
void JGEControl();
BOOL JGEGetKeyState(int key);
bool JGEGetButtonState(u32 button);
bool JGEGetButtonClick(u32 button);
u32 JGEReadKey();
void JGEResetInput();
#else #else
typedef u32 LocalKeySym;
#endif
bool JGEGetButtonState(const JButton button);
bool JGEGetButtonClick(const JButton button);
void JGECreateDefaultBindings();
int JGEGetTime();
u8 JGEGetAnalogX();
u8 JGEGetAnalogY();
#if !defined(WIN32) && !defined(LINUX)
#include <pspgu.h> #include <pspgu.h>
#include <pspkernel.h> #include <pspkernel.h>
@@ -77,46 +77,32 @@ class JGE
{ {
private: private:
JApp *mApp; JApp *mApp;
// JResourceManager *mResourceManager;
// JFileSystem* mFileSystem;
// JParticleSystem* mParticleSystem;
// JMotionSystem* mMotionSystem;
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
float mDeltaTime; float mDeltaTime;
JMusic *mCurrentMusic; JMusic *mCurrentMusic;
#else
SceCtrlData mCtrlPad;
u32 mOldButtons;
u32 mVeryOldButtons;
u64 mLastTime;
u32 mTickFrequency;
#endif #endif
bool mDone; bool mDone;
float mDelta; float mDelta;
bool mDebug; bool mDebug;
bool mPaused; bool mPaused;
char mDebuggingMsg[256]; char mDebuggingMsg[256];
bool mCriticalAssert; bool mCriticalAssert;
const char *mAssertFile; const char *mAssertFile;
int mAssertLine; int mAssertLine;
u32 tickFrequency;
static JGE* mInstance; static JGE* mInstance;
static std::queue<JButton> keyBuffer;
static std::multimap<LocalKeySym, JButton> keyBinds;
typedef std::multimap<LocalKeySym, JButton>::iterator keycodes_it;
friend void Run();
public: public:
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@@ -128,10 +114,9 @@ class JGE
static void Destroy(); static void Destroy();
void Init(); void Init();
void Run();
void End(); void End();
void Update(); void Update(float);
void Render(); void Render();
void Pause(); void Pause();
@@ -154,7 +139,7 @@ class JGE
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Return frame rate. /// Return frame rate.
/// ///
/// @note This is just 1.0f/GetDelat(). /// @note This is just 1.0f/GetDelta().
/// ///
/// @return Number of frames per second. /// @return Number of frames per second.
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@@ -167,29 +152,78 @@ class JGE
/// ///
/// @return Button state. /// @return Button state.
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
bool GetButtonState(u32 button); bool GetButtonState(JButton button);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Check if a button is down the first time. /// Check if a button is down the first time.
/// THIS DOES NOT WORK RELIABLY. DO NOT USE THIS.
/// USE ReadButton() INSTEAD.
/// ///
/// @param button - Button id. /// @param button - Button id.
/// ///
/// @return Button state. /// @return Button state.
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
bool GetButtonClick(u32 button); bool GetButtonClick(JButton button);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Get the next keypress. /// Get the next keypress.
/// ///
/// @return Next pressed button, or 0 if none. /// @return Next pressed button, or 0 if none.
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
u32 ReadButton(); JButton ReadButton();
//////////////////////////////////////////////////////////////////////////
/// Bind an actual key to a symbolic button. A key can be bound to
/// several buttons and even several times to the same button (for
/// double clicks on one button, for example.
///
/// @param keycode - The local code of the key
/// @param button - The button to bind it to
///
/// @return The number of bound keys so far
//////////////////////////////////////////////////////////////////////////
u32 BindKey(LocalKeySym keycode, JButton button);
//////////////////////////////////////////////////////////////////////////
/// Undo a binding.
/// If the second parameter is omitted, remove all bindings to this key ;
/// else, remove exactly once the binding from this key to this button.
///
/// @param keycode - The local code of the key
/// @param button - The button
///
/// @return The number of still bound keys
//////////////////////////////////////////////////////////////////////////
u32 UnbindKey(LocalKeySym keycode, JButton button);
u32 UnbindKey(LocalKeySym keycode);
//////////////////////////////////////////////////////////////////////////
/// Clear bindings.
/// This removes ALL bindings. Take care to re-bind keys after doing it.
///
//////////////////////////////////////////////////////////////////////////
void ClearBindings();
//////////////////////////////////////////////////////////////////////////
/// Reset bindings.
/// This resets ALL bindings to their default value.
///
//////////////////////////////////////////////////////////////////////////
void ResetBindings();
//////////////////////////////////////////////////////////////////////////
/// Iterators for bindings.
//////////////////////////////////////////////////////////////////////////
typedef std::multimap<LocalKeySym, JButton>::const_iterator keybindings_it;
keybindings_it KeyBindings_begin();
keybindings_it KeyBindings_end();
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Reset the input buffer. /// Reset the input buffer.
/// This is necessary because there might be phases when GetButtonState /// This is necessary because there might be phases when only
/// or GetButtonClick are used, thereby accumulating keypresses in the /// GetButtonState is used, thereby accumulating keypresses
/// key buffer. /// in the key buffer.
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void ResetInput(); void ResetInput();
@@ -208,13 +242,28 @@ class JGE
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
u8 GetAnalogY(); u8 GetAnalogY();
//////////////////////////////////////////////////////////////////////////
/// Simulate a keypress, or a keyhold/release.
///
//////////////////////////////////////////////////////////////////////////
void PressKey(const LocalKeySym);
void PressKey(const JButton);
void HoldKey(const LocalKeySym);
void HoldKey(const JButton);
void HoldKey_NoRepeat(const LocalKeySym);
void HoldKey_NoRepeat(const JButton);
void ReleaseKey(const LocalKeySym);
void ReleaseKey(const JButton);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Get if the system is ended or not. /// Get if the system is ended/paused or not.
/// ///
/// @return Status of the system. /// @return Status of the system.
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
bool IsDone() { return mDone; } bool IsDone() { return mDone; }
bool IsPaused() { return mPaused; }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@@ -235,7 +284,7 @@ class JGE
void Assert(const char *filename, long lineNumber); void Assert(const char *filename, long lineNumber);
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
void SetDelta(int delta); void SetDelta(float delta);
#endif #endif
protected: protected:
+3 -3
View File
@@ -67,7 +67,7 @@ class JGuiController
bool mActive; bool mActive;
u32 mActionButton; JButton mActionButton;
int mCurr; int mCurr;
int mStyle; int mStyle;
@@ -94,14 +94,14 @@ class JGuiController
virtual void Render(); virtual void Render();
virtual void Update(float dt); virtual void Update(float dt);
virtual bool CheckUserInput(u32 key); virtual bool CheckUserInput(JButton key);
void Add(JGuiObject* ctrl); void Add(JGuiObject* ctrl);
void RemoveAt(int i); void RemoveAt(int i);
void Remove(int id); void Remove(int id);
void Remove(JGuiObject* ctrl); void Remove(JGuiObject* ctrl);
void SetActionButton(u32 button); void SetActionButton(JButton button);
void SetStyle(int style); void SetStyle(int style);
void SetCursor(JSprite* cursor); void SetCursor(JSprite* cursor);
+23 -19
View File
@@ -111,25 +111,6 @@ typedef uint32_t u32;
#define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) #define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
#define RGBA(r, g, b, a) (((a) << 24) | ((b) << 16) | ((g) << 8) | (r)) #define RGBA(r, g, b, a) (((a) << 24) | ((b) << 16) | ((g) << 8) | (r))
typedef enum PspCtrlButtons
{
PSP_CTRL_SELECT = 0x000001,
PSP_CTRL_START = 0x000008,
PSP_CTRL_UP = 0x000010,
PSP_CTRL_RIGHT = 0x000020,
PSP_CTRL_DOWN = 0x000040,
PSP_CTRL_LEFT = 0x000080,
PSP_CTRL_LTRIGGER = 0x000100,
PSP_CTRL_RTRIGGER = 0x000200,
PSP_CTRL_TRIANGLE = 0x001000,
PSP_CTRL_CIRCLE = 0x002000,
PSP_CTRL_CROSS = 0x004000,
PSP_CTRL_SQUARE = 0x008000,
PSP_CTRL_HOME = 0x010000,
PSP_CTRL_HOLD = 0x020000,
PSP_CTRL_NOTE = 0x800000
} PspCtrlButtons;
#define TEXTURE_FORMAT 0 #define TEXTURE_FORMAT 0
#define GU_PSM_8888 0 #define GU_PSM_8888 0
#define GU_PSM_5551 0 #define GU_PSM_5551 0
@@ -228,6 +209,29 @@ typedef uint32_t u32;
typedef enum Buttons
{
JGE_BTN_NONE = 0, // No button pressed
JGE_BTN_QUIT, // Home on PSP
JGE_BTN_MENU, // Start on PSP
JGE_BTN_CTRL, // Select
JGE_BTN_POWER, // Hold
JGE_BTN_SOUND, // Music note
JGE_BTN_RIGHT,
JGE_BTN_LEFT,
JGE_BTN_UP,
JGE_BTN_DOWN,
JGE_BTN_OK, // Circle in Japan, Cross in Europe
JGE_BTN_CANCEL, // Triangle
JGE_BTN_PRI, // Square (primary)
JGE_BTN_SEC, // Cross or Circle (secondary)
JGE_BTN_PREV, // Left trigger
JGE_BTN_NEXT, // Right trigger
JGE_BTN_MAX = JGE_BTN_NEXT + 1
} JButton;
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
struct Vertex struct Vertex
+183 -205
View File
@@ -8,6 +8,9 @@
// //
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include <iostream>
#include <map>
#include "../include/JGE.h" #include "../include/JGE.h"
#include "../include/JApp.h" #include "../include/JApp.h"
#include "../include/JRenderer.h" #include "../include/JRenderer.h"
@@ -20,11 +23,8 @@
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
#if defined (WIN32) // WIN32 specific code #if defined (WIN32) // WIN32 specific code
#include "../../Dependencies/include/png.h"
int JGE::GetTime(void) #include "../../Dependencies/include/fmod.h"
{
return (int)GetTickCount();
}
u8 JGE::GetAnalogX() u8 JGE::GetAnalogX()
{ {
@@ -48,12 +48,6 @@ u8 JGE::GetAnalogY()
#include "png.h" #include "png.h"
#include "../Dependencies/include/fmod.h" #include "../Dependencies/include/fmod.h"
int JGE::GetTime(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
u8 JGE::GetAnalogX() u8 JGE::GetAnalogX()
{ {
@@ -78,17 +72,156 @@ u8 JGE::GetAnalogY()
#endif #endif
static map<JButton, float> holds;
static map<JButton, float> oldHolds;
#define REPEAT_DELAY 0.5
#define REPEAT_PERIOD 0.07
void JGE::PressKey(const LocalKeySym sym)
{
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
for (keycodes_it it = rng.first; it != rng.second; ++it)
keyBuffer.push(it->second);
}
void JGE::PressKey(const JButton sym)
{
keyBuffer.push(sym);
}
void JGE::HoldKey(const LocalKeySym sym)
{
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
for (keycodes_it it = rng.first; it != rng.second; ++it)
{
keyBuffer.push(it->second);
if (holds.end() == holds.find(it->second))
holds[it->second] = REPEAT_DELAY;
}
}
void JGE::HoldKey_NoRepeat(const LocalKeySym sym)
{
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
for (keycodes_it it = rng.first; it != rng.second; ++it)
{
keyBuffer.push(it->second);
if (holds.end() == holds.find(it->second))
holds[it->second] = NAN;
}
}
void JGE::HoldKey(const JButton sym)
{
keyBuffer.push(sym);
if (holds.end() == holds.find(sym)) holds[sym] = REPEAT_DELAY;
}
void JGE::HoldKey_NoRepeat(const JButton sym)
{
keyBuffer.push(sym);
if (holds.end() == holds.find(sym)) holds[sym] = NAN;
}
void JGE::ReleaseKey(const LocalKeySym sym)
{
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
for (keycodes_it it = rng.first; it != rng.second; ++it)
holds.erase(it->second);
}
void JGE::ReleaseKey(const JButton sym)
{
holds.erase(sym);
}
void JGE::Update(float dt)
{
for (map<JButton, float>::iterator it = holds.begin(); it != holds.end(); ++it)
{
if (it->second < 0) { keyBuffer.push(it->first); it->second = REPEAT_PERIOD; }
it->second -= dt;
}
if (mApp != NULL) mApp->Update();
oldHolds = holds;
}
bool JGE::GetButtonState(JButton button)
{
return (holds.end() != holds.find(button));
}
bool JGE::GetButtonClick(JButton button)
{
cout << "HOLDS : ";
for (map<JButton, float>::iterator it = holds.begin(); it != holds.end(); ++it)
cout << it->first << " ";
cout << endl << "OLDHOLDS : ";
for (map<JButton, float>::iterator it = oldHolds.begin(); it != oldHolds.end(); ++it)
cout << it->first << " ";
cout << endl;
return ((holds.end() != holds.find(button)) && (oldHolds.end() == oldHolds.find(button)));
}
JButton JGE::ReadButton()
{
if (keyBuffer.empty()) return JGE_BTN_NONE;
JButton val = keyBuffer.front();
keyBuffer.pop();
return val;
}
u32 JGE::BindKey(LocalKeySym sym, JButton button)
{
keyBinds.insert(make_pair(sym, button));
return keyBinds.size();
}
u32 JGE::UnbindKey(LocalKeySym sym, JButton button)
{
for (keycodes_it it = keyBinds.begin(); it != keyBinds.end(); )
if (sym == it->first && button == it->second)
{
keycodes_it er = it;
++it;
keyBinds.erase(er);
}
else ++it;
return keyBinds.size();
}
u32 JGE::UnbindKey(LocalKeySym sym)
{
pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
keyBinds.erase(rng.first, rng.second);
return keyBinds.size();
}
void JGE::ClearBindings()
{
keyBinds.clear();
}
void JGE::ResetBindings()
{
keyBinds.clear();
JGECreateDefaultBindings();
}
JGE::keybindings_it JGE::KeyBindings_begin() { return keyBinds.begin(); }
JGE::keybindings_it JGE::KeyBindings_end() { return keyBinds.end(); }
void JGE::ResetInput()
{
while (!keyBuffer.empty()) keyBuffer.pop();
holds.clear();
}
#if defined (WIN32) || defined (LINUX) // Non-PSP code
JGE::JGE() JGE::JGE()
{ {
mApp = NULL; mApp = NULL;
#if defined (WIN32) || defined (LINUX)
strcpy(mDebuggingMsg, ""); strcpy(mDebuggingMsg, "");
mCurrentMusic = NULL; mCurrentMusic = NULL;
#endif
Init(); Init();
} }
@@ -101,127 +234,52 @@ JGE::~JGE()
#if defined (WIN32) || defined (LINUX) // Non-PSP code
void JGE::Init() void JGE::Init()
{ {
mDone = false; mDone = false;
mPaused = false; mPaused = false;
mCriticalAssert = false; mCriticalAssert = false;
JRenderer::GetInstance(); JRenderer::GetInstance();
JFileSystem::GetInstance(); JFileSystem::GetInstance();
JSoundSystem::GetInstance(); JSoundSystem::GetInstance();
} }
void JGE::Run() void JGE::SetDelta(float delta)
{ {
mDeltaTime = (float)delta;
}
void JGE::SetDelta(int delta)
{
mDeltaTime = (float)delta / 1000.0f; // change to second
} }
float JGE::GetDelta() float JGE::GetDelta()
{ {
return mDeltaTime; return mDeltaTime;
//return hge->Timer_GetDelta()*1000;
} }
float JGE::GetFPS() float JGE::GetFPS()
{ {
//return (float)hge->Timer_GetFPS();
return 0.0f; return 0.0f;
} }
bool JGE::GetButtonState(u32 button)
{
//return (gButtons&button)==button;
return JGEGetButtonState(button);
}
bool JGE::GetButtonClick(u32 button)
{
//return (gButtons&button)==button && (gOldButtons&button)!=button;
return JGEGetButtonClick(button);
}
u32 JGE::ReadButton()
{
return JGEReadKey();
}
void JGE::ResetInput()
{
JGEResetInput();
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
#else ///// PSP specified code #else ///// PSP specific code
#include <queue>
static queue<u32> gKeyBuffer;
static const int gKeyCodeList[] = {
PSP_CTRL_SELECT, // Select button.
PSP_CTRL_START, // Start button.
PSP_CTRL_UP, // Up D-Pad button.
PSP_CTRL_RIGHT, // Right D-Pad button.
PSP_CTRL_DOWN, // Down D-Pad button.
PSP_CTRL_LEFT, // Left D-Pad button.
PSP_CTRL_LTRIGGER, // Left trigger.
PSP_CTRL_RTRIGGER, // Right trigger.
PSP_CTRL_TRIANGLE, // Triangle button.
PSP_CTRL_CIRCLE, // Circle button.
PSP_CTRL_CROSS, // Cross button.
PSP_CTRL_SQUARE, // Square button.
PSP_CTRL_HOLD, // Hold button.
/* Do not test keys we cannot get anyway, that's just wasted proc time
PSP_CTRL_HOME, // Home button.
PSP_CTRL_NOTE, // Music Note button.
PSP_CTRL_SCREEN, // Screen button.
PSP_CTRL_VOLUP, // Volume up button.
PSP_CTRL_VOLDOWN, // Volume down button.
PSP_CTRL_WLAN, // _UP Wlan switch up.
PSP_CTRL_REMOTE, // Remote hold position.
PSP_CTRL_DISC, // Disc present.
PSP_CTRL_MS // Memory stick present.
*/
};
static u32 gHolds = 0;
JGE::JGE()
{
mApp = NULL;
Init();
}
JGE::~JGE()
{
JRenderer::Destroy();
JSoundSystem::Destroy();
JFileSystem::Destroy();
}
void JGE::Init() void JGE::Init()
{ {
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
mDebug = true; mDebug = true;
#else #else
mDebug = false; mDebug = false;
#endif #endif
#if defined (WIN32) || defined (LINUX)
tickFrequency = 120;
#else
tickFrequency = sceRtcGetTickResolution();
#endif
if (mDebug) if (mDebug)
pspDebugScreenInit(); // do this so that we can use pspDebugScreenPrintf pspDebugScreenInit(); // do this so that we can use pspDebugScreenPrintf
@@ -237,23 +295,8 @@ void JGE::Init()
mDone = false; mDone = false;
mPaused = false; mPaused = false;
mCriticalAssert = false; mCriticalAssert = false;
mOldButtons = mVeryOldButtons = 0;
mTickFrequency = sceRtcGetTickResolution();
sceRtcGetCurrentTick(&mLastTime);
} }
// returns number of milliseconds since game started
int JGE::GetTime(void)
{
u64 curr;
sceRtcGetCurrentTick(&curr);
return (int)((curr * 1000) / mTickFrequency);
}
float JGE::GetDelta() float JGE::GetDelta()
{ {
return mDelta; return mDelta;
@@ -265,7 +308,19 @@ float JGE::GetFPS()
return 1.0f / mDelta; return 1.0f / mDelta;
} }
u8 JGE::GetAnalogX()
{
return JGEGetAnalogX();
}
u8 JGE::GetAnalogY()
{
return JGEGetAnalogY();
}
/*
bool JGE::GetButtonState(u32 button) bool JGE::GetButtonState(u32 button)
{ {
return (mCtrlPad.Buttons&button)==button; return (mCtrlPad.Buttons&button)==button;
@@ -291,93 +346,23 @@ void JGE::ResetInput()
{ {
while (!gKeyBuffer.empty()) gKeyBuffer.pop(); while (!gKeyBuffer.empty()) gKeyBuffer.pop();
} }
*/
u8 JGE::GetAnalogX()
{
return mCtrlPad.Lx;
}
u8 JGE::GetAnalogY() #endif ///// PSP specific code
{
return mCtrlPad.Ly;
}
#define REPEAT_DELAY 0.5
#define REPEAT_FREQUENCY 7
void JGE::Run()
{
u64 curr;
long long int nextInput = 0;
const u32 ticksPerSecond = sceRtcGetTickResolution();
const u64 repeatDelay = REPEAT_DELAY * ticksPerSecond;
const u64 repeatPeriod = ticksPerSecond / REPEAT_FREQUENCY;
while (!mDone)
{
if (!mPaused)
{
sceRtcGetCurrentTick(&curr);
mDelta = (curr-mLastTime) / (float)mTickFrequency;// * 1000.0f;
sceCtrlPeekBufferPositive(&mCtrlPad, 1);
for (signed int i = sizeof(gKeyCodeList)/sizeof(gKeyCodeList[0]) - 1; i >= 0; --i)
{
if (gKeyCodeList[i] & mCtrlPad.Buttons)
{
if (!(gKeyCodeList[i] & mOldButtons))
{
if (!(gHolds & gKeyCodeList[i])) gKeyBuffer.push(gKeyCodeList[i]);
nextInput = repeatDelay;
gHolds |= gKeyCodeList[i];
}
else if (nextInput < 0)
{
if (!(gHolds & gKeyCodeList[i])) gKeyBuffer.push(gKeyCodeList[i]);
nextInput = repeatPeriod;
gHolds |= gKeyCodeList[i];
}
}
if (!(gKeyCodeList[i] & mCtrlPad.Buttons))
if (gKeyCodeList[i] & mOldButtons)
gHolds &= ~gKeyCodeList[i];
}
mOldButtons = mCtrlPad.Buttons;
nextInput -= (curr - mLastTime);
mLastTime = curr;
Update();
Render();
if (mDebug)
{
if (strlen(mDebuggingMsg)>0)
{
pspDebugScreenSetXY(0, 0);
pspDebugScreenPrintf(mDebuggingMsg);
}
}
mVeryOldButtons = mCtrlPad.Buttons;
}
else
{
sceKernelDelayThread(1);
}
}
}
#endif ///// PSP specified code
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
JGE* JGE::mInstance = NULL; JGE* JGE::mInstance = NULL;
//static int gCount = 0; //static int gCount = 0;
// returns number of milliseconds since game started
int JGE::GetTime()
{
return JGEGetTime();
}
JGE* JGE::GetInstance() JGE* JGE::GetInstance()
{ {
if (mInstance == NULL) if (mInstance == NULL)
@@ -406,22 +391,12 @@ void JGE::SetApp(JApp *app)
mApp = app; mApp = app;
} }
void JGE::Update()
{
if (mApp != NULL)
mApp->Update();
}
void JGE::Render() void JGE::Render()
{ {
JRenderer* renderer = JRenderer::GetInstance(); JRenderer* renderer = JRenderer::GetInstance();
renderer->BeginScene(); renderer->BeginScene();
if (mApp != NULL) mApp->Render();
if (mApp != NULL)
mApp->Render();
renderer->EndScene(); renderer->EndScene();
} }
@@ -473,3 +448,6 @@ void JGE::Assert(const char *filename, long lineNumber)
} }
std::queue<JButton> JGE::keyBuffer;
std::multimap<LocalKeySym, JButton> JGE::keyBinds;
+8 -8
View File
@@ -75,7 +75,7 @@ JGuiController::JGuiController(int id, JGuiListener* listener) : mId(id), mListe
mCursorY = SCREEN_HEIGHT/2; mCursorY = SCREEN_HEIGHT/2;
mShowCursor = false; mShowCursor = false;
mActionButton = PSP_CTRL_CIRCLE; mActionButton = JGE_BTN_OK;
mStyle = JGUI_STYLE_WRAPPING; mStyle = JGUI_STYLE_WRAPPING;
@@ -98,7 +98,7 @@ void JGuiController::Render()
if (mObjects[i]!=NULL) if (mObjects[i]!=NULL)
mObjects[i]->Render(); mObjects[i]->Render();
} }
bool JGuiController::CheckUserInput(u32 key){ bool JGuiController::CheckUserInput(JButton key){
if (key == mActionButton) if (key == mActionButton)
{ {
@@ -109,7 +109,7 @@ bool JGuiController::CheckUserInput(u32 key){
return true; return true;
} }
} }
else if ((PSP_CTRL_LEFT == key) || (PSP_CTRL_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64) else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
{ {
int n = mCurr; int n = mCurr;
n--; n--;
@@ -121,14 +121,14 @@ bool JGuiController::CheckUserInput(u32 key){
n = 0; n = 0;
} }
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_UP)) if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_UP))
{ {
mCurr = n; mCurr = n;
mObjects[mCurr]->Entering(); mObjects[mCurr]->Entering();
} }
return true; return true;
} }
else if ((PSP_CTRL_RIGHT == key) || (PSP_CTRL_DOWN == key)) // || mEngine->GetAnalogY()>192 || mEngine->GetAnalogX()>192) else if ((JGE_BTN_RIGHT == key) || (JGE_BTN_DOWN == key)) // || mEngine->GetAnalogY()>192 || mEngine->GetAnalogX()>192)
{ {
int n = mCurr; int n = mCurr;
n++; n++;
@@ -140,7 +140,7 @@ bool JGuiController::CheckUserInput(u32 key){
n = mCount-1; n = mCount-1;
} }
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_DOWN)) if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
{ {
mCurr = n; mCurr = n;
mObjects[mCurr]->Entering(); mObjects[mCurr]->Entering();
@@ -155,7 +155,7 @@ void JGuiController::Update(float dt)
if (mObjects[i]!=NULL) if (mObjects[i]!=NULL)
mObjects[i]->Update(dt); mObjects[i]->Update(dt);
u32 key = mEngine->ReadButton(); JButton key = mEngine->ReadButton();
CheckUserInput(key); CheckUserInput(key);
} }
@@ -200,7 +200,7 @@ void JGuiController::Remove(JGuiObject* ctrl)
} }
void JGuiController::SetActionButton(u32 button) { mActionButton = button; } void JGuiController::SetActionButton(JButton button) { mActionButton = button; }
void JGuiController::SetStyle(int style) { mStyle = style; } void JGuiController::SetStyle(int style) { mStyle = style; }
void JGuiController::SetCursor(JSprite* cursor) { mCursor = cursor; } void JGuiController::SetCursor(JSprite* cursor) { mCursor = cursor; }
bool JGuiController::IsActive() { return mActive; } bool JGuiController::IsActive() { return mActive; }
+48 -116
View File
@@ -5,7 +5,8 @@
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#include <sys/time.h> #include <sys/time.h>
#include <queue> #include <queue>
#include <iostream> #include <map>
#include <set>
#include "../../JGE/include/JGE.h" #include "../../JGE/include/JGE.h"
#include "../../JGE/include/JTypes.h" #include "../../JGE/include/JTypes.h"
@@ -50,39 +51,35 @@ Display* gXDisplay = NULL;
Window gXWindow = NULL; Window gXWindow = NULL;
GLXWindow glxWin = NULL; GLXWindow glxWin = NULL;
static queue< pair<KeySym, u32> > gKeyBuffer; static std::multiset<JButton> gControllerState;
static u32 gControllerState = 0; static std::multiset<JButton> gPrevControllerState;
static u32 gPrevControllerState = 0;
static u32 gHolds = 0;
static const struct { KeySym keysym; u32 pspCode; } gDefaultBindings[] = static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
{ {
{ XK_Escape, PSP_CTRL_START }, { XK_Escape, JGE_BTN_MENU },
{ XK_Return, PSP_CTRL_START }, { XK_Return, JGE_BTN_MENU },
{ XK_BackSpace, PSP_CTRL_SELECT }, { XK_BackSpace, JGE_BTN_CTRL },
{ XK_Up, PSP_CTRL_UP }, { XK_Up, JGE_BTN_UP },
{ XK_KP_Up, PSP_CTRL_UP }, { XK_KP_Up, JGE_BTN_UP },
{ XK_Down, PSP_CTRL_DOWN }, { XK_Down, JGE_BTN_DOWN },
{ XK_KP_Down, PSP_CTRL_DOWN }, { XK_KP_Down, JGE_BTN_DOWN },
{ XK_Left, PSP_CTRL_LEFT }, { XK_Left, JGE_BTN_LEFT },
{ XK_KP_Left, PSP_CTRL_LEFT }, { XK_KP_Left, JGE_BTN_LEFT },
{ XK_Right, PSP_CTRL_RIGHT }, { XK_Right, JGE_BTN_RIGHT },
{ XK_KP_Right, PSP_CTRL_RIGHT }, { XK_KP_Right, JGE_BTN_RIGHT },
{ XK_space, PSP_CTRL_CIRCLE }, { XK_space, JGE_BTN_OK },
{ XK_Control_L, PSP_CTRL_CIRCLE }, { XK_Control_L, JGE_BTN_OK },
{ XK_Control_R, PSP_CTRL_CIRCLE }, { XK_Control_R, JGE_BTN_OK },
{ XK_Tab, PSP_CTRL_TRIANGLE }, { XK_Tab, JGE_BTN_CANCEL },
{ XK_Alt_L, PSP_CTRL_SQUARE }, { XK_Alt_L, JGE_BTN_PRI },
{ XK_Caps_Lock, PSP_CTRL_CROSS }, { XK_Caps_Lock, JGE_BTN_SEC },
{ XK_Shift_L, PSP_CTRL_LTRIGGER }, { XK_Shift_L, JGE_BTN_PREV },
{ XK_Shift_R, PSP_CTRL_RTRIGGER }, { XK_Shift_R, JGE_BTN_NEXT },
{ XK_F1, PSP_CTRL_HOME }, { XK_F1, JGE_BTN_QUIT },
{ XK_F2, PSP_CTRL_HOLD }, { XK_F2, JGE_BTN_POWER },
{ XK_F3, PSP_CTRL_NOTE } { XK_F3, JGE_BTN_SOUND }
}; };
static vector< pair<KeySym, u32> > gKeyCodes;
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize The GL Window GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize The GL Window
{ {
@@ -210,9 +207,6 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits __attribute__((
return false; return false;
} }
for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
gKeyCodes.push_back(make_pair(gDefaultBindings[i].keysym, gDefaultBindings[i].pspCode));
// Get a suitable framebuffer config // Get a suitable framebuffer config
int numReturned; int numReturned;
GLXFBConfig *fbConfigs = glXChooseFBConfig(gXDisplay, DefaultScreen(gXDisplay), doubleBufferAttributes, &numReturned); GLXFBConfig *fbConfigs = glXChooseFBConfig(gXDisplay, DefaultScreen(gXDisplay), doubleBufferAttributes, &numReturned);
@@ -266,83 +260,37 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits __attribute__((
} }
void Update(float dt)
void JGEControl()
{ {
gPrevControllerState = gControllerState; gPrevControllerState = gControllerState;
}
void Update(int dt)
{
g_engine->SetDelta(dt); g_engine->SetDelta(dt);
g_engine->Update(); g_engine->Update(dt);
JGEControl();
} }
int DrawGLScene(void) // Here's Where We Do All The Drawing int DrawGLScene(void)
{ {
// glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
// glLoadIdentity (); // Reset The Modelview Matrix
//if (g_app)
// g_app->Render();
g_engine->Render(); g_engine->Render();
return true;
// glFlush ();
return true; // Everything Went OK
} }
template <typename T>
static inline bool include(multiset<T> set, T button)
bool JGEGetButtonState(u32 button)
{ {
return gControllerState & button; return set.end() != set.find(button);
} }
bool JGEGetButtonClick(u32 button) void JGECreateDefaultBindings()
{ {
return ((gControllerState & button) && (!(gPrevControllerState & button))); for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
g_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode);
} }
bool JGEGetKeyState(int key __attribute__((unused))) int JGEGetTime()
{ {
return false; struct timeval tv;
} gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
u32 JGEReadKey()
{
if (gKeyBuffer.empty()) return 0;
u32 val = gKeyBuffer.front().second;
gHolds &= ~val;
gKeyBuffer.pop();
return val;
}
u32 JGEReadLocalKey()
{
if (gKeyBuffer.empty()) return 0;
pair <KeyCode, u32> val = gKeyBuffer.front();
gHolds &= ~val.second;
gKeyBuffer.pop();
return val.first;
}
void JGEBindLocalKey(u32 localKey, u32 pspSymbol)
{
}
void JGEResetInput()
{
while (!gKeyBuffer.empty()) gKeyBuffer.pop();
} }
void reshapeFunc(int width, int height) void reshapeFunc(int width, int height)
@@ -420,6 +368,8 @@ int main(int argc, char* argv[])
XSelectInput(gXDisplay, gXWindow, KeyPressMask | KeyReleaseMask | StructureNotifyMask); XSelectInput(gXDisplay, gXWindow, KeyPressMask | KeyReleaseMask | StructureNotifyMask);
XkbSetDetectableAutoRepeat(gXDisplay, true, NULL); XkbSetDetectableAutoRepeat(gXDisplay, true, NULL);
JGECreateDefaultBindings();
static uint64_t tickCount; static uint64_t tickCount;
while (!g_engine->IsDone()) while (!g_engine->IsDone())
{ {
@@ -430,7 +380,7 @@ int main(int argc, char* argv[])
tickCount = tv.tv_sec * 1000 + tv.tv_usec / 1000; tickCount = tv.tv_sec * 1000 + tv.tv_usec / 1000;
dt = (tickCount - lastTickCount); dt = (tickCount - lastTickCount);
lastTickCount = tickCount; lastTickCount = tickCount;
Update(dt); // Update frame Update((float)dt / 1000.0f); // Update frame
DrawGLScene(); // Draw The Scene DrawGLScene(); // Draw The Scene
glXSwapBuffers(gXDisplay, glxWin); glXSwapBuffers(gXDisplay, glxWin);
@@ -439,31 +389,13 @@ int main(int argc, char* argv[])
{ {
case KeyPress: case KeyPress:
{ {
KeySym sym = XKeycodeToKeysym(gXDisplay, event.xkey.keycode, 1); const KeySym sym = XKeycodeToKeysym(gXDisplay, event.xkey.keycode, 1);
if (XK_F == sym) if (sym == XK_F) fullscreen();
fullscreen(); g_engine->HoldKey_NoRepeat(sym);
for (vector< pair<KeySym, u32> >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it)
if (sym == it->first)
{
if (!(gHolds & it->second))
gKeyBuffer.push(*it);
gControllerState |= it->second;
gHolds |= it->second;
break;
}
} }
break; break;
case KeyRelease: case KeyRelease:
{ g_engine->ReleaseKey(XKeycodeToKeysym(gXDisplay, event.xkey.keycode, 1));
KeySym sym = XKeycodeToKeysym(gXDisplay, event.xkey.keycode, 1);
for (vector< pair<KeySym, u32> >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it)
if (sym == it->first)
{
gControllerState &= ~it->second;
gHolds &= ~it->second;
break;
}
}
break; break;
case ConfigureNotify: case ConfigureNotify:
ReSizeGLScene(event.xconfigure.width, event.xconfigure.height); ReSizeGLScene(event.xconfigure.width, event.xconfigure.height);
+143 -34
View File
@@ -13,6 +13,7 @@
#include <pspctrl.h> #include <pspctrl.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <queue>
#include "../../JGE/include/JGE.h" #include "../../JGE/include/JGE.h"
@@ -45,17 +46,17 @@ int mikModThreadID = -1;
bool done = false; bool done = false;
JApp *game = NULL; JApp *game = NULL;
JGE *engine = NULL; JGE *g_engine = NULL;
u32 gTickFrequency;
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
// Exit callback // Exit callback
int exit_callback(int arg1, int arg2, void *common) int exit_callback(int arg1, int arg2, void *common)
{ {
if (engine != NULL) if (g_engine != NULL)
engine->End(); g_engine->End();
sceKernelExitGame(); sceKernelExitGame();
return 0; return 0;
} }
@@ -66,19 +67,15 @@ int power_callback(int unknown, int pwrflags, void *common)
if ((pwrflags & (PSP_POWER_CB_POWER_SWITCH | PSP_POWER_CB_STANDBY)) > 0) if ((pwrflags & (PSP_POWER_CB_POWER_SWITCH | PSP_POWER_CB_STANDBY)) > 0)
{ {
// suspending // suspending
if (engine != NULL) if (g_engine != NULL) g_engine->Pause();
engine->Pause();
} }
else if ((pwrflags & PSP_POWER_CB_RESUME_COMPLETE) > 0) else if ((pwrflags & PSP_POWER_CB_RESUME_COMPLETE) > 0)
{ {
sceKernelDelayThread(1500000); sceKernelDelayThread(1500000);
// resume complete // resume complete
if (engine != NULL) if (g_engine != NULL)
engine->Resume(); g_engine->Resume();
} }
return 0; return 0;
} }
@@ -106,11 +103,7 @@ int SetupCallbacks(void)
int thid = 0; int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) if (thid >= 0) sceKernelStartThread(thid, 0, 0);
{
sceKernelStartThread(thid, 0, 0);
}
return thid; return thid;
} }
@@ -166,11 +159,14 @@ void ExceptionHandler(PspDebugRegBlock * regs)
pspDebugScreenPrintf("\n\nPress X to dump information on file exception.log and quit"); pspDebugScreenPrintf("\n\nPress X to dump information on file exception.log and quit");
pspDebugScreenPrintf("\nPress O to quit"); pspDebugScreenPrintf("\nPress O to quit");
for (;;){ for (;;)
{
sceCtrlReadBufferPositive(&pad, 1); sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_CROSS){ if (pad.Buttons & PSP_CTRL_CROSS)
{
FILE *log = fopen("exception.log", "w"); FILE *log = fopen("exception.log", "w");
if (log != NULL){ if (log != NULL)
{
char testo[512]; char testo[512];
sprintf(testo, "Exception details:\n\n"); sprintf(testo, "Exception details:\n\n");
fwrite(testo, 1, strlen(testo), log); fwrite(testo, 1, strlen(testo), log);
@@ -184,16 +180,17 @@ void ExceptionHandler(PspDebugRegBlock * regs)
fwrite(testo, 1, strlen(testo), log); fwrite(testo, 1, strlen(testo), log);
sprintf(testo, "BadVAddr - %08X\n", (int)regs->badvaddr); sprintf(testo, "BadVAddr - %08X\n", (int)regs->badvaddr);
fwrite(testo, 1, strlen(testo), log); fwrite(testo, 1, strlen(testo), log);
for(i=0; i<32; i+=4){ for (i = 0; i < 32; i += 4)
{
sprintf(testo, "%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]); sprintf(testo, "%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]);
fwrite(testo, 1, strlen(testo), log); fwrite(testo, 1, strlen(testo), log);
} }
fclose(log); fclose(log);
} }
break; break;
}else if (pad.Buttons & PSP_CTRL_CIRCLE){
break;
} }
else if (pad.Buttons & PSP_CTRL_CIRCLE)
break;
sceKernelDelayThread(100000); sceKernelDelayThread(100000);
} }
sceKernelExitGame(); sceKernelExitGame();
@@ -238,7 +235,6 @@ void initExceptionHandler()
sceKernelExitGame(); sceKernelExitGame();
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
// Sort of hack to install exception handler under USER THREAD // Sort of hack to install exception handler under USER THREAD
__attribute__((constructor)) void handlerInit() __attribute__((constructor)) void handlerInit()
@@ -254,17 +250,130 @@ void initExceptionHandler()
#endif #endif
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
{
{ PSP_CTRL_HOME, JGE_BTN_QUIT },
{ PSP_CTRL_START, JGE_BTN_MENU },
{ PSP_CTRL_SELECT, JGE_BTN_CTRL },
{ PSP_CTRL_HOLD, JGE_BTN_POWER },
{ PSP_CTRL_NOTE, JGE_BTN_SOUND },
{ PSP_CTRL_RIGHT, JGE_BTN_RIGHT },
{ PSP_CTRL_LEFT, JGE_BTN_LEFT },
{ PSP_CTRL_UP, JGE_BTN_UP },
{ PSP_CTRL_DOWN, JGE_BTN_DOWN },
{ PSP_CTRL_CIRCLE, JGE_BTN_OK },
{ PSP_CTRL_TRIANGLE, JGE_BTN_CANCEL },
{ PSP_CTRL_SQUARE, JGE_BTN_PRI },
{ PSP_CTRL_CROSS, JGE_BTN_SEC },
{ PSP_CTRL_LTRIGGER, JGE_BTN_PREV },
{ PSP_CTRL_RTRIGGER, JGE_BTN_NEXT }
};
void JGECreateDefaultBindings()
{
for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
g_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode);
}
int JGEGetTime()
{
u64 curr;
sceRtcGetCurrentTick(&curr);
return (int)((curr * 1000) / gTickFrequency);
}
static SceCtrlData gCtrlPad;
u8 JGEGetAnalogX() { return gCtrlPad.Lx; }
u8 JGEGetAnalogY() { return gCtrlPad.Ly; }
void Run()
{
static const int keyCodeList[] = {
PSP_CTRL_SELECT, // Select button.
PSP_CTRL_START, // Start button.
PSP_CTRL_UP, // Up D-Pad button.
PSP_CTRL_RIGHT, // Right D-Pad button.
PSP_CTRL_DOWN, // Down D-Pad button.
PSP_CTRL_LEFT, // Left D-Pad button.
PSP_CTRL_LTRIGGER, // Left trigger.
PSP_CTRL_RTRIGGER, // Right trigger.
PSP_CTRL_TRIANGLE, // Triangle button.
PSP_CTRL_CIRCLE, // Circle button.
PSP_CTRL_CROSS, // Cross button.
PSP_CTRL_SQUARE, // Square button.
PSP_CTRL_HOLD, // Hold button.
/* Do not test keys we cannot get anyway, that's just wasted proc time
PSP_CTRL_HOME, // Home button.
PSP_CTRL_NOTE, // Music Note button.
PSP_CTRL_SCREEN, // Screen button.
PSP_CTRL_VOLUP, // Volume up button.
PSP_CTRL_VOLDOWN, // Volume down button.
PSP_CTRL_WLAN, // _UP Wlan switch up.
PSP_CTRL_REMOTE, // Remote hold position.
PSP_CTRL_DISC, // Disc present.
PSP_CTRL_MS // Memory stick present.
*/
};
u64 curr;
long long int nextInput = 0;
u64 lastTime;
u32 oldButtons;
u32 veryOldButtons;
sceRtcGetCurrentTick(&lastTime);
oldButtons = veryOldButtons = 0;
JGECreateDefaultBindings();
while (!g_engine->mDone)
{
if (!g_engine->mPaused)
{
sceRtcGetCurrentTick(&curr);
float dt = (curr - lastTime) / (float)gTickFrequency;
g_engine->mDelta = dt;
sceCtrlPeekBufferPositive(&gCtrlPad, 1);
for (signed int i = sizeof(keyCodeList)/sizeof(keyCodeList[0]) - 1; i >= 0; --i)
{
if (keyCodeList[i] & gCtrlPad.Buttons)
{
if (!(keyCodeList[i] & oldButtons))
g_engine->HoldKey(keyCodeList[i]);
}
else
if (keyCodeList[i] & oldButtons)
g_engine->ReleaseKey(keyCodeList[i]);
}
oldButtons = gCtrlPad.Buttons;
g_engine->Update(dt);
g_engine->Render();
if (g_engine->mDebug)
{
if (strlen(g_engine->mDebuggingMsg)>0)
{
pspDebugScreenSetXY(0, 0);
pspDebugScreenPrintf(g_engine->mDebuggingMsg);
}
}
veryOldButtons = gCtrlPad.Buttons;
}
else
sceKernelDelayThread(1);
lastTime = curr;
}
}
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
// The main loop // The main loop
int main() int main()
{ {
SetupCallbacks(); SetupCallbacks();
#ifdef DEVHOOK #ifdef DEVHOOK
initExceptionHandler(); initExceptionHandler();
#endif #endif
engine = NULL; g_engine = NULL;
JGameLauncher* launcher = new JGameLauncher(); JGameLauncher* launcher = new JGameLauncher();
@@ -272,30 +381,30 @@ int main()
if ((flags&JINIT_FLAG_ENABLE3D) != 0) if ((flags&JINIT_FLAG_ENABLE3D) != 0)
JRenderer::Set3DFlag(true); JRenderer::Set3DFlag(true);
engine = JGE::GetInstance(); gTickFrequency = sceRtcGetTickResolution();
g_engine = JGE::GetInstance();
game = launcher->GetGameApp(); game = launcher->GetGameApp();
game->Create(); game->Create();
g_engine->SetApp(game);
engine->SetApp(game); Run();
engine->Run();
game->Destroy(); game->Destroy();
delete game; delete game;
game = NULL; game = NULL;
engine->SetApp(NULL); g_engine->SetApp(NULL);
done = true; done = true;
delete launcher; delete launcher;
JGE::Destroy(); JGE::Destroy();
engine = NULL; g_engine = NULL;
sceKernelExitGame(); sceKernelExitGame();
return 0; return 0;
} }
+10 -78
View File
@@ -158,7 +158,6 @@ JGameLauncher* g_launcher = NULL;
static u32 gButtons = 0; static u32 gButtons = 0;
static u32 gOldButtons = 0; static u32 gOldButtons = 0;
static queue< pair<u32, u32> > gKeyBuffer;
static const struct { WPARAM keysym; u32 pspCode; } gDefaultBindings[] = static const struct { WPARAM keysym; u32 pspCode; } gDefaultBindings[] =
{ {
@@ -185,45 +184,23 @@ static const struct { WPARAM keysym; u32 pspCode; } gDefaultBindings[] =
{ VK_F3, PSP_CTRL_NOTE } { VK_F3, PSP_CTRL_NOTE }
}; };
static vector< pair<WPARAM, u32> > gKeyCodes; void JGECreateDefaultBindings()
void JGEControl()
{ {
gOldButtons = gButtons; for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
g_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode);
gButtons = 0;
for (vector< pair<WPARAM, u32> >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it)
if (g_keys[it->first])
gButtons |= it->second;
} }
int JGEGetTime()
BOOL JGEGetKeyState(int key)
{ {
return (g_keys[key]); return (int)GetTickCount();
} }
bool JGEGetButtonState(u32 button)
{
return (gButtons&button)==button;
}
bool JGEGetButtonClick(u32 button)
{
return (gButtons&button)==button && (gOldButtons&button)!=button;
}
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{ {
if (height==0) // Prevent A Divide By Zero By if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One height=1; // Making Height Equal One
}
actualWidth = width; actualWidth = width;
actualHeight = height; actualHeight = height;
@@ -327,15 +304,9 @@ int DrawGLScene(void) // Here's Where We Do All The Drawing
void Update(int dt) void Update(int dt)
{ {
JGEControl(); gPrevControllerState = gControllerState;
g_engine->SetDelta(dt); g_engine->SetDelta(dt);
g_engine->Update(dt);
//if (g_app)
// g_app->Update();
g_engine->Update();
} }
void KillGLWindow(void) // Properly Kill The Window void KillGLWindow(void) // Properly Kill The Window
@@ -351,14 +322,9 @@ void KillGLWindow(void) // Properly Kill The Window
if (hRC) // Do We Have A Rendering Context? if (hRC) // Do We Have A Rendering Context?
{ {
if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts? if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?
{
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC? if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC?
{
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
hRC=NULL; // Set RC To NULL hRC=NULL; // Set RC To NULL
} }
@@ -573,29 +539,6 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscree
return TRUE; // Success return TRUE; // Success
} }
u32 JGEReadKey()
{
if (gKeyBuffer.empty()) return 0;
pair<u32, u32> val = gKeyBuffer.front();
g_holds[val.first] = false;
gKeyBuffer.pop();
return val.second;
}
u32 JGEReadLocalKey()
{
if (gKeyBuffer.empty()) return 0;
u32 val = gKeyBuffer.front().first;
g_holds[val] = false;
gKeyBuffer.pop();
return val;
}
void JGEResetInput()
{
while (!gKeyBuffer.empty()) gKeyBuffer.pop();
}
LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
UINT uMsg, // Message For This Window UINT uMsg, // Message For This Window
WPARAM wParam, // Additional Message Information WPARAM wParam, // Additional Message Information
@@ -641,14 +584,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
case WM_KEYDOWN: // Update Keyboard Buffers For Keys Pressed case WM_KEYDOWN: // Update Keyboard Buffers For Keys Pressed
if ((wParam >= 0) && (wParam <= 255)) // Is Key (wParam) In A Valid Range? if ((wParam >= 0) && (wParam <= 255)) // Is Key (wParam) In A Valid Range?
{ {
g_keys[wParam] = true; // Set The Selected Key (wParam) To True g_engine->HoldKey_NoRepeat(wParam);
if (false == g_holds[wParam])
{
g_holds[wParam] = true;
for (vector< pair<WPARAM, u32> >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it)
if (it->first == wParam)
gKeyBuffer.push(*it);
}
return 0; return 0;
} }
break; // Break break; // Break
@@ -656,8 +592,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
case WM_KEYUP: // Update Keyboard Buffers For Keys Released case WM_KEYUP: // Update Keyboard Buffers For Keys Released
if ((wParam >= 0) && (wParam <= 255)) // Is Key (wParam) In A Valid Range? if ((wParam >= 0) && (wParam <= 255)) // Is Key (wParam) In A Valid Range?
{ {
g_keys[wParam] = FALSE; // Set The Selected Key (wParam) To False g_engine->ReleaseKey(wParam);
g_holds[wParam] = FALSE;
return 0; // Return return 0; // Return
} }
break; break;
@@ -721,8 +656,7 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance
u32 flags = g_launcher->GetInitFlags(); u32 flags = g_launcher->GetInitFlags();
for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i) JGECreateDefaultBindings();
gKeyCodes.push_back(make_pair(gDefaultBindings[i].keysym, gDefaultBindings[i].pspCode));
if ((flags&JINIT_FLAG_ENABLE3D)!=0) if ((flags&JINIT_FLAG_ENABLE3D)!=0)
JRenderer::Set3DFlag(true); JRenderer::Set3DFlag(true);
@@ -753,9 +687,7 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance
if (active) // Program Active? if (active) // Program Active?
{ {
if (g_engine->IsDone()) if (g_engine->IsDone())
{
done=TRUE; // ESC Signalled A Quit done=TRUE; // ESC Signalled A Quit
}
else // Not Time To Quit, Update Screen else // Not Time To Quit, Update Screen
{ {
tickCount = GetTickCount(); // Get The Tick Count tickCount = GetTickCount(); // Get The Tick Count
+4 -1
View File
@@ -2,7 +2,10 @@
#define _DUELLAYERS_H_ #define _DUELLAYERS_H_
#include "GuiLayers.h" #include "GuiLayers.h"
#include "CardSelector.h" #include "PlayGuiObject.h"
template <typename T> class ObjectSelector;
typedef ObjectSelector<PlayGuiObject> CardSelector;
class MTGGuiHand; class MTGGuiHand;
class MTGGuiPlay; class MTGGuiPlay;
+6 -1
View File
@@ -45,6 +45,7 @@ public:
ECON_DIFFICULTY, ECON_DIFFICULTY,
TRANSITIONS, TRANSITIONS,
INTERRUPT_SECONDS, INTERRUPT_SECONDS,
KEY_BINDINGS,
//My interrupts //My interrupts
INTERRUPTMYSPELLS, INTERRUPTMYSPELLS,
INTERRUPTMYABILITIES, INTERRUPTMYABILITIES,
@@ -80,7 +81,7 @@ public:
static string getName(int option); static string getName(int option);
private: private:
static const char* optionNames[]; static const string optionNames[];
}; };
class GameOption { class GameOption {
@@ -130,6 +131,10 @@ private:
bool viewed; //Flag it as "New!" or not. bool viewed; //Flag it as "New!" or not.
}; };
class GameOptionKeyBindings : public GameOption {
virtual bool read(string input);
};
class OptionVolume: public EnumDefinition{ class OptionVolume: public EnumDefinition{
public: public:
enum { MUTE = 0, MAX = 100 }; enum { MUTE = 0, MAX = 100 };
+2 -2
View File
@@ -58,7 +58,7 @@ class OptionSelect:public OptionItem{
virtual void Reload(){initSelections();}; virtual void Reload(){initSelections();};
virtual void Render(); virtual void Render();
virtual bool Selectable(); virtual bool Selectable();
virtual void Entering(u32 key); virtual void Entering(JButton key);
virtual bool Changed() {return (value != prior_value);}; virtual bool Changed() {return (value != prior_value);};
virtual void setData(); virtual void setData();
virtual void initSelections(); virtual void initSelections();
@@ -118,7 +118,7 @@ class OptionProfile:public OptionDirectory{
virtual void addSelection(string s); virtual void addSelection(string s);
virtual bool Selectable() {return canSelect;}; virtual bool Selectable() {return canSelect;};
virtual bool Changed() {return (initialValue != value);}; virtual bool Changed() {return (initialValue != value);};
virtual void Entering(u32 key); virtual void Entering(JButton key);
virtual void Reload(); virtual void Reload();
virtual void Render(); virtual void Render();
virtual void confirmChange(bool confirmed); virtual void confirmChange(bool confirmed);
+93
View File
@@ -0,0 +1,93 @@
#ifndef _SHOP_ITEM_H
#define _SHOP_ITEM_H
#include <JGui.h>
#include <JLBFont.h>
#include "SimpleMenu.h"
#include "MTGDeck.h"
#include "../include/PriceList.h"
#include "../include/PlayerData.h"
#include "../include/CardDisplay.h"
#include "../include/DeckDataWrapper.h"
#include <string>
using std::string;
class hgeDistortionMesh;
#define SHOP_BOOSTERS 3
class ShopItem:public JGuiObject{
private:
friend class ShopItems;
bool mHasFocus;
bool mRelease;
JLBFont *mFont;
string mText;
float xy[8];
JQuad * quad;
JQuad * thumb;
float mScale;
float mTargetScale;
hgeDistortionMesh* mesh;
void updateThumb();
public:
int nameCount;
int quantity;
MTGCard * card;
int price;
ShopItem(int id, JLBFont * font, int _cardid, float _xy[], bool hasFocus, MTGAllCards * collection, int _price, DeckDataWrapper * ddw);
ShopItem(int id, JLBFont * font, char* text, JQuad * _quad, JQuad * _thumb,float _xy[], bool hasFocus, int _price);
~ShopItem();
int updateCount(DeckDataWrapper * ddw);
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(JButton key);
virtual bool ButtonPressed();
const char * getText();
virtual ostream& toString(ostream& out) const;
};
class ShopItems:public JGuiController,public JGuiListener{
private:
PlayerData * playerdata;
PriceList * pricelist;
int mX, mY, mHeight;
JLBFont* mFont;
JTexture * mBgAATex;
JQuad * mBgAA;
MTGAllCards * collection;
SimpleMenu * dialog;
int showPriceDialog;
int setIds[SHOP_BOOSTERS];
MTGCardInstance * displayCards[100];
CardDisplay * display;
void safeDeleteDisplay();
DeckDataWrapper * myCollection;
int lightAlpha;
int alphaChange;
public:
bool showCardList;
ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int _setIds[]);
~ShopItems();
void Render();
virtual void Update(float dt);
void Add(int cardid);
void Add(char * text, JQuad * quad, JQuad * thumb,int _price);
void pricedialog(int id, int mode=1);
virtual void ButtonPressed(int controllerId, int controlId);
bool CheckUserInput(JButton key);
void savePriceList();
void saveAll();
static float _x1[],_y1[],_x2[],_y2[],_x3[],_y3[],_x4[],_y4[];
};
#endif
+26 -26
View File
@@ -46,8 +46,8 @@ public:
virtual PIXEL_TYPE getColor(int type); virtual PIXEL_TYPE getColor(int type);
virtual float getMargin(int type) {return 4;}; virtual float getMargin(int type) {return 4;};
virtual void Entering(u32 key)=0; virtual void Entering(JButton key)=0;
virtual bool Leaving(u32 key)=0; virtual bool Leaving(JButton key)=0;
virtual void Update(float dt)=0; virtual void Update(float dt)=0;
virtual void updateValue(){}; virtual void updateValue(){};
@@ -82,15 +82,15 @@ public:
virtual void renderBack(WGuiBase * it); virtual void renderBack(WGuiBase * it);
virtual void subBack(WGuiBase * item) {}; virtual void subBack(WGuiBase * item) {};
virtual bool CheckUserInput(u32 key) {return false;}; virtual bool CheckUserInput(JButton key) {return false;};
}; };
//This is our base class for concrete items. //This is our base class for concrete items.
class WGuiItem: public WGuiBase{ class WGuiItem: public WGuiBase{
public: public:
virtual void Entering(u32 key); virtual void Entering(JButton key);
virtual bool Leaving(u32 key); virtual bool Leaving(JButton key);
virtual bool CheckUserInput(u32 key); virtual bool CheckUserInput(JButton key);
virtual void Update(float dt) {}; virtual void Update(float dt) {};
virtual void Render(); virtual void Render();
@@ -177,8 +177,8 @@ public:
virtual bool Changed() {return it->Changed();}; virtual bool Changed() {return it->Changed();};
virtual void confirmChange(bool confirmed) {it->confirmChange(confirmed);}; virtual void confirmChange(bool confirmed) {it->confirmChange(confirmed);};
virtual void Entering(u32 key) {it->Entering(key);}; virtual void Entering(JButton key) {it->Entering(key);};
virtual bool Leaving(u32 key) {return it->Leaving(key);}; virtual bool Leaving(JButton key) {return it->Leaving(key);};
virtual void Update(float dt) {it->Update(dt);}; virtual void Update(float dt) {it->Update(dt);};
virtual void updateValue() {it->updateValue();}; virtual void updateValue() {it->updateValue();};
virtual void Reload() {it->Reload();}; virtual void Reload() {it->Reload();};
@@ -208,7 +208,7 @@ public:
virtual void setHeight(float _h) {it->setHeight(_h);}; virtual void setHeight(float _h) {it->setHeight(_h);};
virtual void setHidden(bool bHidden) {it->setHidden(bHidden);}; virtual void setHidden(bool bHidden) {it->setHidden(bHidden);};
virtual void setVisible(bool bVisisble) {it->setVisible(bVisisble);}; virtual void setVisible(bool bVisisble) {it->setVisible(bVisisble);};
virtual bool CheckUserInput(u32 key) {return it->CheckUserInput(key);}; virtual bool CheckUserInput(JButton key) {return it->CheckUserInput(key);};
protected: protected:
WGuiBase * it; WGuiBase * it;
}; };
@@ -251,9 +251,9 @@ public:
virtual void ButtonPressed(int controllerId, int controlId); virtual void ButtonPressed(int controllerId, int controlId);
virtual void confirmChange(bool confirmed); virtual void confirmChange(bool confirmed);
virtual void Entering(u32 key); virtual void Entering(JButton key);
virtual bool Leaving(u32 key); virtual bool Leaving(JButton key);
virtual bool CheckUserInput(u32 key); virtual bool CheckUserInput(JButton key);
bool bRight; bool bRight;
float percentRight; float percentRight;
@@ -269,12 +269,12 @@ public:
virtual bool isModal(); virtual bool isModal();
virtual void setData(); virtual void setData();
virtual void setModal(bool val); virtual void setModal(bool val);
virtual void Entering(u32 key); virtual void Entering(JButton key);
virtual bool Leaving(u32 key); virtual bool Leaving(JButton key);
virtual void Update(float dt); virtual void Update(float dt);
virtual void Overlay(); virtual void Overlay();
virtual void ButtonPressed(int controllerId, int controlId); virtual void ButtonPressed(int controllerId, int controlId);
virtual bool CheckUserInput(u32 key); virtual bool CheckUserInput(JButton key);
string confirm; string confirm;
string cancel; string cancel;
@@ -312,7 +312,7 @@ class WGuiButton: public WGuiDeco{
public: public:
WGuiButton( WGuiBase* _it, int _controller, int _control, JGuiListener * jgl); WGuiButton( WGuiBase* _it, int _controller, int _control, JGuiListener * jgl);
virtual void updateValue(); virtual void updateValue();
virtual bool CheckUserInput(u32 key); virtual bool CheckUserInput(JButton key);
virtual bool Selectable() {return Visible();}; virtual bool Selectable() {return Visible();};
virtual PIXEL_TYPE getColor(int type); virtual PIXEL_TYPE getColor(int type);
virtual int getControlID() {return control;}; virtual int getControlID() {return control;};
@@ -350,7 +350,7 @@ class WGuiMenu: public WGuiItem{
public: public:
friend class WGuiFilters; friend class WGuiFilters;
virtual ~WGuiMenu(); virtual ~WGuiMenu();
WGuiMenu(u32 next, u32 prev, bool mDPad = false, WSyncable * syncme=NULL); WGuiMenu(JButton next, JButton prev, bool mDPad = false, WSyncable * syncme=NULL);
virtual void Render(); virtual void Render();
virtual void Reload(); virtual void Reload();
@@ -358,10 +358,10 @@ public:
virtual void ButtonPressed(int controllerId, int controlId); virtual void ButtonPressed(int controllerId, int controlId);
virtual void Add(WGuiBase* item); //Remember, does not set X & Y of items automatically. virtual void Add(WGuiBase* item); //Remember, does not set X & Y of items automatically.
virtual void confirmChange(bool confirmed); virtual void confirmChange(bool confirmed);
virtual bool Leaving(u32 key); virtual bool Leaving(JButton key);
virtual void Entering(u32 key); virtual void Entering(JButton key);
virtual void subBack(WGuiBase * item); virtual void subBack(WGuiBase * item);
virtual bool CheckUserInput(u32 key); virtual bool CheckUserInput(JButton key);
WGuiBase * Current(); WGuiBase * Current();
virtual int getSelected() {return currentItem;}; virtual int getSelected() {return currentItem;};
virtual bool nextItem(); virtual bool nextItem();
@@ -373,12 +373,12 @@ public:
protected: protected:
virtual void syncMove(); virtual void syncMove();
virtual bool isButtonDir(u32 key, int dir); //For the DPad override. virtual bool isButtonDir(JButton key, int dir); //For the DPad override.
u32 buttonNext, buttonPrev; JButton buttonNext, buttonPrev;
bool mDPad; bool mDPad;
vector<WGuiBase*> items; vector<WGuiBase*> items;
int currentItem; int currentItem;
u32 held; JButton held;
WSyncable * sync; WSyncable * sync;
float duration; float duration;
}; };
@@ -399,7 +399,7 @@ protected:
}; };
class WGuiTabMenu: public WGuiMenu { class WGuiTabMenu: public WGuiMenu {
public: public:
WGuiTabMenu() : WGuiMenu(PSP_CTRL_RTRIGGER,PSP_CTRL_LTRIGGER) {}; WGuiTabMenu() : WGuiMenu(JGE_BTN_NEXT, JGE_BTN_PREV) {};
virtual void Render(); virtual void Render();
virtual void Add(WGuiBase * it); virtual void Add(WGuiBase * it);
void save(); void save();
@@ -415,11 +415,11 @@ public:
friend class WGuiFilterItem; friend class WGuiFilterItem;
WGuiFilters(string header, WSrcCards * src); WGuiFilters(string header, WSrcCards * src);
~WGuiFilters(); ~WGuiFilters();
bool CheckUserInput(u32 key); bool CheckUserInput(JButton key);
string getCode(); //For use in filter factory. string getCode(); //For use in filter factory.
void Update(float dt); void Update(float dt);
void Render(); void Render();
void Entering(u32 key); void Entering(JButton key);
void addColumn(); void addColumn();
bool isAvailable(int type); bool isAvailable(int type);
bool isAvailableCode(string code); bool isAvailableCode(string code);
+1 -1
View File
@@ -52,7 +52,7 @@ int ActionLayer::reactToTargetClick(ActionElement* ability, Targetable * card){
bool ActionLayer::CheckUserInput(u32 key){ bool ActionLayer::CheckUserInput(u32 key){
GameObserver * g = GameObserver::GetInstance(); GameObserver * g = GameObserver::GetInstance();
if (g->waitForExtraPayment && key == PSP_CTRL_CROSS){ if (g->waitForExtraPayment && key == JGE_BTN_SEC){
g->waitForExtraPayment = NULL; g->waitForExtraPayment = NULL;
return 1; return 1;
} }
+12 -12
View File
@@ -538,7 +538,7 @@ void ActionStack::Update(float dt){
for (int i = 0; i < mCount ; i++){ for (int i = 0; i < mCount ; i++){
Interruptible * current = (Interruptible *)mObjects[i]; Interruptible * current = (Interruptible *)mObjects[i];
if (tc->canTarget(current)){ if (tc->canTarget(current)){
if (mObjects[mCurr]) mObjects[mCurr]->Leaving(PSP_CTRL_UP); if (mObjects[mCurr]) mObjects[mCurr]->Leaving(JGE_BTN_UP);
current->display = 1; current->display = 1;
mCurr = i; mCurr = i;
mObjects[mCurr]->Entering(); mObjects[mCurr]->Entering();
@@ -621,32 +621,32 @@ void ActionStack::endOfInterruption(){
bool ActionStack::CheckUserInput(u32 key){ bool ActionStack::CheckUserInput(u32 key){
u32 trigger = (options[Options::REVERSETRIGGERS].number ? PSP_CTRL_RTRIGGER : PSP_CTRL_LTRIGGER); u32 trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_NEXT : JGE_BTN_PREV);
if (mode == ACTIONSTACK_STANDARD){ if (mode == ACTIONSTACK_STANDARD){
if (askIfWishesToInterrupt){ if (askIfWishesToInterrupt){
if (PSP_CTRL_CROSS == key){ if (JGE_BTN_SEC == key){
setIsInterrupting(askIfWishesToInterrupt); setIsInterrupting(askIfWishesToInterrupt);
return true; return true;
}else if ((PSP_CTRL_CIRCLE == key) || (trigger == key) ){ }else if ((JGE_BTN_OK == key) || (trigger == key) ){
cancelInterruptOffer(); cancelInterruptOffer();
return true; return true;
}else if ((PSP_CTRL_SQUARE == key)){ }else if ((JGE_BTN_PRI == key)){
cancelInterruptOffer(2); cancelInterruptOffer(2);
return true; return true;
} }
return true; return true;
}else if (game->isInterrupting){ }else if (game->isInterrupting){
if (PSP_CTRL_CROSS == key){ if (JGE_BTN_SEC == key){
endOfInterruption(); endOfInterruption();
return true; return true;
} }
} }
}else if (mode == ACTIONSTACK_TARGET){ }else if (mode == ACTIONSTACK_TARGET){
if (modal){ if (modal){
if (PSP_CTRL_UP == key){ if (JGE_BTN_UP == key){
if( mObjects[mCurr]){ if( mObjects[mCurr]){
int n = getPreviousIndex(((Interruptible *) mObjects[mCurr]), 0, 0, 1); int n = getPreviousIndex(((Interruptible *) mObjects[mCurr]), 0, 0, 1);
if (n != -1 && n != mCurr && mObjects[mCurr]->Leaving(PSP_CTRL_UP)){ if (n != -1 && n != mCurr && mObjects[mCurr]->Leaving(JGE_BTN_UP)){
mCurr = n; mCurr = n;
mObjects[mCurr]->Entering(); mObjects[mCurr]->Entering();
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
@@ -657,10 +657,10 @@ bool ActionStack::CheckUserInput(u32 key){
} }
} }
return true; return true;
}else if (PSP_CTRL_DOWN == key){ }else if (JGE_BTN_DOWN == key){
if( mObjects[mCurr]){ if( mObjects[mCurr]){
int n = getNextIndex(((Interruptible *) mObjects[mCurr]), 0, 0, 1); int n = getNextIndex(((Interruptible *) mObjects[mCurr]), 0, 0, 1);
if (n!= -1 && n != mCurr && mObjects[mCurr]->Leaving(PSP_CTRL_DOWN)){ if (n!= -1 && n != mCurr && mObjects[mCurr]->Leaving(JGE_BTN_DOWN)){
mCurr = n; mCurr = n;
mObjects[mCurr]->Entering(); mObjects[mCurr]->Entering();
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
@@ -671,7 +671,7 @@ bool ActionStack::CheckUserInput(u32 key){
} }
} }
return true; return true;
}else if (PSP_CTRL_CIRCLE == key){ }else if (JGE_BTN_OK == key){
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
char buf[4096]; char buf[4096];
sprintf(buf, "ACTIONSTACK CLIKED mCurr = %i\n", mCurr); sprintf(buf, "ACTIONSTACK CLIKED mCurr = %i\n", mCurr);
@@ -682,7 +682,7 @@ bool ActionStack::CheckUserInput(u32 key){
} }
return true; //Steal the input to other layers if we're visible return true; //Steal the input to other layers if we're visible
} }
if (PSP_CTRL_TRIANGLE == key){ if (JGE_BTN_CANCEL == key){
if (modal) modal = 0; else modal = 1; if (modal) modal = 0; else modal = 1;
return true; return true;
} }
+5 -5
View File
@@ -78,7 +78,7 @@ void CardDisplay::Update(float dt){
} }
bool CardDisplay::CheckUserInput(u32 key){ bool CardDisplay::CheckUserInput(u32 key){
if (PSP_CTRL_CROSS == key) if (JGE_BTN_SEC == key)
{ {
if (listener){ if (listener){
listener->ButtonPressed(mId, 0); listener->ButtonPressed(mId, 0);
@@ -108,7 +108,7 @@ bool CardDisplay::CheckUserInput(u32 key){
switch(key) switch(key)
{ {
case PSP_CTRL_LEFT : case JGE_BTN_LEFT :
{ {
int n = mCurr; int n = mCurr;
n--; n--;
@@ -116,13 +116,13 @@ bool CardDisplay::CheckUserInput(u32 key){
if (n< 0){n = 0;} if (n< 0){n = 0;}
else{ rotateLeft();} else{ rotateLeft();}
} }
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_LEFT)){ if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_LEFT)){
mCurr = n; mCurr = n;
mObjects[mCurr]->Entering(); mObjects[mCurr]->Entering();
} }
return true; return true;
} }
case PSP_CTRL_RIGHT : case JGE_BTN_RIGHT :
{ {
int n = mCurr; int n = mCurr;
n++; n++;
@@ -130,7 +130,7 @@ bool CardDisplay::CheckUserInput(u32 key){
if (n>= start_item + nb_displayed_items){ if (n>= start_item + nb_displayed_items){
rotateRight(); rotateRight();
} }
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_RIGHT)){ if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_RIGHT)){
mCurr = n; mCurr = n;
mObjects[mCurr]->Entering(); mObjects[mCurr]->Entering();
} }
+14 -13
View File
@@ -8,8 +8,9 @@
using std::cout; using std::cout;
#ifdef True
#undef True
#endif
struct Left : public Exp { static inline bool test(CardSelector::Target* ref, CardSelector::Target* test) struct Left : public Exp { static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
{ return ref->x - test->x > fabs(ref->y - test->y); } }; { return ref->x - test->x > fabs(ref->y - test->y); } };
@@ -119,26 +120,26 @@ bool CardSelector::CheckUserInput(u32 key)
Target* oldactive = active; Target* oldactive = active;
switch (key) switch (key)
{ {
case PSP_CTRL_CROSS: case JGE_BTN_SEC:
GameObserver::GetInstance()->cancelCurrentAction(); GameObserver::GetInstance()->cancelCurrentAction();
return true; return true;
case PSP_CTRL_CIRCLE: case JGE_BTN_OK:
GameObserver::GetInstance()->ButtonPressed(active); GameObserver::GetInstance()->ButtonPressed(active);
return true; return true;
break; break;
case PSP_CTRL_LEFT: case JGE_BTN_LEFT:
active = closest<Left>(cards, limitor, active); active = closest<Left>(cards, limitor, active);
break; break;
case PSP_CTRL_RIGHT: case JGE_BTN_RIGHT:
active = closest<Right>(cards, limitor, active); active = closest<Right>(cards, limitor, active);
break; break;
case PSP_CTRL_UP: case JGE_BTN_UP:
active = closest<Up>(cards, limitor, active); active = closest<Up>(cards, limitor, active);
break; break;
case PSP_CTRL_DOWN: case JGE_BTN_DOWN:
active = closest<Down>(cards, limitor, active); active = closest<Down>(cards, limitor, active);
break; break;
case PSP_CTRL_TRIANGLE: case JGE_BTN_CANCEL:
bigMode = (bigMode+1) % NB_BIG_MODES; bigMode = (bigMode+1) % NB_BIG_MODES;
if(bigMode == BIG_MODE_TEXT) if(bigMode == BIG_MODE_TEXT)
options[Options::DISABLECARDS].number = 1; options[Options::DISABLECARDS].number = 1;
@@ -160,10 +161,10 @@ bool CardSelector::CheckUserInput(u32 key)
if (PlayGuiObject* old = fetchMemory(lasts[owner])) if (PlayGuiObject* old = fetchMemory(lasts[owner]))
switch (key) switch (key)
{ {
case PSP_CTRL_LEFT: if (old->x < oldactive->x) active = old; break; case JGE_BTN_LEFT: if (old->x < oldactive->x) active = old; break;
case PSP_CTRL_RIGHT: if (old->x > oldactive->x) active = old; break; case JGE_BTN_RIGHT: if (old->x > oldactive->x) active = old; break;
case PSP_CTRL_UP: if (old->y < oldactive->y) active = old; break; case JGE_BTN_UP: if (old->y < oldactive->y) active = old; break;
case PSP_CTRL_DOWN: if (old->y > oldactive->y) active = old; break; case JGE_BTN_DOWN: if (old->y > oldactive->y) active = old; break;
default: if (old) active = old; break; default: if (old) active = old; break;
} }
} }
+5 -6
View File
@@ -248,22 +248,21 @@ void GameApp::Update()
{ {
if (systemError.size()) return; if (systemError.size()) return;
JGE* mEngine = JGE::GetInstance(); JGE* mEngine = JGE::GetInstance();
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonClick(PSP_CTRL_TRIANGLE)) if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonClick(JGE_BTN_CANCEL))
{ {
char s[80]; char s[80];
sprintf(s, "ms0:/psp/photo/MTG%d.png", mScreenShotCount++); sprintf(s, "ms0:/psp/photo/MTG%d.png", mScreenShotCount++);
JRenderer::GetInstance()->ScreenShot(s); JRenderer::GetInstance()->ScreenShot(s);
} }
//Exit when START and X ARE PRESSED SIMULTANEOUSLY //Exit when START and X ARE PRESSED SIMULTANEOUSLY
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonState(PSP_CTRL_CROSS)){ if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonState(JGE_BTN_SEC)){
mEngine->End(); mEngine->End();
return; return;
} }
//Restart Rendering engine when START and SQUARE ARE PRESSED SIMULTANEOUSLY //Restart Rendering engine when START and SQUARE ARE PRESSED SIMULTANEOUSLY
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonState(PSP_CTRL_SQUARE)){ if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonState(JGE_BTN_PRI))
JRenderer::Destroy(); JRenderer::Destroy();
}
float dt = mEngine->GetDelta(); float dt = mEngine->GetDelta();
if (dt > 35.0f) // min 30 FPS ;) if (dt > 35.0f) // min 30 FPS ;)
@@ -337,10 +336,10 @@ void GameApp::Render()
nbUpdates+=1; nbUpdates+=1;
JLBFont * mFont= resources.GetJLBFont("simon"); JLBFont * mFont= resources.GetJLBFont("simon");
char buf[512]; char buf[512];
sprintf(buf, "avg:%f - %f fps",totalFPS/nbUpdates, fps); sprintf(buf, "avg:%.02f - %.02f fps",totalFPS/nbUpdates, fps);
if (mFont) { if (mFont) {
mFont->SetColor(ARGB(255,255,255,255)); mFont->SetColor(ARGB(255,255,255,255));
mFont->DrawString(buf,1,1); mFont->DrawString(buf,1,10);
} }
#endif #endif
+48 -10
View File
@@ -5,12 +5,13 @@
#include "../include/Translate.h" #include "../include/Translate.h"
#include "../include/OptionItem.h" #include "../include/OptionItem.h"
#include <iostream> #include <iostream>
#include <sstream>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <stdlib.h> #include <stdlib.h>
#include <JGE.h> #include <JGE.h>
const char * Options::optionNames[] = { const string Options::optionNames[] = {
//Global options //Global options
"Profile", "Profile",
"Lang", "Lang",
@@ -31,6 +32,13 @@ const char * Options::optionNames[] = {
"economic_difficulty", "economic_difficulty",
"transitions", "transitions",
"interruptSeconds", "interruptSeconds",
#if defined(WIN32)
"keybindings_win",
#elsif defined(LINUX)
"keybindings_x",
#else
"keybindings_psp",
#endif
"interruptMySpells", "interruptMySpells",
"interruptMyAbilities", "interruptMyAbilities",
//General interrupts //General interrupts
@@ -57,8 +65,7 @@ const char * Options::optionNames[] = {
}; };
int Options::getID(string name){ int Options::getID(string name){
if(!name.size()) if (0 == name.size()) INVALID_OPTION;
INVALID_OPTION;
std::transform(name.begin(),name.end(),name.begin(),::tolower); std::transform(name.begin(),name.end(),name.begin(),::tolower);
@@ -335,9 +342,6 @@ GameOption& GameOptions::operator[](int optionID){
} }
GameOption * GameOptions::get(int optionID) { GameOption * GameOptions::get(int optionID) {
GameOption * go = NULL;
GameOptionEnum * goEnum = NULL;
//Invalid options! //Invalid options!
if(optionID < 0) if(optionID < 0)
return NULL; return NULL;
@@ -347,6 +351,8 @@ GameOption * GameOptions::get(int optionID) {
values.reserve(optionID); values.reserve(optionID);
while(x <= optionID){ while(x <= optionID){
GameOption * go = NULL;
GameOptionEnum * goEnum = NULL;
switch(x){ switch(x){
//Enum options //Enum options
case Options::HANDDIRECTION: case Options::HANDDIRECTION:
@@ -369,6 +375,9 @@ GameOption * GameOptions::get(int optionID) {
goEnum->def = OptionMaxGrade::getInstance(); goEnum->def = OptionMaxGrade::getInstance();
go = goEnum; go = goEnum;
break; break;
case Options::KEY_BINDINGS:
go = NEW GameOptionKeyBindings();
break;
case Options::ECON_DIFFICULTY: case Options::ECON_DIFFICULTY:
goEnum = NEW GameOptionEnum(); goEnum = NEW GameOptionEnum();
goEnum->def = OptionEconDifficulty::getInstance(); goEnum->def = OptionEconDifficulty::getInstance();
@@ -684,10 +693,7 @@ bool GameOptionEnum::write(std::ofstream * file, string name){
if(!file || !def || number <= 0 || number >= (int) def->values.size()) if(!file || !def || number <= 0 || number >= (int) def->values.size())
return false; return false;
char writer[1024]; (*file) << name << "=" << menuStr() << endl;
sprintf(writer,"%s=%s\n", name.c_str(), menuStr().c_str());
(*file)<<writer;
return true; return true;
} }
@@ -871,3 +877,35 @@ string GameOptionAward::menuStr(){
strftime(buf,255,_("%B %d, %I:%M%p %Y").c_str(),lt); strftime(buf,255,_("%B %d, %I:%M%p %Y").c_str(),lt);
return buf; return buf;
} }
static JButton u32_to_button(u32 b)
{
if (b < JGE_BTN_MAX) return static_cast<JButton>(b);
else return JGE_BTN_NONE;
}
bool GameOptionKeyBindings::read(string input){
istringstream iss(input);
vector< pair<LocalKeySym, JButton> > assoc;
while (iss.good())
{
stringstream s;
iss.get(*(s.rdbuf()), ',');
iss.get();
LocalKeySym local; char sep; u32 button;
s >> local >> sep >> button;
if (':' != sep) return false;
assoc.push_back(make_pair(local, u32_to_button(button)));
}
if (assoc.empty()) return false;
JGE* j = JGE::GetInstance();
j->ClearBindings();
for (vector< pair<LocalKeySym, JButton> >::const_iterator it = assoc.begin(); it != assoc.end(); ++it)
j->BindKey(it->first, it->second);
return true;
}
+10 -13
View File
@@ -110,7 +110,7 @@ void GameStateAwards::Start()
wgh->setDisplay(buf); wgh->setDisplay(buf);
wgh->mFlags = WGuiItem::NO_TRANSLATE; wgh->mFlags = WGuiItem::NO_TRANSLATE;
listview->Entering(0); listview->Entering(JGE_BTN_NONE);
detailview = NULL; detailview = NULL;
setSrc = NULL; setSrc = NULL;
showMenu = false; showMenu = false;
@@ -151,19 +151,18 @@ void GameStateAwards::Render()
void GameStateAwards::Update(float dt) void GameStateAwards::Update(float dt)
{ {
if(mEngine->GetButtonClick(PSP_CTRL_TRIANGLE)) if(mEngine->GetButtonClick(JGE_BTN_CANCEL))
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number; options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
if(showMenu){ if(showMenu){
menu->Update(dt); menu->Update(dt);
} }
else{ else{
u32 key; JButton key;
while ((key = JGE::GetInstance()->ReadButton())){ while ((key = JGE::GetInstance()->ReadButton())){
switch(key){ switch(key){
case PSP_CTRL_START: case JGE_BTN_MENU:
showMenu = true; showMenu = true;
SAFE_DELETE(menu); SAFE_DELETE(menu);
menu = NEW SimpleMenu(-102, this,Constants::MENU_FONT, 50,170); menu = NEW SimpleMenu(-102, this,Constants::MENU_FONT, 50,170);
if(mState == STATE_DETAILS) if(mState == STATE_DETAILS)
@@ -171,10 +170,10 @@ void GameStateAwards::Update(float dt)
menu->Add(1, "Back to Main Menu"); menu->Add(1, "Back to Main Menu");
menu->Add(3, "Cancel"); menu->Add(3, "Cancel");
break; break;
case PSP_CTRL_LTRIGGER: case JGE_BTN_PREV:
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU); mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
break; break;
case PSP_CTRL_CROSS: case JGE_BTN_SEC:
if(mState == STATE_LISTVIEW) if(mState == STATE_LISTVIEW)
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU); mParent->DoTransition(TRANSITION_FADE,GAME_STATE_MENU);
else{ else{
@@ -194,9 +193,7 @@ void GameStateAwards::Update(float dt)
break; break;
} }
} }
} }
if(setSrc) if(setSrc)
setSrc->Update(dt); setSrc->Update(dt);
} }
@@ -217,7 +214,7 @@ bool GameStateAwards::enterSet(int setid){
setSrc->bakeFilters(); setSrc->bakeFilters();
setSrc->Sort(WSrcCards::SORT_COLLECTOR); setSrc->Sort(WSrcCards::SORT_COLLECTOR);
detailview = NEW WGuiMenu(PSP_CTRL_DOWN,PSP_CTRL_UP); detailview = NEW WGuiMenu(JGE_BTN_DOWN, JGE_BTN_UP);
WGuiList * spoiler = NEW WGuiList("Spoiler",setSrc); WGuiList * spoiler = NEW WGuiList("Spoiler",setSrc);
spoiler->setX(210); spoiler->setX(210);
@@ -228,13 +225,13 @@ bool GameStateAwards::enterSet(int setid){
spoiler->Add(NEW WGuiItem(c->data->name)); spoiler->Add(NEW WGuiItem(c->data->name));
} }
setSrc->setOffset(0); setSrc->setOffset(0);
spoiler->Entering(0); spoiler->Entering(JGE_BTN_NONE);
WGuiCardImage * wi = NEW WGuiCardImage(setSrc); WGuiCardImage * wi = NEW WGuiCardImage(setSrc);
wi->setX(105); wi->setX(105);
wi->setY(137); wi->setY(137);
detailview->Add(wi); detailview->Add(wi);
detailview->Add(spoiler); detailview->Add(spoiler);
detailview->Entering(0); detailview->Entering(JGE_BTN_NONE);
return true; return true;
} }
bool GameStateAwards::enterStats(int option){ bool GameStateAwards::enterStats(int option){
@@ -248,7 +245,7 @@ bool GameStateAwards::enterStats(int option){
detailview = NEW WGuiList("Details"); detailview = NEW WGuiList("Details");
detailview->Add(NEW WGuiHeader("Collection Stats")); detailview->Add(NEW WGuiHeader("Collection Stats"));
detailview->Entering(0); detailview->Entering(JGE_BTN_NONE);
//Discover favorite set and unique cards //Discover favorite set and unique cards
int unique = 0; int unique = 0;
+33 -42
View File
@@ -280,43 +280,43 @@ void GameStateDeckViewer::Update(float dt)
if (mStage == STAGE_WAITING || mStage == STAGE_ONSCREEN_MENU){ if (mStage == STAGE_WAITING || mStage == STAGE_ONSCREEN_MENU){
switch (mEngine->ReadButton()) switch (mEngine->ReadButton())
{ {
case PSP_CTRL_LEFT : case JGE_BTN_LEFT :
last_user_activity = 0; last_user_activity = 0;
mStage = STAGE_TRANSITION_LEFT; mStage = STAGE_TRANSITION_LEFT;
break; break;
case PSP_CTRL_RIGHT : case JGE_BTN_RIGHT :
last_user_activity = 0; last_user_activity = 0;
mStage = STAGE_TRANSITION_RIGHT; mStage = STAGE_TRANSITION_RIGHT;
break; break;
case PSP_CTRL_UP : case JGE_BTN_UP :
last_user_activity = 0; last_user_activity = 0;
mStage = STAGE_TRANSITION_UP; mStage = STAGE_TRANSITION_UP;
useFilter[myD]++; useFilter[myD]++;
if(useFilter[myD] >= MAX_SAVED_FILTERS) if(useFilter[myD] >= MAX_SAVED_FILTERS)
useFilter[myD] = 0; useFilter[myD] = 0;
break; break;
case PSP_CTRL_DOWN : case JGE_BTN_DOWN :
last_user_activity = 0; last_user_activity = 0;
mStage = STAGE_TRANSITION_DOWN; mStage = STAGE_TRANSITION_DOWN;
useFilter[myD]--; useFilter[myD]--;
if(useFilter[myD] < 0) if(useFilter[myD] < 0)
useFilter[myD] = MAX_SAVED_FILTERS-1; useFilter[myD] = MAX_SAVED_FILTERS-1;
break; break;
case PSP_CTRL_TRIANGLE: case JGE_BTN_CANCEL:
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number; options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
break; break;
case PSP_CTRL_SQUARE : case JGE_BTN_PRI :
if (last_user_activity > 0.2) if (last_user_activity > 0.2)
{ {
last_user_activity = 0; last_user_activity = 0;
switchDisplay(); switchDisplay();
} }
break; break;
case PSP_CTRL_CIRCLE : case JGE_BTN_OK :
last_user_activity = 0; last_user_activity = 0;
addRemove(cardIndex[2]); addRemove(cardIndex[2]);
break; break;
case PSP_CTRL_CROSS : case JGE_BTN_SEC :
last_user_activity = 0; last_user_activity = 0;
SAFE_DELETE(sellMenu); SAFE_DELETE(sellMenu);
char buffer[4096]; char buffer[4096];
@@ -332,7 +332,7 @@ void GameStateDeckViewer::Update(float dt)
} }
stw.needUpdate = true; stw.needUpdate = true;
break; break;
/*case PSP_CTRL_SQUARE : /*case JGE_BTN_PRI :
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY){ if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY){
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1; last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
}else{ }else{
@@ -340,36 +340,32 @@ void GameStateDeckViewer::Update(float dt)
mStage = STAGE_WAITING; mStage = STAGE_WAITING;
} }
break;*/ break;*/
case PSP_CTRL_START : case JGE_BTN_MENU :
mStage = STAGE_MENU; mStage = STAGE_MENU;
break; break;
case PSP_CTRL_SELECT : case JGE_BTN_CTRL :
mStage = STAGE_FILTERS; mStage = STAGE_FILTERS;
if (displayed_deck == myDeck) { if (displayed_deck == myDeck) {
if (!filterDeck) if (!filterDeck)
filterDeck = NEW WGuiFilters("Filter by...",myDeck); filterDeck = NEW WGuiFilters("Filter by...",myDeck);
filterDeck->Entering(0); filterDeck->Entering(JGE_BTN_NONE);
} else if(displayed_deck == myCollection) { } else if(displayed_deck == myCollection) {
if (!filterCollection) if (!filterCollection)
filterCollection = NEW WGuiFilters("Filter by...",myCollection); filterCollection = NEW WGuiFilters("Filter by...",myCollection);
filterCollection->Entering(0); filterCollection->Entering(JGE_BTN_NONE);
} }
break; break;
case PSP_CTRL_LTRIGGER : case JGE_BTN_PREV :
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY){ if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY)
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1; last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
} else if ((mStage == STAGE_ONSCREEN_MENU) && (--stw.currentPage < 0))
else if ((mStage == STAGE_ONSCREEN_MENU) && (--stw.currentPage < 0)) {
stw.currentPage = stw.pageCount; stw.currentPage = stw.pageCount;
}
break; break;
case PSP_CTRL_RTRIGGER : case JGE_BTN_NEXT :
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY){ if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY)
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1; last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
} else if ((mStage == STAGE_ONSCREEN_MENU) && (++stw.currentPage > stw.pageCount))
else if ((mStage == STAGE_ONSCREEN_MENU) && (++stw.currentPage > stw.pageCount)) {
stw.currentPage = 0; stw.currentPage = 0;
}
break; break;
default : // no keypress default : // no keypress
if (last_user_activity > NO_USER_ACTIVITY_HELP_DELAY){ if (last_user_activity > NO_USER_ACTIVITY_HELP_DELAY){
@@ -377,16 +373,14 @@ void GameStateDeckViewer::Update(float dt)
mStage = STAGE_ONSCREEN_MENU; mStage = STAGE_ONSCREEN_MENU;
onScreenTransition = 1; onScreenTransition = 1;
} else { } else {
if (onScreenTransition >0){ if (onScreenTransition >0)
onScreenTransition-= 0.05f; onScreenTransition-= 0.05f;
}else{ else
onScreenTransition = 0; onScreenTransition = 0;
} }
} } else
}else{
last_user_activity+= dt; last_user_activity+= dt;
} }
}
} if (mStage == STAGE_TRANSITION_RIGHT || mStage == STAGE_TRANSITION_LEFT) { } if (mStage == STAGE_TRANSITION_RIGHT || mStage == STAGE_TRANSITION_LEFT) {
if (mStage == STAGE_TRANSITION_RIGHT){ if (mStage == STAGE_TRANSITION_RIGHT){
@@ -434,16 +428,16 @@ void GameStateDeckViewer::Update(float dt)
} }
}else if (mStage == STAGE_WELCOME){ } else if (mStage == STAGE_WELCOME)
welcome_menu->Update(dt); welcome_menu->Update(dt);
}else if (mStage == STAGE_MENU){ else if (mStage == STAGE_MENU)
menu->Update(dt); menu->Update(dt);
}else if(mStage == STAGE_FILTERS){ else if(mStage == STAGE_FILTERS){
u32 key = mEngine->ReadButton(); JButton key = mEngine->ReadButton();
if (displayed_deck == myDeck) { if (displayed_deck == myDeck) {
if (filterDeck) { if (filterDeck) {
if(key == PSP_CTRL_SELECT){ if (key == JGE_BTN_CTRL) {
useFilter[(displayed_deck == myDeck)] = 0; useFilter[(displayed_deck == myDeck)] = 0;
filterDeck->Finish(); filterDeck->Finish();
filterDeck->Update(dt); filterDeck->Update(dt);
@@ -460,7 +454,7 @@ void GameStateDeckViewer::Update(float dt)
} }
} else { } else {
if (filterCollection) { if (filterCollection) {
if(key == PSP_CTRL_SELECT){ if (key == JGE_BTN_CTRL) {
useFilter[(displayed_deck == myDeck)] = 0; useFilter[(displayed_deck == myDeck)] = 0;
filterCollection->Finish(); filterCollection->Finish();
filterCollection->Update(dt); filterCollection->Update(dt);
@@ -1550,11 +1544,11 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
if(displayed_deck == myDeck){ if(displayed_deck == myDeck){
if(!filterDeck) if(!filterDeck)
filterDeck = NEW WGuiFilters("Filter by...",myDeck); filterDeck = NEW WGuiFilters("Filter by...",myDeck);
filterDeck->Entering(0); filterDeck->Entering(JGE_BTN_NONE);
}else if(displayed_deck == myCollection){ }else if(displayed_deck == myCollection){
if(!filterCollection) if(!filterCollection)
filterCollection = NEW WGuiFilters("Filter by...",myCollection); filterCollection = NEW WGuiFilters("Filter by...",myCollection);
filterCollection->Entering(0); filterCollection->Entering(JGE_BTN_NONE);
} }
break; break;
} }
@@ -1584,18 +1578,15 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
// n cards total, a of them are of desired type (A), x drawn // n cards total, a of them are of desired type (A), x drawn
// returns probability of no A's // returns probability of no A's
float noLuck(int n, int a, int x) { float noLuck(int n, int a, int x) {
if ( (a >= n) || (a == 0)) { if ((a >= n) || (a == 0))
return 1; return 1;
} if ((n == 0) || (x == 0) || (x > n) || (n-a < x))
if ((n == 0) || (x == 0) || (x > n) || (n-a < x)) {
return 0; return 0;
}
a = n - a; a = n - a;
float result = 1; float result = 1;
for (int i=0; i<x; i++) { for (int i=0; i<x; i++)
result *= (float)(a-i)/(n-i); result *= (float)(a-i)/(n-i);
}
return result; return result;
} }
+8 -12
View File
@@ -218,7 +218,7 @@ void GameStateDuel::Update(float dt)
switch (mGamePhase) switch (mGamePhase)
{ {
case DUEL_STATE_ERROR_NO_DECK: case DUEL_STATE_ERROR_NO_DECK:
if (PSP_CTRL_CIRCLE == mEngine->ReadButton()) if (JGE_BTN_OK == mEngine->ReadButton())
mParent->SetNextState(GAME_STATE_DECK_VIEWER); mParent->SetNextState(GAME_STATE_DECK_VIEWER);
break; break;
case DUEL_STATE_CHOOSE_DECK1: case DUEL_STATE_CHOOSE_DECK1:
@@ -344,9 +344,8 @@ void GameStateDuel::Update(float dt)
loadTestSuitePlayers(); loadTestSuitePlayers();
mGamePhase = DUEL_STATE_PLAY; mGamePhase = DUEL_STATE_PLAY;
testSuite->initGame(); testSuite->initGame();
}else{ }else
mGamePhase = DUEL_STATE_END; mGamePhase = DUEL_STATE_END;
}
}else }else
#endif #endif
if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU){ if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU){
@@ -354,9 +353,8 @@ void GameStateDuel::Update(float dt)
Start(); Start();
} }
} }
if (mEngine->GetButtonClick(PSP_CTRL_START)){ if (mEngine->GetButtonClick(JGE_BTN_MENU))
mGamePhase = DUEL_STATE_MENU; mGamePhase = DUEL_STATE_MENU;
}
break; break;
case DUEL_STATE_MENU: case DUEL_STATE_MENU:
menu->Update(dt); menu->Update(dt);
@@ -380,11 +378,10 @@ void GameStateDuel::Update(float dt)
} }
break; break;
default: default:
if (PSP_CTRL_CIRCLE == mEngine->ReadButton()){ if (JGE_BTN_OK == mEngine->ReadButton())
mParent->SetNextState(GAME_STATE_MENU); mParent->SetNextState(GAME_STATE_MENU);
} }
} }
}
void GameStateDuel::Render() void GameStateDuel::Render()
@@ -439,15 +436,14 @@ void GameStateDuel::Render()
case DUEL_STATE_CHOOSE_DECK1_TO_2: case DUEL_STATE_CHOOSE_DECK1_TO_2:
case DUEL_STATE_CHOOSE_DECK2: case DUEL_STATE_CHOOSE_DECK2:
case DUEL_STATE_CHOOSE_DECK2_TO_PLAY: case DUEL_STATE_CHOOSE_DECK2_TO_PLAY:
if (mParent->gameType != GAME_TYPE_CLASSIC){ if (mParent->gameType != GAME_TYPE_CLASSIC)
mFont->DrawString(_("LOADING DECKS").c_str(),0,SCREEN_HEIGHT/2); mFont->DrawString(_("LOADING DECKS").c_str(),0,SCREEN_HEIGHT/2);
}else{ else{
if (opponentMenu){ if (opponentMenu)
opponentMenu->Render(); opponentMenu->Render();
}else if (deckmenu){ else if (deckmenu)
deckmenu->Render(); deckmenu->Render();
} }
}
break; break;
case DUEL_STATE_ERROR_NO_DECK: case DUEL_STATE_ERROR_NO_DECK:
mFont->DrawString(_("NO DECK AVAILABLE,").c_str(),0,SCREEN_HEIGHT/2); mFont->DrawString(_("NO DECK AVAILABLE,").c_str(),0,SCREEN_HEIGHT/2);
+4 -4
View File
@@ -431,7 +431,7 @@ void GameStateMenu::Update(float dt)
} }
if (mGuiController) if (mGuiController)
mGuiController->Update(dt); mGuiController->Update(dt);
if(mEngine->GetButtonState(PSP_CTRL_RTRIGGER)) //Hook for GameStateAward state if(mEngine->GetButtonState(JGE_BTN_NEXT)) //Hook for GameStateAward state
mParent->DoTransition(TRANSITION_FADE,GAME_STATE_AWARDS); //TODO: A slide transition would be nice. mParent->DoTransition(TRANSITION_FADE,GAME_STATE_AWARDS); //TODO: A slide transition would be nice.
break; break;
case MENU_STATE_MAJOR_SUBMENU : case MENU_STATE_MAJOR_SUBMENU :
@@ -472,7 +472,7 @@ void GameStateMenu::Update(float dt)
;// Nothing to do. ;// Nothing to do.
} }
if(mEngine->GetButtonState(PSP_CTRL_LTRIGGER)) { if(mEngine->GetButtonState(JGE_BTN_PREV)) {
//Reset deck of cards //Reset deck of cards
angleMultiplier = MIN_ANGLE_MULTIPLIER; angleMultiplier = MIN_ANGLE_MULTIPLIER;
yW = 55; yW = 55;
@@ -480,12 +480,12 @@ void GameStateMenu::Update(float dt)
if (yW <= 55) if (yW <= 55)
{ {
if (mEngine->GetButtonState(PSP_CTRL_SQUARE)) angleMultiplier += STEP_ANGLE_MULTIPLIER; if (mEngine->GetButtonState(JGE_BTN_PRI)) angleMultiplier += STEP_ANGLE_MULTIPLIER;
else angleMultiplier *= 0.9999; else angleMultiplier *= 0.9999;
if (angleMultiplier > MAX_ANGLE_MULTIPLIER) angleMultiplier = MAX_ANGLE_MULTIPLIER; if (angleMultiplier > MAX_ANGLE_MULTIPLIER) angleMultiplier = MAX_ANGLE_MULTIPLIER;
else if (angleMultiplier < MIN_ANGLE_MULTIPLIER) angleMultiplier = MIN_ANGLE_MULTIPLIER; else if (angleMultiplier < MIN_ANGLE_MULTIPLIER) angleMultiplier = MIN_ANGLE_MULTIPLIER;
if (mEngine->GetButtonState(PSP_CTRL_TRIANGLE) && (dt != 0)) if (mEngine->GetButtonState(JGE_BTN_CANCEL) && (dt != 0))
{ {
angleMultiplier = (cos(timeIndex)*angleMultiplier - M_PI/3 - 0.1 - angleW) / dt; angleMultiplier = (cos(timeIndex)*angleMultiplier - M_PI/3 - 0.1 - angleW) / dt;
yW = yW + 5*dt + (yW - 45) *5* dt; yW = yW + 5*dt + (yW - 45) *5* dt;
+6 -3
View File
@@ -80,6 +80,9 @@ void GameStateOptions::Start()
optionsList->Add(oGra); optionsList->Add(oGra);
optionsTabs->Add(optionsList); optionsTabs->Add(optionsList);
optionsList = NEW WGuiList("Key Bindings");
optionsTabs->Add(optionsList);
optionsList = NEW WGuiList("Credits"); optionsList = NEW WGuiList("Credits");
optionsList->failMsg = ""; optionsList->failMsg = "";
optionsTabs->Add(optionsList); optionsTabs->Add(optionsList);
@@ -89,7 +92,7 @@ void GameStateOptions::Start()
optionsMenu->Add(1, "Save & Back to Main Menu"); optionsMenu->Add(1, "Save & Back to Main Menu");
optionsMenu->Add(3, "Cancel"); optionsMenu->Add(3, "Cancel");
optionsTabs->Entering(0); optionsTabs->Entering(JGE_BTN_NONE);
} }
@@ -121,10 +124,10 @@ void GameStateOptions::Update(float dt)
else switch(mState){ else switch(mState){
default: default:
case SHOW_OPTIONS: case SHOW_OPTIONS:
u32 key; JButton key;
while ((key = JGE::GetInstance()->ReadButton())){ while ((key = JGE::GetInstance()->ReadButton())){
if(!optionsTabs->CheckUserInput(key) && key == PSP_CTRL_START) if(!optionsTabs->CheckUserInput(key) && key == JGE_BTN_MENU)
mState = SHOW_OPTIONS_MENU; mState = SHOW_OPTIONS_MENU;
} }
optionsTabs->Update(dt); optionsTabs->Update(dt);
+18 -19
View File
@@ -71,7 +71,7 @@ void GameStateShop::Start(){
srcCards->setElapsed(15); srcCards->setElapsed(15);
bigSync = 0; bigSync = 0;
shopMenu = NEW WGuiMenu(PSP_CTRL_DOWN,PSP_CTRL_UP,true,&bigSync); shopMenu = NEW WGuiMenu(JGE_BTN_DOWN, JGE_BTN_UP, true, &bigSync);
MTGAllCards * ac = GameApp::collection; MTGAllCards * ac = GameApp::collection;
playerdata = NEW PlayerData(ac);; playerdata = NEW PlayerData(ac);;
myCollection = NEW DeckDataWrapper(playerdata->collection); myCollection = NEW DeckDataWrapper(playerdata->collection);
@@ -87,7 +87,7 @@ void GameStateShop::Start(){
dist->xy = WDistort(_x1[i],_y1[i],_x2[i],_y2[i],_x3[i],_y3[i],_x4[i],_y4[i]); dist->xy = WDistort(_x1[i],_y1[i],_x2[i],_y2[i],_x3[i],_y3[i],_x4[i],_y4[i]);
shopMenu->Add(NEW WGuiButton(dist,-102,i,this)); shopMenu->Add(NEW WGuiButton(dist,-102,i,this));
} }
shopMenu->Entering(0); shopMenu->Entering(JGE_BTN_NONE);
if(!bigDisplay){ if(!bigDisplay){
bigDisplay = NEW WGuiCardImage(srcCards); bigDisplay = NEW WGuiCardImage(srcCards);
@@ -337,7 +337,7 @@ void GameStateShop::beginFilters(){
filterMenu->setHeight(SCREEN_HEIGHT-2); filterMenu->setHeight(SCREEN_HEIGHT-2);
} }
mStage = STAGE_ASK_ABOUT; mStage = STAGE_ASK_ABOUT;
filterMenu->Entering(0); filterMenu->Entering(JGE_BTN_NONE);
} }
void GameStateShop::Update(float dt) void GameStateShop::Update(float dt)
{ {
@@ -353,7 +353,7 @@ void GameStateShop::Update(float dt)
if (mStage != STAGE_FADE_IN) if (mStage != STAGE_FADE_IN)
mElapsed += dt; mElapsed += dt;
u32 btn; JButton btn;
switch(mStage){ switch(mStage){
case STAGE_SHOP_PURCHASE: case STAGE_SHOP_PURCHASE:
if (menu) if (menu)
@@ -362,9 +362,9 @@ void GameStateShop::Update(float dt)
mStage = STAGE_SHOP_SHOP; mStage = STAGE_SHOP_SHOP;
break; break;
case STAGE_SHOP_MENU: case STAGE_SHOP_MENU:
if (menu){ if (menu)
menu->Update(dt); menu->Update(dt);
}else{ else{
menu = NEW SimpleMenu(11,this,Constants::MENU_FONT,SCREEN_WIDTH/2-100,20); menu = NEW SimpleMenu(11,this,Constants::MENU_FONT,SCREEN_WIDTH/2-100,20);
menu->Add(22,"Ask about..."); menu->Add(22,"Ask about...");
menu->Add(14,"Check task board"); menu->Add(14,"Check task board");
@@ -383,10 +383,10 @@ void GameStateShop::Update(float dt)
btn = mEngine->ReadButton(); btn = mEngine->ReadButton();
taskList->Update(dt); taskList->Update(dt);
if ( taskList->getState() != TaskList::TASKS_INACTIVE){ if ( taskList->getState() != TaskList::TASKS_INACTIVE){
if( btn == PSP_CTRL_CROSS || btn == PSP_CTRL_TRIANGLE ){ if ( btn == JGE_BTN_SEC || btn == JGE_BTN_CANCEL ){
taskList->End(); taskList->End();
return; return;
}else if(taskList->getState() == TaskList::TASKS_ACTIVE && btn == PSP_CTRL_START ){ } else if (taskList->getState() == TaskList::TASKS_ACTIVE && btn == JGE_BTN_MENU){
if (!menu) { if (!menu) {
menu = NEW SimpleMenu(11,this,Constants::MENU_FONT,SCREEN_WIDTH/2-100,20); menu = NEW SimpleMenu(11,this,Constants::MENU_FONT,SCREEN_WIDTH/2-100,20);
menu->Add(15,"Return to shop"); menu->Add(15,"Return to shop");
@@ -400,7 +400,7 @@ void GameStateShop::Update(float dt)
} }
#ifdef TESTSUITE #ifdef TESTSUITE
if ((mEngine->GetButtonClick(PSP_CTRL_SQUARE)) && (taskList)) { if ((mEngine->GetButtonClick(JGE_BTN_PRI)) && (taskList)) {
taskList->passOneDay(); taskList->passOneDay();
if (taskList->getTaskCount() < 6) { if (taskList->getTaskCount() < 6) {
taskList->addRandomTask(); taskList->addRandomTask();
@@ -418,7 +418,7 @@ void GameStateShop::Update(float dt)
return; return;
} }
if (filterMenu){ if (filterMenu){
if(btn == PSP_CTRL_SELECT){ if (btn == JGE_BTN_CTRL) {
needLoad = filterMenu->Finish(); needLoad = filterMenu->Finish();
filterMenu->Update(dt); filterMenu->Update(dt);
return; return;
@@ -441,34 +441,33 @@ void GameStateShop::Update(float dt)
menu->Update(dt); menu->Update(dt);
return; return;
} }
if (btn == PSP_CTRL_START){ if (btn == JGE_BTN_MENU){
if (boosterDisplay){ if (boosterDisplay){
deleteDisplay(); deleteDisplay();
return; return;
} }
mStage = STAGE_SHOP_MENU; mStage = STAGE_SHOP_MENU;
return; return;
}else if(btn == PSP_CTRL_SELECT){ } else if (btn == JGE_BTN_CTRL)
beginFilters(); beginFilters();
}else if(btn == PSP_CTRL_SQUARE){ else if (btn == JGE_BTN_PRI) {
srcCards->Shuffle(); srcCards->Shuffle();
load(); load();
}else if(btn == PSP_CTRL_TRIANGLE){ } else if (btn == JGE_BTN_CANCEL)
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number; options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
}else if (boosterDisplay){ else if (boosterDisplay){
if(btn == PSP_CTRL_CROSS) if (btn == JGE_BTN_SEC)
deleteDisplay(); deleteDisplay();
else { else {
boosterDisplay->CheckUserInput(btn); boosterDisplay->CheckUserInput(btn);
boosterDisplay->Update(dt);} boosterDisplay->Update(dt);}
return; return;
}else if(btn == PSP_CTRL_CROSS){ }else if (btn == JGE_BTN_SEC)
bListCards = !bListCards; bListCards = !bListCards;
}else if(shopMenu){ else if (shopMenu){
if (shopMenu->CheckUserInput(btn)) if (shopMenu->CheckUserInput(btn))
srcCards->Touch(); srcCards->Touch();
} }
if (shopMenu) if (shopMenu)
shopMenu->Update(dt); shopMenu->Update(dt);
+9 -9
View File
@@ -143,7 +143,7 @@ bool GuiCombat::CheckUserInput(u32 key)
DamagerDamaged* oldActive = active; DamagerDamaged* oldActive = active;
switch (key) switch (key)
{ {
case PSP_CTRL_CIRCLE: case JGE_BTN_OK:
if (BLK == cursor_pos) if (BLK == cursor_pos)
{ {
if (ORDER == step) go->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); } if (ORDER == step) go->cardClick(active->card); // { activeAtk->card->raiseBlockerRankOrder(active->card); }
@@ -173,7 +173,7 @@ bool GuiCombat::CheckUserInput(u32 key)
clickOK(); clickOK();
} }
break; break;
case PSP_CTRL_TRIANGLE: case JGE_BTN_CANCEL:
if (BLK == cursor_pos) if (BLK == cursor_pos)
{ {
oldActive->zoom = 2.2; oldActive->zoom = 2.2;
@@ -181,7 +181,7 @@ bool GuiCombat::CheckUserInput(u32 key)
cursor_pos = ATK; cursor_pos = ATK;
} }
return true; return true;
case PSP_CTRL_LEFT: case JGE_BTN_LEFT:
switch (cursor_pos) switch (cursor_pos)
{ {
case NONE : break; case NONE : break;
@@ -206,7 +206,7 @@ bool GuiCombat::CheckUserInput(u32 key)
break; break;
} }
break; break;
case PSP_CTRL_RIGHT: case JGE_BTN_RIGHT:
switch (cursor_pos) switch (cursor_pos)
{ {
case NONE : case NONE :
@@ -232,22 +232,22 @@ bool GuiCombat::CheckUserInput(u32 key)
break; break;
} }
break; break;
case PSP_CTRL_DOWN: case JGE_BTN_DOWN:
if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0) break; if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0) break;
removeOne(active, step); removeOne(active, step);
break; break;
case PSP_CTRL_UP: case JGE_BTN_UP:
if (ORDER == step || BLK != cursor_pos) break; if (ORDER == step || BLK != cursor_pos) break;
addOne(active, step); addOne(active, step);
break; break;
case PSP_CTRL_SQUARE: case JGE_BTN_PRI:
active = activeAtk = NULL; cursor_pos = OK; active = activeAtk = NULL; cursor_pos = OK;
break; break;
case PSP_CTRL_RTRIGGER: case JGE_BTN_NEXT:
if (!options[Options::REVERSETRIGGERS].number) return false; if (!options[Options::REVERSETRIGGERS].number) return false;
active = activeAtk = NULL; cursor_pos = OK; active = activeAtk = NULL; cursor_pos = OK;
break; break;
case PSP_CTRL_LTRIGGER: case JGE_BTN_PREV:
if (options[Options::REVERSETRIGGERS].number) return false; if (options[Options::REVERSETRIGGERS].number) return false;
active = activeAtk = NULL; cursor_pos = OK; active = activeAtk = NULL; cursor_pos = OK;
break; break;
+1 -1
View File
@@ -139,7 +139,7 @@ void GuiHandSelf::Repos()
bool GuiHandSelf::CheckUserInput(u32 key) bool GuiHandSelf::CheckUserInput(u32 key)
{ {
u32 trigger = (options[Options::REVERSETRIGGERS].number ? PSP_CTRL_LTRIGGER : PSP_CTRL_RTRIGGER); u32 trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_PREV : JGE_BTN_NEXT);
if (trigger == key) if (trigger == key)
{ {
state = (Open == state ? Closed : Open); state = (Open == state ? Closed : Open);
+2 -3
View File
@@ -7,7 +7,7 @@ GuiLayer::GuiLayer(){
hasFocus = false; hasFocus = false;
mCount = 0; mCount = 0;
mCurr = 0; mCurr = 0;
mActionButton = PSP_CTRL_CIRCLE; mActionButton = JGE_BTN_OK;
} }
GuiLayer::~GuiLayer(){ GuiLayer::~GuiLayer(){
@@ -20,7 +20,7 @@ void GuiLayer::Add(JGuiObject *object){
} }
int GuiLayer::Remove(JGuiObject *object){ int GuiLayer::Remove(JGuiObject *object){
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++)
if (mObjects[i]==object){ if (mObjects[i]==object){
delete mObjects[i]; delete mObjects[i];
mObjects.erase(mObjects.begin()+i); mObjects.erase(mObjects.begin()+i);
@@ -29,7 +29,6 @@ int GuiLayer::Remove(JGuiObject *object){
mCurr = 0; mCurr = 0;
return 1; return 1;
} }
}
return 0; return 0;
} }
+1 -1
View File
@@ -33,7 +33,7 @@ void MTGGamePhase::Update(float dt){
bool MTGGamePhase::CheckUserInput(u32 key){ bool MTGGamePhase::CheckUserInput(u32 key){
GameObserver * game = GameObserver::GetInstance(); GameObserver * game = GameObserver::GetInstance();
if (activeState == INACTIVE){ if (activeState == INACTIVE){
u32 trigger = (options[Options::REVERSETRIGGERS].number ? PSP_CTRL_RTRIGGER : PSP_CTRL_LTRIGGER); u32 trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_NEXT : JGE_BTN_PREV);
if ((trigger == key) && game->currentActionPlayer == game->currentlyActing()) if ((trigger == key) && game->currentActionPlayer == game->currentlyActing())
{ {
activeState = ACTIVE; activeState = ACTIVE;
+1 -1
View File
@@ -9,7 +9,7 @@
#include "../include/WFilter.h" #include "../include/WFilter.h"
#include "../include/DeckDataWrapper.h" #include "../include/DeckDataWrapper.h"
#include "../include/MTGPack.h" #include "../include/MTGPack.h"
#include "../../../JGE/src/TinyXML/tinyxml.h" #include "../../../JGE/src/tinyxml/tinyxml.h"
int MTGPackEntryRandom::addCard(WSrcCards *pool, MTGDeck *to){ int MTGPackEntryRandom::addCard(WSrcCards *pool, MTGDeck *to){
int fails = 0; int fails = 0;
+1 -1
View File
@@ -140,7 +140,7 @@ int MTGAttackRule::reactToClick(MTGCardInstance * card){
if(!card->isAttacker()){ if(!card->isAttacker()){
CardSelector * cs = game->mLayers->cs; CardSelector * cs = game->mLayers->cs;
cs->Limit(this,CardSelector::playZone); cs->Limit(this,CardSelector::playZone);
cs->CheckUserInput(PSP_CTRL_RIGHT); cs->CheckUserInput(JGE_BTN_RIGHT);
cs->Limit(NULL,CardSelector::playZone); cs->Limit(NULL,CardSelector::playZone);
} }
card->toggleAttacker(); card->toggleAttacker();
+2 -2
View File
@@ -61,7 +61,7 @@ void OptionSelect::initSelections(){
} }
} }
void OptionSelect::Entering(u32 key){ void OptionSelect::Entering(JButton key){
OptionItem::Entering(key); OptionItem::Entering(key);
prior_value = value; prior_value = value;
} }
@@ -187,7 +187,7 @@ void OptionProfile::Render(){
mFont->SetScale(1); mFont->SetScale(1);
} }
void OptionProfile::Entering(u32 key){ void OptionProfile::Entering(JButton key){
mFocus = true; mFocus = true;
initialValue = value; initialValue = value;
} }
+553
View File
@@ -0,0 +1,553 @@
#include "../include/config.h"
#include "../include/ShopItem.h"
#include "../include/GameStateShop.h"
#include "../include/CardGui.h"
#include "../include/WResourceManager.h"
#include "../include/Translate.h"
#include <hge/hgedistort.h>
float ShopItems::_x1[] = { 79, 19, 27,103,154,187,102,144,198,133,183};
float ShopItems::_y1[] = {150,194,222,167,164,156,195,190,175,220,220};
float ShopItems::_x2[] = {103, 48, 74,135,183,215,138,181,231,171,225};
float ShopItems::_y2[] = {155,179,218,165,166,155,195,186,177,225,216};
float ShopItems::_x3[] = { 48, 61, 9, 96,139,190, 81,146,187, 97,191};
float ShopItems::_y3[] = {164,205,257,184,180,170,219,212,195,251,252};
float ShopItems::_x4[] = { 76, 90, 65,131,171,221,123,187,225,141,237};
float ShopItems::_y4[] = {169,188,250,182,182,168,220,208,198,259,245};
ShopItem::ShopItem(int id, JLBFont *font, char* text, JQuad * _quad,JQuad * _thumb, float _xy[], bool hasFocus, int _price): JGuiObject(id), mFont(font), mText(text), quad(_quad), thumb(_thumb), price(_price)
{
for (int i = 0; i < 8; ++i){
xy[i] = _xy[i];
}
quantity = 10;
card = NULL;
mHasFocus = hasFocus;
mRelease = false;
mScale = 1.0f;
mTargetScale = 1.0f;
mesh=NEW hgeDistortionMesh(2,2);
mesh->SetTexture(thumb->mTex);
float x0,y0,w0,h0;
thumb->GetTextureRect(&x0,&y0,&w0,&h0);
mesh->SetTextureRect(x0,y0,w0,h0);
mesh->Clear(ARGB(0xFF,0xFF,0xFF,0xFF));
mesh->SetDisplacement(0, 0, xy[0],xy[1], HGEDISP_NODE);
mesh->SetDisplacement(1, 0, xy[2] - w0,xy[3], HGEDISP_NODE);
mesh->SetDisplacement(0, 1,xy[4],xy[5]-h0, HGEDISP_NODE);
mesh->SetDisplacement(1, 1, xy[6]-w0,xy[7]-h0, HGEDISP_NODE);
mesh->SetColor(1,1,ARGB(255,100,100,100));
mesh->SetColor(0,1,ARGB(255,100,100,100));
mesh->SetColor(1,0,ARGB(255,100,100,100));
mesh->SetColor(0,0,ARGB(255,200,200,200));
if (hasFocus)
Entering();
}
ShopItem::ShopItem(int id, JLBFont *font, int _cardid, float _xy[], bool hasFocus, MTGAllCards * collection, int _price, DeckDataWrapper * ddw): JGuiObject(id), mFont(font), price(_price){
for (int i = 0; i < 8; ++i){
xy[i] = _xy[i];
}
mHasFocus = hasFocus;
mRelease = false;
mScale = 1.0f;
mTargetScale = 1.0f;
if (hasFocus)
Entering();
card = collection->getCardById(_cardid);
updateCount(ddw);
quantity = 1 + (rand() % 4);
if (card->getRarity() == Constants::RARITY_L) quantity = 50;
quad = NULL;
mesh = NULL;
thumb = NULL;
updateThumb();
}
int ShopItem::updateCount(DeckDataWrapper * ddw){
if (!card) return 0;
nameCount = ddw->countByName(card);
return nameCount;
}
ShopItem::~ShopItem(){
OutputDebugString("delete shopitem\n");
if(thumb)
resources.Release(thumb->mTex);
SAFE_DELETE(mesh);
}
const char * ShopItem::getText(){
return mText.c_str();
}
void ShopItem::updateThumb(){
if(card == NULL)
return;
if(thumb && mRelease)
resources.Release(thumb->mTex);
mRelease = false;
if(mesh)
SAFE_DELETE(mesh);
else if(thumb)
SAFE_DELETE(thumb);
thumb = resources.RetrieveCard(card,RETRIEVE_LOCK,TEXTURE_SUB_THUMB);
#if defined (WIN32) || defined (LINUX)
//On pcs we render the big image if the thumbnail is not available
if (!thumb) thumb = resources.RetrieveCard(card,RETRIEVE_LOCK);
#endif
if (!thumb)
thumb = CardGui::alternateThumbQuad(card);
else
mRelease = true;
if (thumb){
mesh=NEW hgeDistortionMesh(2,2);
mesh->SetTexture(thumb->mTex);
float x0,y0,w0,h0;
thumb->GetTextureRect(&x0,&y0,&w0,&h0);
mesh->SetTextureRect(x0,y0,w0,h0);
mesh->Clear(ARGB(0xFF,0xFF,0xFF,0xFF));
mesh->SetDisplacement(0, 0, xy[0],xy[1], HGEDISP_NODE);
mesh->SetDisplacement(1, 0, xy[2] - w0,xy[3], HGEDISP_NODE);
mesh->SetDisplacement(0, 1,xy[4],xy[5]-h0, HGEDISP_NODE);
mesh->SetDisplacement(1, 1, xy[6]-w0,xy[7]-h0, HGEDISP_NODE);
mesh->SetColor(1,1,ARGB(255,100,100,100));
mesh->SetColor(0,1,ARGB(255,100,100,100));
mesh->SetColor(1,0,ARGB(255,100,100,100));
mesh->SetColor(0,0,ARGB(255,200,200,200));
}else{
mesh = NULL;
}
}
void ShopItem::Render(){
if (mHasFocus){
mFont->SetColor(ARGB(255,255,255,0));
}else{
mFont->SetColor(ARGB(255,255,255,255));
}
if (!quantity){
mFont->SetColor(ARGB(255,128,128,128));
}
if (card){
if (nameCount){
char buffer[512];
sprintf(buffer, "%s (%i)", _(card->data->name).c_str(), nameCount );
mText = buffer;
}else{
mText = _(card->data->name).c_str();
}
}
JRenderer * renderer = JRenderer::GetInstance();
if (mesh){
mesh->Render(0,0);
}else{
//ERROR Management
}
if (mHasFocus){
if (card) quad = resources.RetrieveCard(card);
if (quad){
float scale = 0.9 * 285/ quad->mHeight;
quad->SetColor(ARGB(255,255,255,255));
renderer->RenderQuad(quad,SCREEN_WIDTH - 105,SCREEN_HEIGHT/2 - 5,0, scale,scale);
}else{
if (card) CardGui::alternateRender(card,Pos(SCREEN_WIDTH - 105,SCREEN_HEIGHT/2 - 5,0.9f* 285/250, 0,255));
}
}
}
void ShopItem::Update(float dt)
{
if (mScale < mTargetScale){
mScale += 8.0f*dt;
if (mScale > mTargetScale)
mScale = mTargetScale;
}else if (mScale > mTargetScale){
mScale -= 8.0f*dt;
if (mScale < mTargetScale)
mScale = mTargetScale;
}
}
void ShopItem::Entering()
{
for (int i = 0; i < 2; ++i){
for (int j = 0; j < 2; ++j){
mesh->SetColor(i,j,ARGB(255,255,255,255));
}
}
mHasFocus = true;
mTargetScale = 1.2f;
}
bool ShopItem::Leaving(JButton key)
{
mesh->SetColor(1,1,ARGB(255,100,100,100));
mesh->SetColor(0,1,ARGB(255,100,100,100));
mesh->SetColor(1,0,ARGB(255,100,100,100));
mesh->SetColor(0,0,ARGB(255,200,200,200));
mHasFocus = false;
mTargetScale = 1.0f;
return true;
}
bool ShopItem::ButtonPressed()
{
return (quantity >0);
}
ShopItems::ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int _setIds[]): JGuiController(id, listener), mX(x), mY(y), mFont(font), collection(_collection){
mHeight = 0;
showPriceDialog = -1;
dialog = NULL;
pricelist = NEW PriceList(RESPATH"/settings/prices.dat",_collection);
playerdata = NEW PlayerData(_collection);
display = NULL;
for (int i=0; i < SHOP_BOOSTERS; i++){
setIds[i] = _setIds[i];
};
myCollection = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), _collection));
showCardList = true;
mBgAA = NULL;
mBgAATex = resources.RetrieveTexture("shop_aliasing.png",RETRIEVE_LOCK);
if(mBgAATex){
mBgAA = resources.RetrieveQuad("shop_aliasing.png");
mBgAA->SetTextureRect(0,1,250,119);
}
lightAlpha = 0;
alphaChange = 0;
}
void ShopItems::Add(int cardid){
int rnd = (rand() % 20);
int price = pricelist->getPrice(cardid);
price = price + price * (rnd -10)/100;
float xy[] = {_x1[mCount],_y1[mCount],_x2[mCount],_y2[mCount],_x3[mCount],_y3[mCount],_x4[mCount],_y4[mCount]};
JGuiController::Add(NEW ShopItem(mCount, mFont, cardid, xy, (mCount == 0),collection, price,myCollection));
mHeight += 22;
}
void ShopItems::Add(char * text, JQuad * quad,JQuad * thumb, int price){
float xy[] = {_x1[mCount],_y1[mCount],_x2[mCount],_y2[mCount],_x3[mCount],_y3[mCount],_x4[mCount],_y4[mCount]};
JGuiController::Add(NEW ShopItem(mCount, mFont, text, quad, thumb, xy, (mCount == 0), price));
mHeight += 22;
}
void ShopItems::Update(float dt){
if (display){
display->Update(dt);
}else{
if (showPriceDialog!=-1){
ShopItem * item = ((ShopItem *)mObjects[showPriceDialog]);
int price = item->price;
char buffer[4096];
sprintf(buffer,"%s : %i credits",item->getText(),price);
if(!dialog){
dialog = NEW SimpleMenu(1,this,Constants::MENU_FONT,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer);
dialog->Add(1,"Yes");
dialog->Add(2,"No");
if(options[Options::CHEATMODE].number) {
dialog->Add(3,"*Steal 1,000 credits*");
}
}
else{
dialog->Update(dt);
}
}else{
SAFE_DELETE(dialog);
JGuiController::Update(dt);
}
}
alphaChange = (500 - (rand() % 1000)) * dt;
lightAlpha+= alphaChange;
if (lightAlpha < 0) lightAlpha = 0;
if (lightAlpha > 50) lightAlpha = 50;
}
void ShopItems::Render(){
JGuiController::Render();
JRenderer * r = JRenderer::GetInstance();
if (mBgAA)
r->RenderQuad(mBgAA,0,SCREEN_HEIGHT-127);
JQuad * quad = resources.RetrieveTempQuad("shop_light.jpg",TEXTURE_SUB_5551);
if (quad){
r->EnableTextureFilter(false);
r->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
quad->SetColor(ARGB(lightAlpha,255,255,255));
r->RenderQuad(quad,0,0);
r->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
r->EnableTextureFilter(true);
}
if (display) display->Render();
if (showPriceDialog!=-1){
if(dialog){
dialog->Render();
}
}
mFont->SetColor(ARGB(255,255,255,255));
char c[4096];
r->FillRect(0,SCREEN_HEIGHT-17,SCREEN_WIDTH,17,ARGB(128,0,0,0));
sprintf(c, "%s", _("[]:other cards").c_str());
unsigned int len = 4 + mFont->GetStringWidth(c);
mFont->DrawString(c,SCREEN_WIDTH-len,SCREEN_HEIGHT-14);
char credits[512];
sprintf(credits,_("credits: %i").c_str(), playerdata->credits);
mFont->SetColor(ARGB(200,0,0,0));
mFont->DrawString(credits, 5, SCREEN_HEIGHT - 12);
mFont->SetColor(ARGB(255,255,255,255));
mFont->DrawString(credits, 5, SCREEN_HEIGHT - 14);
if(mCurr >= 0){
mFont->SetColor(ARGB(255,255,255,0));
ShopItem * item = ((ShopItem *)mObjects[mCurr]);
mFont->DrawString(item->mText.c_str(), SCREEN_WIDTH/2 - 50, SCREEN_HEIGHT - 14,JGETEXT_CENTER);
mFont->SetColor(ARGB(255,255,255,255));
}
if (showCardList){
r->FillRoundRect(290,5, 160, mCount * 20 + 15,5,ARGB(200,0,0,0));
for (int i = 0; i< mCount; ++i){
if (!mObjects[i]) continue;
ShopItem * s = (ShopItem *)(mObjects[i]);
if (i == mCurr) mFont->SetColor(ARGB(255,255,255,0));
else mFont->SetColor(ARGB(255,255,255,255));
char buffer[512];
sprintf(buffer, "%s", s->getText());
float x = 300;
float y = 10 + 20*i;
mFont->DrawString(buffer,x,y);
}
}
}
void ShopItems::pricedialog(int id, int mode){
if (mode){
showPriceDialog = id;
}else{
showPriceDialog = -1;
}
}
void ShopItems::ButtonPressed(int controllerId, int controlId){
if (controllerId == 12){
safeDeleteDisplay();
return;
}
ShopItem * item = ((ShopItem *)mObjects[showPriceDialog]);
int price = item->price;
switch(controlId){
case 1:
if (playerdata->credits >= price){
playerdata->credits -= price;
if (item->card){
int rnd = (rand() % 25);
price = price + (rnd * price)/100;
pricelist->setPrice(item->card->getMTGId(),price);
playerdata->collection->add(item->card);
item->quantity--;
myCollection->Add(item->card);
item->nameCount++;
item->price = price;
}else{
safeDeleteDisplay();
display = NEW CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5);
MTGDeck * tempDeck = NEW MTGDeck(playerdata->collection->database);
int rare_or_mythic = Constants::RARITY_R;
int rnd = rand() % 8;
if (rnd == 0) rare_or_mythic = Constants::RARITY_M;
int sets[] = {setIds[showPriceDialog]};
MTGSetInfo* si = setlist.getInfo(setIds[showPriceDialog]);
tempDeck->addRandomCards(si->booster[MTGSetInfo::RARE], sets,1,rare_or_mythic);
tempDeck->addRandomCards(si->booster[MTGSetInfo::UNCOMMON], sets,1,Constants::RARITY_U);
tempDeck->addRandomCards(si->booster[MTGSetInfo::COMMON], sets,1,Constants::RARITY_C);
tempDeck->addRandomCards(si->booster[MTGSetInfo::LAND], sets,1,Constants::RARITY_L);
//Check for duplicates. Does not guarentee none, just makes them extremely unlikely.
//Code is kind of inefficient, but shouldn't be used often enough to matter.
int loops=0;
for(map<int,int>::iterator it = tempDeck->cards.begin();it!= tempDeck->cards.end() && loops < 15;it++,loops++){
int dupes = it->second - 1;
if(dupes <= 0)
continue;
for(int x=0;x<dupes;x++)
tempDeck->remove(it->first);
int rarity = (int) tempDeck->database->getCardById(it->first)->getRarity();
tempDeck->addRandomCards(dupes,sets,1,rarity);
it = tempDeck->cards.begin();
}
playerdata->collection->add(tempDeck);
myCollection->Add(tempDeck);
for (int j = 0; j < mCount; j++){
ShopItem * si = ((ShopItem *)mObjects[j]);
si->updateCount(myCollection);
}
int i = 0;
for(int cycle=0;cycle<4;cycle++)
for (map<int,int>::iterator it = tempDeck->cards.begin(); it!=tempDeck->cards.end(); it++){
MTGCard * c = tempDeck->getCardById(it->first);
char rarity = c->getRarity();
if((cycle == 0 && rarity == Constants::RARITY_L)
|| (cycle == 1 && rarity == Constants::RARITY_C)
|| (cycle == 2 && rarity == Constants::RARITY_U)
|| (cycle == 3 && (rarity == Constants::RARITY_R || rarity == Constants::RARITY_M)))
for (int j = 0; j < it->second; j++){
MTGCardInstance * card = NEW MTGCardInstance(c, NULL);
displayCards[i] = card;
display->AddCard(card);
i++;
}
}
delete tempDeck;
}
//Check if we just scored an award...
if(myCollection && myCollection->totalPrice() > 10000){
GameOptionAward * goa = dynamic_cast<GameOptionAward *>(&options[Options::AWARD_COLLECTOR]);
if(goa)
goa->giveAward();
}
showPriceDialog = -1;
}else{
//error not enough money
}
break;
case 2:
if (item->card){
int rnd = (rand() % 25);
price = price - (rnd * price)/100;
pricelist->setPrice(item->card->getMTGId(),price);
}
showPriceDialog = -1;
break;
case 3: // (PSY) Cheatmode: get free money
playerdata->credits += 1000;
break;
}
}
void ShopItems::safeDeleteDisplay(){
if (!display) return;
for (int i = 0; i < display->mCount; i++){
delete displayCards[i];
}
SAFE_DELETE(display);
}
void ShopItems::saveAll(){
savePriceList();
playerdata->save();
}
void ShopItems::savePriceList(){
pricelist->save();
}
ShopItems::~ShopItems(){
SAFE_DELETE(pricelist);
SAFE_DELETE(playerdata);
SAFE_DELETE(dialog);
safeDeleteDisplay();
SAFE_DELETE(myCollection);
resources.Release(mBgAATex);
}
ostream& ShopItem::toString(ostream& out) const
{
return out << "ShopItem ::: mHasFocus : " << mHasFocus
<< " ; mFont : " << mFont
<< " ; mText : " << mText
<< " ; quad : " << quad
<< " ; thumb : " << thumb
<< " ; mScale : " << mScale
<< " ; mTargetScale : " << mTargetScale
<< " ; nameCount : " << nameCount
<< " ; quantity : " << quantity
<< " ; card : " << card
<< " ; price : " << price;
}
bool ShopItems::CheckUserInput(JButton key){
if (display && display->CheckUserInput(key))
return true;
if (showPriceDialog == -1) {
JButton buttons[] = {JGE_BTN_LEFT, JGE_BTN_DOWN, JGE_BTN_RIGHT, JGE_BTN_UP, JGE_BTN_OK};
for (int i = 0; i < 5; ++i)
if (key == buttons[i])
showCardList = false;
if (key == JGE_BTN_CANCEL) {
options[Options::DISABLECARDS].number = !options[Options::DISABLECARDS].number;
vector<JGuiObject*>::iterator it;
for(it=mObjects.begin();it!=mObjects.end();it++){
ShopItem * si = dynamic_cast<ShopItem*>(*it);
if(si)
si->updateThumb();
}
return true;
}
if (key == JGE_BTN_SEC){
showCardList = !showCardList;
return true;
}
}
else if(dialog)
return dialog->CheckUserInput(key);
return JGuiController::CheckUserInput(key);
}
+1 -1
View File
@@ -168,7 +168,7 @@ void SimpleMenu::Add(int id, const char * text,string desc, bool forceFocus){
JGuiController::Add(smi); JGuiController::Add(smi);
if (mCount <= maxItems) mHeight += LINE_HEIGHT; if (mCount <= maxItems) mHeight += LINE_HEIGHT;
if (forceFocus){ if (forceFocus){
mObjects[mCurr]->Leaving(PSP_CTRL_DOWN); mObjects[mCurr]->Leaving(JGE_BTN_DOWN);
mCurr = mCount-1; mCurr = mCount-1;
smi->Entering(); smi->Entering();
} }
+19 -29
View File
@@ -188,9 +188,8 @@ void SimplePad::MoveSelection(unsigned char moveto)
if (selected < KPD_MAX && selected >= 0) if (selected < KPD_MAX && selected >= 0)
priorKey = selected; priorKey = selected;
if(moveto < KPD_MAX) { if (moveto < KPD_MAX)
selected = moveto; selected = moveto;
}
else if (moveto == KPD_INPUT) else if (moveto == KPD_INPUT)
selected = KPD_INPUT; selected = KPD_INPUT;
} }
@@ -200,60 +199,51 @@ void SimplePad::Update(float dt){
u32 key = mEngine->ReadButton(); u32 key = mEngine->ReadButton();
//Start button changes capslock setting. //Start button changes capslock setting.
if(key & PSP_CTRL_START) if (key == JGE_BTN_MENU)
{ {
if (selected != KPD_OK) if (selected != KPD_OK)
selected = KPD_OK; selected = KPD_OK;
else else
Finish(); Finish();
} }
else if(key & PSP_CTRL_SELECT){ else if (key == JGE_BTN_CTRL)
bCapslock = !bCapslock; bCapslock = !bCapslock;
}
if (selected == KPD_SPACE){ if (selected == KPD_SPACE){
if(bShowCancel && mEngine->GetButtonClick(PSP_CTRL_RIGHT)) if (bShowCancel && mEngine->GetButtonClick(JGE_BTN_RIGHT))
selected = KPD_CANCEL; selected = KPD_CANCEL;
else if (key & PSP_CTRL_LEFT || key & PSP_CTRL_RIGHT else if (key == JGE_BTN_LEFT || key == JGE_BTN_RIGHT
|| key & PSP_CTRL_UP || key & PSP_CTRL_DOWN) || key == JGE_BTN_UP || key == JGE_BTN_DOWN)
selected = priorKey; selected = priorKey;
} //Moving within/from the text field. } //Moving within/from the text field.
else if (selected == KPD_INPUT){ else if (selected == KPD_INPUT){
if (key & PSP_CTRL_DOWN ) if (key == JGE_BTN_DOWN )
selected = priorKey; selected = priorKey;
if (key & PSP_CTRL_LEFT){ if (key == JGE_BTN_LEFT && cursor > 0) cursor--;
if(cursor > 0) else if (key == JGE_BTN_RIGHT && cursor < buffer.size()) cursor++;
cursor--;
}
else if (key & PSP_CTRL_RIGHT){
if(cursor < buffer.size())
cursor++;
}
} }
else if (selected >= 0 && keys[selected]){ else if (selected >= 0 && keys[selected]){
if (key & PSP_CTRL_LEFT) if (key == JGE_BTN_LEFT)
MoveSelection(keys[selected]->adjacency[KPD_LEFT]); MoveSelection(keys[selected]->adjacency[KPD_LEFT]);
else if (key & PSP_CTRL_RIGHT) else if (key == JGE_BTN_RIGHT)
MoveSelection(keys[selected]->adjacency[KPD_RIGHT]); MoveSelection(keys[selected]->adjacency[KPD_RIGHT]);
if (key & PSP_CTRL_DOWN) if (key == JGE_BTN_DOWN)
MoveSelection(keys[selected]->adjacency[KPD_DOWN]); MoveSelection(keys[selected]->adjacency[KPD_DOWN]);
else if (key & PSP_CTRL_UP) else if (key == JGE_BTN_UP)
MoveSelection(keys[selected]->adjacency[KPD_UP]); MoveSelection(keys[selected]->adjacency[KPD_UP]);
} }
//These bits require a valid key... //These bits require a valid key...
if(selected >= 0 && selected < nbitems && keys[selected]){ if (selected >= 0 && selected < nbitems && keys[selected])
if (key & PSP_CTRL_CIRCLE) if (key == JGE_BTN_OK)
pressKey(keys[selected]->id); pressKey(keys[selected]->id);
} if (buffer.size() > 0 && key == JGE_BTN_SEC)
if (buffer.size() > 0 && key & PSP_CTRL_CROSS)
buffer = buffer.substr(0, buffer.size() - 1); buffer = buffer.substr(0, buffer.size() - 1);
if (buffer.size() && key & PSP_CTRL_LTRIGGER){ if (buffer.size() && key == JGE_BTN_PREV) {
if(cursor > 0) if (cursor > 0) cursor--;
cursor--;
} }
else if (key & PSP_CTRL_RTRIGGER){ else if (key == JGE_BTN_NEXT) {
if (cursor < buffer.size()) if (cursor < buffer.size())
cursor++; cursor++;
else { else {
+46 -45
View File
@@ -40,7 +40,7 @@ void WGuiBase::renderBack(WGuiBase * it){
//WGuiItem //WGuiItem
void WGuiItem::Entering(u32 key){ void WGuiItem::Entering(JButton key){
mFocus = true; mFocus = true;
} }
float WGuiItem::minWidth(){ float WGuiItem::minWidth(){
@@ -52,7 +52,7 @@ float WGuiItem::minHeight(){
return mFont->GetHeight(); return mFont->GetHeight();
} }
bool WGuiItem::Leaving(u32 key){ bool WGuiItem::Leaving(JButton key){
mFocus = false; mFocus = false;
return true; return true;
} }
@@ -90,8 +90,8 @@ string WGuiItem::_(string input){
return input; return input;
return ::_(input); return ::_(input);
} }
bool WGuiItem::CheckUserInput(u32 key){ bool WGuiItem::CheckUserInput(JButton key){
if(mFocus && key == PSP_CTRL_CIRCLE){ if(mFocus && key == JGE_BTN_OK){
updateValue(); updateValue();
return true; return true;
} }
@@ -149,7 +149,7 @@ void WGuiHeader::Render(){
} }
bool WGuiMenu::Leaving(u32 key){ bool WGuiMenu::Leaving(JButton key){
int nbitems = (int) items.size(); int nbitems = (int) items.size();
if(key == buttonNext && currentItem < nbitems-1) if(key == buttonNext && currentItem < nbitems-1)
return false; return false;
@@ -163,7 +163,7 @@ bool WGuiMenu::Leaving(u32 key){
mFocus = false; mFocus = false;
return true; return true;
} }
void WGuiMenu::Entering(u32 key){ void WGuiMenu::Entering(JButton key){
mFocus = true; mFocus = true;
//Try to force a selectable option. //Try to force a selectable option.
@@ -198,7 +198,7 @@ void WGuiMenu::subBack(WGuiBase * item){
} }
//WGuiList //WGuiList
WGuiList::WGuiList(string name, WSyncable * syncme): WGuiMenu(PSP_CTRL_DOWN,PSP_CTRL_UP,false,syncme){ WGuiList::WGuiList(string name, WSyncable * syncme): WGuiMenu(JGE_BTN_DOWN, JGE_BTN_UP, false, syncme){
failMsg = "NO OPTIONS AVAILABLE"; failMsg = "NO OPTIONS AVAILABLE";
width = SCREEN_WIDTH-10; width = SCREEN_WIDTH-10;
height = SCREEN_HEIGHT-10; height = SCREEN_HEIGHT-10;
@@ -237,7 +237,7 @@ void WGuiList::Render(){
if(items[i]->Selectable()) { if(items[i]->Selectable()) {
currentItem = i; currentItem = i;
if(hasFocus()) if(hasFocus())
items[currentItem]->Entering(0); items[currentItem]->Entering(JGE_BTN_NONE);
break; break;
} }
} }
@@ -405,7 +405,7 @@ WDecoConfirm::~WDecoConfirm(){
SAFE_DELETE(confirmMenu); SAFE_DELETE(confirmMenu);
} }
void WDecoConfirm::Entering(u32 key){ void WDecoConfirm::Entering(JButton key){
setFocus(true); setFocus(true);
if(it) if(it)
@@ -435,7 +435,7 @@ void WDecoConfirm::setData(){
it->setData(); it->setData();
} }
bool WDecoConfirm::Leaving(u32 key){ bool WDecoConfirm::Leaving(JButton key){
if(!it) if(!it)
return true; return true;
@@ -458,9 +458,9 @@ bool WDecoConfirm::Leaving(u32 key){
return false; return false;
} }
bool WDecoConfirm::CheckUserInput(u32 key){ bool WDecoConfirm::CheckUserInput(JButton key){
if(hasFocus()){ if(hasFocus()){
if (mState == OP_CONFIRMED && key == PSP_CTRL_CIRCLE) if (mState == OP_CONFIRMED && key == JGE_BTN_OK)
mState = OP_UNCONFIRMED; mState = OP_UNCONFIRMED;
if (mState != OP_CONFIRMING && it){ if (mState != OP_CONFIRMING && it){
@@ -520,8 +520,8 @@ void WGuiButton::updateValue(){
mListener->ButtonPressed(controller, control); mListener->ButtonPressed(controller, control);
} }
bool WGuiButton::CheckUserInput(u32 key){ bool WGuiButton::CheckUserInput(JButton key){
if (hasFocus() && key == PSP_CTRL_CIRCLE){ if (hasFocus() && key == JGE_BTN_OK){
updateValue(); updateValue();
return true; return true;
} }
@@ -605,15 +605,15 @@ void WGuiSplit::setModal(bool val){
return left->setModal(val); return left->setModal(val);
} }
bool WGuiSplit::CheckUserInput(u32 key){ bool WGuiSplit::CheckUserInput(JButton key){
if(hasFocus()){ if(hasFocus()){
if (!bRight){ if (!bRight){
if(left->CheckUserInput(key)) if(left->CheckUserInput(key))
return true; return true;
if(key == PSP_CTRL_RIGHT && !isModal() if(key == JGE_BTN_RIGHT && !isModal()
&& right->Selectable() && left->Leaving(PSP_CTRL_RIGHT)){ && right->Selectable() && left->Leaving(JGE_BTN_RIGHT)){
bRight = !bRight; bRight = !bRight;
right->Entering(PSP_CTRL_RIGHT); right->Entering(JGE_BTN_RIGHT);
return true; return true;
} }
} }
@@ -621,10 +621,10 @@ bool WGuiSplit::CheckUserInput(u32 key){
{ {
if(right->CheckUserInput(key)) if(right->CheckUserInput(key))
return true; return true;
if (key == PSP_CTRL_LEFT && !isModal() if (key == JGE_BTN_LEFT && !isModal()
&& left->Selectable() && right->Leaving(PSP_CTRL_LEFT)){ && left->Selectable() && right->Leaving(JGE_BTN_LEFT)){
bRight = !bRight; bRight = !bRight;
left->Entering(PSP_CTRL_LEFT); left->Entering(JGE_BTN_LEFT);
return true; return true;
} }
} }
@@ -640,14 +640,14 @@ void WGuiSplit::Update(float dt){
left->Update(dt); left->Update(dt);
} }
void WGuiSplit::Entering(u32 key){ void WGuiSplit::Entering(JButton key){
mFocus = true; mFocus = true;
if(bRight) if(bRight)
right->Entering(key); right->Entering(key);
else else
left->Entering(key); left->Entering(key);
} }
bool WGuiSplit::Leaving(u32 key){ bool WGuiSplit::Leaving(JButton key){
if(bRight){ if(bRight){
if(right->Leaving(key)){ if(right->Leaving(key)){
@@ -693,7 +693,7 @@ void WGuiSplit::confirmChange(bool confirmed){
} }
//WGuiMenu //WGuiMenu
WGuiMenu::WGuiMenu(u32 next = PSP_CTRL_RIGHT, u32 prev = PSP_CTRL_LEFT, bool m, WSyncable * syncme): WGuiItem(""){ WGuiMenu::WGuiMenu(JButton next = JGE_BTN_RIGHT, JButton prev = JGE_BTN_LEFT, bool m, WSyncable * syncme): WGuiItem(""){
buttonNext = next; buttonNext = next;
buttonPrev = prev; buttonPrev = prev;
currentItem = -1; currentItem = -1;
@@ -738,14 +738,14 @@ void WGuiMenu::Add(WGuiBase * it){
if(it) if(it)
items.push_back(it); items.push_back(it);
} }
bool WGuiMenu::CheckUserInput(u32 key){ bool WGuiMenu::CheckUserInput(JButton key){
bool kidModal = false; bool kidModal = false;
bool handledInput = false; bool handledInput = false;
int nbitems = (int) items.size(); int nbitems = (int) items.size();
JGE * mEngine = JGE::GetInstance(); JGE * mEngine = JGE::GetInstance();
if(!mEngine->GetButtonState(held)) //Key isn't held down. if(!mEngine->GetButtonState(held)) //Key isn't held down.
held = 0; held = JGE_BTN_NONE;
if(currentItem >= 0 && currentItem < nbitems) if(currentItem >= 0 && currentItem < nbitems)
kidModal = items[currentItem]->isModal(); kidModal = items[currentItem]->isModal();
@@ -790,32 +790,34 @@ void WGuiMenu::syncMove(){
while(i > 0 && sync->next()) while(i > 0 && sync->next())
i = currentItem - sync->getPos(); i = currentItem - sync->getPos();
} }
bool WGuiMenu::isButtonDir(u32 key, int dir){ bool WGuiMenu::isButtonDir(JButton key, int dir){
if(!mDPad) if(!mDPad)
return ((dir > 0 && key == buttonNext) || (dir <= 0 && key == buttonPrev)); return ((dir > 0 && key == buttonNext) || (dir <= 0 && key == buttonPrev));
if(dir <= 0){ if(dir <= 0){
switch(buttonPrev){ switch(buttonPrev){
case PSP_CTRL_LEFT: case JGE_BTN_LEFT:
if(key == PSP_CTRL_UP) if(key == JGE_BTN_UP)
return true; return true;
break; break;
case PSP_CTRL_UP: case JGE_BTN_UP:
if(key == PSP_CTRL_LEFT) if(key == JGE_BTN_LEFT)
return true; return true;
break; break;
default: ; // Nothing
} }
return (key == buttonPrev); return (key == buttonPrev);
}else { }else {
switch(buttonNext){ switch(buttonNext){
case PSP_CTRL_RIGHT: case JGE_BTN_RIGHT:
if(key == PSP_CTRL_DOWN) if(key == JGE_BTN_DOWN)
return true; return true;
break; break;
case PSP_CTRL_DOWN: case JGE_BTN_DOWN:
if(key == PSP_CTRL_RIGHT) if(key == JGE_BTN_RIGHT)
return true; return true;
break; break;
default: ; // Nothing
} }
return (key == buttonNext); return (key == buttonNext);
} }
@@ -1259,7 +1261,7 @@ void WGuiListRow::Render(){
if(items[i]->Selectable()) { if(items[i]->Selectable()) {
currentItem = i; currentItem = i;
if(hasFocus()) if(hasFocus())
items[currentItem]->Entering(0); items[currentItem]->Entering(JGE_BTN_NONE);
break; break;
} }
} }
@@ -1312,8 +1314,8 @@ void WGuiListRow::Render(){
setHeight(tallestRow*numRows+10); setHeight(tallestRow*numRows+10);
} }
WGuiListRow::WGuiListRow(string n, WSyncable * s) : WGuiList(n,s) { WGuiListRow::WGuiListRow(string n, WSyncable * s) : WGuiList(n,s) {
buttonNext = PSP_CTRL_RIGHT; buttonNext = JGE_BTN_RIGHT;
buttonPrev = PSP_CTRL_LEFT; buttonPrev = JGE_BTN_LEFT;
width = SCREEN_WIDTH; width = SCREEN_WIDTH;
height = 20; height = 20;
} }
@@ -1367,7 +1369,7 @@ void WGuiFilters::buildList(){
subMenu = NULL; subMenu = NULL;
list->Add(NEW WGuiHeader(displayValue)); list->Add(NEW WGuiHeader(displayValue));
list->Add(wgs); list->Add(wgs);
list->Entering(0); list->Entering(JGE_BTN_NONE);
} }
WGuiFilters::WGuiFilters(string header, WSrcCards * src) : WGuiItem(header) { WGuiFilters::WGuiFilters(string header, WSrcCards * src) : WGuiItem(header) {
bFinished = false; bFinished = false;
@@ -1417,12 +1419,11 @@ void WGuiFilters::Update(float dt){
it = wgl->items.erase(it); it = wgl->items.erase(it);
bDeleted = true; bDeleted = true;
} }
if(bDeleted){ if(bDeleted)
wgl->Entering(0); wgl->Entering(JGE_BTN_NONE);
} }
} }
} void WGuiFilters::Entering(JButton key){
void WGuiFilters::Entering(u32 key){
bFinished = false; bFinished = false;
WGuiItem::Entering(key); WGuiItem::Entering(key);
} }
@@ -1439,10 +1440,10 @@ void WGuiFilters::Render(){
if(subMenu && !subMenu->closed) if(subMenu && !subMenu->closed)
subMenu->Render(); subMenu->Render();
} }
bool WGuiFilters::CheckUserInput(u32 key){ bool WGuiFilters::CheckUserInput(JButton key){
if(subMenu && !subMenu->closed && subMenu->CheckUserInput(key)) if(subMenu && !subMenu->closed && subMenu->CheckUserInput(key))
return true; return true;
if(key == PSP_CTRL_CROSS){//|| key == PSP_CTRL_START){ if(key == JGE_BTN_SEC){//|| key == JGE_BTN_MENU){
//TODO Pop up a "Are you sure?" dialog. //TODO Pop up a "Are you sure?" dialog.
return true; return true;
} }