summaryrefslogtreecommitdiff
path: root/game/gui/battle.rpy
diff options
context:
space:
mode:
Diffstat (limited to 'game/gui/battle.rpy')
-rw-r--r--game/gui/battle.rpy419
1 files changed, 419 insertions, 0 deletions
diff --git a/game/gui/battle.rpy b/game/gui/battle.rpy
new file mode 100644
index 0000000..0142842
--- /dev/null
+++ b/game/gui/battle.rpy
@@ -0,0 +1,419 @@
+########################################################################################
+# This file is part of Spheres.
+# Copyright (C) 2019 Jesusalva
+
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+########################################################################################
+# Combat Interface
+init python:
+ ####################### Client rendering
+ def c_dragid(dg):
+ if dg == "party1":
+ return 0
+ elif dg == "party2":
+ return 1
+ elif dg == "party3":
+ return 2
+ elif dg == "party4":
+ return 3
+ elif dg == "party5":
+ return 4
+ else:
+ return 0# We can't return -1...
+
+ def combat_action(drags, drop):
+ global use_sphere
+ if not drop:
+ return
+
+ # Define your char slot, and reset the sphere usage for it
+ idn=c_dragid(drags[0].drag_name)
+ use_sphere[idn]=AP_NONE
+
+ # Check if you asked for a skill
+ if (drop.drag_name == "Skill"):
+ renpy.notify("You can't use a skill!")
+ drags[0].snap(0, 30, delay=0.1)
+ #use_sphere[idn]=AP_SKILL
+ return
+
+ # Check if you asked for a sphere
+ if (drop.drag_name == "Sphere"):
+ if (Battle["spheres"][idn]):
+ # Mark to use the sphere - if it exists!
+ drags[0].snap(0, 60, delay=0.1)
+ use_sphere[idn]=AP_SPHERE
+ return
+ else:
+ renpy.notify("You can't use a sphere!")
+ drags[0].snap(0, 30, delay=0.1)
+ return
+ return
+
+# FIXME: Allow to drag spheres instead of whole chars.
+# More checks needed on client, but less on server
+# And spheres are 1D, so much easier on RAM/CPU as well
+init 2 python:
+ def blayout():
+ renpy.call_in_new_context("bl_context")
+ return
+ def blayout2():
+ o1=renpy.call_screen("battle_layout", "Select unit to swap")
+ o2=renpy.call_screen("battle_layout", "Select unit to swap with")
+ if (o1 == o2):
+ return
+ tmp=copy.copy(Battle["party"][o2])
+ Battle["party"][o2]=copy.copy(Battle["party"][o1])
+ Battle["party"][o1]=tmp
+ renpy.notify("Done!")
+ return
+
+label bl_context:
+ $ blayout2()
+ return
+
+#############################################################################
+screen battle():
+ # Background
+ add "bg battle"
+
+ # Load variables
+ python:
+ try:
+ fx1="unit_"+str(Battle["party"][0]["unit_id"])
+ show_img(fx1, False) # Validate
+ except:
+ fx1=""
+ try:
+ fx2="unit_"+str(Battle["party"][1]["unit_id"])
+ show_img(fx2, False) # Validate
+ except:
+ fx2=""
+ try:
+ fx3="unit_"+str(Battle["party"][2]["unit_id"])
+ show_img(fx3, False) # Validate
+ except:
+ fx3=""
+ try:
+ fx4="unit_"+str(Battle["party"][3]["unit_id"])
+ show_img(fx4, False) # Validate
+ except:
+ fx4=""
+ try:
+ fx5="unit_"+str(Battle["party"][4]["unit_id"])
+ show_img(fx5, False) # Validate
+ except:
+ fx5=""
+ try:
+ en1=Battle["enemy"][0]
+ show_img("mob_"+str(en1["unit_id"]), False) # Validate
+ except:
+ en1={"hp": 0}
+ try:
+ en2=Battle["enemy"][1]
+ show_img("mob_"+str(en2["unit_id"]), False) # Validate
+ except:
+ en2={"hp": 0}
+ try:
+ en3=Battle["enemy"][2]
+ show_img("mob_"+str(en3["unit_id"]), False) # Validate
+ except:
+ en3={"hp": 0}
+
+ ####################################################
+ # Render HUD
+ frame:
+ xalign 0.0
+ yalign 0.0
+ xfill True
+ ymaximum 60
+ yfill True
+ background Frame("gui/frame.png", 0, 0)
+ hbox:
+ # Preferences button
+ imagebutton auto "gfx/gui/cog_%s.png" action ShowMenu('preferences')
+ textbutton _("Party") action Function(blayout)
+ null width 20
+ text "%d " % (Battle["turn"])
+ text _(" Turn")
+ null width 300
+ text _("Wave %d/%d" % (Battle["wave"], Battle["max_wave"]))
+ null width 300
+ textbutton _("I'm ready") action Return()
+
+ ####################################################
+ # Render enemies
+
+ # Enemy 1
+ if (en1["hp"] > 0):
+ add At("mob_"+str(en1["unit_id"]), enemy1)
+ vbox:
+ xalign 0.5
+ yanchor 0.5
+ ypos 0.24
+ xmaximum 180
+ ymaximum 20
+ text en1["name"]
+ bar value en1["hp"] range en1["max_hp"]
+
+ # Enemy 2
+ if (en2["hp"] > 0):
+ add At("mob_"+str(en2["unit_id"]), enemy2)
+ vbox:
+ xalign 1.0
+ yanchor 0.5
+ ypos 0.24
+ xmaximum 180
+ ymaximum 20
+ text en2["name"]
+ bar value en2["hp"] range en2["max_hp"]
+
+ # Enemy 3
+ if (en3["hp"] > 0):
+ add At("mob_"+str(en3["unit_id"]), enemy3)
+ vbox:
+ xalign 0.0
+ yanchor 0.5
+ ypos 0.24
+ xmaximum 180
+ ymaximum 20
+ text en3["name"]
+ bar value en3["hp"] range en3["max_hp"]
+
+ ####################################################
+ # Render allies
+ # TODO: Gray out and unmovable if dead
+ # One drag group per party member defined in Battle
+ draggroup:
+ xalign 0.2
+ yalign 1.0
+ xmaximum 160
+ ymaximum 300 # 240 + 60: 30 px each dimension
+ # Display the background
+ drag:
+ child At("gfx/action.png", c_party1)
+ draggable False
+ droppable False
+ # Display the card (if there's one)
+ if (fx1):
+ drag:
+ drag_name "party1"
+ child At(fx1, c_party1)
+ droppable False
+ if (Battle["party"][0]["hp"] > 0):
+ dragged combat_action
+ else:
+ draggable False
+ ypos 30
+ # The action areas
+ drag:
+ drag_name "Skill"
+ child At("gfx/actionarea.png", c_party1)
+ draggable False
+ ypos 0.0
+ drag:
+ drag_name "Sphere"
+ child At("gfx/actionarea.png", c_party1)
+ draggable False
+ yalign 1.0
+ # Display the sphere
+ drag:
+ child ("gfx/sphere/"+str(Battle["spheres"][0])+".png")
+ draggable False
+ droppable False
+ yalign 1.0
+ xalign 0.5
+ if (fx1 and Battle["party"][0]["hp"] <= 0):
+ add At("gfx/off.png", c_party1)
+
+ # One drag group per party member defined in Battle
+ draggroup:
+ xalign 0.4
+ yalign 1.0
+ xmaximum 160
+ ymaximum 300
+ drag:
+ child At("gfx/action.png", c_party2)
+ draggable False
+ droppable False
+ if (fx2):
+ drag:
+ drag_name "party2"
+ child At(fx2, c_party2)
+ droppable False
+ if (Battle["party"][1]["hp"] > 0):
+ dragged combat_action
+ else:
+ draggable False
+ ypos 30
+ drag:
+ drag_name "Skill"
+ child At("gfx/actionarea.png", c_party2)
+ draggable False
+ ypos 0.0
+ drag:
+ drag_name "Sphere"
+ child At("gfx/actionarea.png", c_party2)
+ draggable False
+ yalign 1.0
+ drag:
+ child ("gfx/sphere/"+str(Battle["spheres"][1])+".png")
+ draggable False
+ droppable False
+ yalign 1.0
+ xalign 0.5
+
+ if (fx2 and Battle["party"][1]["hp"] <= 0):
+ add At("gfx/off.png", c_party2)
+ # One drag group per party member defined in Battle
+ draggroup:
+ xalign 0.6
+ yalign 1.0
+ xmaximum 160
+ ymaximum 300
+ drag:
+ child At("gfx/action.png", c_party3)
+ draggable False
+ droppable False
+ if (fx3):
+ drag:
+ drag_name "party3"
+ child At(fx3, c_party3)
+ droppable False
+ if (Battle["party"][2]["hp"] > 0):
+ dragged combat_action
+ else:
+ draggable False
+ ypos 30
+ drag:
+ drag_name "Skill"
+ child At("gfx/actionarea.png", c_party3)
+ draggable False
+ ypos 0.0
+ drag:
+ drag_name "Sphere"
+ child At("gfx/actionarea.png", c_party3)
+ draggable False
+ yalign 1.0
+ drag:
+ child ("gfx/sphere/"+str(Battle["spheres"][2])+".png")
+ draggable False
+ droppable False
+ yalign 1.0
+ xalign 0.5
+
+ if (fx3 and Battle["party"][2]["hp"] <= 0):
+ add At("gfx/off.png", c_party3)
+ # One drag group per party member defined in Battle
+ draggroup:
+ xalign 0.8
+ yalign 1.0
+ xmaximum 160
+ ymaximum 300
+ drag:
+ child At("gfx/action.png", c_party4)
+ draggable False
+ droppable False
+ if (fx4):
+ drag:
+ drag_name "party4"
+ child At(fx4, c_party4)
+ droppable False
+ if (Battle["party"][3]["hp"] > 0):
+ dragged combat_action
+ else:
+ draggable False
+ ypos 30
+ drag:
+ drag_name "Skill"
+ child At("gfx/actionarea.png", c_party4)
+ draggable False
+ ypos 0.0
+ drag:
+ drag_name "Sphere"
+ child At("gfx/actionarea.png", c_party4)
+ draggable False
+ yalign 1.0
+ drag:
+ child ("gfx/sphere/"+str(Battle["spheres"][3])+".png")
+ draggable False
+ droppable False
+ yalign 1.0
+ xalign 0.5
+
+ if (fx4 and Battle["party"][3]["hp"] <= 0):
+ add At("gfx/off.png", c_party4)
+
+
+ ####################################################
+ # Render HPBARs
+ if (fx1):
+ frame:
+ xalign 0.21
+ yalign 1.0
+ ymaximum 10
+ xmaximum 120
+ bar value Battle["party"][0]["hp"] range Battle["party"][0]["max_hp"] xmaximum 120
+
+ if (fx2):
+ frame:
+ xalign 0.4
+ yalign 1.0
+ ymaximum 10
+ xmaximum 120
+ bar value Battle["party"][1]["hp"] range Battle["party"][1]["max_hp"] xmaximum 120
+
+ if (fx3):
+ frame:
+ xalign 0.6
+ yalign 1.0
+ ymaximum 10
+ xmaximum 120
+ bar value Battle["party"][2]["hp"] range Battle["party"][2]["max_hp"] xmaximum 120
+
+ if (fx4):
+ frame:
+ xalign 0.8
+ yalign 1.0
+ ymaximum 10
+ xmaximum 120
+ bar value Battle["party"][3]["hp"] range Battle["party"][3]["max_hp"] xmaximum 120
+
+screen battle_layout(lb="Select unit"):
+ vbox:
+ xalign 0.5
+ yalign 0.3
+ label _("{size=32}{color=#f00}%s{/color}{/size}" % lb)
+ null height 20
+ hbox:
+ for i, item in enumerate(Battle["party"]):
+ imagebutton:
+ if item["unit_id"] > 0:
+ idle At(Composite(
+ (340, 340),
+ (0, 0), "gfx/square/bg.png",
+ (0, 0), "gfx/square/units/%d.png" % item["unit_id"],
+ (0, 0), "gfx/square/%d.png" % allunits[item["unit_id"]]["rare"],
+ ), czoom_70)
+ else:
+ idle At("gfx/square/bg.png", czoom_70)
+ action Return(i)
+ null height 80
+ # The close button returns -1 and comes last (TODO)
+ imagebutton:
+ idle At("gfx/square/back_idle.png", czoom_75)
+ hover At("gfx/square/back_hover.png", czoom_75)
+ action Return(-1)
+