package ru.vagrant_ai.questionmarkgame.obj;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import ru.vagrant_ai.questionmarkgame.main.Game;
import ru.vagrant_ai.questionmarkgame.main.GameplayState;
import ru.vagrant_ai.questionmarkgame.util.MenuButton;
import ru.vagrant_ai.questionmarkgame.util.Text;
import ru.vagrant_ai.questionmarkgame.util.Util;
import ru.vagrant_ai.questionmarkgame.util.list.ITEM;
public class Pause {
private static Image delay;
private static Image power;
private static Image reload;
private static Image spreading;
private final static Color pause_background_col = new Color(20, 20, 20, 85);
private final static Color pause_text_background_col = new Color(5, 5, 5, 200);
private final static Color pause_text_col = new Color(245, 245, 245);
private final static Color pause_text_col2 = new Color(255, 128, 128);
final static byte util_pause_offset = 25;
public static boolean util_state_paused;
static byte util_state_paused_iter;
private final static byte util_state_paused_iter_max = 20;
private static byte state; //0 - menu, 1 - statistic screen, 2 - control screen
public Pause()
{
delay = Util.loadImage("particle/item_icons/p_gun_getdelay1");
power = Util.loadImage("particle/item_icons/p_gun_getpower1");
reload = Util.loadImage("particle/item_icons/p_gun_getreload1");
spreading = Util.loadImage("particle/item_icons/p_gun_getspreading1");
util_state_paused_iter = 0;
util_state_paused = false;
state = 0;
}
public static void render(Graphics g)
{
g.setColor(pause_background_col);
g.fillRect(0, 0, Game.getAppX(), Game.getAppY());
g.setColor(pause_text_background_col);
g.fillRoundRect(200, 170, 400, 260, 25);
Text.drawString(80, Text.extractLength("[PAUSED]", 80), 180+util_pause_offset*0 /*special offset*/, "[PAUSED]", pause_text_col);
switch(state)
{
case 0:
menu(g);
break;
case 1:
statistics(g);
break;
case 2:
controls(g);
break;
}
Text.drawString(48, Text.extractLength("ver. "+Game.ver+" '"+Game.ver_str+"', 2013-2014",48), Game.getAppY()-200, "ver. "+Game.ver+" '"+Game.ver_str+"', 2013-2014", pause_text_col2);
}
private static void menu(Graphics g)
{
if (MenuButton.create("Stats", Text.extractLength("Stats", 60), 200+util_pause_offset*1, pause_text_col, 60))
Pause.setState((byte) 1);
if (MenuButton.create("Controls", Text.extractLength("Controls", 60), 205+util_pause_offset*2, pause_text_col, 60))
Pause.setState((byte) 2);
}
private static void statistics(Graphics g)
{
drawDelay(g);
drawPower(g);
drawReload(g);
drawSpreading(g);
drawUsed(g);
if (MenuButton.create("Back", Text.extractLength("Back", 60), 200+util_pause_offset*6, pause_text_col, 60))
Pause.setState((byte) 0);
}
private static void drawDelay(Graphics g)
{
delay.draw(208, 220);
float length = 80/(float)(GameplayState.player.gun.opt_shoot_delay_min-GameplayState.player.gun.opt_shoot_delay_max)*(GameplayState.player.gun.opt_shoot_delay_min-GameplayState.player.gun.opt_shoot_delay);
g.setColor(Color.white);
g.fillRect(230, 220, length, 16);
g.setColor(Color.gray);
g.setLineWidth(2);
g.drawRect(230, 220, 80, 16);
}
private static void drawPower(Graphics g)
{
power.draw(208, 242);
float length = 80/(float)(GameplayState.player.gun.opt_power_max-GameplayState.player.gun.opt_power_min)*(GameplayState.player.gun.opt_power-GameplayState.player.gun.opt_power_min);
g.setColor(Color.white);
g.fillRect(230, 242, length, 16);
g.setColor(Color.gray);
g.setLineWidth(2);
g.drawRect(230, 242, 80, 16);
}
private static void drawReload(Graphics g)
{
reload.draw(208, 264);
float length = 80/(float)(GameplayState.player.gun.opt_reload_speed_min-GameplayState.player.gun.opt_reload_speed_max)*(GameplayState.player.gun.opt_reload_speed_min-GameplayState.player.gun.opt_reload_speed);
g.setColor(Color.white);
g.fillRect(230, 264, length, 16);
g.setColor(Color.gray);
g.setLineWidth(2);
g.drawRect(230, 264, 80, 16);
}
private static void drawSpreading(Graphics g)
{
spreading.draw(208, 286);
float length = 80/(float)(GameplayState.player.gun.opt_spreading_min-GameplayState.player.gun.opt_spreading_max)*(GameplayState.player.gun.opt_spreading_min-GameplayState.player.gun.opt_spreading);
g.setColor(Color.white);
g.fillRect(230, 286, length, 16);
g.setColor(Color.gray);
g.setLineWidth(2);
g.drawRect(230, 286, 80, 16);
}
private static void drawUsed(Graphics g)
{
HashMap<ITEM, Integer> list = new HashMap<ITEM, Integer>();
List<ITEM> used_list = GameplayState.dispenser.used_items;
for (int i = 0; i < used_list.size(); ++i)
{
if (list.get(used_list.get(i)) == null)
list.put(used_list.get(i), 1);
else
{
int q = list.get(used_list.get(i));
list.remove(used_list.get(i));
list.put(used_list.get(i), q+1);
}
}
int x = 322, y = 220;
for(Entry<ITEM, Integer> entry : list.entrySet())
{
ITEM item = entry.getKey();
int quantity = entry.getValue();
item.getIcon().draw(x, y);
if (quantity > 1)
Text.drawString(20, x+12, y+12, ""+quantity, Color.red);
x += 24;
if (x >= 586)
{
x = 322;
y += 24;
}
}
}
private static void controls(Graphics g)
{
Text.drawString(44, Text.extractLength("WASD, arrow keys - move, repair", 44), 200+util_pause_offset*1, "WASD, arrow keys - move, repair", pause_text_col);
Text.drawString(44, Text.extractLength("Left mouse button - shoot", 44), 200+util_pause_offset*2, "Left mouse button - shoot", pause_text_col);
Text.drawString(44, Text.extractLength("R - reload", 44), 200+util_pause_offset*3, "R - reload", pause_text_col);
Text.drawString(44, Text.extractLength("Esc, P - pause", 44), 200+util_pause_offset*4, "Esc, P - pause", pause_text_col);
if (MenuButton.create("Back", Text.extractLength("Back", 60), 200+util_pause_offset*6, pause_text_col, 60))
Pause.setState((byte) 0);
}
public static void update()
{
if (util_state_paused_iter > 0) //button hold cooldown
{
util_state_paused_iter++;
if (util_state_paused_iter == util_state_paused_iter_max)
util_state_paused_iter = 0;
}
Input input = Game.app.getInput();
if ((input.isKeyDown(Input.KEY_ESCAPE) || input.isKeyDown(Input.KEY_P)) && util_state_paused_iter == 0 && !GameplayState.scene_handler.is_playing)
{
state = 0;
util_state_paused = !util_state_paused;
util_state_paused_iter++;
input.clearKeyPressedRecord();
}
}
public static void setState(byte state)
{
Pause.state = state;
}
}