<commit_before>package ca.sumost.kinetic;

import ca.sumost.kinetic.editor.BoundaryCreator;
import ca.sumost.kinetic.editor.GreenAtomCreator;
import ca.sumost.kinetic.editor.RedAtomCreator;
import ca.sumost.kinetic.editor.WorldEditorListener;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureAdapter;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.viewport.ScreenViewport;

public class GameScreen implements Screen
{
	private final KineticTheoryGame game;
	private final ScreenViewport mViewport;

	private final Stage mStage;
	
	private float mZoomFactor = 1;

	@SuppressWarnings("unused")
	private final Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer();
	private final ShapeRenderer mShapeRenderer = new ShapeRenderer();
	private final WorldEditorListener mEditorListener;
	
	public GameScreen(final KineticTheoryGame g)
	{
		game = g;
		
		mViewport = new ScreenViewport();
		mViewport.setUnitsPerPixel(1f/20f);
		
		mStage = new Stage();
		mStage.addActor(makeRootWidget());
		
		final ScreenConverter sc = new ScreenConverter()
		{
			@Override
			public Vector2 pointToWorld(float xScreen, float yScreen) 
			{
				return mViewport.unproject(new Vector2(xScreen, yScreen));
			}

			@Override
			public Vector2 vectorToWorld(float xScreen, float yScreen) 
			{
				return pointToWorld(xScreen, yScreen).sub(pointToWorld(0, 0));			
			}
		};
		
		InputProcessor zoomByScroll = new InputAdapter()
		{
			@Override
			public boolean scrolled(int amount) 
			{
				float zoomChangeFactor = 0.90f;
				float zoomChange = (amount > 0) ? zoomChangeFactor : 1.0f / zoomChangeFactor;
				setZoom(mZoomFactor * zoomChange);
				return true;
			}
		};
		
		GestureListener zoomByPinch = new GestureAdapter()
		{
			@Override
			public boolean zoom(float initialDistance, float distance) 
			{
				setZoom(initialDistance / distance);
				return true;
			}
		};
		
		mEditorListener = new WorldEditorListener(g.getWorld(), sc);
		
		InputMultiplexer im = new InputMultiplexer(mStage, zoomByScroll, new GestureDetector(zoomByPinch), new GestureDetector(mEditorListener));
		Gdx.input.setInputProcessor(im);
		Gdx.graphics.setContinuousRendering(true);
	}
	
	private Actor makeRootWidget()
	{
		Skin skin = game.getSkin();

		TextButton redAtomButton = new TextButton("RED atom", skin);
		redAtomButton.addListener(new ChangeListener()
		{
			@Override
			public void changed(ChangeEvent event, Actor actor)
			{
				mEditorListener.setCreator(new RedAtomCreator(game.getWorld()));				
			}
		});
		
		TextButton greenAtomButton = new TextButton("GREEN atom", skin);
		greenAtomButton.addListener(new ChangeListener()
		{
			@Override
			public void changed(ChangeEvent event, Actor actor)
			{
				mEditorListener.setCreator(new GreenAtomCreator(game.getWorld()));				
			}
		});
		
		TextButton boundaryButton = new TextButton("Boundary", skin);
		boundaryButton.addListener(new ChangeListener()
		{
			@Override
			public void changed(ChangeEvent event, Actor actor)
			{
				mEditorListener.setCreator(new BoundaryCreator(game.getWorld()));				
			}
		});
		
		VerticalGroup rightButtonBar = new VerticalGroup();
		rightButtonBar.addActor(redAtomButton);
		rightButtonBar.addActor(greenAtomButton);
		rightButtonBar.addActor(boundaryButton);
		
	    Container<VerticalGroup> root = new Container<VerticalGroup>(rightButtonBar).top().right();
	    root.setFillParent(true);
	    //root.setDebug(true);
	    
		return root;
	}

