Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment structurize, improve citizen home assignment #3314

Merged
merged 2 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ tinker_version=2.10.0.+
dynamic_tree_version=0.7.+
jei_version=4.8.5.147
c_b_version=14.0.128
structurize_version=0.10.44-ALPHA
structurize_version=0.10.45-ALPHA
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,41 @@ public final class WindowConstants
public static final String INPUT_QTY = "qty";
public static final String BUTTON_REQUEST = "request";

/**
* Id of the done button in the GUI.
*/
public static final String BUTTON_DONE = "done";

/**
* Id of the citizen name in the GUI.
*/
public static final String CITIZEN_LABEL = "citizen";

/**
* Id of the citizen list in the GUI.
*/
public static final String CITIZEN_LIST = "unassigned";

/**
* Assign button of the gui.
*/
public static final String CITIZEN_DONE = "done";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the string "done" twice there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it's two different buttons, so the id might change for one but not for both at th esame time

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I was looking how many dupes are in window constants - there are fewer than I expected :D


/**
* Link to the xml file of the window.
*/
public static final String ASSIGN_CITIZEN_RESOURCE_SUFFIX = ":gui/windowAssignCitizen.xml";

/**
* Id of the job label in the GUI.
*/
public static final String CITIZEN_JOB = "job";

/**
* Id of the job label in the GUI.
*/
public static final String CITIZEN_LIVING = "living";

