Converted ShatteredPD to Build from Gradle
Major Changes: - Shattered now builds effortlessly either from gradle CLI or android studio - Much better dependency management through gradle (although it's not really used atm) - Separate PD-classes repo is now SPD-classes module within main repo
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Pixel Dungeon
|
||||
* Copyright (C) 2012-2015 Oleg Dolya
|
||||
*
|
||||
* Shattered Pixel Dungeon
|
||||
* Copyright (C) 2014-2016 Evan Debenham
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package com.watabou.noosa.ui;
|
||||
|
||||
import com.watabou.input.Touchscreen.Touch;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.TouchArea;
|
||||
|
||||
public class Button extends Component {
|
||||
|
||||
public static float longClick = 1f;
|
||||
|
||||
protected TouchArea hotArea;
|
||||
|
||||
protected boolean pressed;
|
||||
protected float pressTime;
|
||||
|
||||
protected boolean processed;
|
||||
|
||||
@Override
|
||||
protected void createChildren() {
|
||||
hotArea = new TouchArea( 0, 0, 0, 0 ) {
|
||||
@Override
|
||||
protected void onTouchDown(Touch touch) {
|
||||
pressed = true;
|
||||
pressTime = 0;
|
||||
processed = false;
|
||||
Button.this.onTouchDown();
|
||||
};
|
||||
@Override
|
||||
protected void onTouchUp(Touch touch) {
|
||||
pressed = false;
|
||||
Button.this.onTouchUp();
|
||||
};
|
||||
@Override
|
||||
protected void onClick( Touch touch ) {
|
||||
if (!processed) {
|
||||
Button.this.onClick();
|
||||
}
|
||||
};
|
||||
};
|
||||
add( hotArea );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
|
||||
hotArea.active = visible;
|
||||
|
||||
if (pressed) {
|
||||
if ((pressTime += Game.elapsed) >= longClick) {
|
||||
pressed = false;
|
||||
if (onLongClick()) {
|
||||
|
||||
hotArea.reset();
|
||||
processed = true;
|
||||
onTouchUp();
|
||||
|
||||
Game.vibrate( 50 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void onTouchDown() {};
|
||||
protected void onTouchUp() {};
|
||||
protected void onClick() {};
|
||||
|
||||
protected boolean onLongClick() {
|
||||
return false;
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
hotArea.x = x;
|
||||
hotArea.y = y;
|
||||
hotArea.width = width;
|
||||
hotArea.height = height;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Pixel Dungeon
|
||||
* Copyright (C) 2012-2015 Oleg Dolya
|
||||
*
|
||||
* Shattered Pixel Dungeon
|
||||
* Copyright (C) 2014-2016 Evan Debenham
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package com.watabou.noosa.ui;
|
||||
|
||||
public class CheckBox extends Button {
|
||||
|
||||
protected boolean checked;
|
||||
|
||||
public boolean checked() {
|
||||
return checked;
|
||||
}
|
||||
|
||||
public void checked( boolean value ) {
|
||||
if (checked != value) {
|
||||
checked = value;
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateState() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
checked( !checked );
|
||||
onChange();
|
||||
}
|
||||
|
||||
protected void onChange() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Pixel Dungeon
|
||||
* Copyright (C) 2012-2015 Oleg Dolya
|
||||
*
|
||||
* Shattered Pixel Dungeon
|
||||
* Copyright (C) 2014-2016 Evan Debenham
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package com.watabou.noosa.ui;
|
||||
|
||||
import com.watabou.noosa.Group;
|
||||
|
||||
public class Component extends Group {
|
||||
|
||||
protected float x;
|
||||
protected float y;
|
||||
protected float width;
|
||||
protected float height;
|
||||
|
||||
public Component() {
|
||||
super();
|
||||
createChildren();
|
||||
}
|
||||
|
||||
public Component setPos( float x, float y ) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
layout();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Component setSize( float width, float height ) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
layout();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Component setRect( float x, float y, float width, float height ) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
layout();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean inside( float x, float y ) {
|
||||
return x >= this.x && y >= this.y && x < this.x + width && y < this.y + height;
|
||||
}
|
||||
|
||||
public void fill( Component c ) {
|
||||
setRect( c.x, c.y, c.width, c.height );
|
||||
}
|
||||
|
||||
public float left() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float right() {
|
||||
return x + width;
|
||||
}
|
||||
|
||||
public float centerX() {
|
||||
return x + width / 2;
|
||||
}
|
||||
|
||||
public float top() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public float bottom() {
|
||||
return y + height;
|
||||
}
|
||||
|
||||
public float centerY() {
|
||||
return y + height / 2;
|
||||
}
|
||||
|
||||
public float width() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public float height() {
|
||||
return height;
|
||||
}
|
||||
|
||||
protected void createChildren() {
|
||||
}
|
||||
|
||||
protected void layout() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user