mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-03 13:30:51 +07:00
Can now pick free techs
This commit is contained in:
parent
b6f31af5a4
commit
13974b635b
@ -94,6 +94,8 @@ public class WorldScreen extends CameraStageBaseScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
public void update(){
|
||||||
|
if(game.civInfo.tech.freeTechs!=0)
|
||||||
|
game.setScreen(new TechPickerScreen(game,true));
|
||||||
updateTechButton();
|
updateTechButton();
|
||||||
updateTileTable();
|
updateTileTable();
|
||||||
updateTiles();
|
updateTiles();
|
||||||
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
|||||||
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||||
|
import com.unciv.civinfo.CivilizationTech;
|
||||||
import com.unciv.game.UnCivGame;
|
import com.unciv.game.UnCivGame;
|
||||||
import com.unciv.models.gamebasics.GameBasics;
|
import com.unciv.models.gamebasics.GameBasics;
|
||||||
import com.unciv.models.gamebasics.Technology;
|
import com.unciv.models.gamebasics.Technology;
|
||||||
@ -17,84 +18,20 @@ import java.util.Stack;
|
|||||||
public class TechPickerScreen extends PickerScreen {
|
public class TechPickerScreen extends PickerScreen {
|
||||||
|
|
||||||
HashMap<String, TextButton> techNameToButton = new HashMap<String, TextButton>();
|
HashMap<String, TextButton> techNameToButton = new HashMap<String, TextButton>();
|
||||||
Technology SelectedTech;
|
boolean isFreeTechPick;
|
||||||
com.unciv.civinfo.CivilizationTech civTech = game.civInfo.tech;
|
Technology selectedTech;
|
||||||
ArrayList<String> TechsToResearch = new ArrayList<String>(civTech.techsToResearch);
|
CivilizationTech civTech = game.civInfo.tech;
|
||||||
|
ArrayList<String> techsToResearch = new ArrayList<String>(civTech.techsToResearch);
|
||||||
|
|
||||||
public void SetButtonsInfo() {
|
public TechPickerScreen(final UnCivGame game, boolean freeTechPick){
|
||||||
|
this(game);
|
||||||
for (String techName : techNameToButton.keySet()) {
|
isFreeTechPick=true;
|
||||||
TextButton TB = techNameToButton.get(techName);
|
|
||||||
TB.getStyle().checkedFontColor = Color.BLACK;
|
|
||||||
if (civTech.isResearched(techName)) TB.setColor(Color.GREEN);
|
|
||||||
else if (TechsToResearch.contains(techName)) TB.setColor(Color.BLUE);
|
|
||||||
else if (civTech.canBeResearched(techName)) TB.setColor(Color.WHITE);
|
|
||||||
else TB.setColor(Color.GRAY);
|
|
||||||
|
|
||||||
TB.setChecked(false);
|
|
||||||
TB.setText(techName);
|
|
||||||
|
|
||||||
if (SelectedTech != null) {
|
|
||||||
Technology thisTech = GameBasics.Technologies.get(techName);
|
|
||||||
if (techName.equals(SelectedTech.name)) {
|
|
||||||
TB.setChecked(true);
|
|
||||||
TB.setColor(TB.getColor().lerp(Color.LIGHT_GRAY, 0.5f));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (thisTech.prerequisites.contains(SelectedTech.name)) TB.setText("*" + techName);
|
|
||||||
else if (SelectedTech.prerequisites.contains(techName)) TB.setText(techName + "*");
|
|
||||||
}
|
|
||||||
if (TechsToResearch.contains(techName)) {
|
|
||||||
TB.setText(TB.getText() + " (" + TechsToResearch.indexOf(techName) + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!civTech.isResearched(techName)) TB.setText(TB.getText() + "\r\n" + game.civInfo.turnsToTech(techName) + " turns");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void selectTechnology(Technology tech) {
|
|
||||||
SelectedTech = tech;
|
|
||||||
descriptionLabel.setText(tech.description);
|
|
||||||
|
|
||||||
if (civTech.isResearched(tech.name)) {
|
|
||||||
rightSideButton.setText("Research");
|
|
||||||
rightSideButton.setTouchable(Touchable.disabled);
|
|
||||||
rightSideButton.setColor(Color.GRAY);
|
|
||||||
SetButtonsInfo();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rightSideButton.setTouchable(Touchable.enabled);
|
|
||||||
rightSideButton.setColor(Color.WHITE);
|
|
||||||
|
|
||||||
if (civTech.canBeResearched(tech.name)) {
|
|
||||||
TechsToResearch.clear();
|
|
||||||
TechsToResearch.add(tech.name);
|
|
||||||
} else {
|
|
||||||
Stack<String> Prerequisites = new Stack<String>();
|
|
||||||
ArrayDeque<String> CheckPrerequisites = new ArrayDeque<String>();
|
|
||||||
CheckPrerequisites.add(tech.name);
|
|
||||||
while (!CheckPrerequisites.isEmpty()) {
|
|
||||||
String techNameToCheck = CheckPrerequisites.pop();
|
|
||||||
if (civTech.isResearched(techNameToCheck))
|
|
||||||
continue; //no need to add or check prerequisites
|
|
||||||
Technology techToCheck = GameBasics.Technologies.get(techNameToCheck);
|
|
||||||
for (String str : techToCheck.prerequisites)
|
|
||||||
if (!CheckPrerequisites.contains(str)) CheckPrerequisites.add(str);
|
|
||||||
Prerequisites.add(techNameToCheck);
|
|
||||||
}
|
|
||||||
TechsToResearch.clear();
|
|
||||||
while (!Prerequisites.isEmpty()) TechsToResearch.add(Prerequisites.pop());
|
|
||||||
}
|
|
||||||
|
|
||||||
rightSideButton.setText("Research \r\n" + TechsToResearch.get(0));
|
|
||||||
SetButtonsInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TechPickerScreen(final UnCivGame game) {
|
public TechPickerScreen(final UnCivGame game) {
|
||||||
super(game);
|
super(game);
|
||||||
|
|
||||||
Technology[][] techMatrix = new Technology[10][5]; // Divided into columns, then rows
|
Technology[][] techMatrix = new Technology[10][10]; // Divided into columns, then rows
|
||||||
for (int i = 0; i < techMatrix.length; i++) {
|
for (int i = 0; i < techMatrix.length; i++) {
|
||||||
techMatrix[i] = new Technology[10];
|
techMatrix[i] = new Technology[10];
|
||||||
}
|
}
|
||||||
@ -103,11 +40,10 @@ public class TechPickerScreen extends PickerScreen {
|
|||||||
techMatrix[technology.column.columnNumber-1][technology.row - 1] = technology;
|
techMatrix[technology.column.columnNumber-1][technology.row - 1] = technology;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Table topTable = new Table();
|
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
topTable.row().pad(5);
|
topTable.row().pad(5);
|
||||||
|
|
||||||
for (int j = 0; j < 9; j++) {
|
for (int j = 0; j < 10; j++) {
|
||||||
final Technology tech = techMatrix[j][i];
|
final Technology tech = techMatrix[j][i];
|
||||||
if (tech == null) topTable.add(); // empty cell
|
if (tech == null) topTable.add(); // empty cell
|
||||||
else {
|
else {
|
||||||
@ -125,16 +61,107 @@ public class TechPickerScreen extends PickerScreen {
|
|||||||
SetButtonsInfo();
|
SetButtonsInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
rightSideButton.setText("Research");
|
rightSideButton.setText("Pick a tech");
|
||||||
rightSideButton.setTouchable(Touchable.disabled);
|
rightSideButton.setTouchable(Touchable.disabled);
|
||||||
rightSideButton.setColor(Color.GRAY);
|
rightSideButton.setColor(Color.GRAY);
|
||||||
rightSideButton.addListener(new ClickListener() {
|
rightSideButton.addListener(new ClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void clicked(InputEvent event, float x, float y) {
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
civTech.techsToResearch = TechsToResearch;
|
if (isFreeTechPick) {
|
||||||
|
civTech.techsResearched.add(selectedTech.name);
|
||||||
|
civTech.freeTechs-=1;
|
||||||
|
game.civInfo.notifications.add("We have stumbled upon the discovery of "+selectedTech.name+"!");
|
||||||
|
if(selectedTech.name.equals(civTech.currentTechnology()))
|
||||||
|
civTech.techsToResearch.remove(selectedTech.name);
|
||||||
|
}
|
||||||
|
else civTech.techsToResearch = techsToResearch;
|
||||||
game.setWorldScreen();
|
game.setWorldScreen();
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetButtonsInfo() {
|
||||||
|
for (String techName : techNameToButton.keySet()) {
|
||||||
|
TextButton TB = techNameToButton.get(techName);
|
||||||
|
TB.getStyle().checkedFontColor = Color.BLACK;
|
||||||
|
if (civTech.isResearched(techName)) TB.setColor(Color.GREEN);
|
||||||
|
else if (techsToResearch.contains(techName)) TB.setColor(Color.BLUE);
|
||||||
|
else if (civTech.canBeResearched(techName)) TB.setColor(Color.WHITE);
|
||||||
|
else TB.setColor(Color.GRAY);
|
||||||
|
|
||||||
|
TB.setChecked(false);
|
||||||
|
TB.setText(techName);
|
||||||
|
|
||||||
|
if (selectedTech != null) {
|
||||||
|
Technology thisTech = GameBasics.Technologies.get(techName);
|
||||||
|
if (techName.equals(selectedTech.name)) {
|
||||||
|
TB.setChecked(true);
|
||||||
|
TB.setColor(TB.getColor().lerp(Color.LIGHT_GRAY, 0.5f));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thisTech.prerequisites.contains(selectedTech.name)) TB.setText("*" + techName);
|
||||||
|
else if (selectedTech.prerequisites.contains(techName)) TB.setText(techName + "*");
|
||||||
|
}
|
||||||
|
if (techsToResearch.contains(techName)) {
|
||||||
|
TB.setText(TB.getText() + " (" + techsToResearch.indexOf(techName) + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!civTech.isResearched(techName)) TB.setText(TB.getText() + "\r\n" + game.civInfo.turnsToTech(techName) + " turns");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectTechnology(Technology tech) {
|
||||||
|
selectedTech = tech;
|
||||||
|
descriptionLabel.setText(tech.description);
|
||||||
|
if(isFreeTechPick) {selectTechnologyForFreeTech(tech); return;}
|
||||||
|
|
||||||
|
if (civTech.isResearched(tech.name)) {
|
||||||
|
rightSideButton.setText("Research");
|
||||||
|
rightSideButton.setTouchable(Touchable.disabled);
|
||||||
|
rightSideButton.setColor(Color.GRAY);
|
||||||
|
SetButtonsInfo();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rightSideButton.setTouchable(Touchable.enabled);
|
||||||
|
rightSideButton.setColor(Color.WHITE);
|
||||||
|
|
||||||
|
if (civTech.canBeResearched(tech.name)) {
|
||||||
|
techsToResearch.clear();
|
||||||
|
techsToResearch.add(tech.name);
|
||||||
|
} else {
|
||||||
|
Stack<String> Prerequisites = new Stack<String>();
|
||||||
|
ArrayDeque<String> CheckPrerequisites = new ArrayDeque<String>();
|
||||||
|
CheckPrerequisites.add(tech.name);
|
||||||
|
while (!CheckPrerequisites.isEmpty()) {
|
||||||
|
String techNameToCheck = CheckPrerequisites.pop();
|
||||||
|
if (civTech.isResearched(techNameToCheck))
|
||||||
|
continue; //no need to add or check prerequisites
|
||||||
|
Technology techToCheck = GameBasics.Technologies.get(techNameToCheck);
|
||||||
|
for (String str : techToCheck.prerequisites)
|
||||||
|
if (!CheckPrerequisites.contains(str)) CheckPrerequisites.add(str);
|
||||||
|
Prerequisites.add(techNameToCheck);
|
||||||
|
}
|
||||||
|
techsToResearch.clear();
|
||||||
|
while (!Prerequisites.isEmpty()) techsToResearch.add(Prerequisites.pop());
|
||||||
|
}
|
||||||
|
|
||||||
|
rightSideButton.setText("Research \r\n" + techsToResearch.get(0));
|
||||||
|
SetButtonsInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectTechnologyForFreeTech(Technology tech){
|
||||||
|
if (civTech.canBeResearched(tech.name)) {
|
||||||
|
rightSideButton.setText("Pick " + selectedTech.name+"\r\n as free tech!");
|
||||||
|
rightSideButton.setTouchable(Touchable.enabled);
|
||||||
|
rightSideButton.setColor(Color.WHITE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rightSideButton.setText("Pick a free tech");
|
||||||
|
rightSideButton.setTouchable(Touchable.disabled);
|
||||||
|
rightSideButton.setColor(Color.GRAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user