/**
 * Copyright (C) 2012 MK124
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.gtaun.shoebill.common.dialog;

import java.util.ArrayList;
import java.util.List;

import net.gtaun.shoebill.Shoebill;
import net.gtaun.shoebill.constant.DialogStyle;
import net.gtaun.shoebill.event.dialog.DialogResponseEvent;
import net.gtaun.shoebill.object.Player;
import net.gtaun.util.event.EventManager;

/**
 * 抽象列表对话框类。
 * 
 * @author MK124
 */
public abstract class AbstractListDialog extends AbstractDialog
{
	public static abstract class DialogListItem
	{
		private final String string;
		
		public DialogListItem()
		{
			this("-");
		}
		
		public DialogListItem(String string)
		{
			this.string = string;
		}
		
		public String toItemString()
		{
			return string;
		}
		
		public abstract void onItemSelect();
	}
	

	protected final List<DialogListItem> dialogListItems;
	protected final List<DialogListItem> displayedItems;
	
	
	protected AbstractListDialog(Player player, Shoebill shoebill, EventManager eventManager)
	{
		super(DialogStyle.LIST, player, shoebill, eventManager);
		dialogListItems = new ArrayList<>();
		displayedItems = new ArrayList<>();
	}
	
	@Override
	public void show()
	{
		String listStr = "";
		displayedItems.clear();
		
		for (DialogListItem item : dialogListItems)
		{
			listStr += item.toItemString() + "\n";
			displayedItems.add(item);
		}
		
		show(listStr);
	}
	
	@Override
	protected void onDialogResponse(DialogResponseEvent event)
	{
		if (event.getDialogResponse() == 1)
		{
			int itemId = event.getListitem();
			DialogListItem item = displayedItems.get(itemId);
			
			item.onItemSelect();
		}
		else
		{
			destroy();
		}
	}
}

@@ -1279,32 +1279,1115 @@
  string;%0A%09%09%7D%0A%09%09%0A
+%09%09public boolean isEnabled()%0A%09%09%7B%0A%09%09%09return true;%0A%09%09%7D%0A%09%09%0A%09%09public abstract void onItemSelect();%0A%09%7D%0A%09%0A%09public static abstract class DialogListItemSwitch extends DialogListItem%0A%09%7B%0A%09%09private final String string;%0A%09%09private final String onMessage;%0A%09%09private final String offMessage;%0A%09%09%0A%09%09private boolean switched;%0A%0A%09%09public DialogListItemSwitch(String string, boolean switched, String onMessage, String offMessage)%0A%09%09%7B%0A%09%09%09this.string = string;%0A%09%09%09this.switched = switched;%0A%09%09%09this.onMessage = onMessage;%0A%09%09%09this.offMessage = offMessage;%0A%09%09%7D%0A%09%09%0A%09%09public DialogListItemSwitch(String string, boolean switched)%0A%09%09%7B%0A%09%09%09this.string = string;%0A%09%09%09this.switched = switched;%0A%09%09%09this.onMessage = %22ON%22;%0A%09%09%09this.offMessage = %22OFF%22;%0A%09%09%7D%0A%09%09%0A%09%09public DialogListItemSwitch(String string)%0A%09%09%7B%0A%09%09%09this.string = string;%0A%09%09%09this.onMessage = %22ON%22;%0A%09%09%09this.offMessage = %22OFF%22;%0A%09%09%7D%0A%09%09%0A%09%09public String toItemString()%0A%09%09%7B%0A%09%09%09return string + %22 %5B%22 + (switched ? onMessage : offMessage) + %22%5D%22;%0A%09%09%7D%0A%09%09%0A%09%09public boolean isEnabled()%0A%09%09%7B%0A%09%09%09return true;%0A%09%09%7D%0A%09%09%0A%09%09public boolean isSwitched()%0A%09%09%7B%0A%09%09%09return switched;%0A%09%09%7D%0A%09%09%0A
 %09%09public abstrac

添加数项新功能。