Skip to content

Commit

Permalink
some rename package; update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
hundun000 committed Oct 21, 2023
1 parent 4973a96 commit 817a0dd
Show file tree
Hide file tree
Showing 23 changed files with 369 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public String constructionPrototypeIdToDetailDescriptionConstPart(Language langu
case DemoConstructionPrototypeId.COOKIE_COMPLEX_AUTO_PROVIDER:
case DemoConstructionPrototypeId.COOKIE_SIMPLE_AUTO_PROVIDER:
return "自动获得饼干";
case DemoConstructionPrototypeId.SINGLETON_COOKIE_AUTO_SELLER:
return "自动出售饼干";
case DemoConstructionPrototypeId.EMPTY_CELL:
return "空位置";
default:
Expand All @@ -65,6 +67,8 @@ public String constructionPrototypeIdToDetailDescriptionConstPart(Language langu
case DemoConstructionPrototypeId.COOKIE_COMPLEX_AUTO_PROVIDER:
case DemoConstructionPrototypeId.COOKIE_SIMPLE_AUTO_PROVIDER:
return "Auto gain some cookie";
case DemoConstructionPrototypeId.SINGLETON_COOKIE_AUTO_SELLER:
return "Auto sell some cookie";
case DemoConstructionPrototypeId.EMPTY_CELL:
return "Empty";
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ protected void tryProficiencyOnce() {
long neighborCount = construction.getNeighbors().values().stream()
.map(it -> (BaseConstruction)it)
.filter(it -> it != null
&& it.getSaveData().prototypeId.equals(DemoConstructionPrototypeId.COOKIE_SIMPLE_AUTO_PROVIDER)
&& it.getSaveData().prototypeId.equals(DemoConstructionPrototypeId.COOKIE_COMPLEX_AUTO_PROVIDER)
&& (
it.getSaveData().prototypeId.equals(DemoConstructionPrototypeId.COOKIE_SIMPLE_AUTO_PROVIDER)
|| it.getSaveData().prototypeId.equals(DemoConstructionPrototypeId.COOKIE_COMPLEX_AUTO_PROVIDER)
)
)
.count();
this.changeProficiency((int) neighborCount);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hundun.gdxgame.idledemo.ui.sub;
package hundun.gdxgame.idledemo.ui.achievement;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hundun.gdxgame.idledemo.ui.sub;
package hundun.gdxgame.idledemo.ui.achievement;

import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hundun.gdxgame.idledemo.ui.sub;
package hundun.gdxgame.idledemo.ui.achievement;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hundun.gdxgame.idledemo.ui.sub;
package hundun.gdxgame.idledemo.ui.main;

import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package hundun.gdxgame.idledemo.ui.entity;
package hundun.gdxgame.idledemo.ui.main;

import hundun.gdxgame.idledemo.logic.DemoConstructionPrototypeId;
import hundun.gdxgame.idledemo.logic.ResourceType;
import hundun.gdxgame.idledemo.ui.screen.CookiePlayScreen;
import hundun.gdxgame.idledemo.ui.screen.MainPlayScreen;
import hundun.gdxgame.idleshare.core.framework.model.entity.BaseGameEntityFactory;
import hundun.gdxgame.idleshare.core.framework.model.entity.GameEntity;
import hundun.gdxgame.idleshare.core.starter.ui.screen.play.PlayScreenLayoutConst;
Expand All @@ -19,7 +19,7 @@ public class GameEntityFactory extends BaseGameEntityFactory {

public float RESOURCE_MAX_DRAW_NUM = 15;

public GameEntityFactory(PlayScreenLayoutConst layoutConst, CookiePlayScreen parent) {
public GameEntityFactory(PlayScreenLayoutConst layoutConst, MainPlayScreen parent) {
super(layoutConst, parent);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package hundun.gdxgame.idledemo.ui.main;

import com.badlogic.gdx.scenes.scene2d.ui.Table;
import hundun.gdxgame.gamelib.starter.listerner.IGameAreaChangeListener;
import hundun.gdxgame.gamelib.starter.listerner.ILogicFrameListener;
import hundun.gdxgame.idledemo.DemoIdleGame;
import hundun.gdxgame.idledemo.logic.RootSaveData;
import hundun.gdxgame.idledemo.ui.screen.BaseDemoPlayScreen;
import hundun.gdxgame.idleshare.core.framework.BaseIdleGame;
import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.AbstractConstructionControlBoard;
import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.StarterConstructionControlNode;
import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdleScreen;
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 java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
* @author hundun
* Created on 2021/11/05
*/
public class MainScreenConstructionControlBoard extends Table
implements ILogicFrameListener, IGameAreaChangeListener, IConstructionCollectionListener
{


public static int FIXED_NODE_NUM = 5;

Table childTable;
BaseDemoPlayScreen parent;
protected ISecondaryInfoBoardCallback<BaseConstruction> callback;
/**
* 显示在当前screen的Construction集合。以ConstructionView形式存在。
*/
protected List<MainScreenConstructionControlNode> constructionControlNodes = new ArrayList<>();
public MainScreenConstructionControlBoard(BaseDemoPlayScreen parent, ISecondaryInfoBoardCallback<BaseConstruction> callback) {
this.parent = parent;
this.callback = callback;

childTable = new Table();
childTable.setBackground(parent.getLayoutConst().simpleBoardBackgroundMiddle);

this.add(childTable);

this.setBackground(parent.getLayoutConst().simpleBoardBackground);

if (parent.getGame().debugMode) {
this.debugCell();
}
}

protected int initChild(int areaShownConstructionsSize) {
int childrenSize = FIXED_NODE_NUM;

constructionControlNodes.clear();
childTable.clearChildren();

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

return childrenSize;

}


@Override
public void onLogicFrame() {
constructionControlNodes.forEach(item -> item.subLogicFrame());
}

@Override
public void onGameAreaChange(String last, String current) {
onConstructionCollectionChange();
}

@Override
public void onConstructionCollectionChange() {
List<BaseConstruction> newConstructions = parent.getGame().getIdleGameplayExport().getGameplayContext()
.getConstructionManager().getSingletonConstructionInstancesOrEmpty();

int childrenSize = initChild(newConstructions.size());

for (int i = 0; i < childrenSize && i < newConstructions.size(); i++)
{
constructionControlNodes.get(i).updateAsConstruction(newConstructions.get(i));
}
for (int i = newConstructions.size(); i < childrenSize; i++)
{
constructionControlNodes.get(i).updateAsConstruction(null);
}
parent.getGame().getFrontend().log("ConstructionInfoBorad",
"Constructions change to: " + newConstructions.stream().map(BaseConstruction::getName).collect(Collectors.joining(","))
);
}


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

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import hundun.gdxgame.corelib.base.util.DrawableFactory;
import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
import hundun.gdxgame.idledemo.ui.screen.BaseDemoPlayScreen;
import hundun.gdxgame.idledemo.ui.shared.BaseCellDetailNodeVM;
import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.StarterConstructionControlNode;
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;


/**
* @author hundun
* Created on 2021/11/05
*/
public class MainScreenConstructionControlNode extends BaseCellDetailNodeVM {
BaseDemoPlayScreen parent;
BaseConstruction model;
Label constructionNameLabel;
TextButton upWorkingLevelButton;
TextButton downWorkingLevelButton;
Label workingLevelLabel;

TextButton upgradeButton;
TextButton transformButton;

Table changeWorkingLevelGroup;




public MainScreenConstructionControlNode(
BaseDemoPlayScreen parent,
ISecondaryInfoBoardCallback<BaseConstruction> callback) {
super();
final PlayScreenLayoutConst playScreenLayoutConst = parent.getLayoutConst();
this.parent = parent;

int CHILD_WIDTH = playScreenLayoutConst.CONSTRUCION_CHILD_WIDTH;
int CHILD_HEIGHT = playScreenLayoutConst.CONSTRUCION_CHILD_BUTTON_HEIGHT;
int NAME_CHILD_HEIGHT = playScreenLayoutConst.CONSTRUCION_CHILD_NAME_HEIGHT;

this.constructionNameLabel = new Label("", parent.getGame().getMainSkin());
constructionNameLabel.setWrap(true);


this.upgradeButton = new TextButton("", parent.getGame().getMainSkin());
upgradeButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Gdx.app.log(MainScreenConstructionControlNode.class.getSimpleName(), "upgradeButton changed");
model.getUpgradeComponent().doUpgrade();
}
});

// ------ changeWorkingLevelGroup ------
this.changeWorkingLevelGroup = new Table();

this.downWorkingLevelButton = new TextButton("-", parent.getGame().getMainSkin());
downWorkingLevelButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("ConstructionView", "down clicked");
model.getLevelComponent().changeWorkingLevel(-1);
}
});
changeWorkingLevelGroup.add(downWorkingLevelButton).size(CHILD_WIDTH / 4, CHILD_HEIGHT);

this.workingLevelLabel = new Label("", parent.getGame().getMainSkin());
workingLevelLabel.setAlignment(Align.center);
changeWorkingLevelGroup.add(workingLevelLabel).size(CHILD_WIDTH / 2, CHILD_HEIGHT);

this.upWorkingLevelButton = new TextButton("+", parent.getGame().getMainSkin());
upWorkingLevelButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log(MainScreenConstructionControlNode.class.getSimpleName(), "up clicked");
model.getLevelComponent().changeWorkingLevel(1);
}
});
changeWorkingLevelGroup.add(upWorkingLevelButton).size(CHILD_WIDTH / 4, CHILD_HEIGHT);


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);
}

