propsStore version2 - UQdeco2800/2021-ext-studio-2 GitHub Wiki

Where could be find the prop store?

Description: You can enter the props store through the gold coin icon in the upper right corner of the menu.

How does the prop store look on the whole?

Description: Props store is a place to buy props, and props are placed on shelves.

What sort of props could we purchase?

Description: There are 6 kinds of props in the props store, including firstAidKit, apple, magicPotion, bandage, water and syringe.

Where could we find how many goldCoin we've got?

Description: You can see the number of gold coins in the upper left corner.

The prop firstAidKit and its detail:

The prop apple and its detail:

The prop magicPotion and its detail:

The prop bandage and its detail:

The prop water and its detail:

The prop syringe and its detail:

The backgroundMusic button and its detail:

The exit button:

How they implemented?

They were implemented from PropStoreDisplay.java PropStoreGoldDisplay.java PropStoreItemDisplay.java and PropStoreRecord.java

Under PropStoreDisplay.java:

There are two main func used to create the exit button and the item label

private Table createExitButton(){
        Image exitImg = new Image(ServiceLocator.getResourceService().getAsset("images/achievements/crossButton.png", Texture.class));
        ImageButton exitImageButton = new ImageButton(exitImg.getDrawable());
        exitImageButton.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                game.setScreen(GdxGame.ScreenType.MAIN_MENU);
            }
        });
        Table table = new Table();
        table.setFillParent(true);
        table.top().right();

        table.add(exitImageButton);
        return table;
    }

private Table createItemTable(){
        Table table = new Table();
        table.setFillParent(true);
        table.center();
        PropStoreFactory.getPropStoreItems().forEach(item -> {
            Label price = new Label("Gold $: " + item.price, new Label.LabelStyle(new BitmapFont(), Color.YELLOW));
            price.setFontScale(2f);
            TextButton button = new TextButton("View",skin);
            button.addListener(new ChangeListener() {
                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    entity.getEvents().trigger("openItem", item);
                }
            });
            button.setColor(Color.RED);
            Image img = new Image(ServiceLocator.getResourceService().getAsset(item.path, Texture.class));
            Table itemTable = new Table();
            itemTable.add(img);
            itemTable.row();
            itemTable.add(price);
            itemTable.padLeft(20f).padRight(20f);
            itemTable.row();
            itemTable.add(button);
            table.add(itemTable);



        });

        return table;

    }

Under PropStoreGoldDisplay.java:

There is a func used to display the goldCoin amount:

private void displayGold(){
        Table table = new Table();
        table.setFillParent(true);
        table.top().left();
        Label price = new Label("Total Gold $: " + PropStoreRecord.getGold(), new Label.LabelStyle(new BitmapFont(), Color.YELLOW));
        price.setFontScale(1.5f);
        price.setWrap(true);
        table.add(price);
        stage.addActor(table);


    }

Under PropStoreItemDisplay.java:

There are three func used to display the props details, render the exit button and bought button:

private void openItem(PropItemConfig item){

        dialog = new Dialog("", skin);
        dialog.setModal(true);
        dialog.setMovable(false);
        dialog.setResizable(true);
        Image img = new Image(new Texture(item.path));
        // Image background = new Image(new Texture("images/story/chapterDialog.png"));
        //background.setScaling(Scaling.fit);
        //dialog.setBackground(background.getDrawable());
        dialog.pad(50).padTop(120);
        Label desc = new Label(item.desc, new Label.LabelStyle(new BitmapFont(), Color.DARK_GRAY));
        desc.setFontScale(1.1f);
        desc.setWrap(true);
        desc.setAlignment(Align.center);
        Label price = new Label("Gold $: " + item.price, new Label.LabelStyle(new BitmapFont(), Color.YELLOW));
        dialog.row();
        price.setFontScale(1.5f);
        price.setWrap(true);
        price.setAlignment(Align.center);

       // buyButton.setDisabled(true);
        dialog.getContentTable().add(img).height(122).width(240).row();
        dialog.getContentTable().add(desc).width(600).row();
        dialog.getContentTable().add(price).width(600).row();
        dialog.getButtonTable().add(renderButton(item)).size(600,100).row();
        dialog.getButtonTable().add(renderCloseButton()).size(50, 50).row();
        dialog.show(stage);

    }
private ImageButton renderCloseButton() {
        Image crossButtonImg = new Image(new Texture("images/achievements/crossButton.png"));

        ImageButton closeButton = new ImageButton(crossButtonImg.getDrawable());

        closeButton.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                dialog.hide();
            }
        });

        return closeButton;
    }
private TextButton renderButton(PropItemConfig item){
        if(PropStoreRecord.isItemBought(item)){
            TextButton buyButton = new TextButton("Bought!", skin);
            buyButton.setColor(Color.LIME);
            buyButton.setDisabled(true);
            return buyButton;
        }
        if(PropStoreRecord.hasEnoughGold(item.price)) {
            TextButton buyButton = new TextButton("Buy for " + item.price + " gold", skin);
            buyButton.setColor(Color.ROYAL);
            buyButton.addListener(new ChangeListener() {
                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    PropStoreRecord.buyItem(item);
                    entity.getEvents().trigger("GoldUpdate");
                    buyButton.setText("Bought!");
                    buyButton.setColor(Color.LIME);
                    buyButton.setDisabled(true);
                }
            });
            return buyButton;
        }else{
            TextButton buyButton = new TextButton("You do not have enough Gold", skin);
            buyButton.setColor(Color.BLACK);
            buyButton.setDisabled(true);
            return buyButton;
        }
    }

And under the PropStoreRecord.java

There are few funcs used to record the goldCoin amount:

public static int getGold() {
        Gold goldRecord = FileLoader.readClass(Gold.class, goldPath, location);
        return goldRecord != null ? goldRecord.gold : new Gold().gold;
    }

    public static void setGold(int gold) {
        Gold goldRecord = new Gold();
        goldRecord.gold = gold;
        FileLoader.writeClass(goldRecord, goldPath, location);
    }
    public static void subtractGold(int amount){

        int gold = getGold();
        if(gold >= amount) {
            gold = gold - amount;
            setGold(gold);
        }
    }

UML class diagram

Zoom.png PropStoreDisplay.java

PropStoreGoldDisplay.java

PropStoreItemDisplay.java

UML sequence diagram

PropStoreDisplay.java

PropStoreGoldDisplay.java

PropStoreItemDisplay.java