• R/O
  • SSH

hyakutyping: コミット

ゲーム用のソースコード


コミットメタ情報

リビジョン0f165cdec29515fccc242c4ef2886e73de0e931a (tree)
日時2011-07-19 06:58:24
作者satofumi
コミッターsatofumi

ログメッセージ

ガベージコレクションで使用中のオブジェクトを破壊していたのを修正

変更サマリ

差分

diff -r cc13241f019a -r 0f165cdec295 Option.cpp
--- a/Option.cpp Mon Jul 18 07:08:42 2011 +0900
+++ b/Option.cpp Tue Jul 19 06:58:24 2011 +0900
@@ -10,6 +10,7 @@
1010 #include "Option.h"
1111 #include "LayerManager.h"
1212 #include "CallbackEvent.h"
13+#include "Menu.h"
1314 #include <vector>
1415
1516 using namespace qrk;
@@ -18,29 +19,35 @@
1819
1920 struct Option::pImpl
2021 {
21- typedef vector<Component*> Components;
22+ typedef vector<Menu*> Components;
2223
2324 Rect<long> rect_;
2425 bool acceptable_;
2526 float alpha_;
26- int current_row_;
27+ int current_row_index_;
2728
2829 LayerManager layer_manager_;
2930 CallbackEvent up_event_;
3031 CallbackEvent down_event_;
32+ CallbackEvent left_event_;
33+ CallbackEvent right_event_;
3134
3235 Components components_;
3336
3437
3538 pImpl(const qrk::Rect<long>& rect)
3639 : rect_(rect), acceptable_(false), alpha_(1.0),
37- current_row_(0)
40+ current_row_index_(0)
3841 {
3942 up_event_.key(SDLK_UP, SDL_KEYDOWN, KMOD_NONE);
4043 down_event_.key(SDLK_DOWN, SDL_KEYDOWN, KMOD_NONE);
44+ left_event_.key(SDLK_LEFT, SDL_KEYDOWN, KMOD_NONE);
45+ right_event_.key(SDLK_RIGHT, SDL_KEYDOWN, KMOD_NONE);
4146
4247 layer_manager_.insertEvent(&up_event_);
4348 layer_manager_.insertEvent(&down_event_);
49+ layer_manager_.insertEvent(&left_event_);
50+ layer_manager_.insertEvent(&right_event_);
4451 }
4552
4653
@@ -48,52 +55,63 @@
4855 {
4956 layer_manager_.removeEvent(&up_event_);
5057 layer_manager_.removeEvent(&down_event_);
58+ layer_manager_.removeEvent(&left_event_);
59+ layer_manager_.removeEvent(&right_event_);
5160 }
5261
5362
5463 void draw(const qrk::Rect<long>& area)
5564 {
56- // マウスカーソルの移動があった場合、キー入力によるイベントの
57- // 許可・禁止を無効にする
58- // !!!
59-
60- // キー入力があった場合、マウスのカーソル位置による行の選択を無効にする
61-
62- // 左クリックの処理
63- // !!!
64-
6565 // 上下キーの処理
6666 bool up = up_event_.isActive();
6767 bool down = down_event_.isActive();
68- if (up) {
69- fprintf(stderr, "up\n");
68+ if (up && (current_row_index_ > 0)) {
69+ --current_row_index_;
7070 }
71- if (down) {
72- fprintf(stderr, "down\n");
71+ if (down &&
72+ (current_row_index_ < static_cast<int>(components_.size()) - 1)) {
73+ ++current_row_index_;
7374 }
74- // !!!
75- // current_row_
75+ fprintf(stderr, "current_row_index_: %d\n", current_row_index_);
7676
7777 // 左右キーの処理
78- // !!!
78+ bool left = left_event_.isActive();
79+ bool right = right_event_.isActive();
80+ if (left) {
81+ updateSelectedItem(current_row_index_, -1);
82+ }
83+ if (right) {
84+ updateSelectedItem(current_row_index_, +1);
85+ }
7986
8087 // 各コンポーネントの描画
88+ int index = 0;
8189 for (Components::iterator it = components_.begin();
82- it != components_.end(); ++it) {
83-
84- if (1) {
85- (*it)->setEventAcceptable(false);
86- // !!!
87- }
90+ it != components_.end(); ++it, ++index) {
8891 (*it)->draw(area);
8992 }
9093 }
9194
9295
93- void addComponent(Component* component, const Point<long>& position)
96+ void updateSelectedItem(int index, int xx)
9497 {
95- component->setPosition(position);
96- components_.push_back(component);
98+ Menu* menu = components_[index];
99+ int max_item_index = menu->indexSize();
100+ int next_item_index = static_cast<int>(menu->clickedId()) + xx;
101+ fprintf(stderr, ", %d, ", next_item_index);
102+ if ((next_item_index <= 0) || (next_item_index > max_item_index)) {
103+ return;
104+ }
105+
106+ menu->release();
107+ menu->press(next_item_index);
108+ }
109+
110+ void addSubMenu(qrk::Menu* sub_menu, const Point<long>& position)
111+ {
112+ sub_menu->setPosition(position);
113+ sub_menu->setEventAcceptable(false);
114+ components_.push_back(sub_menu);
97115 }
98116 };
99117
@@ -145,8 +163,7 @@
145163 }
146164
147165
148-void Option::addComponent(Component* component,
149- const qrk::Point<long>& position)
166+void Option::addSubMenu(Menu* sub_menu, const qrk::Point<long>& position)
150167 {
151- pimpl->addComponent(component, position);
168+ pimpl->addSubMenu(sub_menu, position);
152169 }
diff -r cc13241f019a -r 0f165cdec295 Option.h
--- a/Option.h Mon Jul 18 07:08:42 2011 +0900
+++ b/Option.h Tue Jul 19 06:58:24 2011 +0900
@@ -12,6 +12,11 @@
1212 #include "Component.h"
1313 #include <memory>
1414
15+namespace qrk
16+{
17+ class Menu;
18+}
19+
1520
1621 class Option : public qrk::Component
1722 {
@@ -26,7 +31,7 @@
2631 void setRotateAngle(const qrk::Angle& angle);
2732 void draw(const qrk::Rect<long>& area);
2833
29- void addComponent(Component* component, const qrk::Point<long>& position);
34+ void addSubMenu(qrk::Menu* sub_menu, const qrk::Point<long>& position);
3035
3136 private:
3237 Option(const Option& rhs);
diff -r cc13241f019a -r 0f165cdec295 luabindTyping.cpp
--- a/luabindTyping.cpp Mon Jul 18 07:08:42 2011 +0900
+++ b/luabindTyping.cpp Tue Jul 19 06:58:24 2011 +0900
@@ -10,6 +10,7 @@
1010 #include "luabindTyping.h"
1111 #include "hyakutyping.h"
1212 #include "HistoryGraph.h"
13+#include "Menu.h"
1314 #include "Option.h"
1415 #include "Color.h"
1516 #include "Font.h"
@@ -43,6 +44,6 @@
4344 .def("position", &Option::position)
4445 .def("rect", &Option::rect)
4546 .def("setAlpha", &Option::setAlpha)
46- .def("addComponent", &Option::addComponent)
47+ .def("addSubMenu", &Option::addSubMenu)
4748 ];
4849 }
diff -r cc13241f019a -r 0f165cdec295 scripts/first_menu.lua
--- a/scripts/first_menu.lua Mon Jul 18 07:08:42 2011 +0900
+++ b/scripts/first_menu.lua Tue Jul 19 06:58:24 2011 +0900
@@ -126,10 +126,10 @@
126126 end
127127
128128 -- メニューで選択された状態へ遷移させる
129- --if menu_:isClicked() then
130- if true then
131- --selected_index_ = menu_:clickedId()
132- selected_index_ = 3
129+ if menu_:isClicked() then
130+ --if true then
131+ selected_index_ = menu_:clickedId()
132+ --selected_index_ = 3
133133
134134 if selected_index_ == 1 then
135135 require("practice_menu")
diff -r cc13241f019a -r 0f165cdec295 scripts/menu_utils.lua
--- a/scripts/menu_utils.lua Mon Jul 18 07:08:42 2011 +0900
+++ b/scripts/menu_utils.lua Tue Jul 19 06:58:24 2011 +0900
@@ -3,8 +3,8 @@
33 -- $Id: menu_utils.lua,v dfd459a213c3 2010/05/06 16:39:10 Satofumi $
44
55
6-function createMenu(menu, buttons_text, base_rect, font, surfaces, buttons,
7- align)
6+function createMenu(menu, buttons_text, base_rect,
7+ font, surfaces, buttons, align)
88
99 local normal_base_color = Color(1.0, 1.0, 1.0, 0.35)
1010 local normal_base_surface = ColorSurface(base_rect, normal_base_color)
@@ -42,6 +42,7 @@
4242 local button = Button(normal_surface, focused_surface, pressed_surface)
4343 menu:addButton(button, i);
4444
45+ table.insert(surfaces, pressed_surface)
4546 table.insert(surfaces, focused_surface)
4647 table.insert(surfaces, normal_surface)
4748 table.insert(surfaces, text_surface)
diff -r cc13241f019a -r 0f165cdec295 scripts/option_config.lua
--- a/scripts/option_config.lua Mon Jul 18 07:08:42 2011 +0900
+++ b/scripts/option_config.lua Tue Jul 19 06:58:24 2011 +0900
@@ -3,7 +3,6 @@
33 -- Satofumi KAMIMURA
44 -- $Id: option_config.lua,v 4d0ba6dde175 2011/05/15 22:27:49 satofumi $
55
6-
76 require("menu_utils")
87
98
@@ -98,14 +97,13 @@
9897 local option_input_y = 135
9998 option_input_buttons_ = {}
10099 option_input_surfaces_ = {}
101- createMenu(option_input_, buttons_text,
102- base_rect, font_, option_input_surfaces_,
103- option_input_buttons_, "center")
100+ createMenu(option_input_, buttons_text, base_rect, font_,
101+ option_input_surfaces_, option_input_buttons_, "center")
104102
105103 local buttons_step = Point(190, 0)
106104 option_input_:setButtonStep(buttons_step)
107105 option_input_:setEnableClickedAndFocus(true)
108- option_:addComponent(option_input_, Point(option_x, option_input_y))
106+ option_:addSubMenu(option_input_, Point(option_x, option_input_y))
109107
110108
111109 -- フルスクリーン / ウィンドウ
@@ -121,14 +119,13 @@
121119 local option_screen_y = 235
122120 option_screen_buttons_ = {}
123121 option_screen_surfaces_ = {}
124- createMenu(option_screen_, buttons_text,
125- base_rect, font_, option_screen_surfaces_,
126- option_screen_buttons_, "center")
122+ createMenu(option_screen_, buttons_text, base_rect, font_,
123+ option_screen_surfaces_, option_screen_buttons_, "center")
127124
128125 buttons_step = Point(230, 0)
129126 option_screen_:setButtonStep(buttons_step)
130127 option_screen_:setEnableClickedAndFocus(true)
131- option_:addComponent(option_screen_, Point(option_x, option_screen_y))
128+ option_:addSubMenu(option_screen_, Point(option_x, option_screen_y))
132129
133130
134131 -- 曲
@@ -158,14 +155,14 @@
158155 local volume_music_y = music_y
159156 volume_music_buttons_ = {}
160157 volume_music_surfaces_ = {}
161- createMenu(volume_music_, buttons_text,
162- base_rect, font_, volume_music_surfaces_,
163- volume_music_buttons_, "center")
158+ createMenu(volume_music_, buttons_text, base_rect, font_,
159+ volume_music_surfaces_, volume_music_buttons_, "center")
164160
165161 buttons_step = Point(32, 0)
166162 volume_music_:setButtonStep(buttons_step)
167163 volume_music_:setEnableClickedAndFocus(true)
168- option_:addComponent(volume_music_, Point(volume_music_x, volume_music_y))
164+ option_:addSubMenu(volume_music_, Point(volume_music_x, volume_music_y))
165+
169166
170167 -- 効果音の音量
171168 local volume_se_rect = Rect(0, 0, screen_:rect().w, option_font_size)
@@ -174,12 +171,11 @@
174171 local volume_se_y = se_y
175172 volume_se_buttons_ = {}
176173 volume_se_surfaces_ = {}
177- createMenu(volume_se_, buttons_text,
178- base_rect, font_, volume_se_surfaces_,
179- volume_se_buttons_, "center")
174+ createMenu(volume_se_, buttons_text, base_rect, font_,
175+ volume_se_surfaces_, volume_se_buttons_, "center")
180176 volume_se_:setButtonStep(buttons_step)
181177 volume_se_:setEnableClickedAndFocus(true)
182- option_:addComponent(volume_se_, Point(volume_se_x, volume_se_y))
178+ option_:addSubMenu(volume_se_, Point(volume_se_x, volume_se_y))
183179
184180
185181 -- 保存されている設定を読み出して反映させる
旧リポジトリブラウザで表示