1 | #region MIT License |
---|
2 | /* |
---|
3 | * Copyright (c) 2010 Tero Jäntti. |
---|
4 | * |
---|
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
6 | * of this software and associated documentation files (the "Software"), to deal |
---|
7 | * in the Software without restriction, including without limitation the rights |
---|
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
9 | * copies of the Software, and to permit persons to whom the Software is |
---|
10 | * furnished to do so, subject to the following conditions: |
---|
11 | * |
---|
12 | * The above copyright notice and this permission notice shall be included in |
---|
13 | * all copies or substantial portions of the Software. |
---|
14 | * |
---|
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
21 | * THE SOFTWARE. |
---|
22 | */ |
---|
23 | #endregion |
---|
24 | |
---|
25 | using System; |
---|
26 | using System.Collections.Generic; |
---|
27 | using Jypeli; |
---|
28 | using Jypeli.Widgets; |
---|
29 | |
---|
30 | |
---|
31 | class EsineValikko : Widget |
---|
32 | { |
---|
33 | class Valinta : Widget |
---|
34 | { |
---|
35 | public Esine Esine; |
---|
36 | |
---|
37 | public Valinta( double width, double height, Esine e ) |
---|
38 | : base( width, height ) |
---|
39 | { |
---|
40 | this.Esine = e; |
---|
41 | Image = e.Image; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | double esineenLeveys; |
---|
47 | Widget vaakaValikko; |
---|
48 | Widget valintaNuoli; |
---|
49 | List<Valinta> esineet = new List<Valinta>(); |
---|
50 | int valittuIndeksi = 0; |
---|
51 | |
---|
52 | public Esine ValittuEsine |
---|
53 | { |
---|
54 | get |
---|
55 | { |
---|
56 | if ( esineet.Count == 0 ) |
---|
57 | return null; |
---|
58 | return esineet[valittuIndeksi].Esine; |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | public EsineValikko( double leveys, double korkeus ) |
---|
64 | : base( leveys, korkeus ) |
---|
65 | { |
---|
66 | IsVisible = false; |
---|
67 | Color = Color.TransparentBlack; |
---|
68 | esineenLeveys = korkeus / 2; |
---|
69 | |
---|
70 | vaakaValikko = new Widget( new HorizontalLayout() ); |
---|
71 | vaakaValikko.Height = korkeus / 2; |
---|
72 | vaakaValikko.X = 0; |
---|
73 | vaakaValikko.Y = -korkeus / 4; |
---|
74 | vaakaValikko.Color = new Color( 150, 100, 10, 100 ); |
---|
75 | Add( vaakaValikko ); |
---|
76 | |
---|
77 | valintaNuoli = new Widget( esineenLeveys * 0.9, korkeus * 0.4, Shapes.Triangle ); |
---|
78 | valintaNuoli.Color = Color.Red; |
---|
79 | valintaNuoli.Angle = Angle.Degrees( 180 ); |
---|
80 | valintaNuoli.X = 0; |
---|
81 | valintaNuoli.Y = korkeus / 4; |
---|
82 | Add( valintaNuoli ); |
---|
83 | } |
---|
84 | |
---|
85 | public void Vasemmalle() |
---|
86 | { |
---|
87 | if ( esineet.Count == 0 ) |
---|
88 | return; |
---|
89 | |
---|
90 | if ( valittuIndeksi > 0 ) |
---|
91 | valittuIndeksi--; |
---|
92 | else |
---|
93 | valittuIndeksi = esineet.Count - 1; |
---|
94 | |
---|
95 | PaivitaNuoli(); |
---|
96 | } |
---|
97 | |
---|
98 | public void Oikealle() |
---|
99 | { |
---|
100 | if ( esineet.Count == 0 ) |
---|
101 | return; |
---|
102 | |
---|
103 | if ( valittuIndeksi < ( esineet.Count - 1 ) ) |
---|
104 | valittuIndeksi++; |
---|
105 | else |
---|
106 | valittuIndeksi = 0; |
---|
107 | |
---|
108 | PaivitaNuoli(); |
---|
109 | } |
---|
110 | |
---|
111 | void PaivitaNuoli() |
---|
112 | { |
---|
113 | valintaNuoli.X = Left + ( valittuIndeksi * esineenLeveys ) + esineenLeveys / 2; |
---|
114 | } |
---|
115 | |
---|
116 | public void Add( Esine e ) |
---|
117 | { |
---|
118 | Valinta v = new Valinta( esineenLeveys, Height, e ); |
---|
119 | vaakaValikko.Add( v ); |
---|
120 | esineet.Add( v ); |
---|
121 | double uusiLeveys = esineet.Count * esineenLeveys; |
---|
122 | this.Width = uusiLeveys; |
---|
123 | vaakaValikko.Width = uusiLeveys; |
---|
124 | IsVisible = true; |
---|
125 | |
---|
126 | if ( esineet.Count == 1 ) |
---|
127 | valittuIndeksi = 0; |
---|
128 | PaivitaNuoli(); |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | class EsineRuutu : Widget |
---|
134 | { |
---|
135 | Label teksti; |
---|
136 | Timer piilotusAjastin; |
---|
137 | |
---|
138 | public EsineRuutu( Peli peli, double leveys, double korkeus ) |
---|
139 | : base( leveys, korkeus ) |
---|
140 | { |
---|
141 | Color = Color.TransparentBlack; |
---|
142 | Layout = new VerticalLayout(); |
---|
143 | IsVisible = false; |
---|
144 | |
---|
145 | teksti = new Label(); |
---|
146 | teksti.TextColor = Color.GreenYellow; |
---|
147 | Add( teksti ); |
---|
148 | |
---|
149 | Label apuTeksti = new Label( "Kerää painamalla P" ); |
---|
150 | apuTeksti.TextColor = Color.DarkGreen; |
---|
151 | Add( apuTeksti ); |
---|
152 | |
---|
153 | piilotusAjastin = new Timer(); |
---|
154 | piilotusAjastin = new Timer(); |
---|
155 | piilotusAjastin.Interval = 3; |
---|
156 | piilotusAjastin.Trigger += delegate( Timer t ) { Hide(); }; |
---|
157 | peli.Add( piilotusAjastin ); |
---|
158 | } |
---|
159 | |
---|
160 | public void Nayta( Esine e ) |
---|
161 | { |
---|
162 | teksti.Text = e.Tyyppi.ToString(); |
---|
163 | Show(); |
---|
164 | piilotusAjastin.Start( 1 ); |
---|
165 | } |
---|
166 | } |
---|