Skip to content

Commit

Permalink
deskArea workable
Browse files Browse the repository at this point in the history
  • Loading branch information
hundun000 committed Jul 22, 2023
1 parent 9f541f6 commit ced3512
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public DemoSaveHandler(IFrontend frontEnd, ISaveTool<RootSaveData> saveTool) {
@Override
protected RootSaveData genereateStarterRootSaveData() {

GridPosition USELESS_POSITON = new GridPosition(0, 0);

return RootSaveData.builder()
.gameplaySave(GameplaySaveData.builder()
Expand All @@ -38,21 +37,21 @@ protected RootSaveData genereateStarterRootSaveData() {
.prototypeId(ConstructionPrototypeId.COOKIE_CLICK_PROVIDER)
.level(0)
.workingLevel(0)
.position(USELESS_POSITON)
.position( new GridPosition(1, 1))
.build(),
ConstructionPrototypeId.COOKIE_AUTO_PROVIDER,
ConstructionSaveData.builder()
.prototypeId(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER)
.level(1)
.workingLevel(1)
.position(USELESS_POSITON)
.position( new GridPosition(1, -1))
.build(),
ConstructionPrototypeId.COOKIE_AUTO_SELLER,
ConstructionSaveData.builder()
.prototypeId(ConstructionPrototypeId.COOKIE_AUTO_SELLER)
.level(1)
.workingLevel(0)
.position(USELESS_POSITON)
.position( new GridPosition(-1, 1))
.build()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
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.corelib.base.util.DrawableFactory;
import hundun.gdxgame.idledemo.ui.screen.BaseDemoPlayScreen;
import hundun.gdxgame.idleshare.core.framework.model.CameraDataPackage;

import hundun.gdxgame.idleshare.core.framework.model.CameraGestureListener;
import hundun.gdxgame.idleshare.core.framework.model.CameraMouseListener;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
import lombok.Getter;

Expand Down Expand Up @@ -40,20 +43,20 @@ public void updateDeskDatas(

Image background = new Image();

background.setDrawable(new TextureRegionDrawable(new Texture(Gdx.files.internal("棋盘.jpg"))));
background.setDrawable(DrawableFactory.getSimpleBoardBackground());

int roomWidth = 5000;
int roomHeight = 5000;

background.setBounds(0, 0, roomWidth, roomHeight);

this.addActor(background);
//this.addListener(new CameraGestureListener(cameraDataPackage));
//this.addListener(new CameraMouseListener(cameraDataPackage));
this.addListener(new CameraGestureListener(cameraDataPackage));
this.addListener(new CameraMouseListener(cameraDataPackage));
this.getCameraDataPackage().forceSet(
roomWidth / 2.0f + 800,
roomHeight/ 2.0f,
null);
0.0f,
0.0f,
null
);

chessRuntimeDataList.forEach(deskData -> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

public abstract class BaseDemoPlayScreen extends BaseIdlePlayScreen<DemoIdleGame, RootSaveData> implements IGameAreaChangeListener {

public BaseDemoPlayScreen(DemoIdleGame game, String startArea) {
super(game, startArea, customLayoutConst(game));
public BaseDemoPlayScreen(DemoIdleGame game) {
super(game, customLayoutConst(game));
}

private static PlayScreenLayoutConst customLayoutConst(DemoIdleGame game) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

Expand All @@ -10,27 +11,32 @@
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.idleshare.core.framework.model.manager.GameEntityManager;
import hundun.gdxgame.idleshare.core.starter.ui.component.GameImageDrawer;
import hundun.gdxgame.idleshare.core.starter.ui.component.GameImageDrawer.GameImageDrawerOwner;
import hundun.gdxgame.idleshare.core.starter.ui.component.PopupInfoBoard;
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.core.starter.ui.screen.play.PlayScreenLayoutConst;
import hundun.gdxgame.idleshare.gamelib.framework.callback.ISecondaryInfoBoardCallback;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
import lombok.Getter;

/**
* @author hundun
* Created on 2021/11/02
*/
public class CookiePlayScreen extends BaseDemoPlayScreen implements GameImageDrawerOwner {

public class CookiePlayScreen extends BaseDemoPlayScreen
implements GameImageDrawerOwner, ISecondaryInfoBoardCallback<BaseConstruction> {
protected PopupInfoBoard<DemoIdleGame, RootSaveData> secondaryInfoBoard;
protected GameEntityManager gameEntityManager;
protected GameImageDrawer<DemoIdleGame, RootSaveData> gameImageDrawer;
protected AbstractConstructionControlBoard<DemoIdleGame, RootSaveData> constructionControlBoard;

public CookiePlayScreen(DemoIdleGame game) {
super(game, GameArea.AREA_COOKIE);
super(game);
}


Expand All @@ -39,7 +45,7 @@ protected void lazyInitUiRootContext() {
super.lazyInitUiRootContext();

// impl switchable
constructionControlBoard = new FixedConstructionControlBoard<>(this);
constructionControlBoard = new FixedConstructionControlBoard<>(this, this);
uiRootTable.add(constructionControlBoard).height(layoutConst.CONSTRUCION_BOARD_ROOT_BOX_HEIGHT).fill();
}

Expand Down Expand Up @@ -83,4 +89,33 @@ public void onDeskClicked(ChessVM vm) {
public GameEntityManager getGameEntityManager() {
return gameEntityManager;
}

@Override
public void showAndUpdateGuideInfo(BaseConstruction model) {
secondaryInfoBoard.setVisible(true);
secondaryInfoBoard.update(model);
}

@Override
public void hideAndCleanGuideInfo() {
secondaryInfoBoard.setVisible(false);
//popUpInfoBoard.setText("GUIDE_TEXT");
}

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

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

}

@Override
protected void updateUIForShow() {
// start area
setAreaAndNotifyChildren(GameArea.AREA_COOKIE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import hundun.gdxgame.idledemo.ui.entity.DeskAreaVM;
import hundun.gdxgame.idledemo.ui.entity.GameEntityFactory;
import hundun.gdxgame.idleshare.core.framework.model.CameraDataPackage;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;

import java.util.List;

/**
* @author hundun
Expand All @@ -24,7 +27,7 @@ public class ForestPlayScreen extends BaseDemoPlayScreen {
protected Stage deskStage;

public ForestPlayScreen(DemoIdleGame game) {
super(game, GameArea.AREA_FOREST);
super(game);

this.deskCamera = new OrthographicCamera();
this.deskStage = new Stage(new ScreenViewport(deskCamera), game.getBatch());
Expand All @@ -49,6 +52,16 @@ protected void lazyInitBackUiAndPopupUiContent() {
deskAreaVM = new DeskAreaVM(this);
deskStage.addActor(deskAreaVM);
deskStage.setScrollFocus(deskAreaVM);

}

@Override
protected void updateUIForShow() {
List<BaseConstruction> constructions = game.getIdleGameplayExport().getGameplayContext().getConstructionManager()
.getConstructions();
deskAreaVM.updateDeskDatas(constructions);
// start area
setAreaAndNotifyChildren(GameArea.AREA_FOREST);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package hundun.gdxgame.idleshare.core.framework.model;

import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener;

public class CameraGestureListener extends ActorGestureListener {

private final CameraDataPackage cameraDataPackage;
float laseZoomValue;

public CameraGestureListener(CameraDataPackage cameraDataPackage) {
this.cameraDataPackage = cameraDataPackage;
}

@Override
public void zoom(InputEvent event, float initialDistance, float distance) {
super.zoom(event, initialDistance, distance);

float newWeight = (initialDistance / distance) * cameraDataPackage.getCurrentCameraZoomWeight();
cameraDataPackage.modifyCurrentCameraZoomWeight(newWeight - cameraDataPackage.getCurrentCameraZoomWeight());
}

@Override
public void pan(InputEvent event, float x, float y, float deltaX, float deltaY) {
super.pan(event, x, y, deltaX, deltaY);

float cameraDeltaX = -deltaX;
float cameraDeltaY = -deltaY;
cameraDataPackage.modifyCurrentCamera(cameraDeltaX, cameraDeltaY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package hundun.gdxgame.idleshare.core.framework.model;

import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;

public class CameraMouseListener extends InputListener {

private final CameraDataPackage cameraDataPackage;

public CameraMouseListener(CameraDataPackage cameraDataPackage) {
this.cameraDataPackage = cameraDataPackage;
}

@Override
public boolean scrolled(InputEvent event, float x, float y, float amountX, float amountY) {
float deltaValue = (amountX + amountY) * 0.1f;
cameraDataPackage.modifyCurrentCameraZoomWeight(deltaValue);
return super.scrolled(event, x, y, amountX, amountY);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@
import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.ConstructionControlNode;
import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdlePlayScreen;
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;

public abstract class AbstractConstructionControlBoard<T_GAME extends BaseIdleGame<T_SAVE>, T_SAVE> extends Table
implements ILogicFrameListener, IGameAreaChangeListener, IConstructionCollectionListener {
protected BaseIdlePlayScreen<T_GAME, T_SAVE> parent;
protected ISecondaryInfoBoardCallback<BaseConstruction> callback;
/**
* 显示在当前screen的Construction集合。以ConstructionView形式存在。
*/
protected List<ConstructionControlNode<T_GAME, T_SAVE>> constructionControlNodes = new ArrayList<>();



public AbstractConstructionControlBoard(BaseIdlePlayScreen<T_GAME, T_SAVE> parent) {
public AbstractConstructionControlBoard(BaseIdlePlayScreen<T_GAME, T_SAVE> parent, ISecondaryInfoBoardCallback<BaseConstruction> callback) {
super();
this.parent = parent;
this.callback = callback;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import hundun.gdxgame.idleshare.core.framework.BaseIdleGame;
import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdlePlayScreen;
import hundun.gdxgame.idleshare.core.starter.ui.screen.play.PlayScreenLayoutConst;
import hundun.gdxgame.idleshare.gamelib.framework.callback.ISecondaryInfoBoardCallback;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;


Expand All @@ -24,6 +25,7 @@
*/
public class ConstructionControlNode<T_GAME extends BaseIdleGame<T_SAVE>, T_SAVE> extends Table {
BaseIdlePlayScreen<T_GAME, T_SAVE> parent;
ISecondaryInfoBoardCallback<BaseConstruction> callback;
BaseConstruction model;
Label constructionNameLabel;
TextButton upWorkingLevelButton;
Expand All @@ -42,9 +44,13 @@ public class ConstructionControlNode<T_GAME extends BaseIdleGame<T_SAVE>, T_SAVE



public ConstructionControlNode(BaseIdlePlayScreen<T_GAME, T_SAVE> parent, int index, PlayScreenLayoutConst playScreenLayoutConst) {
public ConstructionControlNode(
BaseIdlePlayScreen<T_GAME, T_SAVE> parent,
ISecondaryInfoBoardCallback<BaseConstruction> callback,
int index, PlayScreenLayoutConst playScreenLayoutConst) {
super();
this.parent = parent;
this.callback = callback;

int CHILD_WIDTH = playScreenLayoutConst.CONSTRUCION_CHILD_WIDTH;
int CHILD_HEIGHT = playScreenLayoutConst.CONSTRUCION_CHILD_BUTTON_HEIGHT;
Expand Down Expand Up @@ -76,7 +82,7 @@ public void changed(ChangeEvent event, Actor actor) {
@Override
public void clicked(InputEvent event, float x, float y) {
if (model != null) {
parent.showAndUpdateGuideInfo(model);
callback.showAndUpdateGuideInfo(model);
}
Gdx.app.log(ConstructionControlNode.class.getSimpleName(), "this clicked event");
super.clicked(event, x, y);
Expand All @@ -85,15 +91,15 @@ public void clicked(InputEvent event, float x, float y) {
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
if (model != null && pointer == -1) {
parent.showAndUpdateGuideInfo(model);
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) {
parent.hideAndCleanGuideInfo();
callback.hideAndCleanGuideInfo();
}
super.exit(event, x, y, pointer, toActor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.AbstractConstructionControlBoard;
import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.ConstructionControlNode;
import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdlePlayScreen;

import hundun.gdxgame.idleshare.gamelib.framework.callback.ISecondaryInfoBoardCallback;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;


/**
Expand All @@ -21,9 +22,9 @@ public class FixedConstructionControlBoard<T_GAME extends BaseIdleGame<T_SAVE>,
Table childTable;


public FixedConstructionControlBoard(BaseIdlePlayScreen<T_GAME, T_SAVE> parent) {
public FixedConstructionControlBoard(BaseIdlePlayScreen<T_GAME, T_SAVE> parent, ISecondaryInfoBoardCallback<BaseConstruction> callback) {

super(parent);
super(parent, callback);

childTable = new Table();
childTable.setBackground(parent.getLayoutConst().simpleBoardBackgroundMiddle);
Expand All @@ -45,7 +46,7 @@ protected int initChild(int areaShownConstructionsSize) {
childTable.clearChildren();

for (int i = 0; i < childrenSize; i++) {
ConstructionControlNode constructionView = new ConstructionControlNode(parent, i, parent.getLayoutConst());
ConstructionControlNode constructionView = new ConstructionControlNode(parent, callback, i, parent.getLayoutConst());
constructionControlNodes.add(constructionView);
childTable.add(constructionView).spaceRight(10).expand();
}
Expand Down
Loading

0 comments on commit ced3512

Please sign in to comment.