Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.arsaki.deadescape.views.menu;
- import com.arsaki.deadescape.actors.Block;
- import com.arsaki.deadescape.ext.DarkGroup;
- import com.arsaki.deadescape.xam.extension.XBackground;
- import com.arsaki.deadescape.xam.extension.XGroup;
- import com.arsaki.deadescape.xam.extension.XImage;
- import com.arsaki.deadescape.xam.extension.XStage;
- import com.arsaki.deadescape.xam.extension.XUtils;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.math.MathUtils;
- import com.badlogic.gdx.scenes.scene2d.InputEvent;
- import com.badlogic.gdx.scenes.scene2d.ui.Table;
- import com.badlogic.gdx.scenes.scene2d.utils.DragListener;
- import com.badlogic.gdx.utils.Align;
- import com.badlogic.gdx.utils.Array;
- /**
- * Created by Kharin on 07.12.17.
- */
- public class MenuView extends XGroup {
- Block[][] matrix;
- MenuView instance;
- XBackground background = new XBackground("main_menu_back");
- int GAME_FIELD_WIDTH = 4;
- int GAME_FIELD_HEIGHT = 5;
- XGroup map = new XGroup(XStage.w, XStage.h);
- Array<Block> pickBlocks = new Array<Block>();
- public MenuView() {
- super(XStage.w, XStage.h);
- instance = this;
- addActor(background);
- background.toCenter();
- matrix = new Block[GAME_FIELD_WIDTH][GAME_FIELD_HEIGHT];
- for (int i = 0; i < GAME_FIELD_WIDTH; i++) {
- for (int j = 0; j < GAME_FIELD_HEIGHT; j++) {
- Block cell = new Block(i+":"+j);
- matrix[i][j] = cell;
- map.addActor(cell);
- cell.setPosition(cell.getWidth()/2 + i * cell.getWidth(), cell.getWidth()/2 + j * cell.getHeight(), Align.center);
- }
- }
- addActor(map);
- map.setSize(128 * 4, 128*5);
- map.toCenter();
- map.addListener(new DragListener() {
- @Override
- public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
- int indexX = (int) x / 128;
- int indexY = (int) y / 128;
- indexX = MathUtils.clamp(indexX,0,GAME_FIELD_WIDTH-1);
- indexY = MathUtils.clamp(indexY,0,GAME_FIELD_HEIGHT-1);
- addBlock(matrix[indexX][indexY]);
- return super.touchDown(event, x, y, pointer, button);
- }
- @Override
- public void touchDragged(InputEvent event, float x, float y, int pointer) {
- int indexX = (int) x / 128;
- int indexY = (int) y / 128;
- indexX = MathUtils.clamp(indexX,0,GAME_FIELD_WIDTH-1);
- indexY = MathUtils.clamp(indexY,0,GAME_FIELD_HEIGHT-1);
- addBlock(matrix[indexX][indexY]);
- super.dragStart(event, x, y, pointer);
- super.touchDragged(event, x, y, pointer);
- }
- @Override
- public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
- onTouchUp();
- super.touchUp(event, x, y, pointer, button);
- }
- });
- }
- private void onTouchUp() {
- for(Block[] blocs: matrix) {
- for(Block bloc: blocs)
- bloc.setColor(Color.RED);
- }
- pickBlocks.clear();
- }
- private void addBlock(Block block) {
- if(pickBlocks.contains(block, true)) {
- resetBlocks(block);
- }else {
- pickBlocks.add(block);
- block.setColor(Color.GREEN);
- XUtils.log("pickBlocks "+pickBlocks.size);
- }
- }
- private void resetBlocks(Block block) {
- int index = pickBlocks.indexOf(block, true);
- for(int i = index+1; i < pickBlocks.size; i++) {
- pickBlocks.get(i).setColor(Color.WHITE);
- pickBlocks.removeValue(pickBlocks.get(i), true);
- XUtils.log("pickBlocks "+pickBlocks.size);
- }
- }
- public void dispose() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement