Added sample tutorial text / Refactoring

This commit is contained in:
Anuken
2018-09-22 12:20:04 -04:00
parent 999dd5eb6f
commit b77caed0ba
16 changed files with 199 additions and 93 deletions

View File

@@ -110,9 +110,9 @@ public class SectorsDialog extends FloatingDialog{
float padSectorSize = sectorSize + sectorPadding;
float clipSize = Math.min(width, height);
int shownSectors = (int)(clipSize/padSectorSize);
clip.setSize(clipSize).setCenter(x + width/2f, y + height/2f);
int shownSectorsX = (int)(width/padSectorSize);
int shownSectorsY = (int)(height/padSectorSize);
clip.setSize(width, height).setCenter(x + width/2f, y + height/2f);
Graphics.flush();
boolean clipped = ScissorStack.pushScissors(clip);
@@ -121,8 +121,8 @@ public class SectorsDialog extends FloatingDialog{
Vector2 mouse = Graphics.mouse();
for(int x = -shownSectors; x <= shownSectors; x++){
for(int y = -shownSectors; y <= shownSectors; y++){
for(int x = -shownSectorsX; x <= shownSectorsX; x++){
for(int y = -shownSectorsY; y <= shownSectorsY; y++){
int sectorX = offsetX + x;
int sectorY = offsetY + y;
@@ -130,19 +130,21 @@ public class SectorsDialog extends FloatingDialog{
float drawY = y + height/2f + sectorY * padSectorSize - offsetY * padSectorSize - panY % padSectorSize;
Sector sector = world.sectors().get(sectorX, sectorY);
int size = (sector == null ? 1 : sector.width);
float padding = (size-1) * sectorPadding;
int width = (sector == null ? 1 : sector.width);
int height = (sector == null ? 1 : sector.height);
float paddingx = (width-1) * sectorPadding;
float paddingy = (height-1) * sectorPadding;
if(sector != null && (sector.x != sectorX || sector.y != sectorY)){
continue;
}
drawX += (size-1)/2f*padSectorSize;
drawY += (size-1)/2f*padSectorSize;
drawX += (width-1)/2f*padSectorSize;
drawY += (height-1)/2f*padSectorSize;
if(sector != null && sector.texture != null){
Draw.color(Color.WHITE);
Draw.rect(sector.texture, drawX, drawY, sectorSize * size + padding, sectorSize * size + padding);
Draw.rect(sector.texture, drawX, drawY, sectorSize * width + paddingx, sectorSize * height + paddingy);
}
float stroke = 4f;
@@ -152,8 +154,8 @@ public class SectorsDialog extends FloatingDialog{
}else if(sector == selected){
Draw.color(Palette.place);
stroke = 6f;
}else if(Mathf.inRect(mouse.x, mouse.y, drawX - padSectorSize/2f * size, drawY - padSectorSize/2f * size,
drawX + padSectorSize/2f * size, drawY + padSectorSize/2f * size)){
}else if(Mathf.inRect(mouse.x, mouse.y, drawX - padSectorSize/2f * width, drawY - padSectorSize/2f * height,
drawX + padSectorSize/2f * width, drawY + padSectorSize/2f * height)){
if(clicked){
selectSector(sector);
}
@@ -165,13 +167,13 @@ public class SectorsDialog extends FloatingDialog{
}
Lines.stroke(Unit.dp.scl(stroke));
Lines.crect(drawX, drawY, sectorSize * size + padding, sectorSize * size + padding, (int)stroke);
Lines.crect(drawX, drawY, sectorSize * width + paddingx, sectorSize * height + paddingy, (int)stroke);
}
}
Draw.color(Palette.accent);
Lines.stroke(Unit.dp.scl(4f));
Lines.crect(x + width/2f, y + height/2f, clipSize, clipSize);
Lines.crect(x + width/2f, y + height/2f, width, height);
Draw.reset();
Graphics.flush();

View File

@@ -16,15 +16,14 @@ import io.anuke.mindustry.net.Packets.AdminAction;
import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.ui.IntFormat;
import io.anuke.mindustry.ui.Minimap;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.ucore.core.*;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.scene.Element;
import io.anuke.ucore.scene.Group;
import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.Image;
import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.scene.ui.Label;
import io.anuke.ucore.scene.ui.*;
import io.anuke.ucore.scene.ui.layout.Stack;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
@@ -104,7 +103,8 @@ public class HudFragment extends Fragment{
cont.row();
Table waves = cont.table(this::addWaveTable).touchable(Touchable.enabled).fillX().height(66f).get();
TextButton waves = cont.addButton("", ()->{}).fillX().height(66f).get();
addWaveTable(waves);
cont.row();
@@ -183,6 +183,27 @@ public class HudFragment extends Fragment{
blockfrag.build(Core.scene.getRoot());
}
public void showText(String text){
Table table = new Table("button");
table.update(() -> {
if(state.is(State.menu)){
table.remove();
}
});
table.margin(12);
table.addImage("icon-check").size(16*2).pad(3);
table.add(text).wrap().width(280f).get().setAlignment(Align.center, Align.center);
table.pack();
//create container table which will align and move
Table container = Core.scene.table();
container.top().add(table);
container.setTranslation(0, table.getPrefHeight());
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(4f),
//nesting actions() calls is necessary so the right prefHeight() is used
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.removeActor())));
}
/**
* Show unlock notification for a new recipe.
*/
@@ -282,6 +303,16 @@ public class HudFragment extends Fragment{
}
}
public void showTextDialog(String str){
new FloatingDialog("$text.mission.info"){{
shouldPause = true;
setFillParent(false);
getCell(content()).growX();
content().margin(15).add(str).width(600f).wrap().get().setAlignment(Align.left, Align.left);
buttons().addButton("$text.continue", this::hide).size(140, 60).pad(4);
}}.show();
}
private void toggleMenus(){
wavetable.clearActions();
infolabel.clearActions();
@@ -313,21 +344,30 @@ public class HudFragment extends Fragment{
}
}
private void addWaveTable(Table table){
private void addWaveTable(TextButton table){
wavetable = table;
float uheight = 66f;
IntFormat wavef = new IntFormat("text.wave");
IntFormat timef = new IntFormat("text.wave.waiting");
table.clearChildren();
table.setTouchable(Touchable.enabled);
table.background("button");
table.labelWrap(() -> world.getSector() == null ? wavef.get(state.wave) :
Bundles.format("text.mission.display", world.getSector().currentMission().displayString())).growX()
.get().setAlignment(Align.center, Align.center);
Bundles.format("text.mission.display", world.getSector().currentMission().displayString())).growX();
table.clicked(() -> {
if(world.getSector() != null && world.getSector().currentMission().hasMessage()){
world.getSector().currentMission().showMessage();
}
});
table.setDisabled(() -> !(world.getSector() != null && world.getSector().currentMission().hasMessage()));
table.visible(() -> !((world.getSector() == null && state.mode.disableWaves) || !state.mode.showMission));
playButton(uheight);
//playButton(uheight);
}
private void playButton(float uheight){