1
0

Implement DIALOG (4)

This commit is contained in:
otya128
2016-12-26 22:53:27 +09:00
parent 0f5c8e08a2
commit f556a83695

View File

@@ -13,6 +13,13 @@ class DialogBase
abstract void render();
}
enum ButtonType
{
abxyButton = 1,
dpad = 2,
lrButton = 4,
touchPanel = 8,
}
enum SelectionType
{
ok,
@@ -210,6 +217,10 @@ class Dialog : DialogBase
int show(wstring text, SelectionType selType = SelectionType.ok, wstring caption = "■DIALOG", int timeout = 0)
{
if (selType >= cast(ptrdiff_t)petitcom.dialogResource.buttonCaptions.length || -selType >= 15)
{
throw new OutOfRange("DIALOG", 2);
}
area = petitcom.showTouchScreen();
scope (exit)
petitcom.hideTouchScreen();
@@ -229,11 +240,16 @@ class Dialog : DialogBase
int buttonMarginWidth = 12;
int buttonMarginHeight = 12;
int buttonCount;
Text button1text;
DialogButton button1;
Text button2text;
DialogButton button2;
if (selType >= 0)
{
auto cs = petitcom.dialogResource.buttonCaptions[cast(size_t)selType];
auto button1text = Text(petitcom, cs[0], SDL_Color(0, 0, 0, 255));
auto button1 =
button1text = Text(petitcom, cs[0], SDL_Color(0, 0, 0, 255));
button1 =
new DialogButton(
petitcom.dialogResource.button1,
button1text.texture,
@@ -243,8 +259,6 @@ class Dialog : DialogBase
22,
1
);
Text button2text;
DialogButton button2;
if (cs.length > 1)
{
ubyte sr, sg, sb, sa;
@@ -266,6 +280,7 @@ class Dialog : DialogBase
{
buttons = [button1];
}
}
petitcom.dialog = this;
scope (exit)
petitcom.dialog = null;
@@ -280,8 +295,12 @@ class Dialog : DialogBase
timeoutframe = -timeout;
}
auto startmaincnt = petitcom.maincnt;
auto oldbutton = petitcom.button;
while (!isPressed)
{
auto pbutton = petitcom.button;
auto button = pbutton ^ oldbutton & pbutton;
oldbutton = pbutton;
petitcom.maincnt++;
if (petitcom.maincnt - startmaincnt == timeoutframe)
{
@@ -290,6 +309,8 @@ class Dialog : DialogBase
auto to = petitcom.touchPosition();
auto x = to.display1X;
auto y = to.display1Y;
if (selType >= 0)
{
foreach (b; buttons)
{
if (to.tm == 1 && b.colDetect(x, y))
@@ -302,6 +323,78 @@ class Dialog : DialogBase
isPressed = true;
}
}
}
else
{
auto buttonType = -selType;
if (buttonType & ButtonType.abxyButton)
{
if (button & Button.A)
{
result = ButtonResult.a;
break;
}
if (button & Button.B)
{
result = ButtonResult.b;
break;
}
if (button & Button.X)
{
result = ButtonResult.x;
break;
}
if (button & Button.Y)
{
result = ButtonResult.y;
break;
}
}
if (buttonType & ButtonType.dpad)
{
if (button & Button.UP)
{
result = ButtonResult.up;
break;
}
if (button & Button.DOWN)
{
result = ButtonResult.down;
break;
}
if (button & Button.LEFT)
{
result = ButtonResult.left;
break;
}
if (button & Button.RIGHT)
{
result = ButtonResult.right;
break;
}
}
if (buttonType & ButtonType.lrButton)
{
if (button & Button.L)
{
result = ButtonResult.l;
break;
}
if (button & Button.R)
{
result = ButtonResult.r;
break;
}
}
if (buttonType & ButtonType.touchPanel)
{
if (to.tm == 1)
{
result = ButtonResult.touch;
break;
}
}
}
SDL_Delay(16);
}
return result;