mirror of
https://github.com/jpd002/Play-.git
synced 2025-04-28 13:47:57 +03:00
Experimenting multi directional virtual dpad.
This commit is contained in:
parent
3bc60f4728
commit
ecc5870ca1
6 changed files with 150 additions and 13 deletions
|
@ -59,6 +59,7 @@ CVirtualPad::ItemArray CVirtualPad::GetItems(float screenWidth, float screenHeig
|
||||||
startSelPadPosX + padButtonSize * 2, startSelPadPosY + padButtonSize / 2, startSelPadPosX + padButtonSize * 3, startSelPadPosY + padButtonSize,
|
startSelPadPosX + padButtonSize * 2, startSelPadPosY + padButtonSize / 2, startSelPadPosX + padButtonSize * 3, startSelPadPosY + padButtonSize,
|
||||||
PS2::CControllerInfo::START, "start"));
|
PS2::CControllerInfo::START, "start"));
|
||||||
|
|
||||||
|
#if 0
|
||||||
items.push_back(CreateButtonItem(
|
items.push_back(CreateButtonItem(
|
||||||
dpadPosX + dpadButtonSize * 2, dpadPosY + dpadButtonSize * 0, dpadPosX + dpadButtonSize * 4, dpadPosY + dpadButtonSize * 3,
|
dpadPosX + dpadButtonSize * 2, dpadPosY + dpadButtonSize * 0, dpadPosX + dpadButtonSize * 4, dpadPosY + dpadButtonSize * 3,
|
||||||
PS2::CControllerInfo::DPAD_UP, "up"));
|
PS2::CControllerInfo::DPAD_UP, "up"));
|
||||||
|
@ -71,6 +72,10 @@ CVirtualPad::ItemArray CVirtualPad::GetItems(float screenWidth, float screenHeig
|
||||||
items.push_back(CreateButtonItem(
|
items.push_back(CreateButtonItem(
|
||||||
dpadPosX + dpadButtonSize * 3, dpadPosY + dpadButtonSize * 2, dpadPosX + dpadButtonSize * 6, dpadPosY + dpadButtonSize * 4,
|
dpadPosX + dpadButtonSize * 3, dpadPosY + dpadButtonSize * 2, dpadPosX + dpadButtonSize * 6, dpadPosY + dpadButtonSize * 4,
|
||||||
PS2::CControllerInfo::DPAD_RIGHT, "right"));
|
PS2::CControllerInfo::DPAD_RIGHT, "right"));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
items.push_back(CreateDigitalPadItem(
|
||||||
|
dpadPosX, dpadPosY, dpadPosX + dpadButtonSize * 6, dpadPosY + dpadButtonSize * 6, PS2::CControllerInfo::DPAD_LEFT));
|
||||||
|
|
||||||
items.push_back(CreateButtonItem(
|
items.push_back(CreateButtonItem(
|
||||||
actionPadPosX + padButtonSize * 1, actionPadPosY + padButtonSize * 0, actionPadPosX + padButtonSize * 2, actionPadPosY + padButtonSize * 1,
|
actionPadPosX + padButtonSize * 1, actionPadPosY + padButtonSize * 0, actionPadPosX + padButtonSize * 2, actionPadPosY + padButtonSize * 1,
|
||||||
|
@ -105,7 +110,7 @@ CVirtualPad::ItemArray CVirtualPad::GetItems(float screenWidth, float screenHeig
|
||||||
CVirtualPad::ITEM CVirtualPad::CreateButtonItem(float x1, float y1, float x2, float y2, PS2::CControllerInfo::BUTTON code, const std::string& imageName, const std::string& caption)
|
CVirtualPad::ITEM CVirtualPad::CreateButtonItem(float x1, float y1, float x2, float y2, PS2::CControllerInfo::BUTTON code, const std::string& imageName, const std::string& caption)
|
||||||
{
|
{
|
||||||
ITEM item;
|
ITEM item;
|
||||||
item.isAnalog = false;
|
item.type = ITEM_BUTTON;
|
||||||
item.x1 = x1;
|
item.x1 = x1;
|
||||||
item.y1 = y1;
|
item.y1 = y1;
|
||||||
item.x2 = x2;
|
item.x2 = x2;
|
||||||
|
@ -119,7 +124,7 @@ CVirtualPad::ITEM CVirtualPad::CreateButtonItem(float x1, float y1, float x2, fl
|
||||||
CVirtualPad::ITEM CVirtualPad::CreateAnalogStickItem(float x1, float y1, float x2, float y2, PS2::CControllerInfo::BUTTON codeX, PS2::CControllerInfo::BUTTON codeY, const std::string& imageName)
|
CVirtualPad::ITEM CVirtualPad::CreateAnalogStickItem(float x1, float y1, float x2, float y2, PS2::CControllerInfo::BUTTON codeX, PS2::CControllerInfo::BUTTON codeY, const std::string& imageName)
|
||||||
{
|
{
|
||||||
ITEM item;
|
ITEM item;
|
||||||
item.isAnalog = true;
|
item.type = ITEM_ANALOG_STICK;
|
||||||
item.x1 = x1;
|
item.x1 = x1;
|
||||||
item.y1 = y1;
|
item.y1 = y1;
|
||||||
item.x2 = x2;
|
item.x2 = x2;
|
||||||
|
@ -129,3 +134,17 @@ CVirtualPad::ITEM CVirtualPad::CreateAnalogStickItem(float x1, float y1, float x
|
||||||
item.imageName = imageName;
|
item.imageName = imageName;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CVirtualPad::ITEM CVirtualPad::CreateDigitalPadItem(float x1, float y1, float x2, float y2, PS2::CControllerInfo::BUTTON codeX)
|
||||||
|
{
|
||||||
|
ITEM item;
|
||||||
|
item.type = ITEM_DIGITAL_PAD;
|
||||||
|
item.x1 = x1;
|
||||||
|
item.y1 = y1;
|
||||||
|
item.x2 = x2;
|
||||||
|
item.y2 = y2;
|
||||||
|
item.code0 = codeX;
|
||||||
|
// item.code1 = codeY;
|
||||||
|
item.imageName = "dpad";
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
|
@ -7,13 +7,20 @@
|
||||||
class CVirtualPad
|
class CVirtualPad
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum ITEMTYPE
|
||||||
|
{
|
||||||
|
ITEM_BUTTON,
|
||||||
|
ITEM_ANALOG_STICK,
|
||||||
|
ITEM_DIGITAL_PAD,
|
||||||
|
};
|
||||||
|
|
||||||
struct ITEM
|
struct ITEM
|
||||||
{
|
{
|
||||||
float x1 = 0;
|
float x1 = 0;
|
||||||
float y1 = 0;
|
float y1 = 0;
|
||||||
float x2 = 0;
|
float x2 = 0;
|
||||||
float y2 = 0;
|
float y2 = 0;
|
||||||
bool isAnalog = false;
|
ITEMTYPE type;
|
||||||
PS2::CControllerInfo::BUTTON code0 = PS2::CControllerInfo::MAX_BUTTONS;
|
PS2::CControllerInfo::BUTTON code0 = PS2::CControllerInfo::MAX_BUTTONS;
|
||||||
PS2::CControllerInfo::BUTTON code1 = PS2::CControllerInfo::MAX_BUTTONS;
|
PS2::CControllerInfo::BUTTON code1 = PS2::CControllerInfo::MAX_BUTTONS;
|
||||||
std::string imageName;
|
std::string imageName;
|
||||||
|
@ -26,4 +33,5 @@ public:
|
||||||
private:
|
private:
|
||||||
static ITEM CreateButtonItem(float, float, float, float, PS2::CControllerInfo::BUTTON, const std::string&, const std::string& = "");
|
static ITEM CreateButtonItem(float, float, float, float, PS2::CControllerInfo::BUTTON, const std::string&, const std::string& = "");
|
||||||
static ITEM CreateAnalogStickItem(float, float, float, float, PS2::CControllerInfo::BUTTON, PS2::CControllerInfo::BUTTON, const std::string&);
|
static ITEM CreateAnalogStickItem(float, float, float, float, PS2::CControllerInfo::BUTTON, PS2::CControllerInfo::BUTTON, const std::string&);
|
||||||
|
static ITEM CreateDigitalPadItem(float, float, float, float, PS2::CControllerInfo::BUTTON);
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,24 +53,24 @@ void CInputManager::SetAxisState(int buttonId, float value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_InputManager_setButtonState(JNIEnv* env, jobject obj, jint buttonId, jboolean pressed)
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_InputManager_setButtonState(JNIEnv* env, jclass clazz, jint buttonId, jboolean pressed)
|
||||||
{
|
{
|
||||||
CInputManager::GetInstance().SetButtonState(buttonId, (pressed == JNI_TRUE));
|
CInputManager::GetInstance().SetButtonState(buttonId, (pressed == JNI_TRUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_InputManager_setAxisState(JNIEnv* env, jobject obj, jint buttonId, jfloat value)
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_InputManager_setAxisState(JNIEnv* env, jclass clazz, jint buttonId, jfloat value)
|
||||||
{
|
{
|
||||||
CInputManager::GetInstance().SetAxisState(buttonId, value);
|
CInputManager::GetInstance().SetAxisState(buttonId, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT jstring JNICALL Java_com_virtualapplications_play_InputManager_getVirtualPadItems(JNIEnv* env, jobject obj, jfloat screenWidth, jfloat screenHeight)
|
extern "C" JNIEXPORT jstring JNICALL Java_com_virtualapplications_play_InputManager_getVirtualPadItems(JNIEnv* env, jclass clazz, jfloat screenWidth, jfloat screenHeight)
|
||||||
{
|
{
|
||||||
auto items = CVirtualPad::GetItems(screenWidth, screenHeight);
|
auto items = CVirtualPad::GetItems(screenWidth, screenHeight);
|
||||||
auto documentNode = std::make_unique<Framework::Xml::CNode>("Document", true);
|
auto documentNode = std::make_unique<Framework::Xml::CNode>("Document", true);
|
||||||
for(const auto& item : items)
|
for(const auto& item : items)
|
||||||
{
|
{
|
||||||
auto itemNode = new Framework::Xml::CNode("Item", true);
|
auto itemNode = new Framework::Xml::CNode("Item", true);
|
||||||
itemNode->InsertAttribute("isAnalog", item.isAnalog ? "true" : "false");
|
itemNode->InsertAttribute("type", std::to_string(item.type).c_str());
|
||||||
itemNode->InsertAttribute("x1", std::to_string(item.x1).c_str());
|
itemNode->InsertAttribute("x1", std::to_string(item.x1).c_str());
|
||||||
itemNode->InsertAttribute("y1", std::to_string(item.y1).c_str());
|
itemNode->InsertAttribute("y1", std::to_string(item.y1).c_str());
|
||||||
itemNode->InsertAttribute("x2", std::to_string(item.x2).c_str());
|
itemNode->InsertAttribute("x2", std::to_string(item.x2).c_str());
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.virtualapplications.play;
|
||||||
|
|
||||||
|
import android.graphics.*;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
class VirtualPadDpad extends VirtualPadItem
|
||||||
|
{
|
||||||
|
private final Bitmap _bitmap;
|
||||||
|
|
||||||
|
public VirtualPadDpad(RectF bounds, Bitmap bitmap)
|
||||||
|
{
|
||||||
|
super(bounds);
|
||||||
|
_bitmap = bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPointerDown(float x, float y)
|
||||||
|
{
|
||||||
|
updateButtonState(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPointerUp()
|
||||||
|
{
|
||||||
|
InputManager.setButtonState(InputManagerConstants.BUTTON_UP, false);
|
||||||
|
InputManager.setButtonState(InputManagerConstants.BUTTON_DOWN, false);
|
||||||
|
InputManager.setButtonState(InputManagerConstants.BUTTON_LEFT, false);
|
||||||
|
InputManager.setButtonState(InputManagerConstants.BUTTON_RIGHT, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPointerMove(float x, float y)
|
||||||
|
{
|
||||||
|
updateButtonState(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Canvas canvas)
|
||||||
|
{
|
||||||
|
Paint paint = new Paint();
|
||||||
|
paint.setAntiAlias(true);
|
||||||
|
canvas.drawBitmap(_bitmap, null, _bounds, paint);
|
||||||
|
// canvas.drawRect(_bounds, _paint);
|
||||||
|
// _paint.setColor(Color.RED);
|
||||||
|
// canvas.drawRect(_pressPosition.x - 20, _pressPosition.y - 20, _pressPosition.x + 20, _pressPosition.y + 20, _paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateButtonState(float x, float y)
|
||||||
|
{
|
||||||
|
boolean upPressed = false;
|
||||||
|
boolean downPressed = false;
|
||||||
|
boolean leftPressed = false;
|
||||||
|
boolean rightPressed = false;
|
||||||
|
if(_bounds.contains(x, y))
|
||||||
|
{
|
||||||
|
float localX = _bounds.centerX() - x;
|
||||||
|
float localY = _bounds.centerY() - y;
|
||||||
|
double angle = Math.atan2(localY, localX);
|
||||||
|
int quad = (int)(angle * 8 / Math.PI);
|
||||||
|
//Log.w(Constants.TAG, String.format("Quad: %d", quad));
|
||||||
|
switch(quad)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
leftPressed = true;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
upPressed = true;
|
||||||
|
leftPressed = true;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
upPressed = true;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
case 6:
|
||||||
|
rightPressed = true;
|
||||||
|
upPressed = true;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
case -7:
|
||||||
|
rightPressed = true;
|
||||||
|
break;
|
||||||
|
case -6:
|
||||||
|
case -5:
|
||||||
|
rightPressed = true;
|
||||||
|
downPressed = true;
|
||||||
|
break;
|
||||||
|
case -4:
|
||||||
|
case -3:
|
||||||
|
downPressed = true;
|
||||||
|
break;
|
||||||
|
case -2:
|
||||||
|
case -1:
|
||||||
|
downPressed = true;
|
||||||
|
leftPressed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
InputManager.setButtonState(InputManagerConstants.BUTTON_UP, upPressed);
|
||||||
|
InputManager.setButtonState(InputManagerConstants.BUTTON_DOWN, downPressed);
|
||||||
|
InputManager.setButtonState(InputManagerConstants.BUTTON_LEFT, leftPressed);
|
||||||
|
InputManager.setButtonState(InputManagerConstants.BUTTON_RIGHT, rightPressed);
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,7 @@ public class VirtualPadView extends SurfaceView
|
||||||
_itemBitmaps.put("circle", BitmapFactory.decodeResource(getResources(), R.drawable.circle));
|
_itemBitmaps.put("circle", BitmapFactory.decodeResource(getResources(), R.drawable.circle));
|
||||||
_itemBitmaps.put("lr", BitmapFactory.decodeResource(getResources(), R.drawable.lr));
|
_itemBitmaps.put("lr", BitmapFactory.decodeResource(getResources(), R.drawable.lr));
|
||||||
_itemBitmaps.put("analogStick", BitmapFactory.decodeResource(getResources(), R.drawable.analogstick));
|
_itemBitmaps.put("analogStick", BitmapFactory.decodeResource(getResources(), R.drawable.analogstick));
|
||||||
|
_itemBitmaps.put("dpad", BitmapFactory.decodeResource(getResources(), R.drawable.dpad));
|
||||||
|
|
||||||
setWillNotDraw(false);
|
setWillNotDraw(false);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +68,7 @@ public class VirtualPadView extends SurfaceView
|
||||||
{
|
{
|
||||||
Node itemNode = itemNodes.item(i);
|
Node itemNode = itemNodes.item(i);
|
||||||
NamedNodeMap attributes = itemNode.getAttributes();
|
NamedNodeMap attributes = itemNode.getAttributes();
|
||||||
boolean isAnalog = Boolean.parseBoolean(attributes.getNamedItem("isAnalog").getNodeValue());
|
int type = Integer.parseInt(attributes.getNamedItem("type").getNodeValue());
|
||||||
float x1 = Float.parseFloat(attributes.getNamedItem("x1").getNodeValue());
|
float x1 = Float.parseFloat(attributes.getNamedItem("x1").getNodeValue());
|
||||||
float y1 = Float.parseFloat(attributes.getNamedItem("y1").getNodeValue());
|
float y1 = Float.parseFloat(attributes.getNamedItem("y1").getNodeValue());
|
||||||
float x2 = Float.parseFloat(attributes.getNamedItem("x2").getNodeValue());
|
float x2 = Float.parseFloat(attributes.getNamedItem("x2").getNodeValue());
|
||||||
|
@ -82,13 +83,17 @@ public class VirtualPadView extends SurfaceView
|
||||||
}
|
}
|
||||||
Bitmap bitmap = _itemBitmaps.get(imageName);
|
Bitmap bitmap = _itemBitmaps.get(imageName);
|
||||||
RectF itemRect = new RectF(x1 * density, y1 * density, x2 * density, y2 * density);
|
RectF itemRect = new RectF(x1 * density, y1 * density, x2 * density, y2 * density);
|
||||||
if(isAnalog)
|
switch(type)
|
||||||
{
|
|
||||||
_items.add(new VirtualPadStick(itemRect, code0, code1, bitmap));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
case 0:
|
||||||
_items.add(new VirtualPadButton(itemRect, code0, bitmap, caption));
|
_items.add(new VirtualPadButton(itemRect, code0, bitmap, caption));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_items.add(new VirtualPadStick(itemRect, code0, code1, bitmap));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
_items.add(new VirtualPadDpad(itemRect, bitmap));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
build_android/src/main/res/drawable/dpad.png
Normal file
BIN
build_android/src/main/res/drawable/dpad.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Loading…
Add table
Add a link
Reference in a new issue