mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-14 03:49:13 +07:00
Implemented dual wielding
This commit is contained in:
parent
e5ae5ae122
commit
07bc8a04f6
core
assets/bundles
src/io/anuke/mindustry
core
entities
input
io
resource
ui
world/blocks
@ -122,7 +122,7 @@ text.settings.game=Game
|
||||
text.settings.sound=Sound
|
||||
text.settings.graphics=Graphics
|
||||
text.upgrades=Upgrades
|
||||
text.purchased=[LIME]Purchased!
|
||||
text.purchased=[LIME]Created!
|
||||
text.weapons=Weapons
|
||||
text.paused=Paused
|
||||
text.respawn=Respawning in
|
||||
|
@ -141,6 +141,7 @@ public class Control extends Module{
|
||||
"select", Input.MOUSE_LEFT,
|
||||
"break", Input.MOUSE_RIGHT,
|
||||
"shoot", Input.MOUSE_LEFT,
|
||||
"weapon_alt_select", Input.Q,
|
||||
"zoom_hold", Input.CONTROL_LEFT,
|
||||
"zoom", new Axis(Input.SCROLL),
|
||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
||||
@ -223,7 +224,7 @@ public class Control extends Module{
|
||||
weapons.clear();
|
||||
|
||||
weapons.add(Weapon.blaster);
|
||||
player.weapon = weapons.first();
|
||||
player.weaponLeft = player.weaponRight = weapons.first();
|
||||
|
||||
lastUpdated = -1;
|
||||
wave = 1;
|
||||
@ -672,5 +673,4 @@ public class Control extends Module{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ public class NetClient extends Module {
|
||||
|
||||
public void handleShoot(Weapon weapon, float x, float y, float angle){
|
||||
ShootPacket packet = new ShootPacket();
|
||||
packet.weaponid = (byte)weapon.id;
|
||||
packet.weaponid = weapon.id;
|
||||
packet.x = x;
|
||||
packet.y = y;
|
||||
packet.rotation = angle;
|
||||
|
@ -156,8 +156,7 @@ public class NetServer extends Module{
|
||||
|
||||
Net.handleServer(UpgradePacket.class, packet -> {
|
||||
Weapon weapon = (Weapon)Upgrade.getByID(packet.id);
|
||||
//TODO
|
||||
//Vars.control.removeItems(weapon.requirements);
|
||||
Vars.control.removeItems(UpgradeRecipes.get(weapon));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,6 @@ public class UI extends SceneModule{
|
||||
public SettingsMenuDialog settings;
|
||||
public ControlsDialog controls;
|
||||
public MapEditorDialog editor;
|
||||
public UpgradeDialog upgrades;
|
||||
|
||||
public final MenuFragment menufrag = new MenuFragment();
|
||||
public final ToolFragment toolfrag = new ToolFragment();
|
||||
@ -135,7 +134,6 @@ public class UI extends SceneModule{
|
||||
join = new JoinDialog();
|
||||
discord = new DiscordDialog();
|
||||
load = new LoadDialog();
|
||||
upgrades = new UpgradeDialog();
|
||||
levels = new LevelDialog();
|
||||
settings = new SettingsMenuDialog();
|
||||
paused = new PausedDialog();
|
||||
|
@ -22,7 +22,8 @@ public class Player extends DestructibleEntity implements Syncable{
|
||||
public String name = "name";
|
||||
public boolean isAndroid;
|
||||
|
||||
public Weapon weapon = Weapon.blaster;
|
||||
public Weapon weaponLeft = Weapon.blaster;
|
||||
public Weapon weaponRight = Weapon.blaster;
|
||||
public Mech mech = Mech.standard;
|
||||
|
||||
public float angle;
|
||||
@ -129,7 +130,8 @@ public class Player extends DestructibleEntity implements Syncable{
|
||||
&& !ui.hasMouse() && !control.getInput().onConfigurable();
|
||||
|
||||
if(shooting){
|
||||
weapon.update(player);
|
||||
weaponLeft.update(player, true);
|
||||
weaponRight.update(player, false);
|
||||
}
|
||||
|
||||
if(Inputs.keyDown("dash") && Timers.get(this, "dashfx", 3) && vector.len() > 0){
|
||||
|
@ -80,7 +80,7 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
for(int i = 1; i <= 6 && i <= control.getWeapons().size; i ++){
|
||||
if(Inputs.keyTap("weapon_" + i)){
|
||||
player.weapon = control.getWeapons().get(i - 1);
|
||||
player.weaponLeft = player.weaponRight = control.getWeapons().get(i - 1);
|
||||
ui.weaponfrag.update();
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public class NetworkIO {
|
||||
load(file.read());
|
||||
}
|
||||
|
||||
//TODO GWT support
|
||||
|
||||
public static void load(InputStream is){
|
||||
|
||||
try(DataInputStream stream = new DataInputStream(is)){
|
||||
@ -187,6 +187,7 @@ public class NetworkIO {
|
||||
|
||||
Vars.control.getWeapons().clear();
|
||||
Vars.control.getWeapons().add(Weapon.blaster);
|
||||
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
|
||||
Vars.ui.weaponfrag.update();
|
||||
|
||||
//enemies
|
||||
|
@ -61,7 +61,7 @@ public class Save12 extends SaveFileVersion {
|
||||
|
||||
Vars.control.getWeapons().clear();
|
||||
Vars.control.getWeapons().add(Weapon.blaster);
|
||||
Vars.player.weapon = Weapon.blaster;
|
||||
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
|
||||
|
||||
int weapons = stream.readByte();
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class Save13 extends SaveFileVersion {
|
||||
|
||||
Vars.control.getWeapons().clear();
|
||||
Vars.control.getWeapons().add(Weapon.blaster);
|
||||
Vars.player.weapon = Weapon.blaster;
|
||||
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
|
||||
|
||||
int weapons = stream.readByte();
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class Save14 extends SaveFileVersion{
|
||||
|
||||
Vars.control.getWeapons().clear();
|
||||
Vars.control.getWeapons().add(Weapon.blaster);
|
||||
Vars.player.weapon = Weapon.blaster;
|
||||
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
|
||||
|
||||
int weapons = stream.readByte();
|
||||
|
||||
|
@ -13,8 +13,10 @@ public class UpgradeRecipes {
|
||||
Weapon.mortar, list(stack(Item.titanium, 40), stack(Item.steel, 60))
|
||||
);
|
||||
|
||||
public ItemStack[] get(Upgrade upgrade){
|
||||
return recipes.get(upgrade);
|
||||
private static final ItemStack[] empty = {};
|
||||
|
||||
public static ItemStack[] get(Upgrade upgrade){
|
||||
return recipes.get(upgrade, empty);
|
||||
}
|
||||
|
||||
public static Entries<Upgrade, ItemStack[]> getAllRecipes(){
|
||||
|
@ -30,7 +30,7 @@ public class Weapon extends Upgrade{
|
||||
multigun = new Weapon("multigun", 6, BulletType.multishot){
|
||||
{
|
||||
effect = Fx.shoot2;
|
||||
inaccuracy = 8f;
|
||||
inaccuracy = 6f;
|
||||
}
|
||||
},
|
||||
flamer = new Weapon("flamer", 5, BulletType.flame){
|
||||
@ -39,7 +39,7 @@ public class Weapon extends Upgrade{
|
||||
inaccuracy = 12f;
|
||||
}
|
||||
},
|
||||
railgun = new Weapon("railgun", 40, BulletType.sniper){
|
||||
railgun = new Weapon("railgun", 30, BulletType.sniper){
|
||||
{
|
||||
shootsound = "railgun";
|
||||
effect = Fx.railshoot;
|
||||
@ -67,9 +67,11 @@ public class Weapon extends Upgrade{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void update(Player p){
|
||||
if(Timers.get(p, "reload", reload)){
|
||||
shoot(p, p.x, p.y, Angles.mouseAngle(p.x, p.y));
|
||||
public void update(Player p, boolean left){
|
||||
if(Timers.get(p, "reload"+left, reload)){
|
||||
float ang = Angles.mouseAngle(p.x, p.y);
|
||||
Angles.translation(ang + Mathf.sign(left) * -70f, 2f);
|
||||
shoot(p, p.x + Angles.x(), p.y + Angles.y(), Angles.mouseAngle(p.x + Angles.x(), p.y + Angles.y()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,132 +0,0 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
|
||||
public class UpgradeDialog extends FloatingDialog{
|
||||
boolean wasPaused = false;
|
||||
|
||||
public UpgradeDialog() {
|
||||
super("$text.upgrades");
|
||||
setup();
|
||||
}
|
||||
|
||||
void setup(){
|
||||
/*
|
||||
addCloseButton();
|
||||
|
||||
hidden(()->{
|
||||
if(!wasPaused)
|
||||
GameState.set(State.playing);
|
||||
});
|
||||
shown(()->{
|
||||
wasPaused = GameState.is(State.paused);
|
||||
GameState.set(State.paused);
|
||||
});
|
||||
|
||||
Table weptab = new Table();
|
||||
weptab.margin(20);
|
||||
|
||||
int i = 0;
|
||||
for(Upgrade upgrade : Upgrade.getAllUpgrades()){
|
||||
if(!(upgrade instanceof Weapon)) continue;
|
||||
|
||||
Weapon weapon = (Weapon)upgrade;
|
||||
|
||||
TextButton button = new TextButton(weapon.localized());
|
||||
|
||||
Image img = new Image(Draw.region(weapon.name));
|
||||
button.add(img).size(8*5);
|
||||
button.getCells().reverse();
|
||||
button.row();
|
||||
button.margin(14);
|
||||
button.getLabelCell().left();
|
||||
button.pack();
|
||||
|
||||
button.update(()->{
|
||||
if(control.hasWeapon(weapon)){
|
||||
button.setDisabled(true);
|
||||
button.setColor(Color.GRAY);
|
||||
}else if(!control.hasItems(weapon.requirements)){
|
||||
button.setDisabled(true);
|
||||
}else{
|
||||
button.setDisabled(false);
|
||||
button.setColor(Color.WHITE);
|
||||
}
|
||||
});
|
||||
|
||||
if(i > 0 && (i)%2==0)
|
||||
weptab.row();
|
||||
|
||||
i++;
|
||||
|
||||
weptab.add(button).width(220);
|
||||
|
||||
Table tiptable = new Table();
|
||||
|
||||
Listenable run = ()->{
|
||||
tiptable.clearChildren();
|
||||
|
||||
String description = weapon.description;
|
||||
|
||||
tiptable.background("pane");
|
||||
tiptable.add("[orange]" + weapon.localized(), 0.5f).left().padBottom(4f);
|
||||
|
||||
Table reqtable = new Table();
|
||||
|
||||
tiptable.row();
|
||||
tiptable.add(reqtable).left();
|
||||
|
||||
if(!control.hasWeapon(weapon)){
|
||||
ItemStack[] req = weapon.requirements;
|
||||
for(ItemStack s : req){
|
||||
|
||||
int amount = Math.min(control.getAmount(s.item), s.amount);
|
||||
reqtable.addImage(Draw.region("icon-" + s.item.name)).padRight(3).size(8*2);
|
||||
reqtable.add(
|
||||
(amount >= s.amount ? "" : "[RED]")
|
||||
+ amount + " / " +s.amount, 0.5f).left();
|
||||
reqtable.row();
|
||||
}
|
||||
}
|
||||
|
||||
tiptable.row();
|
||||
tiptable.add().size(10);
|
||||
tiptable.row();
|
||||
tiptable.add("[gray]" + description).left();
|
||||
tiptable.row();
|
||||
if(control.hasWeapon(weapon)){
|
||||
tiptable.add("$text.purchased").padTop(6).left();
|
||||
}
|
||||
tiptable.margin(14f);
|
||||
};
|
||||
|
||||
run.listen();
|
||||
|
||||
Tooltip<Table> tip = new Tooltip<>(tiptable, run);
|
||||
|
||||
tip.setInstant(true);
|
||||
|
||||
button.addListener(tip);
|
||||
|
||||
button.clicked(()->{
|
||||
if(button.isDisabled()) return;
|
||||
|
||||
control.removeItems(weapon.requirements);
|
||||
control.addWeapon(weapon);
|
||||
ui.weaponfrag.update();
|
||||
run.listen();
|
||||
Effects.sound("purchase");
|
||||
|
||||
if(Net.active() && Net.client()){
|
||||
Vars.netClient.handleUpgrade(weapon);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
content().add("$text.weapons");
|
||||
content().row();
|
||||
content().add(weptab);
|
||||
content().row();
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
@ -241,7 +241,6 @@ public class BlocksFragment implements Fragment{
|
||||
}).expandX().padLeft(3).top().right().size(40f, 44f).padTop(-2);
|
||||
}
|
||||
|
||||
|
||||
desctable.add().pad(2);
|
||||
|
||||
Table requirements = new Table();
|
||||
@ -252,12 +251,11 @@ public class BlocksFragment implements Fragment{
|
||||
desctable.left();
|
||||
|
||||
for(ItemStack stack : recipe.requirements){
|
||||
ItemStack fs = stack;
|
||||
requirements.addImage(Draw.region("icon-"+stack.item.name)).size(8*3);
|
||||
Label reqlabel = new Label("");
|
||||
|
||||
reqlabel.update(()->{
|
||||
int current = control.getAmount(fs.item);
|
||||
int current = control.getAmount(stack.item);
|
||||
String text = Mathf.clamp(current, 0, stack.amount) + "/" + stack.amount;
|
||||
|
||||
reqlabel.setColor(current < stack.amount ? Colors.get("missingitems") : Color.WHITE);
|
||||
@ -271,8 +269,7 @@ public class BlocksFragment implements Fragment{
|
||||
|
||||
desctable.row();
|
||||
|
||||
Label label = new Label("[health]"+ Bundles.get("text.health")+": " + recipe.result.health + (recipe.result.description == null ?
|
||||
"" : ("\n[]" + recipe.result.description)));
|
||||
Label label = new Label("[health]"+ Bundles.get("text.health")+": " + recipe.result.health);
|
||||
label.setWrap(true);
|
||||
desctable.add(label).width(200).padTop(4).padBottom(2);
|
||||
|
||||
|
@ -5,6 +5,7 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.scene.ui.ButtonGroup;
|
||||
import io.anuke.ucore.scene.ui.ImageButton;
|
||||
import io.anuke.ucore.scene.ui.Tooltip;
|
||||
@ -29,6 +30,7 @@ public class WeaponFragment implements Fragment{
|
||||
weapontable.clearChildren();
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
group.setMaxCheckCount(2);
|
||||
|
||||
weapontable.defaults().size(58, 62);
|
||||
|
||||
@ -39,12 +41,16 @@ public class WeaponFragment implements Fragment{
|
||||
group.add(button);
|
||||
|
||||
button.clicked(()->{
|
||||
if(weapon == player.weapon) return;
|
||||
player.weapon = weapon;
|
||||
//if(weapon == player.weapon) return;
|
||||
if(Inputs.keyDown("weapon_alt_select")){
|
||||
player.weaponRight = weapon;
|
||||
}else {
|
||||
player.weaponLeft = weapon;
|
||||
}
|
||||
button.setChecked(true);
|
||||
});
|
||||
|
||||
button.setChecked(weapon == player.weapon);
|
||||
button.update(() -> button.setChecked(weapon == player.weaponLeft || weapon == player.weaponRight)); //TODO
|
||||
|
||||
weapontable.add(button);
|
||||
|
||||
@ -52,7 +58,7 @@ public class WeaponFragment implements Fragment{
|
||||
String description = weapon.description;
|
||||
|
||||
tiptable.background("button");
|
||||
tiptable.add("$weapon."+weapon.name+".name", 0.5f).left().padBottom(3f);
|
||||
tiptable.add(weapon.localized(), 0.5f).left().padBottom(3f);
|
||||
|
||||
tiptable.row();
|
||||
tiptable.row();
|
||||
|
@ -50,7 +50,7 @@ public class DefenseBlocks{
|
||||
repairturret = new RepairTurret("repairturret"){
|
||||
{
|
||||
range = 30;
|
||||
reload = 60f;
|
||||
reload = 40f;
|
||||
health = 60;
|
||||
}
|
||||
},
|
||||
@ -58,7 +58,7 @@ public class DefenseBlocks{
|
||||
megarepairturret = new RepairTurret("megarepairturret"){
|
||||
{
|
||||
range = 44;
|
||||
reload = 30f;
|
||||
reload = 20f;
|
||||
powerUsed = 0.15f;
|
||||
health = 90;
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.UpgradeRecipes;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.function.Listenable;
|
||||
import io.anuke.ucore.scene.style.TextureRegionDrawable;
|
||||
import io.anuke.ucore.scene.ui.ImageButton;
|
||||
@ -17,12 +20,11 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import static io.anuke.mindustry.Vars.control;
|
||||
|
||||
public class WeaponFactory extends Block implements Configurable{
|
||||
protected ObjectMap<Weapon, ItemStack[]> costs = new ObjectMap<>();
|
||||
|
||||
public WeaponFactory(String name){
|
||||
super(name);
|
||||
solid = true;
|
||||
breakable = true;
|
||||
destructible = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -31,13 +33,11 @@ public class WeaponFactory extends Block implements Configurable{
|
||||
|
||||
Table content = new Table();
|
||||
|
||||
content.add("$text.upgrades").colspan(3).row();
|
||||
|
||||
for(Upgrade upgrade : Upgrade.getAllUpgrades()){
|
||||
if(!(upgrade instanceof Weapon)) continue;
|
||||
Weapon weapon = (Weapon)upgrade;
|
||||
|
||||
ItemStack[] requirements = costs.get(weapon);
|
||||
ItemStack[] requirements = UpgradeRecipes.get(weapon);
|
||||
|
||||
Table tiptable = new Table();
|
||||
|
||||
@ -47,7 +47,7 @@ public class WeaponFactory extends Block implements Configurable{
|
||||
String description = weapon.description;
|
||||
|
||||
tiptable.background("pane");
|
||||
tiptable.add("[orange]" + weapon.localized(), 0.5f).left().padBottom(4f);
|
||||
tiptable.add("[orange]" + weapon.localized(), 0.5f).left().padBottom(2f);
|
||||
|
||||
Table reqtable = new Table();
|
||||
|
||||
@ -67,14 +67,14 @@ public class WeaponFactory extends Block implements Configurable{
|
||||
}
|
||||
|
||||
tiptable.row();
|
||||
tiptable.add().size(10);
|
||||
tiptable.add().size(4);
|
||||
tiptable.row();
|
||||
tiptable.add("[gray]" + description).left();
|
||||
tiptable.row();
|
||||
if(control.hasWeapon(weapon)){
|
||||
tiptable.add("$text.purchased").padTop(6).left();
|
||||
tiptable.add("$text.purchased").padTop(4).left();
|
||||
}
|
||||
tiptable.margin(14f);
|
||||
tiptable.margin(8f);
|
||||
};
|
||||
|
||||
run.listen();
|
||||
@ -84,10 +84,18 @@ public class WeaponFactory extends Block implements Configurable{
|
||||
tip.setInstant(true);
|
||||
|
||||
ImageButton button = content.addImageButton("white", 8*4, () -> {
|
||||
control.removeItems(requirements);
|
||||
control.addWeapon(weapon);
|
||||
Vars.ui.weaponfrag.update();
|
||||
run.listen();
|
||||
Effects.sound("purchase");
|
||||
|
||||
}).size(49f, 54f).padBottom(-5)
|
||||
.get();
|
||||
if(Net.active() && Net.client()){
|
||||
Vars.netClient.handleUpgrade(weapon);
|
||||
}
|
||||
}).size(49f, 54f).padBottom(-5).get();
|
||||
|
||||
button.setDisabled(() -> control.hasWeapon(weapon));
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(Draw.region(weapon.name));
|
||||
button.addListener(tip);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user