<commit_before>package com.letscode.lcg.screens;

import net.engio.mbassy.listener.Handler;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.letscode.lcg.Assets;
import com.letscode.lcg.Context;
import com.letscode.lcg.actor.Board;
import com.letscode.lcg.actor.FieldActor;
import com.letscode.lcg.actor.ParticleSystem;
import com.letscode.lcg.enums.ActionCost;
import com.letscode.lcg.enums.BuildMode;
import com.letscode.lcg.enums.BuildingGoldCost;
import com.letscode.lcg.enums.CommandType;
import com.letscode.lcg.model.Field;
import com.letscode.lcg.network.Events;
import com.letscode.lcg.network.messages.GameEndMessage;
import com.letscode.lcg.network.messages.MoveDoneMessage;
import com.letscode.lcg.network.messages.MoveMessage;
import com.letscode.lcg.network.messages.NextPlayerMessage;
import com.letscode.lcg.network.messages.YourTurnMessage;
import com.letscode.ui.BaseScreen;
import com.letscode.ui.UiApp;

public class PlayScreen extends BaseScreen {
	Context context;	
	
	Button endTurnButton;
	Button buildTownhallButton, buildGoldmineButton, buildBarricadeButton;
	Label actionPointsValueLabel, goldValueLabel, turnPlayerLabel;
	
	Board board;
	
	public PlayScreen(Context context) {
		super(context.app);
		this.context = context;
		UiApp app = context.app;
		Events.subscribe(this);
		
		mainTable.setBackground(new TextureRegionDrawable(Assets.backgroundTexture));

		Label actionPointsLabel = new Label("Action Points:", app.skin);
		actionPointsValueLabel = new Label("0", app.skin);
		
		Label goldLabel = new Label("Gold: ", app.skin);
		goldValueLabel = new Label("0", app.skin);
		
		Table statsTable = new Table(app.skin);
		statsTable.setBackground(app.skin.getDrawable("window1"));
		statsTable.add(actionPointsLabel);
		statsTable.add(actionPointsValueLabel);
		statsTable.row();
		statsTable.add(goldLabel);
		statsTable.add(goldValueLabel);
		mainTable.add(statsTable);
		
		// Setup things about player's turn
        Table turnTable = new Table(app.skin);
        turnTable.setBackground(app.skin.getDrawable("window1"));
        turnPlayerLabel = new Label("hgw", app.skin);
        turnPlayerLabel.setAlignment(Align.center);
        setTurnPlayerLabel(context.network.getClientNickname());
        endTurnButton = new TextButton("End turn", app.skin);
        endTurnButton.addListener(endTurnButtonListener);
        endTurnButton.setColor(Color.valueOf("808080"));
        endTurnButton.setVisible(false);
        turnTable.add(turnPlayerLabel).expandX().fill();
        turnTable.row();
        turnTable.add(endTurnButton).spaceTop(20);
        mainTable.add(turnTable).expandX().fill();
		
		// Setup build buttons
        Table buttonsTable = new Table(app.skin);
        buttonsTable.setBackground(app.skin.getDrawable("window1"));
        
        buildTownhallButton = new TextButton("Townhall", app.skin);
        buildTownhallButton .setColor(Color.valueOf("808080"));
        buildTownhallButton.addListener(buildTownhallButtonListener);
        Table buildTownhallTable = new Table(app.skin);
        Image buildTownhallImage = new Image(new TextureRegionDrawable(Assets.townhallTexture));
        buildTownhallTable.add(buildTownhallImage).maxWidth(64).maxHeight(64).center();
        buildTownhallTable.row();
        buildTownhallTable.add(buildTownhallButton);
        buildGoldmineButton = new TextButton("Goldmine", app.skin);
        buildGoldmineButton.setColor(Color.valueOf("808080"));
        buildGoldmineButton.addListener(buildGoldmineButtonListener);
        Table buildGoldmineTable = new Table(app.skin);
        Image buildGoldmineImage = new Image(new TextureRegionDrawable(Assets.goldmineTexture));
        buildGoldmineTable.add(buildGoldmineImage).maxWidth(64).maxHeight(64).center();
        buildGoldmineTable.row();
        buildGoldmineTable.add(buildGoldmineButton);
        buildBarricadeButton = new TextButton("Barricade", app.skin);
        buildBarricadeButton.setColor(Color.valueOf("808080"));
        buildBarricadeButton.addListener(buildBarricadeButtonListener);
        Table buildBarricadeTable = new Table(app.skin);
        Image buildBarricadeImage = new Image(new TextureRegionDrawable(Assets.barricadeTexture));
        buildBarricadeTable.add(buildBarricadeImage).maxWidth(64).maxHeight(64).center();
        buildBarricadeTable.row();
        buildBarricadeTable.add(buildBarricadeButton);
        buttonsTable.add(buildTownhallTable);
        buttonsTable.add(buildGoldmineTable);
        buttonsTable.add(buildBarricadeTable);
        mainTable.add(buttonsTable);
        
        // Setup game board
		board = new Board(context);
		
        mainTable.row();
        Table boardTable = new Table(app.skin);
        boardTable.setBackground(app.skin.getDrawable("window1"));
        boardTable.setColor(Color.valueOf("335B3388"));
        boardTable.add(board).expand().fill();
        mainTable.add(boardTable).expand().fill().colspan(3);
        
        mainTable.layout();
        
        board.init();
        board.addListener(boardListener);
        
        context.app.setClearColor(Color.valueOf("9EAE9E"));
	}

