Skip to content

Commit

Permalink
Testing potential dialog system
Browse files Browse the repository at this point in the history
  • Loading branch information
Meshulam Silk committed Nov 24, 2013
1 parent 3871b13 commit 6fd3151
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/com/moomoohk/Grame/AI/AStarPathfindingMovementAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void newGame()
AStarPathfindingMovementAI aStar = new AStarPathfindingMovementAI();
monster.addAI(aStar, b.ID);
monster.setSpeed(5);
b.addGrameObject(player, new Coordinates(0, 0));
b.addGrameObject(player, new Coordinates(10, 10));
b.addGrameObject(monster, new Coordinates(18, 10), 1);
for (int i = 1; i <= 10; i++)
new Schematic().load(b, GrameUtils.randomCoordinates(b));
Expand Down
2 changes: 2 additions & 0 deletions src/com/moomoohk/Grame/Essentials/GrameUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.moomoohk.Grame.commands.SetSpriteCommand;
import com.moomoohk.Grame.commands.SetVisibleCommand;
import com.moomoohk.Grame.commands.SetWraparoundCommand;
import com.moomoohk.Grame.commands.ShowDialogCommand;
import com.moomoohk.MooCommands.CommandsManager;
import com.moomoohk.MooConsole.Console;
import com.moomoohk.MooConsole.HelpCommand;
Expand Down Expand Up @@ -479,6 +480,7 @@ private static void loadBasicCommands()
new SetSpeedCommand();
new SetSpriteCommand();
new SetWraparoundCommand();
new ShowDialogCommand();
print("Loaded " + (CommandsManager.getAllCommands().size() - prevLength) + " commands.", MessageLevel.DEBUG);
}

Expand Down
13 changes: 13 additions & 0 deletions src/com/moomoohk/Grame/Graphics/PostProcessing/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public class Label
private Color textColor, backColor;
private Font font;

public Label()
{
this(0, 0, null, null, null, null, 0, 0, 0, 0);
}

public Label(int centerX, int centerY, String text, Font font, Color textColor, Color backColor, int paddingTop, int paddingLeft, int paddingRight, int paddingBottom)
{
this.centerX = centerX;
Expand Down Expand Up @@ -54,6 +59,14 @@ public int getPaddingLeft()
return paddingLeft;
}

public void setPadding(int padding)
{
this.paddingTop = padding;
this.paddingLeft = padding;
this.paddingRight = padding;
this.paddingBottom = padding;
}

public void setPaddingBottom(int paddingBottom)
{
this.paddingBottom = paddingBottom;
Expand Down
16 changes: 14 additions & 2 deletions src/com/moomoohk/Grame/Graphics/RenderManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ public static void render(final int bID, Render render)
applyGaussianBlur();
setOverlayColor(Color.gray.brighter());
drawLabel(new Label(mainCanvas.getWidth() / 2, mainCanvas.getHeight() / 2, "Paused", new Font("LucidaTypewriter", Font.BOLD, 40), Color.white, Color.black, 10, 15, 15, 10));
for (Label l : labels)
drawLabel(l);
}

for (Label l : labels)
drawLabel(l);

if (drawCoordinates)
{
g2.setColor(Color.blue);
Expand Down Expand Up @@ -393,4 +394,15 @@ public static void dispose()
mainFrame.dispose();
}
}

public static void addLabel(Label l)
{
labels.add(l);
}

public static void removeLabel(Label l)
{
if(labels.contains(l))
labels.remove(l);
}
}
51 changes: 51 additions & 0 deletions src/com/moomoohk/Grame/commands/ShowDialogCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.moomoohk.Grame.commands;

import java.util.ArrayList;

import com.moomoohk.Grame.Essentials.GrameManager;
import com.moomoohk.Grame.test.Dialog;
import com.moomoohk.MooCommands.Command;

public class ShowDialogCommand extends Command
{

@Override
public String getCommand()
{
return "dialog";
}

@Override
public String getHelpMessage()
{
return "DEBUG: Prints some dialog on a speecified Grame Object";
}

@Override
public String getUsage()
{
return "dialog <go ID>";
}

@Override
public int getMaxParams()
{
return 1;
}

@Override
public int getMinParams()
{
return 1;
}

@Override
protected void execute(String[] params)
{
ArrayList<String> lines = new ArrayList<String>();
lines.add("My name is Inigo Montoya");
lines.add("You killed my father");
lines.add("Prepare to die");
new Dialog(lines, 5000, GrameManager.findGrameObject(Integer.parseInt(params[0]))).start();
}
}
70 changes: 70 additions & 0 deletions src/com/moomoohk/Grame/test/Dialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.moomoohk.Grame.test;

import java.awt.Color;
import java.util.ArrayList;

import com.moomoohk.Grame.Essentials.Coordinates;
import com.moomoohk.Grame.Essentials.GrameManager;
import com.moomoohk.Grame.Graphics.RenderManager;
import com.moomoohk.Grame.Graphics.PostProcessing.Label;
import com.moomoohk.Grame.Interfaces.GrameObject;

public class Dialog implements Runnable
{
private ArrayList<String> lines;
private Label label;
private long interval;
private GrameObject go;

public Dialog(ArrayList<String> lines, long interval, GrameObject go)
{
this.label = new Label();
this.label.setBackColor(Color.black);
this.label.setTextColor(Color.white);
this.label.setPadding(10);
this.lines = lines;
this.interval = interval;
this.go = go;
RenderManager.addLabel(this.label);
}

public void start()
{
new Thread(this).start();
}

@Override
public void run()
{
GrameManager.pauseAllGrameObjects(true);
int squareWidth = RenderManager.getMainCanvas().getWidth() / GrameManager.findBase(RenderManager.getMainBase()).getColumns(), squareHeight = RenderManager.getMainCanvas().getHeight() / GrameManager.findBase(RenderManager.getMainBase()).getRows();
Coordinates goPos = this.go.getPos(RenderManager.getMainBase());
this.label.setCenterX(Math.max(50, goPos.getX() * squareWidth + squareWidth / 2));
this.label.setCenterY(Math.max(50, goPos.getY() * squareHeight));
for (String line : this.lines)
{
for (int i = 0; i <= line.length(); i++)
{
this.label.setText(line.substring(0, i));
try
{
Thread.sleep(50);
}
catch (Exception e)
{
e.printStackTrace();
}
}
try
{
Thread.sleep(this.interval);
}
catch (Exception e)
{
e.printStackTrace();
}
}
RenderManager.removeLabel(this.label);
GrameManager.pauseAllGrameObjects(false);
}
}

0 comments on commit 6fd3151

Please sign in to comment.