Skip to content

Commit

Permalink
update UI; fix ConstructionManager remove logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hundun000 committed Oct 21, 2023
1 parent 566f975 commit 4366311
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void onConstructionCollectionChange()
{
if (detailingConstruction != null)
{
detailingConstruction = screen.getGame().getIdleGameplayExport().getGameplayContext().getConstructionManager().getConstructionAt(detailingConstruction.getPosition());
detailingConstruction = screen.getGame().getIdleGameplayExport().getGameplayContext().getConstructionManager().getWorldConstructionAt(detailingConstruction.getPosition());
selectCell(detailingConstruction);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@ protected RootSaveData genereateStarterRootSaveData() {
Map<String, ConstructionSaveData> map = new HashMap<>();

GridPosition uselessPosition = new GridPosition(0, 0);
List<GridPosition> worldGridPositions = JavaFeatureForGwt.listOf(
new GridPosition(-1, -1),
new GridPosition(-1, 0),
new GridPosition(-1, 1),
new GridPosition(0, -1),
new GridPosition(0, 0),
new GridPosition(0, 1),
new GridPosition(1, 5),
new GridPosition(1, 4),
new GridPosition(1, 6)
);
GridPosition providerPosition = new GridPosition(1, 1);
List<GridPosition> worldGridPositions = new ArrayList<>();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
GridPosition emptyPosition = new GridPosition(i, j);
if (!emptyPosition.equals(providerPosition)) {
worldGridPositions.add(emptyPosition);
}
}
}
map.put(
DemoConstructionPrototypeId.MAIN_MUSHROOM + "_" + SINGLETON,
ConstructionSaveData.builder()
Expand Down Expand Up @@ -74,7 +73,7 @@ protected RootSaveData genereateStarterRootSaveData() {
.prototypeId(DemoConstructionPrototypeId.EPOCH_1_MUSHROOM_AUTO_PROVIDER)
.level(1)
.workingLevel(1)
.position(worldGridPositions.remove(0))
.position(providerPosition)
.build()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
import hundun.gdxgame.idledemo.logic.DemoBuiltinConstructionsLoader;
import hundun.gdxgame.idledemo.logic.DemoConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.ResourceType;
import hundun.gdxgame.idledemo.logic.construction.BaseIdleDemoConstruction;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
Expand All @@ -17,13 +18,13 @@

public class EpochCounterPrototype extends AbstractConstructionPrototype {
public static DescriptionPackage descriptionPackageEN = DescriptionPackage.builder()
.levelDescriptionProvider(DescriptionPackageFactory.NO_LEVEL_IMP)
.levelDescriptionProvider(DescriptionPackageFactory.WORKING_LEVEL_IMP)
.proficiencyDescriptionProvider(DescriptionPackageFactory.EN_PROFICIENCY_IMP)
.build();


public static DescriptionPackage descriptionPackageCN = DescriptionPackage.builder()
.levelDescriptionProvider(DescriptionPackageFactory.CN_NO_LEVEL_IMP)
.levelDescriptionProvider(DescriptionPackageFactory.CN_WORKING_LEVEL_IMP)
.proficiencyDescriptionProvider(DescriptionPackageFactory.CN_PROFICIENCY_IMP)
.build();

Expand Down Expand Up @@ -57,6 +58,23 @@ public BaseConstruction getInstance(GridPosition position) {
SimpleAutoOutputComponent outputComponent = new SimpleAutoOutputComponent(thiz);
thiz.setOutputComponent(outputComponent);

thiz.getUpgradeComponent().setUpgradeCostPack(DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf(
ResourceType.DNA_POINT, 0
)));
thiz.getUpgradeComponent().setCalculateCostFunction((baseValue, level) -> {
switch (level) {
case 0:
return 50L;
case 1:
return 100L;
case 2:
return 150L;
default:
return 1L;
}
});
thiz.getLevelComponent().maxLevel = 3;

return thiz;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import hundun.gdxgame.idledemo.ui.shared.BaseCellDetailNodeVM;
import hundun.gdxgame.idledemo.ui.shared.ConstructionDetailPartVM;
import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.StarterConstructionControlNode;
import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.StarterConstructionControlNode.StarterSecondaryInfoBoardCallerClickListener;
import hundun.gdxgame.idleshare.core.starter.ui.screen.play.PlayScreenLayoutConst;
import hundun.gdxgame.idleshare.gamelib.framework.callback.IConstructionCollectionListener;
import hundun.gdxgame.idleshare.gamelib.framework.callback.ISecondaryInfoBoardCallback;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.UpgradeComponent.UpgradeState;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -40,7 +42,6 @@ public class MainScreenConstructionControlBoard extends Table
protected ISecondaryInfoBoardCallback<BaseConstruction> callback;

protected SellerPart sellerPart;
protected ConstructionDetailPartVM sellerDetailPart;
protected EpochPart epochPart;
protected ConstructionDetailPartVM epochDetailPart;
public MainScreenConstructionControlBoard(BaseDemoPlayScreen parent, ISecondaryInfoBoardCallback<BaseConstruction> callback) {
Expand Down Expand Up @@ -81,9 +82,6 @@ public void onConstructionCollectionChange() {
this.sellerPart = new SellerPart(parent, callback);
this.add(sellerPart).spaceRight(10).expand();

this.sellerDetailPart = new ConstructionDetailPartVM(parent);
this.add(sellerDetailPart).spaceRight(10).expand();

this.epochPart = new EpochPart(parent, callback);
this.add(epochPart).spaceRight(10).expand();

Expand All @@ -95,14 +93,13 @@ public void onConstructionCollectionChange() {
.findAny()
.orElse(null);
this.sellerPart.updateAsConstruction(sellerConstruction);
this.sellerDetailPart.rebuildCells(sellerConstruction);

BaseConstruction epochConstruction = singletonConstructions.stream()
.filter(it -> it.getPrototypeId().equals(DemoConstructionPrototypeId.EPOCH_COUNTER))
.findAny()
.orElse(null);
this.epochPart.updateAsConstruction(epochConstruction);
this.epochDetailPart.rebuildCells(sellerConstruction);
this.epochDetailPart.rebuildCells(epochConstruction);

parent.getGame().getFrontend().log("ConstructionInfoBorad",
"Constructions change to: " + singletonConstructions.stream().map(BaseConstruction::getName).collect(Collectors.joining(","))
Expand All @@ -121,7 +118,6 @@ public static class EpochPart extends BaseCellDetailNodeVM {




public EpochPart(
BaseDemoPlayScreen parent,
ISecondaryInfoBoardCallback<BaseConstruction> callback) {
Expand Down Expand Up @@ -156,33 +152,7 @@ public void changed(ChangeEvent event, Actor actor) {
this.add(upgradeButton).size(CHILD_WIDTH, CHILD_HEIGHT).row();
this.add(workingLevelLabel).size(CHILD_WIDTH, CHILD_HEIGHT).row();
this.setBackground(DrawableFactory.createBorderBoard(30, 10, 0.8f, 1));
this.addListener(new ClickListener() {

@Override
public void clicked(InputEvent event, float x, float y) {
if (model != null) {
callback.showAndUpdateGuideInfo(model);
}
Gdx.app.log(StarterConstructionControlNode.class.getSimpleName(), "this clicked event");
super.clicked(event, x, y);
}

@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
if (model != null && pointer == -1) {
callback.showAndUpdateGuideInfo(model);
}
super.enter(event, x, y, pointer, fromActor);
}

@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
if (pointer == -1) {
callback.hideAndCleanGuideInfo();
}
super.exit(event, x, y, pointer, toActor);
}
});
this.addListener(new StarterSecondaryInfoBoardCallerClickListener(model, callback));
}

private void update() {
Expand All @@ -199,10 +169,8 @@ private void update() {
}
// ------ update text ------
constructionNameLabel.setText(JavaFeatureForGwt.stringFormat(
"%s (%s, %s)",
model.getName(),
model.getSaveData().getPosition().getX(),
model.getSaveData().getPosition().getY()
"%s",
model.getName()
));
upgradeButton.setText(model.getDescriptionPackage().getUpgradeButtonText());
workingLevelLabel.setText(model.getLevelComponent().getWorkingLevelDescription());
Expand Down Expand Up @@ -248,7 +216,7 @@ public static class SellerPart extends BaseCellDetailNodeVM {

Table changeWorkingLevelGroup;


Table detailGroup;


public SellerPart(
Expand Down Expand Up @@ -302,40 +270,17 @@ public void clicked(InputEvent event, float x, float y) {
});
changeWorkingLevelGroup.add(upWorkingLevelButton).size(CHILD_WIDTH / 4, CHILD_HEIGHT);

detailGroup = new Table();

this.transformButton = new TextButton("-", parent.getGame().getMainSkin());
// ------ this ------
this.add(constructionNameLabel).size(CHILD_WIDTH, NAME_CHILD_HEIGHT).row();
this.add(upgradeButton).size(CHILD_WIDTH, CHILD_HEIGHT).row();
this.add(changeWorkingLevelGroup).size(CHILD_WIDTH, CHILD_HEIGHT).row();
this.setBackground(DrawableFactory.createBorderBoard(30, 10, 0.8f, 1));
this.addListener(new ClickListener() {

@Override
public void clicked(InputEvent event, float x, float y) {
if (model != null) {
callback.showAndUpdateGuideInfo(model);
}
Gdx.app.log(StarterConstructionControlNode.class.getSimpleName(), "this clicked event");
super.clicked(event, x, y);
}
this.add(detailGroup).row();

@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
if (model != null && pointer == -1) {
callback.showAndUpdateGuideInfo(model);
}
super.enter(event, x, y, pointer, fromActor);
}

@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
if (pointer == -1) {
callback.hideAndCleanGuideInfo();
}
super.exit(event, x, y, pointer, toActor);
}
});
this.setBackground(DrawableFactory.createBorderBoard(30, 10, 0.8f, 1));
this.addListener(new StarterSecondaryInfoBoardCallerClickListener(model, callback));
}

private void update() {
Expand All @@ -350,6 +295,16 @@ private void update() {
//textButton.setVisible(true);
//Gdx.app.log("ConstructionView", model.getName() + " set to its view");
}

detailGroup.clearChildren();
ConstructionDetailPartVM.resourcePackAsActor(model.getOutputComponent().getOutputCostPack(), detailGroup, parent);

ConstructionDetailPartVM.resourcePackAsActor(model.getOutputComponent().getOutputGainPack(), detailGroup, parent);

if (model.getUpgradeComponent().getUpgradeState() == UpgradeState.HAS_NEXT_UPGRADE) {
ConstructionDetailPartVM.resourcePackAsActor(model.getUpgradeComponent().getUpgradeCostPack(), detailGroup, parent);
}

// ------ update text ------
constructionNameLabel.setText(JavaFeatureForGwt.stringFormat(
"%s (%s, %s)",
Expand All @@ -358,7 +313,7 @@ private void update() {
model.getSaveData().getPosition().getY()
));
upgradeButton.setText(model.getDescriptionPackage().getUpgradeButtonText());
workingLevelLabel.setText(model.getLevelComponent().getWorkingLevelDescription());
workingLevelLabel.setText(model.getLevelComponent().getWorkingLevelDescription() + "; max: " + model.getMaxLevel());


// ------ update clickable-state ------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,40 @@

import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Image;

import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import hundun.gdxgame.idledemo.DemoIdleGame;
import hundun.gdxgame.idledemo.logic.DemoScreenId;
import hundun.gdxgame.idledemo.logic.ResourceType;
import hundun.gdxgame.idledemo.logic.RootSaveData;
import hundun.gdxgame.idledemo.ui.main.MainScreenConstructionControlBoard;
import hundun.gdxgame.idledemo.ui.world.HexCellVM;
import hundun.gdxgame.idledemo.ui.main.GameEntityFactory;
import hundun.gdxgame.idleshare.core.framework.BaseIdleGame;
import hundun.gdxgame.idleshare.core.framework.model.manager.GameEntityManager;
import hundun.gdxgame.idleshare.core.starter.ui.component.GameImageDrawer;
import hundun.gdxgame.idleshare.core.starter.ui.component.PopupInfoBoard;
import hundun.gdxgame.idleshare.core.starter.ui.component.ResourceAmountPairNode;
import hundun.gdxgame.idleshare.core.starter.ui.component.animation.MainClickerAnimationVM;
import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdleScreen;
import hundun.gdxgame.idleshare.gamelib.framework.callback.ISecondaryInfoBoardCallback;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.UpgradeComponent.UpgradeState;
import hundun.gdxgame.idleshare.gamelib.framework.model.resource.ResourcePack;
import hundun.gdxgame.idleshare.gamelib.framework.model.resource.ResourcePair;

/**
* @author hundun
* Created on 2021/11/02
*/
public class MainPlayScreen extends BaseDemoPlayScreen
implements ISecondaryInfoBoardCallback<BaseConstruction> {
protected PopupInfoBoard<DemoIdleGame, RootSaveData> secondaryInfoBoard;
protected MainScreenPopupInfoBoard secondaryInfoBoard;
protected GameEntityManager gameEntityManager;
protected GameImageDrawer<DemoIdleGame, RootSaveData> gameImageDrawer;
protected MainClickerAnimationVM<DemoIdleGame, RootSaveData> mainClickerAnimationVM;
Expand All @@ -33,6 +44,36 @@ public MainPlayScreen(DemoIdleGame game) {
super(game, DemoScreenId.SCREEN_MAIN);
}

public static class MainScreenPopupInfoBoard extends Table {

MainPlayScreen parent;

public MainScreenPopupInfoBoard(MainPlayScreen parent) {
//super("GUIDE_TEXT", parent.game.getButtonSkin());
this.parent = parent;
//this.setBounds(5, GameAreaControlBoard.Y, GameAreaControlBoard.X - 10, 120);
this.setTouchable(Touchable.disabled);
this.setBackground(parent.getLayoutConst().simpleBoardBackground);
this.setVisible(false);
}


private void rebuildCells(BaseConstruction model) {
this.clearChildren();

add(new Label(model.getDetailDescroptionConstPart(), parent.getGame().getMainSkin()))
.colspan(3)
.left()
.row();

}

public void update(BaseConstruction model) {
rebuildCells(model);
}


}

@Override
protected void lazyInitUiRootContext() {
Expand Down Expand Up @@ -104,7 +145,7 @@ public void hideAndCleanGuideInfo() {
protected void lazyInitBackUiAndPopupUiContent() {
super.lazyInitBackUiAndPopupUiContent();

this.secondaryInfoBoard = new PopupInfoBoard<>(this);
this.secondaryInfoBoard = new MainScreenPopupInfoBoard(this);
popupRootTable.add(secondaryInfoBoard).bottom().expand().row();
popupRootTable.add(new Image())
.height(layoutConst.CONSTRUCION_BOARD_ROOT_BOX_HEIGHT);
Expand Down
Loading

0 comments on commit 4366311

Please sign in to comment.