	@Override
	public void resize(int width, int height) {
		super.resize(width, height);
		getStage().getCamera().update();
		context.shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
	}
	
	private void setBuildMode(BuildMode buildMode) {
		context.currentBuildMode = buildMode;
		
		buildTownhallButton.setDisabled(true);
		buildTownhallButton.setChecked(buildMode == BuildMode.Townhall);
		buildTownhallButton.setDisabled(false);
		buildGoldmineButton.setDisabled(true);
		buildGoldmineButton.setChecked(buildMode == BuildMode.Goldmine);
		buildGoldmineButton.setDisabled(false);
		buildBarricadeButton.setDisabled(true);
		buildBarricadeButton.setChecked(buildMode == BuildMode.Barricade);
		buildBarricadeButton.setDisabled(false);
	}
	
	private void setTurnPlayerLabel(String playerName) {
		boolean thisPlayerMoves = playerName.equals(context.getPlayerNickname());
		String labelText = thisPlayerMoves ? "Now you move!" : (playerName != null ? playerName : "");
		turnPlayerLabel.setText(labelText);
		turnPlayerLabel.setColor(context.colorsForPlayers.get(playerName));
	}
	
	/**
	 * Checks if move is possible and then it's being made.
	 * 
	 * @param fieldActor
	 */
	private void tryToMakeMove(FieldActor fieldActor) {
		CommandType commandType = null;
		boolean shouldSendCommand = false;
		int rowIndex = fieldActor.getRowIndex();
		int colIndex = fieldActor.getColIndex();
		Field field = context.map.getField(rowIndex, colIndex);
		String thisPlayerName = context.getPlayerNickname();
		boolean isOwnedByPlayer = context.map.isFieldOwnedBy(thisPlayerName, rowIndex, colIndex);
		boolean canPlayerBuildOnField = isOwnedByPlayer && field.building == null;
		int currentActionPoints = Integer.parseInt(actionPointsValueLabel.getText().toString());
		int currentGold = Integer.parseInt(goldValueLabel.getText().toString());<commit_msg>something<commit_after>package com.letscode.lcg.screens;

import net.engio.mbassy.listener.Handler;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.letscode.lcg.Assets;
import com.letscode.lcg.Context;
import com.letscode.lcg.actor.Board;
import com.letscode.lcg.actor.FieldActor;
import com.letscode.lcg.actor.ParticleSystem;
import com.letscode.lcg.enums.ActionCost;
import com.letscode.lcg.enums.BuildMode;
import com.letscode.lcg.enums.BuildingGoldCost;
import com.letscode.lcg.enums.CommandType;
import com.letscode.lcg.model.Field;
import com.letscode.lcg.network.Events;
import com.letscode.lcg.network.messages.GameEndMessage;
import com.letscode.lcg.network.messages.MoveDoneMessage;
import com.letscode.lcg.network.messages.MoveMessage;
import com.letscode.lcg.network.messages.NextPlayerMessage;
import com.letscode.lcg.network.messages.YourTurnMessage;
import com.letscode.ui.BaseScreen;
import com.letscode.ui.UiApp;

public class PlayScreen extends BaseScreen {
	Context context;	
	
	Button endTurnButton;
	Button buildTownhallButton, buildGoldmineButton, buildBarricadeButton;
	Label actionPointsValueLabel, goldValueLabel, turnPlayerLabel;
	
	Board board;
	
	public PlayScreen(Context context) {
		super(context.app);
		this.context = context;
		UiApp app = context.app;
		Events.subscribe(this);
		
		mainTable.setBackground(new TextureRegionDrawable(Assets.backgroundTexture));

		Label actionPointsLabel = new Label("Action Points:", app.skin);
		actionPointsValueLabel = new Label("0", app.skin);
		
		Label goldLabel = new Label("Gold: ", app.skin);
		goldValueLabel = new Label("0", app.skin);
		
		Table statsTable = new Table(app.skin);
		statsTable.setBackground(app.skin.getDrawable("window1"));
		statsTable.add(actionPointsLabel);
		statsTable.add(actionPointsValueLabel);
		statsTable.row();
		statsTable.add(goldLabel);
		statsTable.add(goldValueLabel);
		mainTable.add(statsTable);
		
		// Setup things about player's turn
        Table turnTable = new Table(app.skin);
        turnTable.setBackground(app.skin.getDrawable("window1"));
        turnPlayerLabel = new Label("hgw", app.skin);
        turnPlayerLabel.setAlignment(Align.center);
        setTurnPlayerLabel(context.network.getClientNickname());
        endTurnButton = new TextButton("End turn", app.skin);
        endTurnButton.addListener(endTurnButtonListener);
        endTurnButton.setColor(Color.valueOf("808080"));
        endTurnButton.setVisible(false);
        turnTable.add(turnPlayerLabel).expandX().fill();
        turnTable.row();
        turnTable.add(endTurnButton).spaceTop(20);
        mainTable.add(turnTable).expandX().fill();
		
		// Setup build buttons
        Table buttonsTable = new Table(app.skin);
        buttonsTable.setBackground(app.skin.getDrawable("window1"));
        
        buildTownhallButton = new TextButton("Townhall", app.skin);
        buildTownhallButton .setColor(Color.valueOf("808080"));
        buildTownhallButton.addListener(buildTownhallButtonListener);
        Table buildTownhallTable = new Table(app.skin);
        Image buildTownhallImage = new Image(new TextureRegionDrawable(Assets.townhallTexture));
        buildTownhallTable.add(buildTownhallImage).maxWidth(64).maxHeight(64).center();
        buildTownhallTable.row();
        buildTownhallTable.add(buildTownhallButton);
        buildGoldmineButton = new TextButton("Goldmine", app.skin);
        buildGoldmineButton.setColor(Color.valueOf("808080"));
        buildGoldmineButton.addListener(buildGoldmineButtonListener);
        Table buildGoldmineTable = new Table(app.skin);
        Image buildGoldmineImage = new Image(new TextureRegionDrawable(Assets.goldmineTexture));
        buildGoldmineTable.add(buildGoldmineImage).maxWidth(64).maxHeight(64).center();
        buildGoldmineTable.row();
        buildGoldmineTable.add(buildGoldmineButton);
        buildBarricadeButton = new TextButton("Barricade", app.skin);
        buildBarricadeButton.setColor(Color.valueOf("808080"));
        buildBarricadeButton.addListener(buildBarricadeButtonListener);
        Table buildBarricadeTable = new Table(app.skin);
        Image buildBarricadeImage = new Image(new TextureRegionDrawable(Assets.barricadeTexture));
        buildBarricadeTable.add(buildBarricadeImage).maxWidth(64).maxHeight(64).center();
        buildBarricadeTable.row();
        buildBarricadeTable.add(buildBarricadeButton);
        buttonsTable.add(buildTownhallTable);
        buttonsTable.add(buildGoldmineTable);
        buttonsTable.add(buildBarricadeTable);
        mainTable.add(buttonsTable);
        
        // Setup game board
		board = new Board(context);
		
        mainTable.row();
        Table boardTable = new Table(app.skin);
        boardTable.setBackground(app.skin.getDrawable("window1"));
        boardTable.setColor(Color.valueOf("335B3388"));
        boardTable.add(board).expand().fill();
        mainTable.add(boardTable).expand().fill().colspan(3);
        
        mainTable.layout();
        
        board.init();
        board.addListener(boardListener);
        
        context.app.setClearColor(Color.valueOf("9EAE9E"));
	}

	@Override
	public void resize(int width, int height) {
		super.resize(width, height);
		getStage().getCamera().update();
		context.shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
	}
	
	private void setBuildMode(BuildMode buildMode) {
		context.currentBuildMode = buildMode;
		
		buildTownhallButton.setDisabled(true);
		buildTownhallButton.setChecked(buildMode == BuildMode.Townhall);
		buildTownhallButton.setDisabled(false);
		buildGoldmineButton.setDisabled(true);
		buildGoldmineButton.setChecked(buildMode == BuildMode.Goldmine);
		buildGoldmineButton.setDisabled(false);
		buildBarricadeButton.setDisabled(true);
		buildBarricadeButton.setChecked(buildMode == BuildMode.Barricade);
		buildBarricadeButton.setDisabled(false);
	}
	
	private void setTurnPlayerLabel(String playerName) {
		boolean thisPlayerMoves = playerName.equals(context.getPlayerNickname());
		String labelText = thisPlayerMoves ? "Now you move!" : (playerName != null ? "Now: " + playerName : "");
		turnPlayerLabel.setText(labelText);
		turnPlayerLabel.setColor(context.colorsForPlayers.get(playerName));
	}
	
	/**
	 * Checks if move is possible and then it's being made.
	 * 
	 * @param fieldActor
	 */
	private void tryToMakeMove(FieldActor fieldActor) {
		CommandType commandType = null;
		boolean shouldSendCommand = false;
		int rowIndex = fieldActor.getRowIndex();
		int colIndex = fieldActor.getColIndex();
		Field field = context.map.getField(rowIndex, colIndex);
		String thisPlayerName = context.getPlayerNickname();
		boolean isOwnedByPlayer = context.map.isFieldOwnedBy(thisPlayerName, rowIndex, colIndex);
		boolean canPlayerBuildOnField = isOwnedByPlayer && field.building == null;
		int currentActionPoints = Integer.parseInt(actionPointsValueLabel.getText().toString());
		int currentGold = Integer.parseInt(goldValueLabel.getText().toString());
{'fraction_non_alphanumeric': 0.11354398846204275, 'fraction_numerical': 0.008653467942834666, 'mean_word_length': 4.654188287620459, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5893066', 'n_tokens_mistral': 4858, 'n_tokens_neox': 4575, 'n_words': 678}