home · contact · privacy
TCE: Only create exit between six holes.
[plomrogue] / client / windows.py
1 # This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
2 # or any later version. For details on its copyright, license, and warranties,
3 # see the file NOTICE in the root directory of the PlomRogue source package.
4
5
6 import math
7 import curses
8
9 from client.config.world_data import world_data
10
11
12 def win_map(self):
13     win_size = self.size
14     offset = [0, 0]
15     for i in range(2):
16         if world_data["map_center"][i] * (i + 1) > win_size[i] / 2 and \
17                 win_size[i] < world_data["map_size"] * (i + 1):
18             if world_data["map_center"][i] * (i + 1) \
19                 < world_data["map_size"] * (i + 1) - win_size[i] / 2:
20                 offset[i] = world_data["map_center"][i] * (i + 1) \
21                     - int(win_size[i] / 2)
22                 if i == 1:
23                     offset[1] = offset[1] + world_data["map_center"][0] % 2
24             else:
25                 offset[i] = world_data["map_size"] * (i + 1) - win_size[i] + i
26     winmap_size = [world_data["map_size"], world_data["map_size"] * 2 + 1]
27     winmap = []
28     curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
29     curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
30     for y in range(world_data["map_size"]):
31         for x in range(world_data["map_size"]):
32             char = world_data["fov_map"][y * world_data["map_size"] + x]
33             if world_data["look_mode"] and y == world_data["map_center"][0] \
34                     and x == world_data["map_center"][1]:
35                 if char == " ":
36                     char = \
37                         world_data["mem_map"][y * world_data["map_size"] + x]
38                 winmap += [(char, curses.A_REVERSE), (" ", curses.A_REVERSE)]
39                 continue
40             if char == " ":
41                 char = world_data["mem_map"][y * world_data["map_size"] + x]
42                 attribute = curses.color_pair(1) if char == " " \
43                     else curses.color_pair(2)
44                 winmap += [(char, attribute), (" ", attribute)]
45             else:
46                 winmap += char + " "
47         if y % 2 == 0:
48             winmap += "  "
49     return offset, winmap_size, winmap
50
51
52 def win_inventory(self):
53     win_size = self.size
54     winmap = []
55     winmap_size = [0, win_size[1]]
56     for line in world_data["inventory"]:
57         winmap_size[1] = winmap_size[1] if len(line) <= winmap_size[1] \
58             else len(line)
59     count = 0
60     for line in world_data["inventory"]:
61         padding_size = winmap_size[1] - len(line)
62         line += (" " * padding_size)
63         if count == world_data["inventory_selection"]:
64             line_new = []
65             for x in range(len(line)):
66                 line_new += [(line[x], curses.A_REVERSE)]
67             line = line_new
68         winmap += line
69         winmap_size[0] = winmap_size[0] + 1
70         count += 1
71     offset = [0, 0]
72     if world_data["inventory_selection"] > win_size[0]/2:
73         if world_data["inventory_selection"] < len(world_data["inventory"]) \
74             - win_size[0]/2:
75             offset[0] = world_data["inventory_selection"] - int(win_size[0]/2)
76         else:
77             offset[0] = len(world_data["inventory"]) - win_size[0]
78     return offset, winmap_size, winmap
79
80
81 def win_look(self):
82     winmap = ""
83     winmap_size = [0, 0]
84     for line in world_data["look"]:
85         winmap_size[1] = winmap_size[1] if len(line) <= winmap_size[1] \
86             else len(line)
87     for line in world_data["look"]:
88         padding_size = winmap_size[1] - len(line)
89         winmap += line + (" " * padding_size)
90         winmap_size[0] = winmap_size[0] + 1
91     offset = [world_data["look_scroll"], 0]
92     return offset, winmap_size, winmap
93
94
95 def win_info(self):
96     winmap = "T: " + str(world_data["turn"]) \
97         + " H: " + str(world_data["lifepoints"]) \
98         + " S: " + str(world_data["satiation"])
99     winmap_size = [1, len(winmap)]
100     offset = [0, 0]
101     return offset, winmap_size, winmap
102
103
104 def win_log(self):
105     win_size = self.size
106     offset = [0, 0]
107     winmap = ""
108     number_of_lines = 0
109     for line in world_data["log"]:
110         number_of_lines += math.ceil(len(line) / win_size[1])
111         mod = len(line) % win_size[1]
112         padding_size = 0 if mod == 0 else win_size[1] - mod
113         winmap += line + (padding_size * " ")
114     if number_of_lines < win_size[0]:
115         winmap = (" " * win_size[1] * (win_size[0] - number_of_lines)) + winmap
116         number_of_lines = win_size[0]
117     elif number_of_lines > win_size[0]:
118         offset[0] = number_of_lines - win_size[0]
119     winmap_size = [number_of_lines, win_size[1]]
120     return offset, winmap_size, winmap