Ver código fonte

Name menu fully functional. Materia menu header implemented.

Iñigo Valentin 3 anos atrás
pai
commit
11c72b8cde

+ 1 - 0
V-Gears/src/core/ScriptManager.cpp

@@ -76,6 +76,7 @@ void ScriptManager::Input(const VGears::Event& event){
         || event.param1 == OIS::KC_UP
         || event.param1 == OIS::KC_PGUP
         || event.param1 == OIS::KC_PGDOWN
+        || event.param1 == OIS::KC_BACK
         || event.param1 == OIS::KC_A || event.param1 == OIS::KC_B || event.param1 == OIS::KC_C
         || event.param1 == OIS::KC_D || event.param1 == OIS::KC_E || event.param1 == OIS::KC_F
         || event.param1 == OIS::KC_G || event.param1 == OIS::KC_H || event.param1 == OIS::KC_I

+ 1 - 0
V-Gears/src/core/Utilites.cpp

@@ -255,6 +255,7 @@ KeyName key_names[] = {
     {"F12", OIS::KC_F12},
     {"PGUP", OIS::KC_PGUP},
     {"PGDN", OIS::KC_PGDOWN},
+    {"BackSpace", OIS::KC_BACK},
     {"UNASSIGNED", OIS::KC_UNASSIGNED},
 };
 

+ 1 - 0
data/data/screens.xml

@@ -10,6 +10,7 @@
     <prototype file_name="screens/item_menu/prototypes.xml" />
     <screen file_name="screens/item_menu/item_menu.xml" />
     <screen file_name="screens/equip_menu/equip_menu.xml" />
+    <screen file_name="screens/materia_menu/materia_menu.xml" />
     <screen file_name="screens/name_menu/name_menu.xml" />
 
     <!-- Dialogs -->

+ 19 - 8
data/data/screens/name_menu/name_menu.xml

@@ -35,15 +35,26 @@
                 <sprite name="Score12" x="110" y="11" width="8" height="0.3" colour="0.6 0.6 0.6" visible="true"/>
             </widget>
         </widget>
-        <widget name="Options" x="100%-80" y="94" width="80" height="100%-94" visible="true">
+        <widget name="Options" x="100%-80" y="100%-58" width="80" height="58" visible="true">
             <prototype name="Window" />
-            <text_area name="Clear" x="15" y="10" font="FFVIIFont" visible="true" />
-            <text_area name="Default" x="15" y="20" font="FFVIIFont" visible="true" />
-            <text_area name="Confirm" x="15" y="30" font="FFVIIFont" visible="true" />
-            <sprite name="Cursor" image="images/icons/cursor.png" x="-5" y="10" width="24" height="17" visible="true">
-                <animation name="Position1" length="0" y="0:10" />
-                <animation name="Position2" length="0" y="0:20" />
-                <animation name="Position3" length="0" y="0:30" />
+            <text_area name="Clear" text_name="NameMenuClear" x="15" y="100%-50" font="FFVIIFont" visible="true" />
+            <text_area name="Default" text_name="NameMenuDefault" x="15" y="100%-35" font="FFVIIFont" visible="true" />
+            <text_area name="Confirm" text_name="NameMenuConfirm" x="15" y="100%-20" font="FFVIIFont" visible="true" />
+            <sprite name="Cursor" image="images/icons/cursor.png" x="-10" y="100%-48" width="24" height="17" visible="true">
+                <animation name="Position1" length="0" y="0:100%-50" />
+                <animation name="Position2" length="0" y="0:100%-35" />
+                <animation name="Position3" length="0" y="0:100%-20" />
+            </sprite>
+        </widget>
+        <widget name="Confirm" x="50%-60" y="50%-40" width="120" height="80" visible="false" >
+            <prototype name="Window" />
+            <text_area name="Ask" text_name="NameMenuConfirmMsg" x="20" y="10" width="100" height="12" font="FFVIIFont" visible="true" />
+            <text_area name="Name" x="22" y="30" font="FFVIIFont" visible="true" colour="0 0.8 1"/>
+            <text_area name="Yes" text_name="Yes" x="20" y="55" font="FFVIIFont" visible="true" />
+            <text_area name="No" text_name="No" x="80" y="55" font="FFVIIFont" visible="true" />
+            <sprite name="Cursor" image="images/icons/cursor.png" x="-4" y="55" width="24" height="17" visible="true">
+                <animation name="Position1" length="0" x="0:-4" />
+                <animation name="Position2" length="0" x="0:56" />
             </sprite>
         </widget>
     </widget>

+ 2 - 1
data/data/scripts/menu/main_menu.lua

@@ -91,7 +91,8 @@ UiContainer.MainMenu = {
                     if self.select_character_for_menu == 2 then -- Magic menu
                         print("Open magic menu for char in slot " .. self.character_position)
                     elseif self.select_character_for_menu == 3 then -- Materia menu
-                        print("Open materia menu for char in slot " .. self.character_position)
+                        UiContainer.current_character_id = FFVII.Party[self.character_position]
+                        script:request_end_sync(Script.UI, "MateriaMenu", "show", 0)
                     elseif self.select_character_for_menu == 4 then -- Equip menu
                         UiContainer.current_character_id = FFVII.Party[self.character_position]
                         script:request_end_sync(Script.UI, "EquipMenu", "show", 0)

+ 151 - 23
data/data/scripts/menu/name_menu.lua

@@ -12,7 +12,7 @@ UiContainer.NameMenu = {
     --- Default name.
     default_name = "",
 
-    --- Currently input-ed name
+    --- Currently input-ed name.
     name = "",
 
     --- Max number of characters allowed in a name.
@@ -21,7 +21,20 @@ UiContainer.NameMenu = {
     --- Current text cursor
     text_cursor = 1,
 
-    letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+    --- Accepted characters in a name.
+    letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ",
+
+    --- Current options cursor position.
+    options_position = 1,
+
+    --- Total options cursor position.
+    options_position_total = 3,
+
+    --- Current confirm dialog cursor position.
+    confirm_position = 1,
+
+    --- Total confirm dialog cursor position.
+    confirm_position_total = 2,
 
     --- Run when the menu is creaded.
     --
@@ -37,13 +50,51 @@ UiContainer.NameMenu = {
     -- @param event Trigger event. Normally, "Press".
     on_button = function(self, button, event)
         if UiContainer.current_menu == "name" then
-            print("BUTTON " .. button .. " on " .. UiContainer.current_menu .. "." .. UiContainer.current_submenu)
 
             if UiContainer.current_submenu == "confirm" then
+                if button == "Right" then
+                    self.confirm_position = self.confirm_position + 1
+                    if self.confirm_position > self.confirm_position_total then
+                        self.confirm_position = 1
+                    end
+                    ui_manager:get_widget("NameMenu.Container.Confirm.Cursor"):set_default_animation("Position" .. self.confirm_position)
+                elseif button == "Left" then
+                    self.confirm_position = self.confirm_position - 1
+                    if self.confirm_position < 1 then
+                        self.confirm_position = self.confirm_position_total
+                    end
+                    ui_manager:get_widget("NameMenu.Container.Confirm.Cursor"):set_default_animation("Position" .. self.confirm_position)
+                elseif button == "Enter" then
+                    if self.confirm_position == 2 then -- Back
+                        UiContainer.current_submenu = ""
+                        ui_manager:get_widget("NameMenu.Container.Confirm"):set_visible(false)
+                    elseif self.confirm_position == 1 then
+                        ui_manager:get_widget("NameMenu.Container.Confirm"):set_visible(false)
+                        self.apply_name(self);
+                    end
+                end
             elseif UiContainer.current_submenu == "" then
-                local character_index = string.find(self.letters, button)
-                if button == "Up" and event == "Press" then
-                elseif button == "Down" then
+                -- Before handling buttons, get keycode, for letters and space.
+                local character_index
+                if button == "Space" then
+                    character_index = string.find(self.letters, " ")
+                else
+                    character_index = string.find(self.letters, button)
+                end
+
+                -- Handle buttons.
+                if button == "Down" then
+                    self.options_position = self.options_position + 1
+                    if self.options_position > self.options_position_total then
+                        self.options_position = 1
+                    end
+                    ui_manager:get_widget("NameMenu.Container.Options.Cursor"):set_default_animation("Position" .. self.options_position)
+                elseif button == "Up" then
+                    self.options_position = self.options_position - 1
+                    if self.options_position < 1 then
+                        self.options_position = self.options_position_total
+                    end
+                    ui_manager:get_widget("NameMenu.Container.Options.Cursor"):set_default_animation("Position" .. self.options_position)
                 elseif button == "Left" then
                     if self.text_cursor > 1 then
                         self.text_cursor = self.text_cursor - 1
@@ -55,9 +106,37 @@ UiContainer.NameMenu = {
                         self.draw_cursor(self)
                     end
                 elseif button == "Enter" then
-                -- TODO: Else Letters
+                    if self.options_position == 1 then -- Clear name.
+                        self.name = ""
+                        self.text_cursor = 1
+                        self.populate_name(self)
+                        self.draw_cursor(self)
+                    elseif self.options_position == 2 then -- Default name.
+                        self.name = self.default_name
+                        self.text_cursor = math.min(#(self.name) + 1, self.max_characters)
+                        self.populate_name(self)
+                        self.draw_cursor(self)
+                    elseif self.options_position == 3 then -- Show confirm dialog.
+                        self.format_name(self)
+                        self.populate_name(self)
+                        self.draw_cursor(self)
+                        if #(self.name) > 0 then
+                            UiContainer.current_submenu = "confirm"
+                            local name_display = self.name -- Pad with spaces, to display only.
+                            while #(name_display) < self.max_characters do
+                                name_display = " " .. name_display
+                            end
+                            ui_manager:get_widget("NameMenu.Container.Confirm.Name"):set_text(name_display)
+                            ui_manager:get_widget("NameMenu.Container.Confirm"):set_visible(true)
+                            self.confirm_position = 1
+                            ui_manager:get_widget("NameMenu.Container.Options.Cursor"):set_default_animation("Position" .. self.options_position)
+                        else
+                            print("BEEP no name")
+                        end
+                    end
+                -- TODO: Implement backspace, but how?
+                -- Letters and spaces
                 elseif character_index ~= nil then
-                    print(" LETTER " .. character_index)
                     self.set_char(self, character_index)
                     self.text_cursor = math.min(self.text_cursor + 1, self.max_characters)
                     self.populate_name(self)
@@ -68,38 +147,45 @@ UiContainer.NameMenu = {
         return 0
     end,
 
-    --- Opens the main menu.
+    --- Opens the name menu.
     --
-    -- Populates and updates displayed data before opening.
+    -- Populates and updates displayed data before opening. It also pauses the game. Shows a fade
+    -- effect.
     show = function(self)
         entity_manager:set_paused(true)
         FFVII.MenuSettings.pause_available = false
+        script:request_end_sync(Script.UI, "Fade", "fade_out", 0)
         ui_manager:get_widget("NameMenu"):set_visible(true)
         UiContainer.current_menu = "name"
         UiContainer.current_submenu = ""
         ui_manager:get_widget("NameMenu.Container.Character.Portrait"):set_image("images/characters/" .. tostring(self.id) .. ".png")
-        self.default_name = Characters[self.id].name
-        self.name = Characters[self.id].name
+        if (string.lower(Characters[self.id].name) == "ex-soldier") then
+            -- HACK: Hack for Ex-Soldier default. Can this be extracted from menu.lgp?
+            self.default_name = "Cloud"
+            self.name = "Cloud"
+        else
+            self.default_name = Characters[self.id].name
+            self.name = Characters[self.id].name
+        end
         self.text_cursor = math.min(#(self.name) + 1, self.max_characters)
         self.populate_name(self)
         self.draw_cursor(self)
+        script:request_end_sync(Script.UI, "Fade", "fade_in", 0)
         return 0;
     end,
 
+    --- Redraws the text cursor, indicating the current character.
     draw_cursor = function(self)
-        -- TODO: Do this with animations.
         for i = 1, self.max_characters do
             if self.text_cursor == i then
-                print("")
                 ui_manager:get_widget("NameMenu.Container.Character.Name.Score" .. tostring(i)):set_height(1.8)
-                --ui_manager:get_widget("NameMenu.Container.Character.Name.Score" .. tostring(i)):set_default_animation("Active")
             else
                 ui_manager:get_widget("NameMenu.Container.Character.Name.Score" .. tostring(i)):set_height(0.3)
-                --ui_manager:get_widget("NameMenu.Container.Character.Name.Score" .. tostring(i)):set_default_animation("Inactive")
             end
         end
     end,
 
+    --- Writes the name characters in the name input line.
     populate_name = function(self)
         for i = 1, self.max_characters do
             if #(self.name) < i then
@@ -111,34 +197,76 @@ UiContainer.NameMenu = {
         end
     end,
 
-    --- Sets a character in the current cursor position
+    --- Sets a character in the current cursor position.
     set_char = function(self, character_index)
         local temp_name = ""
         for i = 1, self.max_characters do
             if i == self.text_cursor then
-                -- TODO: First position or after space: Use upper case table
-                if self.text_cursor == 1 or self.name:sub(i - 1, i - 1) == " " then
+                -- First position or after space: Use upper case.
+                if i == 1 or temp_name:sub(i - 1, i - 1) == " " then
                     temp_name = temp_name .. self.letters:sub(character_index, character_index)
                 else
                     temp_name = temp_name .. string.lower(self.letters:sub(character_index, character_index))
                 end
-                print("NEW: " .. self.letters:sub(character_index, character_index))
             elseif #(self.name) >= i then
-                -- TODO: First position or after space: to upper, else to lower
-                temp_name = temp_name .. self.name:sub(i, i)
-                print("OLD: " .. self.name:sub(i, i))
+                if i == 1 or temp_name:sub(i - 1, i - 1) == " " then
+                    temp_name = temp_name .. string.upper(self.name:sub(i, i))
+                else
+                    temp_name = temp_name .. string.lower(self.name:sub(i, i))
+                end
+            else
+                temp_name = temp_name .. " "
             end
         end
         self.name = temp_name
     end,
 
+    --- Formats the current name.
+    --
+    -- Removes leading, trailing and double spaces, trims the length, and ensures capitalization.
+    format_name = function(self)
+        local temp_name = self.name
+        -- Trailing and leading spaces: Remove.
+        temp_name = string.gsub(temp_name, '^%s*(.-)%s*$', '%1')
+        -- Double (or more) spaces: One space.
+        temp_name = temp_name:gsub("%s+", " ")
+        -- Length. Trim to self.max_characters
+        if #(temp_name) > self.max_characters then
+            temp_name = temp_name:sub(1, self.max_characters)
+        end
+        -- Capitalization
+        self.name = ""
+        for i = 1, #(temp_name) do
+            if i == 1 or temp_name:sub(i - 1, i - 1) == " " then
+                self.name = self.name .. string.upper(temp_name:sub(i, i))
+            else
+                self.name = self.name .. string.lower(temp_name:sub(i, i))
+            end
+        end
+    end,
+
+    apply_name = function(self)
+
+        if self.chocobo == false then
+            Characters[self.id].name = self.name
+            export_character_names()
+        else
+            -- TODO: Do chocobo.
+        end
+        self.hide(self)
+    end,
+
     --- Hides the item menu and goes back to the main menu.
+    --
+    -- It also unpauses the game. Shows a fade effect.
     hide = function(self)
+        script:request_end_sync(Script.UI, "Fade", "fade_out", 0)
         ui_manager:get_widget("NameMenu"):set_visible(false)
         UiContainer.current_menu = ""
         UiContainer.current_submenu = ""
         FFVII.MenuSettings.pause_available = true
         entity_manager:set_paused(false)
+        script:request_end_sync(Script.UI, "Fade", "fade_in", 0)
         return 0;
     end,
 }