Explorar o código

Basic controls for the battle command window

Iñigo Valentin %!s(int64=3) %!d(string=hai) anos
pai
achega
e0e8ad5343

+ 26 - 12
data/data/screens/battle/battle.xml

@@ -31,18 +31,32 @@
             </widget>
             <widget name="Commands" x="22%" y="5%" width="60" height="95%" visible="false">
                 <prototype name="Window" />
-                <text_area name="Cmd1" x="5" y="0%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd2" x="5" y="22%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd3" x="5" y="44%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd4" x="5" y="66%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd5" x="55" y="0%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd6" x="55" y="22%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd7" x="55" y="44%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd8" x="55" y="66%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd9" x="100" y="0%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd10" x="100" y="22%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd11" x="100" y="44%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
-                <text_area name="Cmd12" x="100" y="66%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd1" x="10" y="0%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd2" x="10" y="22%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd3" x="10" y="44%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd4" x="10" y="66%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd5" x="60" y="0%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd6" x="60" y="22%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd7" x="60" y="44%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd8" x="60" y="66%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd9" x="105" y="0%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd10" x="105" y="22%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd11" x="105" y="44%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <text_area name="Cmd12" x="105" y="66%+5" width="100%-5" height="25%" font="FFVIIFont" text_name="BattleUiHp" visible="true" />
+                <sprite name="Cursor" image="icons/cursor.png" x="132" y="99" width="24" height="16" visible="true">
+                    <animation name="Position1" length="0" x="0:-15" y="0:0%+7" />
+                    <animation name="Position2" length="0" x="0:-15" y="0:22%+7" />
+                    <animation name="Position3" length="0" x="0:-15" y="0:44%+7" />
+                    <animation name="Position4" length="0" x="0:-15" y="0:66%+7" />
+                    <animation name="Position5" length="0" x="0:35" y="0:0%+7" />
+                    <animation name="Position6" length="0" x="0:35" y="0:22%+7" />
+                    <animation name="Position7" length="0" x="0:35" y="0:44%+7" />
+                    <animation name="Position8" length="0" x="0:35" y="0:66%+7" />
+                    <animation name="Position9" length="0" x="0:80" y="0:0%+7" />
+                    <animation name="Position10" length="0" x="0:80" y="0:22%+7" />
+                    <animation name="Position11" length="0" x="0:80" y="0:44%+7" />
+                    <animation name="Position12" length="0" x="0:80" y="0:66%+7" />
+                </sprite>
             </widget>
         </widget>
     </widget>

+ 98 - 0
data/data/scripts/battle/battle_ui.lua

@@ -16,6 +16,24 @@ UiContainer.BattleUi = {
         return 0
     end,
 
+    --- Indicates what the current cursor is for.
+    --
+    -- Possible values are "wait" (no cursor), "command" (for command selection), "list" (for
+    -- magic, item, summon... selection), and "target" for target selection.
+    window_state = "wait", -- wait, command, list, target
+
+    --- Current position for the cursor in the command window.
+    cursor_command = 1,
+
+    --- Current position for the cursor in the list window.
+    cursor_list = 1,
+
+    --- Current position for the cursor in the target window.
+    cursor_target = 1,
+
+    --- ID of the character the cursor is for.
+    current_character_window = -1,
+
     --- Handles button events.
     --
     -- For the current submenu, handles directional keys, enter and escape events.
@@ -28,6 +46,71 @@ UiContainer.BattleUi = {
         if button == "K" then
             Battle.finish()
         end
+        if self.window_state == "command" then
+            local command_count = #self.party[self.current_character_window].command
+            if button == "Down" then
+                if self.cursor_command < 4 then
+                    -- 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))
+                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))
+                elseif command_count > self.cursor_command then
+                    -- Else, allow one position down only if there are more comands.
+                    self.cursor_command = self.cursor_command + 1
+                    ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                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))
+                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))
+                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
+                    while self.cursor_command > command_count do
+                        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))
+                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))
+                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))
+                    else
+                        local new_position = self.cursor_command + 4 * math.floor(command_count / 4)
+                        while new_position > command_count do
+                            new_position = new_position - 4
+                        end
+                        self.cursor_command = new_position
+                        ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                    end
+                end
+            elseif button == "Right" then
+                if command_count > 4 then
+                    self.cursor_command = self.cursor_command + 4
+                    if self.cursor_command > command_count then
+                        self.cursor_command = self.cursor_command - 4 * math.floor(self.cursor_command / 4)
+                        if self.cursor_command < 1 then
+                            self.cursor_command = self.cursor_command + 4
+                        end
+                    end
+                    ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+                end
+            -- TODO: elseif accept, skip buttons...
+            end
+        end
         return 0
     end,
 
@@ -207,6 +290,17 @@ UiContainer.BattleUi = {
     -- Shows the command window for a character
     -- @param party_id The ID of the party member whose commands to show
     show_commands = function(self, party_id)
+        self.current_character_window = party_id
+        self.cursor_command = 1
+        -- Colour the character name
+        for c = 1, #self.party do
+            if c == party_id then
+                ui_manager:get_widget("BattleUi.Container.Bottom.Character" .. tostring(c) .. ".Left.Name"):set_colour(1, 1, 0)
+            else
+                ui_manager:get_widget("BattleUi.Container.Bottom.Character" .. tostring(c) .. ".Left.Name"):set_colour(1, 1, 1)
+            end
+            ui_manager:get_widget("BattleUi.Container.Bottom.Character" .. tostring(c) .. ".Left.Name"):set_text(Characters[Party[c]].name)
+        end
         ui_manager:get_widget("BattleUi.Container.Bottom.Commands"):set_visible(true)
         -- Resize the window
         ui_manager:get_widget("BattleUi.Container.Bottom.Commands"):set_width(
@@ -220,6 +314,10 @@ UiContainer.BattleUi = {
             ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cmd" .. tostring(pos)):set_text(Game.Commands[cmd].name)
             ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cmd" .. tostring(pos)):set_visible(true)
         end
+        -- Set and show cursor
+        ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_visible(true)
+        ui_manager:get_widget("BattleUi.Container.Bottom.Commands.Cursor"):set_default_animation("Position" .. tostring(self.cursor_command))
+        self.window_state = "command"
 
     end,
 

+ 1 - 1
src/core/BattleManager.cpp

@@ -306,10 +306,10 @@ void BattleManager::LoadParty(){
 
     // TODO: Read this from data/gamedata/characters.xml
     for (int i = 0; i < positions.size(); i ++){
+        if (party.at(positions.at(i)) == - 1) continue;
         std::string name = "";
         std::string model = "";
 
-
         for (XmlBattleCharactersFile::BattleCharacter character : character_model_map_){
             if (character.id == party.at(positions.at(i))){
                 model = "characters/" + character.models.at(0).model;

+ 1 - 1
src/core/XmlBattleCharactersFile.cpp

@@ -21,7 +21,7 @@ XmlBattleCharactersFile::XmlBattleCharactersFile(const Ogre::String& file): XmlF
     TiXmlNode* node = file_.RootElement();
     if (node == nullptr || node->ValueStr() != "characters"){
         LOG_ERROR(
-          file_.ValueStr() + " is not a valid battle scenes file! No <characters> in root."
+          file_.ValueStr() + " is not a valid battle characters file! No <characters> in root."
         );
         return;
     }