Skip to content

Commit

Permalink
Ability hotbar fixes & adjustments, keys can now be rebound or unboun…
Browse files Browse the repository at this point in the history
…d correctly via KeyDialog

* Store game version in manifest
  • Loading branch information
Hitonoriol committed May 11, 2021
1 parent baa3390 commit 83dd4e0
Show file tree
Hide file tree
Showing 22 changed files with 349 additions and 215 deletions.
87 changes: 44 additions & 43 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
allprojects {
apply plugin: "eclipse"
apply plugin: "eclipse"

version = '1.0'
ext {
appName = "MadSand"
gdxVersion = '1.9.13'
roboVMVersion = '2.3.12'
box2DLightsVersion = '1.5'
ashleyVersion = '1.7.3'
aiVersion = '1.6.0'
}
version = 'Alpha v0.49.5-rc1'

ext {
appName = "MadSand"
gdxVersion = '1.9.13'
roboVMVersion = '2.3.12'
box2DLightsVersion = '1.5'
ashleyVersion = '1.7.3'
aiVersion = '1.6.0'
}

repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}

project(":desktop") {
apply plugin: "java-library"
apply plugin: "java-library"

dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
}
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
}
}

project(":core") {
apply plugin: "java-library"
apply plugin: "java-library"

dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile group: 'com.badlogicgames.gdx', name: 'gdx-ai', version: '1.6.0'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
compile group: 'org.apache.commons', name: 'commons-text', version: '1.9'
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile group: 'com.badlogicgames.gdx', name: 'gdx-ai', version: '1.6.0'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
compile group: 'org.apache.commons', name: 'commons-text', version: '1.9'
implementation group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.12.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.1'
implementation 'me.xdrop:fuzzywuzzy:1.3.1'
compile files('../lib/luaj-jse-3.0.2.jar')
compile files('../lib/jrand-0.2.7-alpha.jar')
}
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.12.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.1'
implementation 'me.xdrop:fuzzywuzzy:1.3.1'
compile files('../lib/luaj-jse-3.0.2.jar')
compile files('../lib/jrand-0.2.7-alpha.jar')
}
}
62 changes: 51 additions & 11 deletions core/src/hitonoriol/madsand/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -78,23 +80,24 @@
import hitonoriol.madsand.world.WorkerType;
import hitonoriol.madsand.world.World;

