Skip to content

Commit

Permalink
More stats, more info (ldtteam#8819)
Browse files Browse the repository at this point in the history
Make stats a scrolling list
Add dropdown to select different time intervals
Add 4 new stat types
Fix builder stat
  • Loading branch information
Raycoms committed Jan 5, 2023
1 parent 8380511 commit 01fdfaf
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public final class StatisticsConstants
public static final String ITEMS_DELIVERED = "items_delivered";
public static final String ITEMS_CRAFTED = "items_crafted";
public static final String FOOD_SERVED = "food_served";
public static final String CITIZENS_HEALED = "citizens_healed";
public static final String CROPS_HARVESTED = "crops_harvested";
public static final String LAND_TILLED = "land_tilled";
public static final String FISH_CAUGHT = "fish_caught";

}
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ public final class WindowConstants
*/
public static final String BUTTON_PREVIOUS_COLOR_ID = "previousColor";

/**
* This drop down list is used to choose an interval.
*/
public static final String DROPDOWN_INTERVAL_ID = "intervals";

/**
* This drop down list is used to choose which Color should be used.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.minecolonies.coremod.client.gui.townhall;

import com.ldtteam.blockui.Pane;
import com.ldtteam.blockui.PaneBuilders;
import com.ldtteam.blockui.controls.*;
import com.ldtteam.blockui.views.DropDownList;
import com.ldtteam.blockui.views.ScrollingList;
import com.ldtteam.blockui.views.View;
import com.minecolonies.api.colony.ICitizenDataView;
import com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;
import java.util.*;

import static com.minecolonies.api.util.constant.TranslationConstants.PARTIAL_HAPPINESS_MODIFIER_NAME;
import static com.minecolonies.api.util.constant.TranslationConstants.PARTIAL_STATS_MODIFIER_NAME;
Expand All @@ -22,6 +25,29 @@
*/
public class WindowStatsPage extends AbstractWindowTownHall
{
/**
* Map of intervals.
*/
private static final LinkedHashMap<String, Integer> INTERVAL = new LinkedHashMap<>();

static
{
INTERVAL.put("com.minecolonies.coremod.gui.interval.yesterday", 1);
INTERVAL.put("com.minecolonies.coremod.gui.interval.lastweek", 7);
INTERVAL.put("com.minecolonies.coremod.gui.interval.100days", 100);
INTERVAL.put("com.minecolonies.coremod.gui.interval.alltime", -1);
}

/**
* Drop down list for interval.
*/
private DropDownList intervalDropdown;

/**
* Current selected interval.
*/
public String selectedInterval = "com.minecolonies.coremod.gui.interval.yesterday";

/**
* Constructor for the town hall window.
*
Expand Down Expand Up @@ -110,19 +136,67 @@ else if (value > 0.75)
*/
private void updateStats()
{
final View pane = findPaneOfTypeByID("statspage", View.class);
int yPos = 65;
final @NotNull List<String> stats = new ArrayList<>(building.getColony().getStatisticsManager().getStatTypes());

for (final String entry : building.getColony().getStatisticsManager().getStatTypes())
findPaneOfTypeByID("stats", ScrollingList.class).setDataProvider(new ScrollingList.DataProvider()
{
final Text label = new Text();
label.setSize(136, 11);
label.setPosition(25, yPos);
label.setColors(BLACK);
label.setText(new TranslatableComponent(PARTIAL_STATS_MODIFIER_NAME + entry, building.getColony().getStatisticsManager().getStatTotal(entry)));
pane.addChild(label);
/**
* The number of rows of the list.
* @return the number.
*/
@Override
public int getElementCount()
{
return stats.size();
}

yPos += 12;
/**
* Inserts the elements into each row.
* @param index the index of the row/list element.
* @param rowPane the parent Pane for the row, containing the elements to update.
*/
@Override
public void updateElement(final int index, @NotNull final Pane rowPane)
{
int stat = building.getColony().getStatisticsManager().getStatTotal(stats.get(index));
int interval = INTERVAL.get(selectedInterval);
if (interval > 0)
{
stat = building.getColony().getStatisticsManager().getStatsInPeriod(stats.get(index), building.getColony().getDay() - interval, building.getColony().getDay());
}

final Text resourceLabel = rowPane.findPaneOfTypeByID("desc", Text.class);
resourceLabel.setText(new TranslatableComponent(PARTIAL_STATS_MODIFIER_NAME + stats.get(index), stat));
}
});

intervalDropdown = findPaneOfTypeByID(DROPDOWN_INTERVAL_ID, DropDownList.class);
intervalDropdown.setHandler(this::onDropDownListChanged);

intervalDropdown.setDataProvider(new DropDownList.DataProvider()
{
@Override
public int getElementCount()
{
return INTERVAL.size();
}

@Override
public String getLabel(final int index)
{
return new TranslatableComponent((String) INTERVAL.keySet().toArray()[index]).getString();
}
});
intervalDropdown.setSelectedIndex(new ArrayList<>(INTERVAL.keySet()).indexOf(selectedInterval));
}

private void onDropDownListChanged(final DropDownList dropDownList)
{
final String temp = (String) INTERVAL.keySet().toArray()[dropDownList.getSelectedIndex()];
if (!temp.equals(selectedInterval))
{
selectedInterval = temp;
updateStats();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ public final class ColonyView implements IColonyView
*/
private IStatisticsManager statisticManager = new StatisticsManager(this);

/**
* Day in the colony.
*/
private int day;

/**
* Base constructor for a colony.
*
Expand Down Expand Up @@ -424,6 +429,7 @@ public static void serializeNetworkData(@NotNull Colony colony, @NotNull Friendl
colony.getGraveManager().write(graveTag);
buf.writeNbt(graveTag); // this could be more efficient, but it should usually be short anyway
colony.getStatisticsManager().serialize(buf);
buf.writeInt(colony.getDay());
}

/**
Expand Down Expand Up @@ -896,6 +902,7 @@ public IMessage handleColonyViewMessage(@NotNull final FriendlyByteBuf buf, @Not

this.graveManager.read(buf.readNbt());
this.statisticManager.deserialize(buf);
this.day = buf.readInt();
return null;
}

Expand Down Expand Up @@ -1570,6 +1577,6 @@ public IStatisticsManager getStatisticsManager()
@Override
public int getDay()
{
return 0;
return this.day;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public WorkerBuildingModule(
@Override
public boolean assignCitizen(final ICitizenData citizen)
{
if (citizen.getWorkBuilding() != null)
if (citizen.getWorkBuilding() != null && citizen.getEntity().isPresent() && !citizen.getEntity().get().getCitizenDiseaseHandler().isSick())
{
for (final WorkerBuildingModule module : citizen.getWorkBuilding().getModules(WorkerBuildingModule.class))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraftforge.common.Tags;
import net.minecraftforge.network.PacketDistributor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -61,6 +60,7 @@
import static com.minecolonies.api.util.constant.CitizenConstants.BLOCK_BREAK_SOUND_RANGE;
import static com.minecolonies.api.util.constant.Constants.STACKSIZE;
import static com.minecolonies.api.util.constant.Constants.TICKS_SECOND;
import static com.minecolonies.api.util.constant.StatisticsConstants.*;
import static com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD;
import static com.minecolonies.api.util.constant.TranslationConstants.*;

Expand Down Expand Up @@ -643,6 +643,8 @@ private boolean hoeIfAble(BlockPos position, final ScarecrowTileEntity field)
world.setBlockAndUpdate(position, Blocks.FARMLAND.defaultBlockState());
worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1);
worker.decreaseSaturationForContinuousAction();
worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(LAND_TILLED);

return true;
}
return false;
Expand Down Expand Up @@ -671,11 +673,14 @@ private boolean harvestIfAble(BlockPos position)
{
worker.getCitizenExperienceHandler().addExperience(XP_PER_HARVEST);
harvestCrop(position.above());
worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(CROPS_HARVESTED);

return true;
}

if (mineBlock(position.above()))
{
worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(CROPS_HARVESTED);
worker.getCitizenExperienceHandler().addExperience(XP_PER_HARVEST);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*;
import static com.minecolonies.api.util.constant.Constants.TICKS_SECOND;
import static com.minecolonies.api.util.constant.StatisticsConstants.FISH_CAUGHT;
import static com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD;
import static com.minecolonies.api.util.constant.TranslationConstants.WATER_TOO_FAR;
import static com.minecolonies.coremod.entity.NewBobberEntity.XP_PER_CATCH;
Expand Down Expand Up @@ -434,6 +435,7 @@ private IAIState doFishing()
{
playCaughtFishSound();
this.incrementActionsDoneAndDecSaturation();
worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(FISH_CAUGHT);

if (worker.getRandom().nextDouble() < CHANCE_NEW_POND)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ public void triggerSuccess(final BlockPos pos, final List<ItemStack> list, final
{
structureAI.getWorker().getCitizenColonyHandler().getColony().addWayPoint(worldPos, state);
}
structureAI.getWorker().getCitizenColonyHandler().getColony().getStatisticsManager().increment(BLOCKS_PLACED);
}

@Override
Expand All @@ -229,6 +228,7 @@ public void triggerEntitySuccess(final BlockPos blockPos, final List<ItemStack>
for (final ItemStack stack : list)
{
structureAI.reduceNeededResources(stack);
structureAI.getWorker().getCitizenColonyHandler().getColony().getStatisticsManager().increment(BLOCKS_PLACED);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.minecolonies.api.util.constant.CitizenConstants.TAG_DISEASE;
import static com.minecolonies.api.util.constant.CitizenConstants.TAG_IMMUNITY;
import static com.minecolonies.api.util.constant.Constants.ONE_HUNDRED_PERCENT;
import static com.minecolonies.api.util.constant.StatisticsConstants.CITIZENS_HEALED;

/**
* Handler taking care of citizens getting stuck.
Expand Down Expand Up @@ -182,6 +183,8 @@ public void cure()
{
immunityTicks = IMMUNITY_TIME;
}

citizen.getCitizenColonyHandler().getColony().getStatisticsManager().increment(CITIZENS_HEALED);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<window size="524 243" pause="false" lightbox="false">
<layout source="minecolonies:gui/townhall/windowtownhall.xml"/>
<view size="200 243" id="statspage" pos="90 0"/>
<view size="200 243" pos="90 0">
<dropdown id="intervals"
size="129 17"
pos="20 65"
maxContentHeight="75"
dropDownSize="140 75"
source="minecolonies:textures/gui/builderhut/builder_button_medium_large.png"
textcolor="black">
<buttonimage id="button" size="129 17" pos="0 0" source="minecolonies:textures/gui/builderhut/builder_button_medium_large.png" textcolor="black"
label="$(com.minecolonies.coremod.gui.interval.yesterday)"/>
</dropdown>
<list id="stats" size="160 145" pos="20 80">
<label id="desc" size="160 13" pos="0 0" color="black"> </label>
</list>
</view>
<view size="200 243" id="happinesspage" pos="280 0"/>
</window>
12 changes: 10 additions & 2 deletions src/main/resources/assets/minecolonies/lang/manual_en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,15 @@
"com.minecolonies.coremod.gui.townhall.stats.mobs_killed": "Killed Mobs: %d",
"com.minecolonies.coremod.gui.townhall.stats.items_crafted": "Crafted Items: %d",
"com.minecolonies.coremod.gui.townhall.stats.items_delivered": "Delivered Items: %d",
"com.minecolonies.coremod.gui.townhall.stats.food_served": "Served Food: %d",
"com.minecolonies.coremod.gui.townHall.map": "Town Map",
"com.minecolonies.coremod.townhall.map.warning": "Drop-off a normal scale Minecraft map in the Town Hall inventory first to unlock the map."
"com.minecolonies.coremod.townhall.map.warning": "Drop-off a normal scale Minecraft map in the Town Hall inventory first to unlock the map.",
"com.minecolonies.coremod.gui.townhall.stats.food_served": "Served Food: %d",
"com.minecolonies.coremod.gui.townhall.stats.citizens_healed": "Citzens Healed: %d",
"com.minecolonies.coremod.gui.townhall.stats.crops_harvested": "Crops Harvested: %d",
"com.minecolonies.coremod.gui.townhall.stats.land_tilled": "Land Tilled: %d",
"com.minecolonies.coremod.gui.townhall.stats.fish_caught": "Fish Caught: %d",
"com.minecolonies.coremod.gui.interval.yesterday": "Since Yesterday",
"com.minecolonies.coremod.gui.interval.lastweek": "Last Week",
"com.minecolonies.coremod.gui.interval.100days": "Last 100 Days",
"com.minecolonies.coremod.gui.interval.alltime": "All Time"
}

0 comments on commit 01fdfaf

Please sign in to comment.