Search in sources :

Example 1 with Profile

use of com.janfic.games.computercombat.model.Profile in project computercombat by janfic.

the class LoginScreen method showWindow.

public void showWindow(Message message) {
    popup = new Window("", skin);
    popup.defaults().space(5);
    Label messageLabel = new Label("", skin);
    messageLabel.setWrap(true);
    messageLabel.setAlignment(Align.center);
    TextButton okayButton = new TextButton("Okay", skin);
    if (null != message.type) {
        switch(message.type) {
            case ERROR:
                popup.getTitleLabel().setText("ERROR");
                messageLabel.setText("Something went wrong. Try again.");
                popup.add(messageLabel).expand().grow().row();
                okayButton.addListener(new ClickListener() {

                    @Override
                    public void clicked(InputEvent event, float x, float y) {
                        popup.remove();
                    }
                });
                break;
            case PROFILE_INFO:
                Profile profile = SQLAPI.getSingleton().loadProfile(message.getMessage());
                game.setCurrentProfile(profile);
                game.pushScreen(new PlayScreen(game));
                break;
            case VERIFY_WITH_CODE:
                if (verifying == false) {
                    popup.getTitleLabel().setText("Verification");
                    popup.add(messageLabel).growX().row();
                    messageLabel.setText("Enter Verification Code:");
                    TextField codeField = new TextField("", skin);
                    codeField.setTextFieldFilter(new TextFieldFilter.DigitsOnlyFilter());
                    popup.add(codeField).row();
                    okayButton.addListener(new ClickListener() {

                        @Override
                        public void clicked(InputEvent event, float x, float y) {
                            if (codeField.getText().trim().length() > 0) {
                                game.getServerAPI().sendMessage(new Message(Type.VERIFICATION_CODE, userNameField.getText().trim() + "," + codeField.getText().trim()));
                                verifying = true;
                                popup.remove();
                            }
                        }
                    });
                } else {
                    popup.getTitleLabel().setText("Incorrect Verification Code");
                    messageLabel.setText("Incorrect Code. Try again.");
                    popup.add(messageLabel).expand().grow().row();
                    okayButton.addListener(new ClickListener() {

                        @Override
                        public void clicked(InputEvent event, float x, float y) {
                            popup.remove();
                        }
                    });
                    verifying = false;
                }
                break;
            case NO_AUTH:
                popup.getTitleLabel().setText("Incorrect Login");
                messageLabel.setText("Username or Password incorrect. Try Again");
                popup.add(messageLabel).expand().grow().row();
                okayButton.addListener(new ClickListener() {

                    @Override
                    public void clicked(InputEvent event, float x, float y) {
                        popup.remove();
                    }
                });
                break;
            case SUCCESS:
                if (verifying) {
                    popup.getTitleLabel().setText("Success!");
                    messageLabel.setText("Email Successfully Verified!");
                    popup.add(messageLabel).expand().grow().row();
                    okayButton.addListener(new ClickListener() {

                        @Override
                        public void clicked(InputEvent event, float x, float y) {
                            popup.remove();
                            verifying = false;
                        }
                    });
                }
                break;
            default:
                break;
        }
    }
    popup.add(okayButton).row();
    popup.setSize(stage.getWidth() / 2, stage.getHeight() / 2);
    popup.setPosition(stage.getWidth() / 4, stage.getHeight() / 4);
    stage.addActor(popup);
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Message(com.janfic.games.computercombat.network.Message) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextFieldFilter(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldFilter) Profile(com.janfic.games.computercombat.model.Profile) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 2 with Profile

use of com.janfic.games.computercombat.model.Profile in project computercombat by janfic.

the class SQLAPI method loadProfile.

public Profile loadProfile(String uid) {
    System.out.println("[SERVER][MYSQL]: Loading Player Profile");
    try {
        String sql = "SELECT *\n" + "FROM profile\n" + "WHERE profile.uid = '" + uid + "';";
        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery(sql);
        Profile profile = new Profile(uid);
        while (rs.next()) {
            profile.setName(rs.getString("username"));
            profile.setEmail(rs.getString("email"));
            profile.setPackets(rs.getInt("packets"));
        }
        return profile;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Profile(com.janfic.games.computercombat.model.Profile) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException)

Example 3 with Profile

use of com.janfic.games.computercombat.model.Profile in project computercombat by janfic.

the class CollectionScreen method buildCollection.

public void buildCollection() {
    Profile profile = game.getCurrentProfile();
    Map<Card, Integer> playerCards = new HashMap<>();
    Map<Card, Integer> allCards = new HashMap<>();
    List<Card> ac = SQLAPI.getSingleton().getCardsInfo(null, null);
    playerCards = SQLAPI.getSingleton().getPlayerOwnedCards(profile.getUID());
    for (Card card : ac) {
        for (Card c : playerCards.keySet()) {
            if (card.getID() == c.getID()) {
                card.setOwnerUID(profile.getUID());
                break;
            }
        }
    }
    for (Card card : ac) {
        allCards.put(card, 0);
    }
    for (Card card : playerCards.keySet()) {
        allCards.put(card, playerCards.get(card));
    }
    collection.clearChildren();
    int row = 0;
    for (Card card : allCards.keySet()) {
        CollectionCard cc = new CollectionCard(game, skin, card, allCards.get(card));
        if (allCards.get(card) == 0) {
            cc.setColor(1, 1, 1, 0.5f);
        }
        if (filterWindow.getFilter().filter(card, null, null)) {
            cards.add(cc);
            collection.add(cc);
            row++;
            if (row % 4 == 0) {
                collection.row();
                row = 0;
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Profile(com.janfic.games.computercombat.model.Profile) CollectionCard(com.janfic.games.computercombat.actors.CollectionCard) Card(com.janfic.games.computercombat.model.Card)

Example 4 with Profile

use of com.janfic.games.computercombat.model.Profile in project computercombat by janfic.

the class DecksScreen method buildCollection.

public void buildCollection() {
    Profile profile = game.getCurrentProfile();
    software = SQLAPI.getSingleton().getPlayerOwnedCards(profile.getUID());
    collection.clearChildren();
    int row = 0;
    for (Card card : software.keySet()) {
        Table cardTable = new Table();
        CollectionCard cc = new CollectionCard(game, skin, card, software.get(card));
        cardTable.add(cc).colspan(3).grow().row();
        TextButton addButton = new TextButton("+", skin) {

            @Override
            public void act(float delta) {
                // To change body of generated methods, choose Tools | Templates.
                super.act(delta);
                if (selectedDeck != null && selectedDeck.getDeck().getCardCount(card.getID()) >= software.get(card)) {
                    this.setColor(Color.RED);
                } else {
                    this.setColor(Color.WHITE);
                }
            }
        };
        addButton.addListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                if (selectedDeck != null) {
                    if (selectedDeck.getDeck().getCardCount(card.getID()) < software.get(card)) {
                        selectedDeck.getDeck().addCard(card, 1);
                        updateDeckCards();
                    }
                }
            }
        });
        TextButton removeButton = new TextButton("-", skin);
        removeButton.addListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                if (selectedDeck != null) {
                    selectedDeck.getDeck().removeCard(card, 1);
                    updateDeckCards();
                }
            }
        });
        Label amountInDeck = new Label("-", skin) {

            @Override
            public void act(float delta) {
                super.act(delta);
                if (selectedDeck != null) {
                    this.setText("" + selectedDeck.getDeck().getCardCount(card.getID()));
                } else {
                    this.setText("-");
                }
            }
        };
        cardTable.add(removeButton).expandX().width(30);
        cardTable.add(amountInDeck);
        cardTable.add(addButton).expandX().width(30);
        if (filterWindow.getFilter().filter(card, null, null)) {
            collection.add(cardTable);
            collectionToDeckDragAndDrop.addSource(new Source(cc) {

                @Override
                public Payload dragStart(InputEvent ie, float f, float f1, int i) {
                    Payload payload = new Payload();
                    payload.setObject(card);
                    BorderedArea dragActor = new BorderedArea(skin);
                    dragActor.setWidth(48);
                    dragActor.setHeight(48);
                    dragActor.add(new Image(game.getAssetManager().get("texture_packs/" + card.getCollection().getTextureName() + ".atlas", TextureAtlas.class).findRegion(card.getTextureName()))).width(46).height(46);
                    payload.setDragActor(dragActor);
                    return payload;
                }
            });
            row++;
            if (row % 2 == 0) {
                collection.row();
                row = 0;
            }
        }
    }
}
Also used : Profile(com.janfic.games.computercombat.model.Profile) Card(com.janfic.games.computercombat.model.Card) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 5 with Profile