	@Override
	public void render(float delta) 
	{
		Gdx.gl.glClearColor(0, 0, 0.2f, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);<commit_msg>Change to checkbox, put inside a buttongroup.<commit_after>package ca.sumost.kinetic;

import ca.sumost.kinetic.editor.BoundaryCreator;
import ca.sumost.kinetic.editor.GreenAtomCreator;
import ca.sumost.kinetic.editor.RedAtomCreator;
import ca.sumost.kinetic.editor.WorldEditorListener;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureAdapter;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.viewport.ScreenViewport;

public class GameScreen implements Screen
{
	private final KineticTheoryGame game;
	private final ScreenViewport mViewport;

	private final Stage mStage;
	
	private float mZoomFactor = 1;

	@SuppressWarnings("unused")
	private final Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer();
	private final ShapeRenderer mShapeRenderer = new ShapeRenderer();
	private final WorldEditorListener mEditorListener;
	
	public GameScreen(final KineticTheoryGame g)
	{
		game = g;
		
		mViewport = new ScreenViewport();
		mViewport.setUnitsPerPixel(1f/20f);
		
		mStage = new Stage();
		mStage.addActor(makeRootWidget());
		
		final ScreenConverter sc = new ScreenConverter()
		{
			@Override
			public Vector2 pointToWorld(float xScreen, float yScreen) 
			{
				return mViewport.unproject(new Vector2(xScreen, yScreen));
			}

			@Override
			public Vector2 vectorToWorld(float xScreen, float yScreen) 
			{
				return pointToWorld(xScreen, yScreen).sub(pointToWorld(0, 0));			
			}
		};
		
		InputProcessor zoomByScroll = new InputAdapter()
		{
			@Override
			public boolean scrolled(int amount) 
			{
				float zoomChangeFactor = 0.90f;
				float zoomChange = (amount > 0) ? zoomChangeFactor : 1.0f / zoomChangeFactor;
				setZoom(mZoomFactor * zoomChange);
				return true;
			}
		};
		
		GestureListener zoomByPinch = new GestureAdapter()
		{
			@Override
			public boolean zoom(float initialDistance, float distance) 
			{
				setZoom(initialDistance / distance);
				return true;
			}
		};
		
		mEditorListener = new WorldEditorListener(g.getWorld(), sc);
		
		InputMultiplexer im = new InputMultiplexer(mStage, zoomByScroll, new GestureDetector(zoomByPinch), new GestureDetector(mEditorListener));
		Gdx.input.setInputProcessor(im);
		Gdx.graphics.setContinuousRendering(true);
	}
	
	private Actor makeRootWidget()
	{
		Skin skin = game.getSkin();

		Button redAtomButton = new CheckBox("RED atom", skin);
		redAtomButton.center().addListener(new ChangeListener()
		{
			@Override
			public void changed(ChangeEvent event, Actor actor)
			{
				mEditorListener.setCreator(new RedAtomCreator(game.getWorld()));				
			}
		});
		
		Button greenAtomButton = new CheckBox("GREEN atom", skin);
		greenAtomButton.center().addListener(new ChangeListener()
		{
			@Override
			public void changed(ChangeEvent event, Actor actor)
			{
				mEditorListener.setCreator(new GreenAtomCreator(game.getWorld()));				
			}
		});
		
		Button boundaryButton = new CheckBox("Boundary", skin);
		boundaryButton.center().addListener(new ChangeListener()
		{
			@Override
			public void changed(ChangeEvent event, Actor actor)
			{
				mEditorListener.setCreator(new BoundaryCreator(game.getWorld()));				
			}
		});

		VerticalGroup rightButtonBar = new VerticalGroup();
		rightButtonBar.addActor(redAtomButton);
		rightButtonBar.addActor(greenAtomButton);
		rightButtonBar.addActor(boundaryButton);
		
		ButtonGroup group = new ButtonGroup(redAtomButton, greenAtomButton, boundaryButton);
		
	    Container<VerticalGroup> root = new Container<VerticalGroup>(rightButtonBar).top().right();
	    root.setFillParent(true);
	    //root.setDebug(true);
	    
		return root;
	}

	@Override
	public void render(float delta) 
	{
		Gdx.gl.glClearColor(0, 0, 0.2f, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
{'fraction_non_alphanumeric': 0.10354776661679846, 'fraction_numerical': 0.008121393460141057, 'mean_word_length': 4.68936170212766, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6122367', 'n_tokens_mistral': 3512, 'n_tokens_neox': 3032, 'n_words': 553}