aboutsummaryrefslogtreecommitdiff
path: root/src/org/happysanta/gd/Menu/ActionMenuElement.java
blob: fb0b706f0cb3135b2e578745e4f708a98dc0fbdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package org.happysanta.gd.Menu;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import org.happysanta.gd.Menu.Views.MenuImageView;
import org.happysanta.gd.Menu.Views.MenuTextView;
import org.happysanta.gd.R;

import static org.happysanta.gd.Helpers.getDp;
import static org.happysanta.gd.Helpers.getGDActivity;

public class ActionMenuElement
		extends ClickableMenuElement
		implements MenuHandler, MenuElement {

	protected static final int DISABLED_COLOR = 0xff999999;
	public static final int LOCK_IMAGE_MARGIN_RIGHT = 5;
	public static final int locks[] = new int[]{
			R.drawable.s_lock0,
			R.drawable.s_lock1,
			R.drawable.s_lock2
	};

	public static final int LINE_SPACING = 15;
	public static final int X_OFFSET = 48;

	public static final int OK = 0;
	public static final int BACK = 1;
	public static final int EXIT = 2;
	public static final int YES = 3;
	public static final int NO = 4;
	public static final int PLAY_MENU = 5;
	public static final int GO_TO_MAIN = 6;
	public static final int RESTART = 7;
	public static final int NEXT = 8;
	public static final int CONTINUE = 9;
	public static final int INSTALL = 10;
	public static final int LOAD = 11;
	public static final int SELECT_FILE = 12;
	public static final int DELETE = 13;
	public static final int RESTART_WITH_NEW_LEVEL = 14;
	public static final int SEND_LOGS = 15;

	protected MenuHandler handler;
	protected boolean isLocked = false;
	protected boolean isBlackLock = true;
	protected MenuImageView lockImage = null;

	protected int actionValue = -1;

	public ActionMenuElement(String s, int value, MenuHandler handler) {
		actionValue = value;
		this.handler = handler;

		text = s;

		createAllViews();
	}

	@Override
	protected void createAllViews() {
		super.createAllViews();

		Context context = getGDActivity();
		lockImage = new MenuImageView(context);
		lockImage.setScaleType(ImageView.ScaleType.CENTER);
		lockImage.setVisibility(View.GONE);

		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
		lp.setMargins(0, 0, getDp(ActionMenuElement.LOCK_IMAGE_MARGIN_RIGHT), 0);
		lockImage.setLayoutParams(lp);

		layout.addView(lockImage, 1);
	}

	public ActionMenuElement(String s, MenuHandler handler/*, MenuScreen screen*/) {
		this(s, -1, handler);
	}

	public int getActionValue() {
		return actionValue;
	}

	public void setHandler(MenuHandler hander) {
		this.handler = hander;
	}

	public void setLock(boolean flag, boolean flag1) {
		isLocked = flag;
		isBlackLock = flag1;

		lockImage.setVisibility(isLocked ? View.VISIBLE : View.GONE);
		lockImage.setImageResource(locks[isBlackLock ? 0 : 1]);
	}

	@Override
	public void setText(String s) {
		text = s;
		updateViewText();
	}

	@Override
	public void performAction(int k) {
		if (disabled || handler == null) return;

		if (k == MenuScreen.KEY_FIRE) {
			handler.handleAction(this);
		}
	}

	@Override
	protected void onHighlightChanged() {
		lockImage.setImageResource(locks[isHighlighted ? 2 : (isBlackLock ? 0 : 1)]);
	}

	@Override
	public MenuScreen getCurrentMenu() {
		return null;
	}

	@Override
	public void setCurrentMenu(MenuScreen e1, boolean flag) {
	}

	@Override
	public void handleAction(MenuElement item) {
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;

		if (disabled) {
			((MenuTextView) textView).setTextColor(DISABLED_COLOR);
		} else {
			((MenuTextView) textView).setTextColor(defaultColorStateList());
		}
	}

}