Iñigo Valentin před 3 roky
rodič
revize
69df312c26

+ 4 - 4
README.md

@@ -23,9 +23,9 @@ Note that, while these are actual screenshots of V-Gears, none of the images, sp
 |[<img src="https://v-gears.inigovalentin.com/img/screenshot/transparent_dialogs.png" alt="Transparency" width="250"/>](https://v-gears.inigovalentin.com/img/screenshot/transparent_dialogs.png "Transparency")|[<img src="https://v-gears.inigovalentin.com/img/screenshot/timers.png" alt="Timers" width="250"/>](https://v-gears.inigovalentin.com/img/screenshot/timers.png "Timers")|[<img src="https://v-gears.inigovalentin.com/img/screenshot/choices.png" alt="Choices" width="250"/>](https://v-gears.inigovalentin.com/img/screenshot/choices.png "Choices")|
 
 ### Battle:
-|**Battle UI**|
-|--|
-|[<img src="https://v-gears.inigovalentin.com/img/screenshot/battle.png" alt="Battle UI" width="250"/>](https://v-gears.inigovalentin.com/img/screenshot/battle.png "Battle UI")|
+|**Battle UI**|**Battle Flow**|
+|--|--|
+|[<img src="https://v-gears.inigovalentin.com/img/screenshot/battle.png" alt="Battle UI" width="250"/>](https://v-gears.inigovalentin.com/img/screenshot/battle.png "Battle UI")|[<img src="https://v-gears.inigovalentin.com/img/screenshot/battle.gif" alt="Battle Flow" width="250"/>](https://v-gears.inigovalentin.com/img/screenshot/battle.gif "Battle Flow")|
 
 ### Menus:
 |**Begin**|**Main**|**Name**|
@@ -54,7 +54,7 @@ Well, let's call it a work in progress... of a work in progress.
 |:--:|:--:|
 |A few field maps|Most field maps|
 |Some menus|Some other menus|
-|Sound (mostly)|Battles, in general.|
+|Sound (mostly)|Battle mechanics.|
 |Saving / Loading|The world map, also in general|
 |Timers|Minigames|
 | |Party switching|

+ 2 - 0
data/data/screens/battle/prototypes.xml

@@ -20,7 +20,9 @@
                 <sprite name="MpLineShadow" x="0" y="11" width="100%" height="1" colour="0 0 0" visible="true" />
             </widget>
             <sprite name="Limit" image="icons/battle_bar.png" x="60%" y="0" width="18%" height="14" visible="true" />
+            <sprite name="LimitFill"  x="60%+3" y="3" width="0" height="8" colour="1 0 1" visible="true" />
             <sprite name="Atb" image="icons/battle_bar.png" x="80%" y="0" width="18%" height="14" visible="true" />
+            <sprite name="AtbFill"  x="80%+3" y="3" width="0" height="8" colour="1 1 0" visible="true" />
         </widget>
     </prototype>
 </prototypes>

+ 2 - 0
data/data/screens/begin_menu/begin_menu.xml

@@ -8,6 +8,7 @@
             <animation name="Position4" length="0" y="0:122" />
             <animation name="Position5" length="0" y="0:134" />
             <animation name="Position6" length="0" y="0:146" />
+            <animation name="Position7" length="0" y="0:158" />
         </sprite>
         <text_area name="Text1" x="158" y="80" text_name="BeginMenuNewGame" font="FFVIIFont" visible="true" />
         <text_area name="Text2" x="158" y="92" text_name="BeginMenuLoadGame" font="FFVIIFont" visible="true" />
@@ -15,5 +16,6 @@
         <text_area name="Text4" x="158" y="122" text_name="BeginMenu3" font="FFVIIFont" visible="true" />
         <text_area name="Text5" x="158" y="134" text_name="BeginMenu4" font="FFVIIFont" visible="true" />
         <text_area name="Text6" x="158" y="146" text_name="BeginMenu5" font="FFVIIFont" visible="true" />
+        <text_area name="Text7" x="158" y="158" text_name="BeginMenu6" font="FFVIIFont" visible="true" />
     </widget>
 </screen>

+ 71 - 6
data/data/scripts/battle/battle_ui.lua

@@ -46,6 +46,7 @@ UiContainer.BattleUi = {
         if button == "K" then
             Battle.finish()
         end
+        -- Handle command cursors
         if self.window_state == "command" then
             local command_count = #self.party[self.current_character_window].command
             if button == "Down" then
@@ -53,24 +54,34 @@ UiContainer.BattleUi = {
                     -- If on the first three ones, always alow to go down to reach "Item"
                     self.cursor_command = self.cursor_command + 1
                     ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                    audio_manager:play_sound("Cursor")
                 elseif self.cursor_command % 4 == 0 then
                     -- If on a multiple of 4, go to the top of the column
                     self.cursor_command = self.cursor_command - 3
                     ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                    audio_manager:play_sound("Cursor")
                 elseif command_count > self.cursor_command then
-                    -- Else, allow one position down only if there are more comands.
+                    -- If there is a command below, allow one position down.
                     self.cursor_command = self.cursor_command + 1
                     ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                    audio_manager:play_sound("Cursor")
+                else
+                    -- Back to the first row
+                    self.cursor_command = 4 * math.floor(self.cursor_command / 4) + 1
+                    ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                    audio_manager:play_sound("Cursor")
                 end
             elseif button == "Up" then
                 if self.cursor_command == 1 then
                     -- If on "Attack, always go to item
                     self.cursor_command = 4
                     ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                    audio_manager:play_sound("Cursor")
                 elseif self.cursor_command > 1 and self.cursor_command < 5 then
                     -- If on the second, third, or fourth, always alwow to go down to reach "Attack" from "Item"
                     self.cursor_command = self.cursor_command - 1
                     ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                    audio_manager:play_sound("Cursor")
                 elseif self.cursor_command % 4 == 1 and command_count > self.cursor_command then
                     -- If on the first row, go to the last where there is a command
                     self.cursor_command = self.cursor_command + 3
@@ -78,16 +89,19 @@ UiContainer.BattleUi = {
                         self.cursor_command = self.cursor_command - 1
                     end
                     ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                    audio_manager:play_sound("Cursor")
                 else
                     -- Else, always allow to go one up.
                     self.cursor_command = self.cursor_command - 1
                     ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                    audio_manager:play_sound("Cursor")
                 end
             elseif button == "Left" then
                 if command_count > 4 then
                     if self.cursor_command > 4 then
                         self.cursor_command = self.cursor_command - 4
                         ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                        audio_manager:play_sound("Cursor")
                     else
                         local new_position = self.cursor_command + 4 * math.floor(command_count / 4)
                         while new_position > command_count do
@@ -95,6 +109,7 @@ UiContainer.BattleUi = {
                         end
                         self.cursor_command = new_position
                         ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                        audio_manager:play_sound("Cursor")
                     end
                 end
             elseif button == "Right" then
@@ -107,6 +122,7 @@ UiContainer.BattleUi = {
                         end
                     end
                     ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                    audio_manager:play_sound("Cursor")
                 end
             -- TODO: elseif accept, skip buttons...
             end
@@ -114,6 +130,36 @@ UiContainer.BattleUi = {
         return 0
     end,
 
+    tick = function(self)
+        --print("CALLED BattleUI:tick()")
+        if self.window_state ~= "wait" then
+            do return end
+        end
+        for i = 1, #self.party do
+            if self.party[i].dead == false then -- TODO: Or stopped
+                if self.party[i].atb < 100 then
+                    -- TODO: Consider haste/slow
+                    self.party[i].atb = self.party[i].atb + 0.01 * Characters[self.party[i].character].stats.dex.total -- TODO
+                    if self.party[i].atb >= 100 then
+                        print(Characters[self.party[i].character].name .. " ATB full")
+                        ui_manager:get_widget("BattleUi.Container.Bottom.Character" .. tostring(i) .. ".Right.AtbFill"):set_colour(0, 1, 0)
+                        self:show_commands(i)
+                    end
+                    -- Fill ATB UI bar
+                    -- 0   -> 0%
+                    -- 100 -> 18%-6
+                    local width_percent = math.min(18, 18 * self.party[i].atb / 100)
+                    local width_fixed = math.max(-6, -6 * width_percent / 18)
+                    ui_manager:get_widget("BattleUi.Container.Bottom.Character" .. tostring(i) .. ".Right.AtbFill"):set_width(width_percent, width_fixed)
+                end
+            end
+        end
+        --print("ENDED BattleUI:tick()")
+    end,
+
+    --- Loads party character data
+    --
+    -- Reads materia, calculates stats, computes attacks...
     load_party_members = function(self)
         for i = 1, Party.MAX do
             if Party[i] ~= nil then
@@ -122,6 +168,7 @@ UiContainer.BattleUi = {
                 --math.randomseed(('' .. os.time()):reverse())
                 -- TODO: Consider battle layouts.
                 -- TODO: Check random seed
+                self.party[i].dead = false
                 self.party[i].atb = math.random(0, 100)
                 self.party[i].command = {}
                 self.party[i].magic = {}
@@ -131,6 +178,13 @@ UiContainer.BattleUi = {
                 self.party[i].long_range = false
                 self.party[i].mega_all = false
                 self.party[i].pre_emptive = 0
+                -- Fill Limit UI bar
+                -- 0   -> 0%
+                -- 255 -> 18%-6
+                local width_percent = math.min(18, 18 * Characters[self.party[i].character].limit.bar / 255)
+                local width_fixed = math.max(-6, -6 * width_percent / 18)
+                ui_manager:get_widget("BattleUi.Container.Bottom.Character" .. tostring(i) .. ".Right.LimitFill"):set_width(width_percent, width_fixed)
+                -- Read materia
                 local w_magic = false
                 local w_item = false
                 local w_summon = false
@@ -272,16 +326,26 @@ UiContainer.BattleUi = {
         ui_manager:get_widget("BattleUi"):set_visible(true)
         self.active = true;
 
-        -- Set help window transparency
+        -- Lopad party data
+        self:load_party_members()
+
+        -- Set various transparencies
         ui_manager:get_widget("BattleUi.Container.Help.Center"):set_alpha(0.5)
         ui_manager:get_widget("BattleUi.Container.Message.Center"):set_alpha(0.5)
+        ui_manager:get_widget("BattleUi.Container.Message.Center"):set_alpha(0.5)
+        for i = 1, #self.party do
+            ui_manager:get_widget(
+              "BattleUi.Container.Bottom.Character" .. tostring(i) .. ".Right.AtbFill"
+            ):set_alpha(0.45)
+            ui_manager:get_widget(
+              "BattleUi.Container.Bottom.Character" .. tostring(i) .. ".Right.LimitFill"
+            ):set_alpha(0.45)
+        end
 
-        -- Lopad party data
-        self:load_party_members()
 
         -- DEBUG:
-        ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Center"):set_alpha(0.5)
-        self:show_commands(1)
+        --ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Center"):set_alpha(0.5)
+        --self:show_commands(1)
 
         return 0;
     end,
@@ -292,6 +356,7 @@ UiContainer.BattleUi = {
     show_commands = function(self, party_id)
         self.current_character_window = party_id
         self.cursor_command = 1
+        self.window_state = "command"
         -- Colour the character name
         for c = 1, #self.party do
             if c == party_id then

+ 2 - 0
data/data/scripts/debug_data.lua

@@ -46,6 +46,8 @@ Inventory.money = 1234567
 Inventory.sort(Inventory.ORDER.NAME)
 Characters[0].stats.hp.current = 12345
 Characters[0].stats.hp.base = 54321
+Characters[0].stats.dex.base = 11
+Characters[0].stats.dex.total = 11
 Characters[0].armor.id = 268
 Characters[0].armor.materia = {
     [0] = {id = 62, ap = 5340},

+ 9 - 1
data/data/scripts/menu/begin_menu.lua

@@ -7,7 +7,7 @@ UiContainer.BeginMenu = {
     position = 1,
 
     -- Max cursor position
-    position_total = 6,
+    position_total = 7,
 
     --- Run when the menu is created.
     --
@@ -93,6 +93,14 @@ UiContainer.BeginMenu = {
                     console("debug_walkmesh false")
                     script:request_end_sync(Script.UI, "BeginMenu", "hide", 0)
                     MenuSettings.pause_available = true
+                elseif self.position == 7 then
+                    --load_field_map_request("startmap", "")
+                    console("camera_free false")
+                    console("debug_walkmesh false")
+                    script:request_end_sync(Script.UI, "BeginMenu", "hide", 0)
+                    set_party(0, 2, 3)
+                    Battle.start(220)
+                    MenuSettings.pause_available = true
                 end
             elseif button == "Down" then
                 audio_manager:play_sound("Cursor")

+ 1 - 0
data/data/texts/english/menu.xml

@@ -27,6 +27,7 @@
     <text name="BeginMenu3"><colour value="0.5 0.5 0.5">DEBUG: Entity testarea</colour></text>
     <text name="BeginMenu4"><colour value="0.5 0.5 0.5">DEBUG: World map test</colour></text>
     <text name="BeginMenu5"><colour value="0.5 0.5 0.5">DEBUG: Debug Room</colour></text>
+    <text name="BeginMenu6"><colour value="0.5 0.5 0.5">DEBUG: Test Battle</colour></text>
 
     <text name="PauseMenuHeader">Paused</text>
     <text name="PauseMenuText">Are you want to quit?</text>

+ 4 - 1
src/core/BattleManager.cpp

@@ -23,6 +23,7 @@
 #include "core/AudioManager.h"
 #include "core/BattleManager.h"
 #include "core/CameraManager.h"
+#include "core/Console.h"
 #include "core/DialogsManager.h"
 #include "core/Enemy.h"
 #include "core/EntityManager.h"
@@ -338,6 +339,8 @@ void BattleManager::LoadParty(){
 
 void BattleManager::UpdateField(){}
 
-void BattleManager::UpdateBattle(){}
+void BattleManager::UpdateBattle(){
+    ScriptManager::getSingleton().RunString("UiContainer.BattleUi:tick()");
+}
 
 void BattleManager::UpdateWorld(){}

+ 2 - 0
src/core/GameFrameListener.cpp

@@ -15,6 +15,7 @@
 
 #include <OgreStringConverter.h>
 #include "VGearsGameState.h"
+#include "core/BattleManager.h"
 #include "core/GameFrameListener.h"
 #include "core/CameraManager.h"
 #include "core/ConfigVar.h"
@@ -93,6 +94,7 @@ bool GameFrameListener::frameStarted(const Ogre::FrameEvent& evt){
     CameraManager::getSingleton().Update();
     EntityManager::getSingleton().Update();
     DialogsManager::getSingleton().Update();
+    BattleManager::getSingleton().Update();
     return true;
 }
 

+ 2 - 0
src/core/ScriptManagerBinds.h

@@ -840,8 +840,10 @@ void ScriptManager::InitBinds(){
           .def("set_z", (void(UiWidget::*)(const float)) &UiWidget::SetZ)
           .def("get_width", (float(UiWidget::*)()) &UiWidget::ScriptGetWidth)
           .def("set_width", (void(UiWidget::*)(const float)) &UiWidget::ScriptSetWidth)
+          .def("set_width", (void(UiWidget::*)(const float, const float)) &UiWidget::SetWidth)
           .def("get_height", (float(UiWidget::*)()) &UiWidget::ScriptGetHeight)
           .def("set_height", (void(UiWidget::*)(const float)) &UiWidget::ScriptSetHeight)
+          .def("set_height", (void(UiWidget::*)(const float, const float)) &UiWidget::SetHeight)
           .def("set_text", (void(UiWidget::*)(const char*)) &UiWidget::SetText)
           .def("set_image", (void(UiWidget::*)(const char*)) &UiWidget::SetImage)
     ];