New descriptive text popup feature for deck selection

http://wololo.net/forum/viewtopic.php?f=13&t=2423
This commit is contained in:
techdragon.nguyen@gmail.com
2010-11-18 15:48:48 +00:00
parent f7bcbb42dc
commit 2a8f8074e6
17 changed files with 5715 additions and 5198 deletions
+124 -123
View File
@@ -1,123 +1,124 @@
//-------------------------------------------------------------------------------------
//
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
//
// Licensed under the BSD license, see LICENSE in JGE root for details.
//
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
//
//-------------------------------------------------------------------------------------
#ifndef _JGUI_H
#define _JGUI_H
#include <ostream>
#include "JGE.h"
#include "JSprite.h"
#define MAX_GUIOBJECT 64
#define JGUI_STYLE_LEFTRIGHT 0x01
#define JGUI_STYLE_UPDOWN 0x02
#define JGUI_STYLE_WRAPPING 0x04
#define JGUI_INITIAL_DELAY 0.4
#define JGUI_REPEAT_DELAY 0.2
const int kCancelMenuID = -1;
class JGuiListener
{
public:
virtual ~JGuiListener() {}
virtual void ButtonPressed(int controllerId, int controlId) = 0;
};
class JGuiObject
{
protected:
static JGE* mEngine;
private:
int mId;
public:
JGuiObject(int id);
virtual ~JGuiObject();
virtual void Render() = 0;
virtual std::ostream& toString(std::ostream&) const = 0;
virtual void Update(float dt);
virtual void Entering(); // when focus is transferring to this obj
virtual bool Leaving(JButton key); // when focus is transferring away from this obj, true to go ahead
virtual bool ButtonPressed(); // action button pressed, return false to ignore
// Used for mouse support so that the GUI engine can found out which Object was selected
virtual bool getTopLeft(int& top, int& left) {return false;};
int GetId();
};
class JGuiController
{
protected:
static JGE* mEngine;
int mId;
bool mActive;
JButton mActionButton;
JButton mCancelButton;
int mCurr;
int mStyle;
JSprite* mCursor;
bool mShowCursor;
int mCursorX;
int mCursorY;
int mBgX;
int mBgY;
const JTexture* mBg;
PIXEL_TYPE mShadingColor;
Rect* mShadingBg;
JGuiListener* mListener;
//int mKeyHoldTime;
public:
vector<JGuiObject*> mObjects;
int mCount;
JGuiController(int id, JGuiListener* listener);
~JGuiController();
virtual void Render();
virtual void Update(float dt);
virtual bool CheckUserInput(JButton key);
void Add(JGuiObject* ctrl);
void RemoveAt(int i);
void Remove(int id);
void Remove(JGuiObject* ctrl);
void SetActionButton(JButton button);
void SetStyle(int style);
void SetCursor(JSprite* cursor);
bool IsActive();
void SetActive(bool flag);
//void SetImageBackground(const JTexture* tex, int x, int y);
//void SetShadingBackground(int x, int y, int width, int height, PIXEL_TYPE color);
};
ostream& operator<<(ostream &out, const JGuiObject &j);
#endif
//-------------------------------------------------------------------------------------
//
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
//
// Licensed under the BSD license, see LICENSE in JGE root for details.
//
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
//
//-------------------------------------------------------------------------------------
#ifndef _JGUI_H
#define _JGUI_H
#include <ostream>
#include "JGE.h"
#include "JSprite.h"
#define MAX_GUIOBJECT 64
#define JGUI_STYLE_LEFTRIGHT 0x01
#define JGUI_STYLE_UPDOWN 0x02
#define JGUI_STYLE_WRAPPING 0x04
#define JGUI_INITIAL_DELAY 0.4
#define JGUI_REPEAT_DELAY 0.2
const int kCancelMenuID = -1;
const int kInfoMenuID = -200;
class JGuiListener
{
public:
virtual ~JGuiListener()
{
}
virtual void ButtonPressed(int controllerId, int controlId) = 0;
};
class JGuiObject
{
protected:
static JGE* mEngine;
private:
int mId;
public:
JGuiObject(int id);
virtual ~JGuiObject();
virtual void Render() = 0;
virtual std::ostream& toString(std::ostream&) const = 0;
virtual void Update(float dt);
virtual void Entering(); // when focus is transferring to this obj
virtual bool Leaving(JButton key); // when focus is transferring away from this obj, true to go ahead
virtual bool ButtonPressed(); // action button pressed, return false to ignore
// Used for mouse support so that the GUI engine can found out which Object was selected
virtual bool getTopLeft(int& top, int& left)
{
return false;
}
;
int GetId();
};
class JGuiController
{
protected:
static JGE* mEngine;
int mId;
bool mActive;
JButton mActionButton;
JButton mCancelButton;
int mCurr;
int mStyle;
JSprite* mCursor;
bool mShowCursor;
int mCursorX;
int mCursorY;
int mBgX;
int mBgY;
const JTexture* mBg;
PIXEL_TYPE mShadingColor;
Rect* mShadingBg;
JGuiListener* mListener;
//int mKeyHoldTime;
public:
vector<JGuiObject*> mObjects;
int mCount;
JGuiController(int id, JGuiListener* listener);
~JGuiController();
virtual void Render();
virtual void Update(float dt);
virtual bool CheckUserInput(JButton key);
void Add(JGuiObject* ctrl);
void RemoveAt(int i);
void Remove(int id);
void Remove(JGuiObject* ctrl);
void SetActionButton(JButton button);
void SetStyle(int style);
void SetCursor(JSprite* cursor);
bool IsActive();
void SetActive(bool flag);
};
ostream& operator<<(ostream &out, const JGuiObject &j);
#endif
+256 -247
View File
@@ -1,247 +1,256 @@
//-------------------------------------------------------------------------------------
//
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
//
// Licensed under the BSD license, see LICENSE in JGE root for details.
//
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
//
//-------------------------------------------------------------------------------------
#include "../include/JGE.h"
#include "../include/JGui.h"
JGE* JGuiObject::mEngine = NULL;
JGE* JGuiController::mEngine = NULL;
JGuiObject::JGuiObject(int id): mId(id)
{
mEngine = JGE::GetInstance();
}
JGuiObject::~JGuiObject()
{
// JGERelease();
}
bool JGuiObject::Leaving(JButton key __attribute__((unused)))
{
return true;
}
bool JGuiObject::ButtonPressed()
{
return false;
}
void JGuiObject::Entering()
{
}
int JGuiObject::GetId()
{
return mId;
}
void JGuiObject::Update(float dt __attribute__((unused)))
{
}
ostream& operator<<(ostream &out, const JGuiObject &j)
{
return j.toString(out);
}
JGuiController::JGuiController(int id, JGuiListener* listener) : mId(id), mListener(listener)
{
mEngine = JGE::GetInstance();
mBg = NULL;
mShadingBg = NULL;
mCount = 0;
mCurr = 0;
mCursorX = SCREEN_WIDTH/2;
mCursorY = SCREEN_HEIGHT/2;
mShowCursor = false;
mActionButton = JGE_BTN_OK;
mCancelButton = JGE_BTN_MENU;
mStyle = JGUI_STYLE_WRAPPING;
mActive = true;
}
JGuiController::~JGuiController()
{
for (int i=0;i<mCount;i++)
if (mObjects[i]!=NULL)
delete mObjects[i];
}
void JGuiController::Render()
{
for (int i=0;i<mCount;i++)
if (mObjects[i]!=NULL)
mObjects[i]->Render();
}
bool JGuiController::CheckUserInput(JButton key){
if (!mCount) return false;
if (key == mActionButton)
{
if (mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
{
if (mListener != NULL)
mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
return true;
}
}
else if (key == mCancelButton)
{
if (mListener != NULL)
{
mListener->ButtonPressed(mId, kCancelMenuID);
}
}
else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
{
int n = mCurr;
n--;
if (n<0)
{
if ((mStyle&JGUI_STYLE_WRAPPING))
n = mCount-1;
else
n = 0;
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_UP))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
return true;
}
else if ((JGE_BTN_RIGHT == key) || (JGE_BTN_DOWN == key)) // || mEngine->GetAnalogY()>192 || mEngine->GetAnalogX()>192)
{
int n = mCurr;
n++;
if (n>mCount-1)
{
if ((mStyle&JGUI_STYLE_WRAPPING))
n = 0;
else
n = mCount-1;
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
return true;
}
else
{ // a dude may have clicked somewhere, we're gonna select the closest object from where he clicked
int x, y;
unsigned int distance2;
unsigned int minDistance2 = -1;
int n = mCurr;
if(mEngine->GetLeftClickCoordinates(x, y))
{
for(int i = 0; i < mCount; i++)
{
int top, left;
if(mObjects[i]->getTopLeft(top, left))
{
distance2 = (top-y)*(top-y) + (left-x)*(left-x);
if(distance2 < minDistance2)
{
minDistance2 = distance2;
n = i;
}
}
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
mEngine->LeftClickedProcessed();
return true;
}
}
return false;
}
void JGuiController::Update(float dt)
{
for (int i=0;i<mCount;i++)
if (mObjects[i]!=NULL)
mObjects[i]->Update(dt);
JButton key = mEngine->ReadButton();
CheckUserInput(key);
}
void JGuiController::Add(JGuiObject* ctrl)
{
mObjects.push_back(ctrl);
mCount++;
}
void JGuiController::RemoveAt(int i){
if (!mObjects[i]) return;
mObjects.erase(mObjects.begin()+i);
delete mObjects[i];
mCount--;
if (mCurr == mCount)
mCurr = 0;
return;
}
void JGuiController::Remove(int id)
{
for (int i=0;i<mCount;i++)
{
if (mObjects[i] != NULL && mObjects[i]->GetId()==id) {
RemoveAt(i);
return;
}
}
}
void JGuiController::Remove(JGuiObject* ctrl)
{
for (int i=0;i<mCount;i++)
{
if (mObjects[i] != NULL && mObjects[i]==ctrl) {
RemoveAt(i);
return;
}
}
}
void JGuiController::SetActionButton(JButton button) { mActionButton = button; }
void JGuiController::SetStyle(int style) { mStyle = style; }
void JGuiController::SetCursor(JSprite* cursor) { mCursor = cursor; }
bool JGuiController::IsActive() { return mActive; }
void JGuiController::SetActive(bool flag) { mActive = flag; }
//-------------------------------------------------------------------------------------
//
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
//
// Licensed under the BSD license, see LICENSE in JGE root for details.
//
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
//
//-------------------------------------------------------------------------------------
#include "../include/JGE.h"
#include "../include/JGui.h"
JGE* JGuiObject::mEngine = NULL;
JGE* JGuiController::mEngine = NULL;
JGuiObject::JGuiObject(int id) :
mId(id)
{
mEngine = JGE::GetInstance();
}
JGuiObject::~JGuiObject()
{
// JGERelease();
}
bool JGuiObject::Leaving(JButton key __attribute__((unused)))
{
return true;
}
bool JGuiObject::ButtonPressed()
{
return false;
}
void JGuiObject::Entering()
{
}
int JGuiObject::GetId()
{
return mId;
}
void JGuiObject::Update(float dt __attribute__((unused)))
{
}
ostream& operator<<(ostream &out, const JGuiObject &j)
{
return j.toString(out);
}
JGuiController::JGuiController(int id, JGuiListener* listener) :
mId(id), mListener(listener)
{
mEngine = JGE::GetInstance();
mBg = NULL;
mShadingBg = NULL;
mCount = 0;
mCurr = 0;
mCursorX = SCREEN_WIDTH / 2;
mCursorY = SCREEN_HEIGHT / 2;
mShowCursor = false;
mActionButton = JGE_BTN_OK;
mCancelButton = JGE_BTN_MENU;
mStyle = JGUI_STYLE_WRAPPING;
mActive = true;
}
JGuiController::~JGuiController()
{
for (int i = 0; i < mCount; i++)
if (mObjects[i] != NULL) delete mObjects[i];
}
void JGuiController::Render()
{
for (int i = 0; i < mCount; i++)
if (mObjects[i] != NULL) mObjects[i]->Render();
}
bool JGuiController::CheckUserInput(JButton key)
{
if (!mCount) return false;
if (key == mActionButton)
{
if (!mObjects.empty() && mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
{
if (mListener != NULL) mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
return true;
}
}
else if (key == mCancelButton)
{
if (mListener != NULL)
{
mListener->ButtonPressed(mId, kCancelMenuID);
}
}
else if (JGE_BTN_CANCEL == key)
{
if (mListener != NULL) mListener->ButtonPressed(mId, kInfoMenuID);
}
else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
{
int n = mCurr;
n--;
if (n < 0)
{
if ((mStyle & JGUI_STYLE_WRAPPING))
n = mCount - 1;
else
n = 0;
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_UP))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
return true;
}
else if ((JGE_BTN_RIGHT == key) || (JGE_BTN_DOWN == key)) // || mEngine->GetAnalogY()>192 || mEngine->GetAnalogX()>192)
{
int n = mCurr;
n++;
if (n > mCount - 1)
{
if ((mStyle & JGUI_STYLE_WRAPPING))
n = 0;
else
n = mCount - 1;
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
return true;
}
else
{ // a dude may have clicked somewhere, we're gonna select the closest object from where he clicked
int x, y;
unsigned int distance2;
unsigned int minDistance2 = -1;
int n = mCurr;
if (mEngine->GetLeftClickCoordinates(x, y))
{
for (int i = 0; i < mCount; i++)
{
int top, left;
if (mObjects[i]->getTopLeft(top, left))
{
distance2 = (top - y) * (top - y) + (left - x) * (left - x);
if (distance2 < minDistance2)
{
minDistance2 = distance2;
n = i;
}
}
}
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
{
mCurr = n;
mObjects[mCurr]->Entering();
}
mEngine->LeftClickedProcessed();
return true;
}
}
return false;
}
void JGuiController::Update(float dt)
{
for (int i = 0; i < mCount; i++)
if (mObjects[i] != NULL) mObjects[i]->Update(dt);
JButton key = mEngine->ReadButton();
CheckUserInput(key);
}
void JGuiController::Add(JGuiObject* ctrl)
{
mObjects.push_back(ctrl);
mCount++;
}
void JGuiController::RemoveAt(int i)
{
if (!mObjects[i]) return;
mObjects.erase(mObjects.begin() + i);
delete mObjects[i];
mCount--;
if (mCurr == mCount) mCurr = 0;
return;
}
void JGuiController::Remove(int id)
{
for (int i = 0; i < mCount; i++)
{
if (mObjects[i] != NULL && mObjects[i]->GetId() == id)
{
RemoveAt(i);
return;
}
}
}
void JGuiController::Remove(JGuiObject* ctrl)
{
for (int i = 0; i < mCount; i++)
{
if (mObjects[i] != NULL && mObjects[i] == ctrl)
{
RemoveAt(i);
return;
}
}
}
void JGuiController::SetActionButton(JButton button)
{
mActionButton = button;
}
void JGuiController::SetStyle(int style)
{
mStyle = style;
}
void JGuiController::SetCursor(JSprite* cursor)
{
mCursor = cursor;
}
bool JGuiController::IsActive()
{
return mActive;
}
void JGuiController::SetActive(bool flag)
{
mActive = flag;
}