@JsonAutoDetect(fieldVisibility = Visibility.ANY)
public class Player extends Entity {
@JsonIgnore
public PlayerStats stats; // Reference to the same Stats object as super.stats
float elapsedTime;// For player animation
float origMoveSpeed = 0, runSpeedCoef = 3.5f;

public int targetedByNpcs = 0;
public Set<Integer> unlockedItems = new HashSet<>(); // set of items player obtained at least once
public List<Integer> craftRecipes = new ArrayList<>(); // list of items which recipes are available to the player
public List<Integer> buildRecipes = new ArrayList<>();
public QuestWorker quests = new QuestWorker();
public Set<String> luaActions = new HashSet<>(); // Set for one-time lua actions
public HashMap<Integer, Integer> killCount = new HashMap<>();
public Reputation reputation = new Reputation();
public List<Ability> abilities = new ArrayList<>();
public LinkedHashMap<Integer, Integer> abilityKeyBinds = new LinkedHashMap<>();
public int settlementsEstablished = 0;
private int targetedByNpcs = 0;
private Set<Integer> unlockedItems = new HashSet<>(); // set of items player obtained at least once
private List<Integer> craftRecipes = new ArrayList<>(); // list of items which recipes are available to the player
private List<Integer> buildRecipes = new ArrayList<>();
private QuestWorker quests = new QuestWorker();
private Set<String> luaActions = new HashSet<>(); // Set for one-time lua actions
private HashMap<Integer, Integer> killCount = new HashMap<>();
private Reputation reputation = new Reputation();
private List<Ability> abilities = new ArrayList<>();
private LinkedHashMap<Integer, Integer> abilityKeyBinds = new LinkedHashMap<>();
private int settlementsEstablished = 0;

private TimedAction scheduledAction;

Expand Down Expand Up @@ -127,6 +130,38 @@ public void postLoadInit() {
abilityKeyBinds.forEach((key, abilityId) -> bindAbility(key, abilityId));
}

public int getEstablishedSettlements() {
return settlementsEstablished;
}

public void establishSettlement() {
++settlementsEstablished;
}

public QuestWorker getQuestWorker() {
return quests;
}

public List<Ability> getAbilities() {
return abilities;
}

public HashMap<Integer, Integer> getTotalKillCount() {
return killCount;
}

public Reputation getReputation() {
return reputation;
}

public List<Integer> getBuildRecipes() {
return buildRecipes;
}

public List<Integer> getCraftRecipes() {
return craftRecipes;
}

public PlayerStats stats() {
return (PlayerStats) super.stats();
}
Expand Down Expand Up @@ -173,6 +208,10 @@ public int getAbilityKey(int id) {
}

public void bindAbility(int key, int abilityId) {
int oldKey;
if ((oldKey = getAbilityKey(abilityId)) != -1 && oldKey != key)
unbindAbility(oldKey);

if (abilityKeyBinds.getOrDefault(key, -1) != abilityId)
abilityKeyBinds.put(key, abilityId);

Expand All @@ -183,6 +222,7 @@ public void bindAbility(int key, int abilityId) {
public void unbindAbility(int key) {
abilityKeyBinds.remove(key);
Keyboard.getKeyBindManager().unbind(key);
Gui.overlay.hotbar.refresh();
}

public void refreshEquipment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ActiveAbility addBonusCost(float cost) {
@Override
public String toString() {
return super.toString() + Resources.LINEBREAK
+ "[" + staminaCost + " stamina]";
+ "(" + staminaCost + " stamina)";
}

public String getBindKeyString() {
Expand Down
2 changes: 1 addition & 1 deletion core/src/hitonoriol/madsand/entities/npc/AbstractNpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ else if (dst <= OPTIMAL_DST && dst >= meleeAttackDst)
}

public void act(float time) {
boolean badRep = World.player.reputation.isHostile(stats.faction);
boolean badRep = World.player.getReputation().isHostile(stats.faction);
tickCharge += (timePassed = time);

if (pauseFlag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void generate() {
randomHuntQuest();
break;
case Craft:
if (World.player.craftRecipes.isEmpty()) {
if (World.player.getCraftRecipes().isEmpty()) {
generate();
return;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ private void randomResourceQuest() {
}

private void randomCraftQuest() {
randomItemQuest(World.player.craftRecipes);
randomItemQuest(World.player.getCraftRecipes());
}

private void randomFetchQuest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void completeQuest(Quest quest) {
player.inventory.delItem(quest.removeOnCompletion);
player.inventory.putItem(quest.rewardItems);
player.addExp(quest.exp);
player.reputation.change(quest.getNpc().stats.faction, Reputation.QUEST_REWARD);
player.getReputation().change(quest.getNpc().stats.faction, Reputation.QUEST_REWARD);
MadSand.notice("You get " + quest.exp + " EXP!");

if (!quest.repeatable)
Expand Down
28 changes: 25 additions & 3 deletions core/src/hitonoriol/madsand/gui/OverlayMouseoverListener.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package hitonoriol.madsand.gui;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Event;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputEvent.Type;
import com.badlogic.gdx.scenes.scene2d.InputListener;

import hitonoriol.madsand.Gui;
Expand All @@ -11,27 +13,47 @@
*/

public class OverlayMouseoverListener extends InputListener {

private static final OverlayMouseoverListener instance = new OverlayMouseoverListener();

private InputEvent.Type prevEvent = null;

public OverlayMouseoverListener() {
super();
}

@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
if (prevEvent == Type.touchDown)
return;

Gui.gameUnfocused = true;
Gui.overlay.hideTooltip();
}

@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
event.cancel();
return false;
}

@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
if (!Gui.dialogActive) {
Gui.gameUnfocused = false;
Gui.overlay.showTooltip();
}
}


@Override
public boolean handle(Event e) {
boolean result = super.handle(e);

if (e instanceof InputEvent)
prevEvent = ((InputEvent) e).getType();

return result;
}

public static OverlayMouseoverListener instance() {
return instance;
}
Expand Down
14 changes: 10 additions & 4 deletions core/src/hitonoriol/madsand/gui/dialogs/AbilityDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private void addAbilityButton(Ability abstrAbility) {
.ifPresent(
ability -> {
Player player = MadSand.player();
int currentKey = player.getAbilityKey(ability.id);

addButton(abstrAbility,
() -> {
Expand All @@ -90,10 +91,15 @@ private void addAbilityButton(Ability abstrAbility) {
() -> new KeyDialog(key -> {
player.bindAbility(key, ability.id);
refresh();
}).show())
.size(75, BTN_HEIGHT)
.padRight(5)
.row();
}, currentKey).setRemoveBindingAction(
() -> {
player.unbindAbility(currentKey);
refresh();
})
.show())
.size(75, BTN_HEIGHT)
.padRight(5)
.row();
});

abstrAbility.as(PassiveAbility.class)
Expand Down
Loading

0 comments on commit 83dd4e0

Please sign in to comment.