@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);
}
});
}

private void update() {
// ------ update show-state ------
if (model == null) {
setVisible(false);
//textButton.setVisible(false);
//Gdx.app.log("ConstructionView", this.hashCode() + " no model");
return;
} else {
setVisible(true);
//textButton.setVisible(true);
//Gdx.app.log("ConstructionView", model.getName() + " set to its view");
}
// ------ update text ------
constructionNameLabel.setText(JavaFeatureForGwt.stringFormat(
"%s (%s, %s)",
model.getName(),
model.getSaveData().getPosition().getX(),
model.getSaveData().getPosition().getY()
));
upgradeButton.setText(model.getDescriptionPackage().getUpgradeButtonText());
workingLevelLabel.setText(model.getLevelComponent().getWorkingLevelDescription());


// ------ update clickable-state ------

if (model.getUpgradeComponent().canUpgrade()) {
upgradeButton.setDisabled(false);
upgradeButton.getLabel().setColor(Color.WHITE);
} else {
upgradeButton.setDisabled(true);
upgradeButton.getLabel().setColor(Color.RED);
}
if (model.getUpgradeComponent().canTransfer())
{
transformButton.setDisabled(false);
transformButton.getLabel().setColor(Color.WHITE);
}
else
{
transformButton.setDisabled(true);
transformButton.getLabel().setColor(Color.RED);
}

boolean canUpWorkingLevel = model.getLevelComponent().canChangeWorkingLevel(1);
if (canUpWorkingLevel) {
upWorkingLevelButton.setDisabled(false);
upWorkingLevelButton.getLabel().setColor(Color.WHITE);
} else {
upWorkingLevelButton.setDisabled(true);
upWorkingLevelButton.getLabel().setColor(Color.RED);
}

boolean canDownWorkingLevel = model.getLevelComponent().canChangeWorkingLevel(-1);
if (canDownWorkingLevel) {
downWorkingLevelButton.setDisabled(false);
downWorkingLevelButton.getLabel().setColor(Color.WHITE);
} else {
downWorkingLevelButton.setDisabled(true);
downWorkingLevelButton.getLabel().setColor(Color.RED);
}
// ------ update model ------
//model.onLogicFrame();

}


public void updateAsConstruction(BaseConstruction construction) {
this.model = construction;
if (construction != null) {
if (construction.getLevelComponent().isTypeWorkingLevelChangeable()) {
this.upWorkingLevelButton.setVisible(true);
this.downWorkingLevelButton.setVisible(true);
} else {
this.upWorkingLevelButton.setVisible(false);
this.downWorkingLevelButton.setVisible(false);
}
}
update();
}

@Override
public void subLogicFrame() {
update();
}
}
Loading

0 comments on commit 817a0dd

Please sign in to comment.