Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended log and alternative navigation. #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added assets/joystick.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/toolbar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/com/watabou/pixeldungeon/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Assets {
public static final String HP_BAR = "hp_bar.png";
public static final String XP_BAR = "exp_bar.png";
public static final String TOOLBAR = "toolbar.png";
public static final String JOYSTICK = "joystick.png";

public static final String WARRIOR = "warrior.png";
public static final String MAGE = "mage.png";
Expand Down
19 changes: 19 additions & 0 deletions src/com/watabou/pixeldungeon/PixelDungeon.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,25 @@ public static void intro( boolean value ) {
public static boolean intro() {
return Preferences.INSTANCE.getBoolean( Preferences.KEY_INTRO, true );
}

public static void joystick( boolean value ) {
Preferences.INSTANCE.put( Preferences.KEY_JOYSTICK, value );
if (scene() instanceof GameScene) {
((GameScene)scene()).joystick( value );
}
}

public static boolean joystick () {
return Preferences.INSTANCE.getBoolean( Preferences.KEY_JOYSTICK, true );
}

public static void continuous( boolean value ) {
Preferences.INSTANCE.put( Preferences.KEY_CONTINUOUS, value );
}

public static boolean continuous () {
return Preferences.INSTANCE.getBoolean( Preferences.KEY_CONTINUOUS, true );
}

/*
* <--- Preferences
Expand Down
2 changes: 2 additions & 0 deletions src/com/watabou/pixeldungeon/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ enum Preferences {
public static final String KEY_DONATED = "donated";
public static final String KEY_INTRO = "intro";
public static final String KEY_BRIGHTNESS = "brightness";
public static final String KEY_JOYSTICK = "joystick";
public static final String KEY_CONTINUOUS = "continuous";

private SharedPreferences prefs;

Expand Down
82 changes: 82 additions & 0 deletions src/com/watabou/pixeldungeon/scenes/CellSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@

import com.watabou.input.Touchscreen.Touch;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.Game;
import com.watabou.pixeldungeon.Dungeon;
import com.watabou.pixeldungeon.DungeonTilemap;
import com.watabou.pixeldungeon.PixelDungeon;
import com.watabou.pixeldungeon.levels.Level;
import com.watabou.utils.GameMath;
import com.watabou.utils.PointF;
import com.watabou.utils.Point;

public class CellSelector extends TouchArea {

Expand All @@ -31,6 +35,11 @@ public class CellSelector extends TouchArea {
public boolean enabled;

private float dragThreshold;

private boolean pressed;
private float pressTime;
private boolean continuous;
private float continuousThreshold = 0.2f;

public CellSelector( DungeonTilemap map ) {
super( map );
Expand Down Expand Up @@ -73,6 +82,7 @@ public void select( int cell ) {

@Override
protected void onTouchDown( Touch t ) {
continuous = false;

if (t != touch && another == null) {

Expand All @@ -89,11 +99,80 @@ protected void onTouchDown( Touch t ) {
startZoom = camera.zoom;

dragging = false;
} else {
pressed = true;
}
}

@Override
public void update () {
if (!pressed || dragging || pinching)
return;

if (!(pressTime >= continuousThreshold)) {
pressTime += Game.elapsed;
return;
}

continuous = PixelDungeon.continuous();
if (!continuous)
return;

float size = DungeonTilemap.SIZE*camera.zoom;
PointF p = Dungeon.hero.sprite.worldToCamera( Dungeon.hero.pos );
Point hero = camera.cameraToScreen (p.x, p.y);
hero.x += size/2;
hero.y += size/2;
float x = Math.abs( touch.current.x - hero.x );
float y = Math.abs( touch.current.y - hero.y );
float x2 = 0, y2 = 0;
if (Math.abs(x) > Math.abs(y)) {
x2 += size;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same for if and else.

y2 += (y*(x2/x));
} else {
y2 += size;
x2 += (x*(y2/y));
}

if (touch.current.x < hero.x)
x2 *= -1;

if (touch.current.y < hero.y)
y2 *= -1;

int cell = ((DungeonTilemap)target).screenToTile( hero.x + (int)x2, hero.y + (int)y2 );
if (!Dungeon.level.passable[cell]) {
int[] neighbours = {Dungeon.hero.pos+1,
Dungeon.hero.pos+1+Level.WIDTH,
Dungeon.hero.pos+Level.WIDTH,
Dungeon.hero.pos-1+Level.WIDTH,
Dungeon.hero.pos-1,
Dungeon.hero.pos-1-Level.WIDTH,
Dungeon.hero.pos-Level.WIDTH,
Dungeon.hero.pos+1-Level.WIDTH};

for (int i = 0; i < 8; i++) {
if (neighbours[i] != cell)
continue;

int next = (i+1 >= 8) ? 0 : i+1;
int prv = (i-1 < 0) ? 7 : i-1;

if (Dungeon.level.passable[neighbours[next]])
cell = neighbours[next];

if (Dungeon.level.passable[neighbours[prv]])
cell = neighbours[prv];
}
}

select( cell );
}

@Override
protected void onTouchUp( Touch t ) {
pressed = false;
pressTime = 0;
if (pinching && (t == touch || t == another)) {

pinching = false;
Expand All @@ -117,6 +196,9 @@ protected void onTouchUp( Touch t ) {
@Override
protected void onDrag( Touch t ) {

if (continuous)
return;

camera.target = null;

if (pinching) {
Expand Down
14 changes: 13 additions & 1 deletion src/com/watabou/pixeldungeon/scenes/GameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.watabou.pixeldungeon.ui.Toast;
import com.watabou.pixeldungeon.ui.Toolbar;
import com.watabou.pixeldungeon.ui.Window;
import com.watabou.pixeldungeon.ui.Joystick;
import com.watabou.pixeldungeon.utils.GLog;
import com.watabou.pixeldungeon.windows.WndBag.Mode;
import com.watabou.pixeldungeon.windows.WndGame;
Expand Down Expand Up @@ -109,6 +110,7 @@ public class GameScene extends PixelScene {
private Group statuses;
private Group emoicons;

private Joystick joystick;
private Toolbar toolbar;
private Toast prompt;

Expand Down Expand Up @@ -136,7 +138,7 @@ public void create() {

ripples = new Group();
terrain.add( ripples );

tiles = new DungeonTilemap();
terrain.add( tiles );

Expand Down Expand Up @@ -228,6 +230,12 @@ public void create() {
log.camera = uiCamera;
log.setRect( 0, toolbar.top(), attack.left(), 0 );
add( log );

joystick = new Joystick ();
joystick.camera = uiCamera;
joystick.setPos(5, toolbar.top()-60);
joystick (PixelDungeon.joystick ());
add (joystick);

if (Dungeon.depth < Statistics.deepestFloor) {
GLog.i( TXT_WELCOME_BACK, Dungeon.depth );
Expand Down Expand Up @@ -364,6 +372,10 @@ public void brightness( boolean value ) {
fog.aa = 0f;
}
}

public void joystick( boolean value ) {
joystick.visible = value;
}

private void addHeapSprite( Heap heap ) {
ItemSprite sprite = heap.sprite = (ItemSprite)heaps.recycle( ItemSprite.class );
Expand Down
42 changes: 38 additions & 4 deletions src/com/watabou/pixeldungeon/ui/GameLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@
package com.watabou.pixeldungeon.ui;

import java.util.regex.Pattern;
import java.util.List;
import java.util.ArrayList;

import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.ui.Component;
import com.watabou.noosa.Gizmo;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.noosa.TouchArea;
import com.watabou.pixeldungeon.windows.WndLog;
import com.watabou.pixeldungeon.scenes.PixelScene;
import com.watabou.pixeldungeon.sprites.CharSprite;
import com.watabou.pixeldungeon.utils.GLog;
import com.watabou.pixeldungeon.utils.Utils;
import com.watabou.pixeldungeon.scenes.GameScene;

import com.watabou.utils.Signal;

public class GameLog extends Component implements Signal.Listener<String> {
Expand All @@ -34,7 +42,10 @@ public class GameLog extends Component implements Signal.Listener<String> {
private static final Pattern PUNCTUATION = Pattern.compile( ".*[.,;?! ]$" );

private BitmapTextMultiline lastEntry;
private List<BitmapTextMultiline> entries = new ArrayList<BitmapTextMultiline> ();
private int lastColor;
private WndLog window;
private TouchArea hotArea;

public GameLog() {
super();
Expand All @@ -47,6 +58,16 @@ public void newLine() {
lastEntry = null;
}

@Override
protected void createChildren() {
hotArea = new TouchArea( 0, 0, 0, 0 ) {
protected void onTouchUp( Touch touch ) {
GameScene.show( new WndLog (entries) );
}
};
add( hotArea );
}

@Override
public void onSignal( String text ) {

Expand Down Expand Up @@ -84,26 +105,39 @@ public void onSignal( String text ) {
lastEntry.measure();
lastEntry.hardlight( color );
lastColor = color;
entries.add ( lastEntry );
add( lastEntry );

}

if (length > MAX_MESSAGES) {
remove( members.get( 0 ) );
remove( entries.get(entries.size()-MAX_MESSAGES) );
}

layout();
}

@Override
protected void layout() {
float pos = y;
float pos = bottom();
for (int i=length-1; i >= 0; i--) {
BitmapTextMultiline entry = (BitmapTextMultiline)members.get( i );
Gizmo item = members.get( i );
if (item == hotArea)
continue;

BitmapTextMultiline entry = (BitmapTextMultiline)item;
entry.x = x;
entry.y = pos - entry.height();
pos -= entry.height();
}

height = bottom ()-pos;
y = pos;

hotArea.active = visible;
hotArea.x = x;
hotArea.y = y;
hotArea.width = width;
hotArea.height = height;
}

@Override
Expand Down