use of com.janfic.games.computercombat.model.Profile in project computercombat by janfic.

the class DecksScreen method show.

@Override
public void show() {
    this.stageCamera = new OrthographicCamera(1920 / 4, 1080 / 4);
    this.isPopup = false;
    this.stage = ComputerCombatGame.makeNewStage(stageCamera);
    Profile profile = game.getCurrentProfile();
    software = SQLAPI.getSingleton().getPlayerOwnedCards(profile.getUID());
    Gdx.input.setInputProcessor(stage);
    filterWindow = new FilterWindowActor(game, skin);
    table = new Table();
    table.setFillParent(true);
    table.defaults().space(3);
    table.pad(2);
    Table titleTable = new Table(skin);
    titleTable.setBackground("border");
    Label title = new Label("Decks", skin);
    title.setAlignment(Align.center);
    TextButton backButton = new TextButton("Back", skin);
    backButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.popScreen();
        }
    });
    titleTable.add(backButton);
    titleTable.add(title).growX().row();
    decksTable = new Table(skin);
    decksTable.defaults().space(3);
    Label decksTitle = new Label("Decks", skin, "title");
    decksTitle.setAlignment(Align.center);
    decks = new Table();
    decks.defaults().space(5).height(60).width(70);
    populateDecks();
    ScrollPane decksScroll = new ScrollPane(decks, skin);
    decksScroll.setFadeScrollBars(false);
    decksScroll.addListener(new InputListener() {

        @Override
        public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
            stage.setScrollFocus(decksScroll);
        }
    });
    createButton = new TextButton("Create", skin);
    createButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            Window window = new Window("Create New Deck", skin);
            window.setSize(stage.getWidth() / 2, stage.getHeight() / 2);
            window.setPosition(stage.getWidth() / 4, stage.getHeight() / 4);
            Table table = new Table();
            TextButton doneButton = new TextButton("Done", skin);
            TextButton cancelButton = new TextButton("Cancel", skin);
            TextField deckNameField = new TextField("", skin);
            doneButton.addListener(new ClickListener() {

                @Override
                public void clicked(InputEvent event, float x, float y) {
                    Deck deck = new Deck(deckNameField.getText());
                    SQLAPI.getSingleton().savePlayerDeck(deck, game.getCurrentProfile().getUID());
                    game.getCurrentProfile().getDecks().add(deck);
                    populateDecks();
                    window.remove();
                    isPopup = false;
                }
            });
            cancelButton.addListener(new ClickListener() {

                @Override
                public void clicked(InputEvent event, float x, float y) {
                    window.remove();
                    isPopup = false;
                }
            });
            table.add(new Label("Enter New Deck Name:", skin)).center().expand().row();
            table.add(deckNameField).expand().row();
            table.add(doneButton).growX().row();
            table.add(cancelButton).growX().row();
            window.add(table).grow();
            isPopup = true;
            stage.addActor(window);
        }
    });
    deleteButton = new TextButton("Delete", skin);
    deleteButton.setColor(Color.LIGHT_GRAY);
    deleteButton.setDisabled(true);
    deleteButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (selectedDeck == null) {
                return;
            }
            Window window = new Window("Delete Deck", skin);
            window.setSize(stage.getWidth() / 2, stage.getHeight() / 2);
            window.setPosition(stage.getWidth() / 4, stage.getHeight() / 4);
            Table table = new Table();
            TextButton doneButton = new TextButton("Delete Deck", skin);
            TextButton cancelButton = new TextButton("Cancel", skin);
            doneButton.addListener(new ClickListener() {

                @Override
                public void clicked(InputEvent event, float x, float y) {
                    if (selectedDeck == null) {
                        return;
                    }
                    game.getCurrentProfile().getDecks().remove(selectedDeck.getDeck());
                    SQLAPI.getSingleton().deletePlayerDeck(selectedDeck.getDeck(), game.getCurrentProfile().getUID());
                    selectedDeck = null;
                    deckCards.clearChildren();
                    populateDecks();
                    window.remove();
                    deleteButton.setColor(Color.LIGHT_GRAY);
                    isPopup = false;
                }
            });
            cancelButton.addListener(new ClickListener() {

                @Override
                public void clicked(InputEvent event, float x, float y) {
                    window.remove();
                    isPopup = false;
                }
            });
            Label l = new Label("Are you sure you want to delete deck: \"" + selectedDeck.getDeck().getName() + "\"?\nThis action cannot be undone!", skin);
            l.setAlignment(Align.center);
            l.setWrap(true);
            table.add(l).grow().row();
            table.add(doneButton).growX().row();
            table.add(cancelButton).growX().row();
            window.add(table).grow();
            isPopup = true;
            stage.addActor(window);
        }
    });
    decksTable.add(decksTitle).growX().row();
    decksTable.add(decksScroll).grow().row();
    decksTable.add(createButton).growX().row();
    decksTable.add(deleteButton).growX().row();
    deckTable = new Table(skin);
    deckTable.defaults().space(3);
    Label cardsTitle = new Label("Cards", skin, "title");
    cardsTitle.setAlignment(Align.center);
    deckSize = new ProgressBar(0, 8, 1, false, skin);
    deckSize.setWidth(100);
    Stack deckSizeStack = new Stack();
    deckSizeStack.add(deckSize);
    Table deckSizeOverlay = new Table();
    deckSizeArea = new OverlayTextLabelArea<DeckActor>(skin, selectedDeck) {

        @Override
        public String updateLabel(DeckActor dataObject) {
            if (dataObject != null) {
                int amount = dataObject.getDeck().getCardCount(-1);
                deckSize.setValue(dataObject.getDeck().getCardCount(-1));
                return "" + dataObject.getDeck().getCardCount(-1);
            } else {
                return "-";
            }
        }
    };
    deckSizeOverlay.add(deckSizeArea).expand().fillX().width(9).height(9);
    deckSizeStack.add(deckSizeOverlay);
    deckCards = new Table();
    deckCards.defaults().space(5);
    ScrollPane deckCardsPane = new ScrollPane(deckCards, skin);
    deckCardsPane.setFadeScrollBars(false);
    deckCardsPane.addListener(new InputListener() {

        @Override
        public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
            stage.setScrollFocus(deckCardsPane);
        }
    });
    TextButton saveButton = new TextButton("Save", skin);
    saveButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (selectedDeck != null) {
                int amount = selectedDeck.getDeck().getCardCount(-1);
                if (amount != 8) {
                    Window window = new Window("Invalid Deck", skin);
                    window.setSize(stage.getWidth() / 2f, stage.getHeight() / 2f);
                    window.setPosition(stage.getWidth() / 4f, stage.getHeight() / 4f);
                    Label info = new Label("The selected deck will be saved. But it is invalid for play due because it has " + amount + " cards.\n Decks must have exactly 8 cards.", skin);
                    info.setWrap(true);
                    info.setAlignment(Align.center);
                    TextButton okay = new TextButton("Okay", skin);
                    okay.addListener(new ClickListener() {

                        @Override
                        public void clicked(InputEvent event, float x, float y) {
                            window.remove();
                            SQLAPI.getSingleton().savePlayerDeck(selectedDeck.getDeck(), game.getCurrentProfile().getUID());
                            saveButton.addAction(Actions.sequence(Actions.color(Color.GREEN), Actions.color(Color.WHITE, 2)));
                        }
                    });
                    window.add(info).grow().row();
                    window.add(okay).growX().row();
                    stage.addActor(window);
                } else {
                    SQLAPI.getSingleton().savePlayerDeck(selectedDeck.getDeck(), game.getCurrentProfile().getUID());
                    saveButton.addAction(Actions.sequence(Actions.color(Color.GREEN), Actions.color(Color.WHITE, 2)));
                }
            }
        }
    });
    deckTable.add(cardsTitle).growX().row();
    deckTable.add(deckSizeStack).width(100).row();
    deckTable.add(deckCardsPane).grow().row();
    deckTable.add(saveButton).growX().row();
    collectionTable = new Table(skin);
    collectionTable.defaults().space(3);
    Table titleRow = new Table(skin);
    titleRow.setBackground("border");
    Label collectionTitle = new Label("Collection", skin);
    collectionTitle.setAlignment(Align.center);
    TextButton filterButton = new TextButton("Filter", skin);
    filterButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            filterWindow.setSize(4 * stage.getWidth() / 5, 4 * stage.getHeight() / 5);
            filterWindow.setPosition(stage.getWidth() / 10, stage.getHeight() / 10);
            filterWindow.addApplyButtonListener(new ClickListener() {

                @Override
                public void clicked(InputEvent event, float x, float y) {
                    buildCollection();
                }
            });
            filterButton.getStage().addActor(filterWindow);
        }
    });
    titleRow.add(collectionTitle).growX();
    titleRow.add(filterButton);
    collection = new Table(skin);
    collection.defaults().space(5).growY();
    ScrollPane collectionPane = new ScrollPane(collection, skin);
    collectionPane.setFadeScrollBars(false);
    collectionPane.addListener(new InputListener() {

        @Override
        public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
            stage.setScrollFocus(collectionPane);
        }
    });
    collectionTable.add(titleRow).growX().row();
    collectionTable.add(collectionPane).grow().row();
    table.add(titleTable).growX().colspan(3).row();
    table.add(decksTable).width(Value.percentWidth(0.20f, table)).growY();
    table.add(deckTable).width(Value.percentWidth(0.25f, table)).growY();
    table.add(collectionTable).grow().row();
    stage.addActor(table);
    this.deckToCollectionDragAndDrop = new DragAndDrop();
    this.collectionToDeckDragAndDrop = new DragAndDrop();
    deckToCollectionDragAndDrop.addTarget(new Target(collectionPane) {

        @Override
        public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
            return true;
        }

        @Override
        public void drop(Source source, Payload payload, float x, float y, int pointer) {
            if (selectedDeck == null) {
                return;
            }
            Card card = (Card) payload.getObject();
            selectedDeck.getDeck().removeCard(card, 1);
            updateDeckCards();
        }
    });
    collectionToDeckDragAndDrop.addTarget(new Target(deckCardsPane) {

        @Override
        public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
            return true;
        }

        @Override
        public void drop(Source source, Payload payload, float x, float y, int pointer) {
            if (selectedDeck == null) {
                return;
            }
            Card card = (Card) payload.getObject();
            if (card.getID() == 0) {
                // prevent adding computer to deck
                return;
            }
            if (selectedDeck.getDeck().getCardCount(card.getID()) < software.get(card)) {
                selectedDeck.getDeck().addCard(card, 1);
                updateDeckCards();
            }
        }
    });
    buildCollection();
}
Also used : Profile(com.janfic.games.computercombat.model.Profile) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Deck(com.janfic.games.computercombat.model.Deck) Card(com.janfic.games.computercombat.model.Card) DragAndDrop(com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop)

Aggregations

Profile (com.janfic.games.computercombat.model.Profile)6 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)3 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)3 Card (com.janfic.games.computercombat.model.Card)3 FileHandle (com.badlogic.gdx.files.FileHandle)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)1 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)1 TextFieldFilter (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldFilter)1 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)1 DragAndDrop (com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop)1 CollectionCard (com.janfic.games.computercombat.actors.CollectionCard)1 Deck (com.janfic.games.computercombat.model.Deck)1 Message (com.janfic.games.computercombat.network.Message)1 ResultSet (java.sql.ResultSet)1 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)1 Statement (java.sql.Statement)1