| 1 | //  SuperTux | 
|---|
| 2 | //  Copyright (C) 2016 Hume2 <teratux.mail@gmail.com> | 
|---|
| 3 | // | 
|---|
| 4 | //  This program is free software: you can redistribute it and/or modify | 
|---|
| 5 | //  it under the terms of the GNU General Public License as published by | 
|---|
| 6 | //  the Free Software Foundation, either version 3 of the License, or | 
|---|
| 7 | //  (at your option) any later version. | 
|---|
| 8 | // | 
|---|
| 9 | //  This program is distributed in the hope that it will be useful, | 
|---|
| 10 | //  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 11 | //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 12 | //  GNU General Public License for more details. | 
|---|
| 13 | // | 
|---|
| 14 | //  You should have received a copy of the GNU General Public License | 
|---|
| 15 | //  along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| 16 |  | 
|---|
| 17 | #include "gui/item_script_line.hpp" | 
|---|
| 18 |  | 
|---|
| 19 | #include "control/input_manager.hpp" | 
|---|
| 20 | #include "gui/menu_manager.hpp" | 
|---|
| 21 | #include "gui/menu_script.hpp" | 
|---|
| 22 | #include "supertux/colorscheme.hpp" | 
|---|
| 23 | #include "supertux/console.hpp" | 
|---|
| 24 | #include "supertux/globals.hpp" | 
|---|
| 25 | #include "supertux/resources.hpp" | 
|---|
| 26 | #include "video/drawing_context.hpp" | 
|---|
| 27 |  | 
|---|
| 28 | ItemScriptLine::ItemScriptLine(std::string* input_, int id_) : | 
|---|
| 29 | ItemTextField( "", input_, id_) | 
|---|
| 30 | { | 
|---|
| 31 | } | 
|---|
| 32 |  | 
|---|
| 33 | void | 
|---|
| 34 | ItemScriptLine::draw(DrawingContext& context, const Vector& pos, int , bool active) { | 
|---|
| 35 | std::string r_input = *input; | 
|---|
| 36 | bool fl = active && (int(g_real_time*2)%2); | 
|---|
| 37 | if ( fl ) { | 
|---|
| 38 | r_input += "_"; | 
|---|
| 39 | } | 
|---|
| 40 | context.color().draw_text(Resources::console_font, r_input, | 
|---|
| 41 | Vector(pos.x + 16.0f, | 
|---|
| 42 | pos.y - Resources::console_font->get_height() / 2.0f), | 
|---|
| 43 | ALIGN_LEFT, LAYER_GUI, ColorScheme::Menu::field_color); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | int | 
|---|
| 47 | ItemScriptLine::get_width() const { | 
|---|
| 48 | return static_cast<int>(Resources::console_font->get_text_width(*input)) + 16 + flickw; | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | void | 
|---|
| 52 | ItemScriptLine::(const MenuAction& action) { | 
|---|
| 53 | ItemTextField::process_action(action); | 
|---|
| 54 | const Controller& controller = InputManager::current()->get_controller(); | 
|---|
| 55 | if (action == MenuAction::HIT && controller.pressed(Control::MENU_SELECT)) { | 
|---|
| 56 | auto  = dynamic_cast<ScriptMenu*>(MenuManager::instance().current_menu()); | 
|---|
| 57 | if (!menu) { | 
|---|
| 58 | return; | 
|---|
| 59 | } | 
|---|
| 60 | menu->add_line(); | 
|---|
| 61 | } | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | void | 
|---|
| 65 | ItemScriptLine::invalid_remove() { | 
|---|
| 66 | auto  = dynamic_cast<ScriptMenu*>(MenuManager::instance().current_menu()); | 
|---|
| 67 | if (!menu) { | 
|---|
| 68 | return; | 
|---|
| 69 | } | 
|---|
| 70 | menu->remove_line(); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | /* EOF */ | 
|---|
| 74 |  | 
|---|