v0.3.4a: re-added align methods pt.2
Also moved rendered text multiline into the core game
This commit is contained in:
committed by
Evan Debenham
parent
ac9c50f2ac
commit
b110c0db8c
@@ -20,8 +20,6 @@
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||
@@ -31,6 +29,8 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AttackIndicator extends Tag {
|
||||
|
||||
private static final float ENABLED = 1.0f;
|
||||
@@ -68,6 +68,7 @@ public class AttackIndicator extends Tag {
|
||||
if (sprite != null) {
|
||||
sprite.x = x + (width - sprite.width()) / 2;
|
||||
sprite.y = y + (height - sprite.height()) / 2;
|
||||
PixelScene.align(sprite);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +143,7 @@ public class AttackIndicator extends Tag {
|
||||
|
||||
sprite.x = x + (width - sprite.width()) / 2 + 1;
|
||||
sprite.y = y + (height - sprite.height()) / 2;
|
||||
PixelScene.align(sprite);
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.Image;
|
||||
import com.watabou.noosa.RenderedText;
|
||||
import com.watabou.noosa.audio.Sample;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Badges;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.Image;
|
||||
import com.watabou.noosa.RenderedText;
|
||||
import com.watabou.noosa.audio.Sample;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BadgesList extends ScrollPane {
|
||||
|
||||
@@ -108,9 +108,11 @@ public class BadgesList extends ScrollPane {
|
||||
protected void layout() {
|
||||
icon.x = x;
|
||||
icon.y = y + (height - icon.height) / 2;
|
||||
PixelScene.align(icon);
|
||||
|
||||
label.x = icon.x + icon.width + 2;
|
||||
label.y = y + (height - label.baseLine()) / 2;
|
||||
PixelScene.align(label);
|
||||
}
|
||||
|
||||
public boolean onClick( float x, float y ) {
|
||||
|
||||
@@ -40,11 +40,13 @@ public class CheckBox extends RedButton {
|
||||
|
||||
text.x = x + margin;
|
||||
text.y = y + margin;
|
||||
PixelScene.align(text);
|
||||
|
||||
margin = (height - icon.height) / 2;
|
||||
|
||||
icon.x = x + width - margin - icon.width;
|
||||
icon.y = y + margin;
|
||||
PixelScene.align(icon);
|
||||
}
|
||||
|
||||
public boolean checked() {
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||
|
||||
import com.watabou.noosa.BitmapText;
|
||||
import com.watabou.noosa.Camera;
|
||||
import com.watabou.noosa.Image;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.watabou.noosa.BitmapText;
|
||||
import com.watabou.noosa.Camera;
|
||||
import com.watabou.noosa.Image;
|
||||
|
||||
public class DangerIndicator extends Tag {
|
||||
|
||||
@@ -69,7 +69,8 @@ public class DangerIndicator extends Tag {
|
||||
|
||||
private void placeNumber() {
|
||||
number.x = right() - 11 - number.width();
|
||||
number.y = y + (height - number.baseLine()) / 2;
|
||||
number.y = y + (height - number.baseLine()) / 2f;
|
||||
PixelScene.align(number);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,6 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||
import com.watabou.noosa.RenderedTextMultiline;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
import com.watabou.utils.Signal;
|
||||
|
||||
|
||||
@@ -20,18 +20,19 @@
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.watabou.noosa.Image;
|
||||
import com.watabou.noosa.ui.Button;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.DungeonTilemap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||
import com.watabou.noosa.Image;
|
||||
import com.watabou.noosa.ui.Button;
|
||||
|
||||
public class QuickSlotButton extends Button implements WndBag.Listener {
|
||||
|
||||
@@ -122,6 +123,7 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
|
||||
|
||||
crossB.x = x + (width - crossB.width) / 2;
|
||||
crossB.y = y + (height - crossB.height) / 2;
|
||||
PixelScene.align(crossB);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.watabou.noosa.Image;
|
||||
import com.watabou.noosa.NinePatch;
|
||||
import com.watabou.noosa.RenderedText;
|
||||
import com.watabou.noosa.audio.Sample;
|
||||
import com.watabou.noosa.ui.Button;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
|
||||
public class RedButton extends Button {
|
||||
|
||||
@@ -66,10 +66,12 @@ public class RedButton extends Button {
|
||||
|
||||
text.x = x + (width - text.width()) / 2;
|
||||
text.y = y + (height - text.baseLine()) / 2;
|
||||
PixelScene.align(text);
|
||||
|
||||
if (icon != null) {
|
||||
icon.x = x + text.x - icon.width() - 2;
|
||||
icon.y = y + (height - icon.height()) / 2;
|
||||
PixelScene.align(icon);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2015 Oleg Dolya
|
||||
*
|
||||
* 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.shatteredpixel.shatteredpixeldungeon.ui;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.watabou.noosa.RenderedText;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RenderedTextMultiline extends Component {
|
||||
|
||||
private int maxWidth = Integer.MAX_VALUE;
|
||||
public int nLines;
|
||||
|
||||
private String text;
|
||||
private List<String> tokens;
|
||||
private ArrayList<RenderedText> words = new ArrayList<>();
|
||||
|
||||
private int size;
|
||||
private float zoom;
|
||||
private int color = -1;
|
||||
|
||||
private static final String SPACE = " ";
|
||||
private static final String NEWLINE = "\n";
|
||||
private static final String UNDERSCORE = "_";
|
||||
|
||||
private boolean chinese = false;
|
||||
|
||||
public RenderedTextMultiline(int size){
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public RenderedTextMultiline(String text, int size){
|
||||
this.size = size;
|
||||
text(text);
|
||||
}
|
||||
|
||||
public void text(String text){
|
||||
this.text = text;
|
||||
|
||||
if (text != null && !text.equals("")) {
|
||||
//conversion for chinese text
|
||||
|
||||
chinese = text.replaceAll("\\p{Han}", "").length() != text.length();
|
||||
|
||||
if (chinese){
|
||||
tokens = Arrays.asList(text.split(""));
|
||||
} else {
|
||||
tokens = Arrays.asList(text.split("(?<= )|(?= )|(?<=\n)|(?=\n)"));
|
||||
}
|
||||
build();
|
||||
}
|
||||
}
|
||||
|
||||
public void text(String text, int maxWidth){
|
||||
this.maxWidth = maxWidth;
|
||||
text(text);
|
||||
}
|
||||
|
||||
public String text(){
|
||||
return text;
|
||||
}
|
||||
|
||||
public void maxWidth(int maxWidth){
|
||||
if (this.maxWidth != maxWidth){
|
||||
this.maxWidth = maxWidth;
|
||||
layout();
|
||||
}
|
||||
}
|
||||
|
||||
public int maxWidth(){
|
||||
return maxWidth;
|
||||
}
|
||||
|
||||
private void build(){
|
||||
clear();
|
||||
words = new ArrayList<>();
|
||||
boolean highlighting = false;
|
||||
for (String str : tokens){
|
||||
if (str.equals(UNDERSCORE)){
|
||||
highlighting = !highlighting;
|
||||
} else if (str.equals(NEWLINE)){
|
||||
words.add(null);
|
||||
} else if (!str.equals(SPACE)){
|
||||
RenderedText word;
|
||||
if (str.startsWith(UNDERSCORE) && str.endsWith(UNDERSCORE)){
|
||||
word = new RenderedText(str.substring(1, str.length()-1), size);
|
||||
word.hardlight(0xFFFF44);
|
||||
} else {
|
||||
if (str.startsWith(UNDERSCORE)){
|
||||
highlighting = !highlighting;
|
||||
word = new RenderedText(str.substring(1, str.length()), size);
|
||||
} else if (str.endsWith(UNDERSCORE)) {
|
||||
word = new RenderedText(str.substring(0, str.length()-1), size);
|
||||
} else {
|
||||
word = new RenderedText(str, size);
|
||||
}
|
||||
if (highlighting) word.hardlight(0xFFFF44);
|
||||
else if (color != -1) word.hardlight(color);
|
||||
|
||||
if (str.endsWith(UNDERSCORE)) highlighting = !highlighting;
|
||||
}
|
||||
word.scale.set(zoom);
|
||||
words.add(word);
|
||||
add(word);
|
||||
|
||||
if (height < word.baseLine()) height = word.baseLine();
|
||||
|
||||
}
|
||||
}
|
||||
layout();
|
||||
}
|
||||
|
||||
public void zoom(float zoom){
|
||||
this.zoom = zoom;
|
||||
for (RenderedText word : words) {
|
||||
if (word != null) word.scale.set(zoom);
|
||||
}
|
||||
}
|
||||
|
||||
public void hardlight(int color){
|
||||
this.color = color;
|
||||
for (RenderedText word : words) {
|
||||
if (word != null) word.hardlight( color );
|
||||
}
|
||||
}
|
||||
|
||||
public void invert(){
|
||||
if (words != null) {
|
||||
for (RenderedText word : words) {
|
||||
if (word != null) {
|
||||
word.ra = 0.77f;
|
||||
word.ga = 0.73f;
|
||||
word.ba = 0.62f;
|
||||
word.rm = -0.77f;
|
||||
word.gm = -0.73f;
|
||||
word.bm = -0.62f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
super.layout();
|
||||
float x = this.x;
|
||||
float y = this.y;
|
||||
float height = 0;
|
||||
nLines = 1;
|
||||
|
||||
for (RenderedText word : words){
|
||||
if (word == null) {
|
||||
//newline
|
||||
y += height+0.5f;
|
||||
x = this.x;
|
||||
nLines++;
|
||||
} else {
|
||||
if (word.height() > height) height = word.baseLine();
|
||||
|
||||
if ((x - this.x) + word.width() > maxWidth){
|
||||
y += height+0.5f;
|
||||
x = this.x;
|
||||
nLines++;
|
||||
}
|
||||
|
||||
word.x = x;
|
||||
word.y = y;
|
||||
PixelScene.align(word);
|
||||
x += word.width();
|
||||
if (!chinese) x ++;
|
||||
else x--;
|
||||
|
||||
if ((x - this.x) > width) width = (x - this.x);
|
||||
|
||||
}
|
||||
}
|
||||
this.height = (y - this.y) + height+0.5f;
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,9 @@ public class ResumeIndicator extends Tag {
|
||||
protected void layout() {
|
||||
super.layout();
|
||||
|
||||
icon.x = x+1 + (width - icon.width) / 2;
|
||||
icon.y = y + (height - icon.height) / 2;
|
||||
icon.x = x+1 + (width - icon.width) / 2f;
|
||||
icon.y = y + (height - icon.height) / 2f;
|
||||
PixelScene.align(icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,17 @@
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.BloodParticle;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
|
||||
import com.watabou.input.Touchscreen.Touch;
|
||||
import com.watabou.noosa.BitmapText;
|
||||
import com.watabou.noosa.Camera;
|
||||
@@ -31,16 +42,6 @@ import com.watabou.noosa.particles.BitmaskEmitter;
|
||||
import com.watabou.noosa.particles.Emitter;
|
||||
import com.watabou.noosa.ui.Button;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.BloodParticle;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
|
||||
|
||||
public class StatusPane extends Component {
|
||||
|
||||
@@ -138,11 +139,13 @@ public class StatusPane extends Component {
|
||||
|
||||
shield.size( width, shield.height );
|
||||
|
||||
avatar.x = shield.x + 15 - avatar.width / 2;
|
||||
avatar.y = shield.y + 16 - avatar.height / 2;
|
||||
avatar.x = shield.x + 15 - avatar.width / 2f;
|
||||
avatar.y = shield.y + 16 - avatar.height / 2f;
|
||||
PixelScene.align(avatar);
|
||||
|
||||
compass.x = avatar.x + avatar.width / 2 - compass.origin.x;
|
||||
compass.y = avatar.y + avatar.height / 2 - compass.origin.y;
|
||||
compass.x = avatar.x + avatar.width / 2f - compass.origin.x;
|
||||
compass.y = avatar.y + avatar.height / 2f - compass.origin.y;
|
||||
PixelScene.align(compass);
|
||||
|
||||
hp.x = 30;
|
||||
hp.y = 3;
|
||||
@@ -193,8 +196,9 @@ public class StatusPane extends Component {
|
||||
lastLvl = Dungeon.hero.lvl;
|
||||
level.text( Integer.toString( lastLvl ) );
|
||||
level.measure();
|
||||
level.x = 27.5f - level.width() / 2;
|
||||
level.y = 28.0f - level.baseLine() / 2;
|
||||
level.x = 27.5f - level.width() / 2f;
|
||||
level.y = 28.0f - level.baseLine() / 2f;
|
||||
PixelScene.align(level);
|
||||
}
|
||||
|
||||
int k = IronKey.curDepthQuantity;
|
||||
|
||||
@@ -20,11 +20,10 @@
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||
|
||||
import com.watabou.noosa.NinePatch;
|
||||
import com.watabou.noosa.RenderedTextMultiline;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.watabou.noosa.NinePatch;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
|
||||
public class Toast extends Component {
|
||||
|
||||
@@ -70,10 +69,12 @@ public class Toast extends Component {
|
||||
bg.size( width, height );
|
||||
|
||||
close.setPos(
|
||||
bg.x + bg.width() - bg.marginHor() / 2 - MARGIN_HOR - close.width(),
|
||||
y + (height - close.height()) / 2 );
|
||||
bg.x + bg.width() - bg.marginHor() / 2f - MARGIN_HOR - close.width(),
|
||||
y + (height - close.height()) / 2f );
|
||||
PixelScene.align(close);
|
||||
|
||||
text.setPos(close.left() - MARGIN_HOR - text.width(), y + (height - text.height()) / 2);
|
||||
PixelScene.align(text);
|
||||
}
|
||||
|
||||
public void text( String txt ) {
|
||||
|
||||
Reference in New Issue
Block a user