/**
* public constructor to hide implicit public one.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.minecolonies.coremod.client.gui;

import com.minecolonies.api.util.BlockPosUtil;
import com.minecolonies.api.util.LanguageHandler;
import com.minecolonies.api.util.constant.Constants;
import com.minecolonies.blockout.Pane;
Expand All @@ -11,6 +12,7 @@
import com.minecolonies.coremod.MineColonies;
import com.minecolonies.coremod.colony.CitizenDataView;
import com.minecolonies.coremod.colony.ColonyView;
import com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBarracksTower;
import com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHome;
import com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView;
import com.minecolonies.coremod.network.messages.AssignUnassignMessage;
Expand All @@ -22,57 +24,29 @@
import java.util.List;
import java.util.stream.Collectors;

import static com.minecolonies.api.util.constant.WindowConstants.*;

/**
* Window for the hiring or firing of a worker.
*/
public class WindowAssignCitizen extends Window implements ButtonHandler
{
/**
* Id of the done button in the GUI.
*/
private static final String BUTTON_DONE = "done";

/**
* Id of the cancel button in the GUI.
*/
private static final String BUTTON_CANCEL = "cancel";

/**
* Id of the citizen name in the GUI.
*/
private static final String CITIZEN_LABEL = "citizen";

/**
* Id of the citizen list in the GUI.
*/
private static final String CITIZEN_LIST = "unassigned";

/**
* Assign button of the gui.
*/
private static final String CITIZEN_DONE = "done";

/**
* Link to the xml file of the window.
*/
private static final String BUILDING_NAME_RESOURCE_SUFFIX = ":gui/windowAssignCitizen.xml";

/**
* Id of the job label in the GUI.
*/
private static final String CITIZEN_JOB = "job";
/**
*
* The view of the current building.
*/
private final AbstractBuildingView building;

/**
* List of citizens which can be assigned.
*/
private final ScrollingList citizenList;

/**
* The colony.
*/
private final ColonyView colony;

/**
* Contains all the citizens.
*/
Expand All @@ -86,7 +60,7 @@ public class WindowAssignCitizen extends Window implements ButtonHandler
*/
public WindowAssignCitizen(final ColonyView c, final BlockPos buildingId)
{
super(Constants.MOD_ID + BUILDING_NAME_RESOURCE_SUFFIX);
super(Constants.MOD_ID + ASSIGN_CITIZEN_RESOURCE_SUFFIX);
this.colony = c;
building = colony.getBuilding(buildingId);
citizenList = findPaneOfTypeByID(CITIZEN_LIST, ScrollingList.class);
Expand All @@ -103,8 +77,8 @@ private void updateCitizens()

//Removes all citizens which already have a job.
citizens = colony.getCitizens().values().stream()
.filter(citizen -> citizen.getHomeBuilding() == null).sorted(Comparator.comparing(CitizenDataView::getName))
.collect(Collectors.toList());
.filter(cit -> cit.getHomeBuilding() == null || !(colony.getBuilding(cit.getHomeBuilding()) instanceof BuildingBarracksTower.View) && !cit.getHomeBuilding().equals(building.getID()))
.sorted(Comparator.comparing(CitizenDataView::getName)).collect(Collectors.toList());
}

/**
Expand Down Expand Up @@ -144,7 +118,31 @@ public void updateElement(final int index, @NotNull final Pane rowPane)
if (building instanceof BuildingHome.View)
{
rowPane.findPaneOfTypeByID(CITIZEN_LABEL, Label.class).setLabelText(citizen.getName());
rowPane.findPaneOfTypeByID(CITIZEN_JOB, Label.class).setLabelText(LanguageHandler.format(citizen.getJob()));

final BlockPos work = citizen.getWorkBuilding();
String workString = "";
if (work != null)
{
workString = " " + BlockPosUtil.getDistance2D(work, building.getLocation()) + " blocks";
}

final BlockPos home = citizen.getHomeBuilding();
String homeString = "";
if (home != null)
{
if (work != null)
{
homeString = LanguageHandler.format("com.minecolonies.coremod.gui.homeHut.currently", BlockPosUtil.getDistance2D(work, home));

}
else
{
homeString = LanguageHandler.format("com.minecolonies.coremod.gui.homeHut.current", home.getX(), home.getY(), home.getZ());
}
}

rowPane.findPaneOfTypeByID(CITIZEN_JOB, Label.class).setLabelText(LanguageHandler.format(citizen.getJob()) + workString);
rowPane.findPaneOfTypeByID(CITIZEN_LIVING, Label.class).setLabelText(homeString);

final Button done = rowPane.findPaneOfTypeByID(CITIZEN_DONE, Button.class);
if (colony.isManualHousing())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ public void messageOnServerThread(final AssignUnassignMessage message, final Ent
}

final CitizenData citizen = colony.getCitizenManager().getCitizen(message.citizenID);
if (message.assign && !((BuildingHome) building).isFull() && citizen.getHomeBuilding() == null)
if (message.assign && !building.isFull() && !building.equals(citizen.getHomeBuilding()))
{
((BuildingHome) building).assignCitizen(citizen);
if (citizen.getHomeBuilding() != null)
{
citizen.getHomeBuilding().removeCitizen(citizen);
}
building.assignCitizen(citizen);
}
else if (((BuildingHome) building).hasAssignedCitizen(citizen))
else if (building.hasAssignedCitizen(citizen))
{
building.removeCitizen(citizen);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
lightbox="true"
xsi:noNamespaceSchemaLocation="file:../../../../java/com/minecolonies/blockout/blockOut.xsd">

<label size="100% 11" pos="0 50" textalign="TOP_MIDDLE" color="white" label="$(com.minecolonies.coremod.gui.hiring.description)"/>
<label size="100% 11" pos="0 50" textalign="TOP_MIDDLE" color="white" label="$(com.minecolonies.coremod.gui.assigning.description)"/>
<list id="unassigned" size="70% 120" pos="60 70" align="TOP_MIDDLE">
<view size="70% 30">
<view size="70% 40">
<label id="citizen" size="60 12" pos="5 4" textalign="MIDDLE_LEFT" color="yellow"/>
<label id="job" size="60 12" pos="5 14" textalign="MIDDLE_LEFT" color="red"/>
<button id="done" size="45 15" pos="125 3" label="$(com.minecolonies.coremod.gui.hiring.buttonHire)"/>
<label id="job" size="60 12" pos="5 14" textalign="MIDDLE_LEFT" color="yellow"/>
<label id="living" size="60 12" pos="5 24" textalign="MIDDLE_LEFT" color="red"/>
<button id="done" size="45 15" pos="125 3" label="$(com.minecolonies.coremod.gui.hiring.buttonAssign)"/>
</view>
</list>
<button id="cancel" size="200 20" pos="110 194" label="$(gui.cancel)"/>
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/assets/minecolonies/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ com.minecolonies.coremod.gui.citizen.skills.endurance=Endurance: %d
com.minecolonies.coremod.gui.townHall.rename.title=Rename Your Colony
com.minecolonies.coremod.gui.workerHuts.information=Information
com.minecolonies.coremod.gui.hiring.description=Choose a worker for the job.
com.minecolonies.coremod.gui.assigning.description=Choose a citizen to assign to live here.

com.minecolonies.coremod.gui.townHall.population.deliverymen=Deliverymen: %d
com.minecolonies.coremod.gui.townHall.population.miners=Miners: %d
com.minecolonies.coremod.gui.townHall.population.fishermen=Fishermen: %d
Expand All @@ -178,6 +180,7 @@ com.minecolonies.coremod.gui.workerHuts.build=Build Building
com.minecolonies.coremod.gui.workerHuts.buildRepair=Build Options
com.minecolonies.coremod.gui.workerHuts.lumberjackHut=Lumberjack's Hut
com.minecolonies.coremod.gui.hiring.buttonHire=Hire
com.minecolonies.coremod.gui.hiring.buttonAssign=Assign
com.minecolonies.coremod.gui.townHall.togglespec=Toggle Specialization
com.minecolonies.coremod.gui.workerHuts.repair=Repair
com.minecolonies.coremod.gui.citizen.skills.dexterity=Dexterity: %d
Expand Down Expand Up @@ -867,4 +870,7 @@ com.minecolonies.coremod.job.StoneSmeltery=Stone Smelter
com.minecolonies.coremod.job.Blacksmith=Blacksmith
com.minecolonies.coremod.job.Stonemason=Stonemason
com.minecolonies.coremod.job.Sawmill=Woodworker
com.minecolonies.coremod.ai.wrongFood=The food I have is too raw to eat!
com.minecolonies.coremod.ai.wrongFood=The food I have is too raw to eat!

com.minecolonies.coremod.gui.homeHut.current=Current home: %d %d %d
com.minecolonies.coremod.gui.homeHut.currently=Currently: %d blocks
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"type": "item",
"weight": 0.2,
"weight": 1,
"quality": 1,
"name": "minecolonies:chiefsword"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"textures": {
"4": "minecolonies:blocks/baker/sacksmallflour",
"5": "minecolonies:blocks/baker/quern",
"particle": "minecolonies:blocks/quern"
"particle": "minecolonies:blocks/baker/quern"
},
"elements": [
{
Expand Down