Skip to content

Commit

Permalink
WIP WorldCellDetailBoard
Browse files Browse the repository at this point in the history
  • Loading branch information
hundun000 committed Sep 10, 2023
1 parent de7423e commit 792dd86
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public class ConstructionPrototypeId {
public static final String COOKIE_CLICK_PROVIDER = "ENUM_CSTR@COOKIE_CLICK_PROVIDER";
public static final String COOKIE_AUTO_PROVIDER = "ENUM_CSTR@COOKIE_AUTO_PROVIDER";
public static final String COOKIE_AUTO_SELLER = "ENUM_CSTR@COOKIE_AUTO_SELLER";
public static final String DIRT = "ENUM_CSTR@DIRT";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
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 com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import hundun.gdxgame.corelib.base.util.DrawableFactory;
import hundun.gdxgame.idledemo.DemoIdleGame;
import hundun.gdxgame.idledemo.ui.screen.ForestPlayScreen;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
import lombok.Getter;

Expand All @@ -21,11 +24,12 @@ public class ChessVM extends Table {
DeskAreaVM deskAreaVM;
@Getter
BaseConstruction deskData;
public ForestPlayScreen parent;

Label mainLabel;
Image image;

public ChessVM(DeskAreaVM deskAreaVM, BaseConstruction deskData) {
public ChessVM(ForestPlayScreen parent, DeskAreaVM deskAreaVM, BaseConstruction deskData) {
this.game = deskAreaVM.screen.getGame();
this.deskAreaVM = deskAreaVM;
this.deskData = deskData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import hundun.gdxgame.corelib.base.util.DrawableFactory;
import hundun.gdxgame.idledemo.ui.screen.BaseDemoPlayScreen;
import hundun.gdxgame.idledemo.ui.screen.ForestPlayScreen;
import hundun.gdxgame.idleshare.core.framework.model.CameraDataPackage;

import hundun.gdxgame.idleshare.core.framework.model.CameraGestureListener;
Expand All @@ -21,13 +22,13 @@


public class DeskAreaVM extends Table {
public BaseDemoPlayScreen screen;
public ForestPlayScreen screen;
@Getter
Map<String, ChessVM> nodes = new LinkedHashMap<>();
@Getter
CameraDataPackage cameraDataPackage;

public DeskAreaVM(BaseDemoPlayScreen screen) {
public DeskAreaVM(ForestPlayScreen screen) {
this.screen = screen;
this.cameraDataPackage = new CameraDataPackage();

Expand Down Expand Up @@ -60,7 +61,7 @@ public void updateDeskDatas(

chessRuntimeDataList.forEach(deskData -> {

ChessVM actor = new ChessVM(this, deskData);
ChessVM actor = new ChessVM(screen, this, deskData);
nodes.put(deskData.getId(), actor);
actor.addListener(new DeskClickListener(screen, actor));
this.addActor(actor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import hundun.gdxgame.idledemo.DemoIdleGame;
import hundun.gdxgame.idledemo.logic.GameArea;
import hundun.gdxgame.idledemo.logic.ResourceType;
import hundun.gdxgame.idledemo.logic.RootSaveData;
import hundun.gdxgame.idledemo.ui.entity.ChessVM;
import hundun.gdxgame.idledemo.ui.entity.DeskAreaVM;
import hundun.gdxgame.idledemo.ui.entity.GameEntityFactory;
import hundun.gdxgame.idledemo.ui.world.WorldCellDetailBoardVM;
import hundun.gdxgame.idleshare.core.framework.model.CameraDataPackage;
import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.AbstractConstructionControlBoard;
import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.fixed.FixedConstructionControlBoard;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
import lombok.Getter;

import java.util.List;

Expand All @@ -26,23 +31,31 @@ public class ForestPlayScreen extends BaseDemoPlayScreen {
protected OrthographicCamera deskCamera;
protected Stage deskStage;

protected WorldCellDetailBoardVM worldCellDetailBoardVM;

public ForestPlayScreen(DemoIdleGame game) {
super(game);

this.deskCamera = new OrthographicCamera();
this.deskStage = new Stage(new ScreenViewport(deskCamera), game.getBatch());
}




@Override
protected void lazyInitUiRootContext() {
super.lazyInitUiRootContext();

worldCellDetailBoardVM = new WorldCellDetailBoardVM(this);
uiRootTable.add(worldCellDetailBoardVM).height(layoutConst.CONSTRUCION_BOARD_ROOT_BOX_HEIGHT).fill();
}

protected void lazyInitLogicContext() {
super.lazyInitLogicContext();

storageInfoTable.lazyInit(ResourceType.VALUES_FOR_SHOW_ORDER);
gameAreaControlBoard.lazyInit(GameArea.values);

this.getGame().getIdleGameplayExport().getGameplayContext().getEventManager().registerListener(worldCellDetailBoardVM);
}

@Override
Expand Down Expand Up @@ -92,6 +105,6 @@ protected InputProcessor provideDefaultInputProcessor() {

@Override
public void onDeskClicked(ChessVM vm) {

worldCellDetailBoardVM.updateDetail(vm.getDeskData());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package hundun.gdxgame.idledemo.ui.world;

import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import hundun.gdxgame.gamelib.starter.listerner.ILogicFrameListener;
import hundun.gdxgame.idledemo.ui.screen.BaseDemoPlayScreen;

import java.util.ArrayList;
import java.util.List;

public class BaseCellDetailBoardVM extends Table implements ILogicFrameListener {
protected BaseDemoPlayScreen parent;



protected List<CellDetailInnerBoardVM> contents = new ArrayList<>();

public void onLogicFrame()
{
contents.forEach(it -> {
it.update();
});
}

public void postPrefabInitialization(BaseDemoPlayScreen parent)
{
//super("GUIDE_TEXT", parent.game.getButtonSkin());
this.parent = parent;
this.setBackground(new TextureRegionDrawable(parent.getGame().getTextureManager().getDefaultBoardNinePatchTexture()));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package hundun.gdxgame.idledemo.ui.world;

import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import hundun.gdxgame.idledemo.ui.screen.BaseDemoPlayScreen;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition;

public class CellDetailInnerBoardVM extends Table {

Label label;

public void postPrefabInitialization(BaseDemoPlayScreen parent) {
label = new Label("", parent.getGame().getMainSkin());
this.add(label);
}

public void update() {

}


public void update(BaseConstruction construction, GridPosition position) {
label.setText("construction: " + construction.getName());
}

public void update(AbstractConstructionPrototype constructionPrototype, GridPosition position) {
label.setText("constructionPrototype: " + constructionPrototype.getPrototypeId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package hundun.gdxgame.idledemo.ui.world;

import com.badlogic.gdx.scenes.scene2d.ui.Table;
import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId;
import hundun.gdxgame.idledemo.ui.screen.ForestPlayScreen;
import hundun.gdxgame.idleshare.gamelib.framework.callback.IConstructionCollectionListener;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

public class WorldCellDetailBoardVM extends BaseCellDetailBoardVM implements IConstructionCollectionListener {
@Getter
@Setter
public BaseConstruction data;


public WorldCellDetailBoardVM(ForestPlayScreen parent)
{
super.postPrefabInitialization(parent);
updateDetail(null);
}

public void updateDetail(BaseConstruction construction)
{
this.data = construction;
if (construction == null)
{
updateAsEmpty();
return;
}

switch (construction.getPrototypeId())
{
case ConstructionPrototypeId.DIRT:
updateAsConstructionPrototypeDetail(construction);
break;
default:
updateAsConstructionDetail(construction);
break;
}
}
private void updateAsEmpty()
{
this.clearChildren();
contents.clear();
}

private void updateAsConstructionDetail(BaseConstruction construction)
{
this.clearChildren();
contents.clear();

CellDetailInnerBoardVM innerBoardVM = new CellDetailInnerBoardVM();
innerBoardVM.postPrefabInitialization(parent);
innerBoardVM.update(construction, construction.getSaveData().getPosition());
this.add(innerBoardVM);
contents.add(innerBoardVM);

}

private void updateAsConstructionPrototypeDetail(BaseConstruction construction)
{
this.clearChildren();
contents.clear();

List<AbstractConstructionPrototype> constructionPrototypes = parent.getGame().getIdleGameplayExport()
.getGameplayContext()
.getConstructionManager()
.getAreaShownConstructionPrototypesOrEmpty(parent.getArea());

constructionPrototypes.forEach(constructionPrototype -> {
CellDetailInnerBoardVM innerBoardVM = new CellDetailInnerBoardVM();
innerBoardVM.postPrefabInitialization(parent);
innerBoardVM.update(constructionPrototype, construction.getSaveData().getPosition());
this.add(innerBoardVM);
contents.add(innerBoardVM);
});

}

@Override
public void onConstructionCollectionChange()
{
if (data != null)
{
data = parent.getGame().getIdleGameplayExport().getGameplayContext().getConstructionManager().getConstructionAt(data.getPosition());
updateDetail(data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,10 @@ public void AddToRemoveQueue(BaseConstruction construction)
public ITileNode<Void> getValidNodeOrNull(GridPosition position) {
return getConstructionAt(position);
}

public List<AbstractConstructionPrototype> getAreaShownConstructionPrototypesOrEmpty(String gameArea) {
return areaControlableConstructionPrototypeVMPrototypeIds.get(gameArea).stream()
.map(it -> gameContext.getConstructionFactory().getPrototype(it))
.collect(Collectors.toList());
}
}

0 comments on commit 792dd86

Please sign in to comment.